Search in sources :

Example 26 with LocalPreferences

use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.

the class ConferenceRoomBrowser method createRoom.

/**
 * Create a new room based on room table selection.
 */
private void createRoom() {
    RoomCreationDialog mucRoomDialog = new RoomCreationDialog();
    final MultiUserChat groupChat = mucRoomDialog.createGroupChat(SparkManager.getMainWindow(), serviceName);
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (null != groupChat) {
        // Join Room
        try {
            GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(groupChat);
            groupChat.create(pref.getNickname());
            chatManager.getChatContainer().addChatRoom(room);
            chatManager.getChatContainer().activateChatRoom(room);
            // Send Form
            Form form = groupChat.getConfigurationForm().createAnswerForm();
            if (mucRoomDialog.isPasswordProtected()) {
                String password = mucRoomDialog.getPassword();
                room.setPassword(password);
                form.setAnswer("muc#roomconfig_passwordprotectedroom", true);
                form.setAnswer("muc#roomconfig_roomsecret", password);
            }
            form.setAnswer("muc#roomconfig_roomname", mucRoomDialog.getRoomName());
            form.setAnswer("muc#roomconfig_roomdesc", mucRoomDialog.getRoomTopic());
            if (mucRoomDialog.isPermanent()) {
                form.setAnswer("muc#roomconfig_persistentroom", true);
            }
            List<String> owners = new ArrayList<>();
            owners.add(SparkManager.getSessionManager().getBareAddress());
            form.setAnswer("muc#roomconfig_roomowners", owners);
            // new DataFormDialog(groupChat, form);
            groupChat.sendConfigurationForm(form);
            addRoomToTable(groupChat.getRoom(), XmppStringUtils.parseLocalpart(groupChat.getRoom()), 1);
        } catch (XMPPException | SmackException e1) {
            Log.error("Error creating new room.", e1);
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            JOptionPane.showMessageDialog(this, Res.getString("message.room.creation.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

Example 27 with LocalPreferences

use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.

the class ConferenceUtils method inviteUsersToRoom.

/**
 * Invites users to an existing room.
 *
 * @param serviceName the service name to use.
 * @param roomName    the name of the room.
 * @param jids        a collection of the users to invite.
 */
public static void inviteUsersToRoom(String serviceName, String roomName, Collection<String> jids, boolean randomName) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    boolean useTextField = pref.isUseAdHocRoom();
    Collection<BookmarkedConference> rooms = null;
    if (!useTextField) {
        try {
            rooms = retrieveBookmarkedConferences();
        } catch (Exception ex) {
            Log.error(ex);
        }
        useTextField = !randomName || (rooms == null || rooms.size() == 0);
    }
    InvitationDialog inviteDialog = new InvitationDialog(useTextField);
    inviteDialog.inviteUsersToRoom(serviceName, rooms, roomName, jids);
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) SmackException(org.jivesoftware.smack.SmackException) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 28 with LocalPreferences

use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.

the class GatewayPlugin method initialize.

public void initialize() {
    ProviderManager.addIQProvider(Gateway.ELEMENT_NAME, Gateway.NAMESPACE, new Gateway.Provider());
    LocalPreferences localPref = SettingsManager.getLocalPreferences();
    useTab = localPref.getShowTransportTab();
    transferTab.setBackground((Color) UIManager.get("ContactItem.background"));
    SwingWorker thread = new SwingWorker() {

        public Object construct() {
            try {
                // Let's try and avoid any timing issues with the gateway presence.
                Thread.sleep(5000);
                populateTransports();
            } catch (Exception e) {
                Log.error(e);
                return false;
            }
            return true;
        }

        public void finished() {
            transferTab.setLayout(new VerticalFlowLayout(0, 0, 0, true, false));
            Boolean transportExists = (Boolean) get();
            if (!transportExists) {
                return;
            }
            if (TransportUtils.getTransports().size() > 0 && useTab) {
                SparkManager.getWorkspace().getWorkspacePane().addTab(Res.getString("title.transports"), SparkRes.getImageIcon(SparkRes.TRANSPORT_ICON), transferTab);
            }
            for (final Transport transport : TransportUtils.getTransports()) {
                addTransport(transport);
            }
            // Register presences.
            registerPresenceListener();
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SmackException(org.jivesoftware.smack.SmackException) VerticalFlowLayout(org.jivesoftware.spark.component.VerticalFlowLayout)

Example 29 with LocalPreferences

use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.

the class ContactListAssistantPlugin method initialize.

@Override
public void initialize() {
    moveToMenu = new JMenu(Res.getString("menuitem.move.to"));
    copyToMenu = new JMenu(Res.getString("menuitem.copy.to"));
    localPreferences = new LocalPreferences();
    final ContactList contactList = SparkManager.getContactList();
    contactList.addContextMenuListener(new ContextMenuListener() {

        @Override
        public void poppingUp(Object object, final JPopupMenu popup) {
            final Collection<ContactItem> contactItems = Collections.unmodifiableCollection(contactList.getSelectedUsers());
            if (!contactItems.isEmpty()) {
                final List<ContactGroup> contactGroups = contactList.getContactGroups();
                Collections.sort(contactGroups, ContactList.GROUP_COMPARATOR);
                for (final ContactGroup group : contactGroups) {
                    if (group.isUnfiledGroup() || group.isOfflineGroup()) {
                        continue;
                    }
                    if (isContactItemInGroup(contactItems, group)) {
                        continue;
                    }
                    final Action moveAction = new AbstractAction() {

                        private static final long serialVersionUID = 6542011870221162331L;

                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            moveItems(contactItems, group.getGroupName());
                        }
                    };
                    final Action copyAction = new AbstractAction() {

                        private static final long serialVersionUID = 2232885525630977329L;

                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            copyItems(contactItems, group.getGroupName());
                        }
                    };
                    moveAction.putValue(Action.NAME, group.getGroupName());
                    moveToMenu.add(moveAction);
                    copyAction.putValue(Action.NAME, group.getGroupName());
                    copyToMenu.add(copyAction);
                }
                popup.addPopupMenuListener(new PopupMenuListener() {

                    @Override
                    public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) {
                    }

                    @Override
                    public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) {
                        moveToMenu.removeAll();
                        copyToMenu.removeAll();
                        popup.removePopupMenuListener(this);
                    }

                    @Override
                    public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) {
                        moveToMenu.removeAll();
                        copyToMenu.removeAll();
                        popup.removePopupMenuListener(this);
                    }
                });
                int index = -1;
                if (!Default.getBoolean("DISABLE_RENAMES") && Enterprise.containsFeature(Enterprise.RENAMES_FEATURE)) {
                    for (int i = 0; i < popup.getComponentCount(); i++) {
                        Object o = popup.getComponent(i);
                        if (o instanceof JMenuItem && ((JMenuItem) o).getText().equals(Res.getString("menuitem.rename"))) {
                            index = i;
                            break;
                        }
                    }
                } else
                    index = 3;
                if (contactItems.size() == 1) {
                    // Add MOVE/COPY options right after the RENAME option or in it's place if it doesn't exist.
                    if (index != -1) {
                        // See if we should disable the "Move to" and "Copy to" menu options
                        if (!Default.getBoolean("DISABLE_MOVE_AND_COPY") && Enterprise.containsFeature(Enterprise.MOVE_COPY_FEATURE)) {
                            popup.add(moveToMenu, index + 1);
                            popup.add(copyToMenu, index + 2);
                        }
                    }
                } else if (contactItems.size() > 1) {
                    // See if we should disable the "Move to" and "Copy to" menu options
                    if (!Default.getBoolean("DISABLE_MOVE_AND_COPY") && Enterprise.containsFeature(Enterprise.MOVE_COPY_FEATURE)) {
                        popup.addSeparator();
                        popup.add(moveToMenu);
                        popup.add(copyToMenu);
                    }
                    // Clean up the extra separator if "Broadcast" menu items are disabled
                    if (!Default.getBoolean("DISABLE_BROADCAST_MENU_ITEM") && Enterprise.containsFeature(Enterprise.BROADCAST_FEATURE))
                        popup.addSeparator();
                }
            }
        }

        @Override
        public void poppingDown(JPopupMenu popup) {
        }

        @Override
        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
    updateAvatarsInContactList();
    SettingsManager.addPreferenceListener(preference -> updateAvatarsInContactList());
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) ContactList(org.jivesoftware.spark.ui.ContactList) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu) Collection(java.util.Collection) List(java.util.List) ContactList(org.jivesoftware.spark.ui.ContactList) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ContactGroup(org.jivesoftware.spark.ui.ContactGroup) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 30 with LocalPreferences

use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.

the class EmoticonManager method setActivePack.

/**
 * Sets the active emoticon set.
 *
 * @param pack
 *            the archive containing the emotiocon pack.
 */
public void setActivePack(String pack) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    pref.setEmoticonPack(pack);
    SettingsManager.saveSettings();
    imageMap.clear();
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Aggregations

LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)48 SmackException (org.jivesoftware.smack.SmackException)9 XMPPException (org.jivesoftware.smack.XMPPException)8 SwingWorker (org.jivesoftware.spark.util.SwingWorker)8 File (java.io.File)7 Message (org.jivesoftware.smack.packet.Message)5 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)5 Form (org.jivesoftware.smackx.xdata.Form)5 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)5 ActionEvent (java.awt.event.ActionEvent)4 ArrayList (java.util.ArrayList)4 AbstractAction (javax.swing.AbstractAction)4 Action (javax.swing.Action)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Date (java.util.Date)3 JPopupMenu (javax.swing.JPopupMenu)3 ChatManager (org.jivesoftware.spark.ChatManager)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2