Search in sources :

Example 46 with LocalPreferences

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

the class NotificationsPreference method commit.

public void commit() {
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    pref.setShowToasterPopup(panel.showToaster());
    pref.setDisableAsteriskToasterPopup(panel.disableAsteriskToaster());
    pref.setWindowTakesFocus(panel.shouldWindowPopup());
    pref.setNotificationsDisplayTime(panel.getNotificationsDisplayTime());
    pref.setOfflineNotifications(panel.isOfflineNotificationOn());
    pref.setOnlineNotifications(panel.isOnlineNotificationOn());
    pref.setCheckForBeta(panel.isBetaCheckingEnabled());
    pref.setTypingNotificationOn(panel.isTypingNotification());
    pref.setSystemTrayNotificationEnabled(panel.isSystemTrayNotificationEnabled());
    SettingsManager.saveSettings();
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 47 with LocalPreferences

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

the class ApplePlugin method sparkIsIdle.

private void sparkIsIdle() {
    LocalPreferences localPref = SettingsManager.getLocalPreferences();
    if (!localPref.isIdleOn()) {
        return;
    }
    try {
        // Handle if spark is not connected to the server.
        if (SparkManager.getConnection() == null || !SparkManager.getConnection().isConnected()) {
            return;
        }
        // Change Status
        Workspace workspace = SparkManager.getWorkspace();
        if (workspace != null) {
            Presence presence = workspace.getStatusBar().getPresence();
            long diff = System.currentTimeMillis() - lastActive;
            boolean idle = diff > 60000 * 60;
            if (presence.getMode() == Presence.Mode.available && idle) {
                unavailable = true;
                StatusItem away = workspace.getStatusBar().getStatusItem("Away");
                Presence p = away.getPresence();
                p.setStatus(Res.getString("message.away.idle"));
                previousPriority = presence.getPriority();
                p.setPriority(0);
                SparkManager.getSessionManager().changePresence(p);
            }
        }
    } catch (Exception e) {
        Log.error("Error with IDLE status.", e);
    }
}
Also used : StatusItem(org.jivesoftware.spark.ui.status.StatusItem) Presence(org.jivesoftware.smack.packet.Presence) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) IOException(java.io.IOException) Workspace(org.jivesoftware.spark.Workspace)

Example 48 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.
 * @throws Exception if there is an error during check
 */
public void checkForUpdate(boolean explicit) throws Exception {
    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() {

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

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

                    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();
            }

            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)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