Search in sources :

Example 31 with LocalPreferences

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

the class Downloads method getFileChooser.

/**
 * Returns a {@link JFileChooser} starting at the DownloadDirectory
 *
 * @return the filechooser
 */
public static JFileChooser getFileChooser() {
    if (chooser == null) {
        LocalPreferences _localPreferences = SettingsManager.getLocalPreferences();
        downloadedDir = new File(_localPreferences.getDownloadDir());
        chooser = new JFileChooser(downloadedDir);
        if (Spark.isWindows()) {
            chooser.setFileSystemView(new WindowsFileSystemView());
        }
    }
    return chooser;
}
Also used : JFileChooser(javax.swing.JFileChooser) WindowsFileSystemView(org.jivesoftware.spark.util.WindowsFileSystemView) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) File(java.io.File)

Example 32 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();
                contactGroups.sort(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(Default.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(Default.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(Default.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(Default.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 33 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)

Example 34 with LocalPreferences

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

the class GatewayPlugin method initialize.

@Override
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() {

        @Override
        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;
        }

        @Override
        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 35 with LocalPreferences

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

the class CheckUpdates method checkForUpdate.

/**
 * Checks Spark Manager and/or Jive Software for the latest version of Spark.
 *
 * @param explicit true if the user explicitly asks for the latest version.
 */
public void checkForUpdate(boolean explicit) {
    if (UPDATING) {
        return;
    }
    UPDATING = true;
    if (isLocalBuildAvailable()) {
        return;
    }
    LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
    // defaults to 7, 0=disabled
    int CheckForUpdates = localPreferences.getCheckForUpdates();
    if (CheckForUpdates == 0) {
        return;
    }
    Date lastChecked = localPreferences.getLastCheckForUpdates();
    if (lastChecked == null) {
        lastChecked = new Date();
        // This is the first invocation of Communicator
        localPreferences.setLastCheckForUpdates(lastChecked);
        SettingsManager.saveSettings();
    }
    // Check to see if it has been a CheckForUpdates (default 7) days
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(lastChecked);
    calendar.add(Calendar.DATE, CheckForUpdates);
    final Date lastCheckedPlusAPeriod = calendar.getTime();
    boolean periodOrLonger = new Date().getTime() >= lastCheckedPlusAPeriod.getTime();
    if (periodOrLonger || explicit || sparkPluginInstalled) {
        if (!explicit && !localPreferences.isBetaCheckingEnabled()) {
            return;
        }
        // Check version on server.
        lastChecked = new Date();
        localPreferences.setLastCheckForUpdates(lastChecked);
        SettingsManager.saveSettings();
        final SparkVersion serverVersion = newBuildAvailable();
        if (serverVersion == null) {
            UPDATING = false;
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            if (explicit) {
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.no.updates"), Res.getString("title.no.updates"), JOptionPane.INFORMATION_MESSAGE);
            }
            return;
        }
        // Otherwise updates are available
        String downloadURL = serverVersion.getDownloadURL();
        String filename = downloadURL.substring(downloadURL.lastIndexOf("/") + 1);
        if (filename.indexOf('=') != -1) {
            filename = filename.substring(filename.indexOf('=') + 1);
        }
        // Set Download Directory
        final File downloadDir = new File(Spark.getSparkUserHome(), "updates");
        downloadDir.mkdirs();
        // Set file to download.
        final File fileToDownload = new File(downloadDir, filename);
        if (fileToDownload.exists()) {
            fileToDownload.delete();
        }
        ConfirmDialog confirm = new ConfirmDialog();
        confirm.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("title.new.version.available"), Res.getString("message.new.spark.available", filename), Res.getString("yes"), Res.getString("no"), null);
        confirm.setDialogSize(400, 300);
        confirm.setConfirmListener(new ConfirmListener() {

            @Override
            public void yesOption() {
                SwingWorker worker = new SwingWorker() {

                    @Override
                    public Object construct() {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            Log.error(e);
                        }
                        return "ok";
                    }

                    @Override
                    public void finished() {
                        if (Spark.isWindows()) {
                            downloadUpdate(fileToDownload, serverVersion);
                        } else {
                            // Launch browser to download page.
                            try {
                                if (sparkPluginInstalled) {
                                    BrowserLauncher.openURL(serverVersion.getDownloadURL());
                                } else {
                                    BrowserLauncher.openURL("http://www.igniterealtime.org/downloads/index.jsp#spark");
                                }
                            } catch (Exception e) {
                                Log.error(e);
                            }
                            UPDATING = false;
                        }
                    }
                };
                worker.start();
            }

            @Override
            public void noOption() {
                UPDATING = false;
            }
        });
    } else {
        UPDATING = false;
    }
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) IOException(java.io.IOException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ConfirmListener(org.jivesoftware.spark.component.ConfirmDialog.ConfirmListener) File(java.io.File) ConfirmDialog(org.jivesoftware.spark.component.ConfirmDialog)

Aggregations

LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)55 SmackException (org.jivesoftware.smack.SmackException)12 XMPPException (org.jivesoftware.smack.XMPPException)11 SwingWorker (org.jivesoftware.spark.util.SwingWorker)9 EntityBareJid (org.jxmpp.jid.EntityBareJid)9 File (java.io.File)8 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)8 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)7 Message (org.jivesoftware.smack.packet.Message)6 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 ActionEvent (java.awt.event.ActionEvent)5 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 ChatManager (org.jivesoftware.spark.ChatManager)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 Insets (java.awt.Insets)3 IOException (java.io.IOException)3 KeyManagementException (java.security.KeyManagementException)3 AbstractAction (javax.swing.AbstractAction)3