Search in sources :

Example 36 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) Workspace(org.jivesoftware.spark.Workspace)

Example 37 with LocalPreferences

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

the class Spark method loadLanguage.

/**
 * Loads the language set by the user. If no language is set, then the default implementation will be used.
 */
private void loadLanguage() {
    final LocalPreferences preferences = SettingsManager.getLocalPreferences();
    final String setLanguage = preferences.getLanguage();
    if (ModelUtil.hasLength(setLanguage)) {
        Locale[] locales = Locale.getAvailableLocales();
        for (Locale locale : locales) {
            if (locale.toString().equals(setLanguage)) {
                Locale.setDefault(locale);
                break;
            }
        }
    }
}
Also used : Locale(java.util.Locale) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 38 with LocalPreferences

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

the class AccountCreationWizard method getConnection.

/**
 * Creates an XMPPConnection based on the users settings.
 *
 * @return the XMPPConnection created.
 */
private XMPPConnection getConnection() throws SmackException, IOException, XMPPException {
    final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
    int port = localPreferences.getXmppPort();
    String serverName = getServer();
    int checkForPort = serverName.indexOf(":");
    if (checkForPort != -1) {
        String portString = serverName.substring(checkForPort + 1);
        if (ModelUtil.hasLength(portString)) {
            // Set new port.
            port = Integer.parseInt(portString);
        }
    }
    ConnectionConfiguration.SecurityMode securityMode = localPreferences.getSecurityMode();
    boolean useOldSSL = localPreferences.isSSL();
    boolean hostPortConfigured = localPreferences.isHostAndPortConfigured();
    final XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword("username", "password").setXmppDomain(serverName).setPort(port).setCompressionEnabled(localPreferences.isCompressionEnabled()).setSecurityMode(securityMode);
    if (hostPortConfigured) {
        builder.setHost(localPreferences.getXmppHost());
    }
    if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
        // plain connections which is 5222.
        try {
            SSLContext context = SparkSSLContextCreator.setUpContext(SparkSSLContextCreator.Options.ONLY_SERVER_SIDE);
            builder.setSslContextFactory(() -> {
                return context;
            });
            builder.setSecurityMode(securityMode);
        } catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException | NoSuchProviderException e) {
            Log.warning("Couldnt establish secured connection", e);
        }
    }
    if (securityMode != ConnectionConfiguration.SecurityMode.disabled && useOldSSL) {
        if (!hostPortConfigured) {
            // SMACK 4.1.9 does not support XEP-0368, and does not apply a port change, if the host is not changed too.
            // Here, we force the host to be set (by doing a DNS lookup), and force the port to 5223 (which is the
            // default 'old-style' SSL port).
            DnsName serverNameDnsName = DnsName.from(serverName);
            java.util.List<InetAddress> resolvedAddresses = DNSUtil.getDNSResolver().lookupHostAddress(serverNameDnsName, null, DnssecMode.disabled);
            if (resolvedAddresses.isEmpty()) {
                throw new SmackException.SmackMessageException("Could not resolve " + serverNameDnsName);
            }
            builder.setHost(resolvedAddresses.get(0).getHostName());
            builder.setPort(5223);
        }
        builder.setSocketFactory(new SparkSSLSocketFactory(SparkSSLContextCreator.Options.ONLY_SERVER_SIDE));
        // SMACK 4.1.9  does not recognize an 'old-style' SSL socket as being secure, which will cause a failure when
        // the 'required' Security Mode is defined. Here, we work around this by replacing that security mode with an
        // 'if-possible' setting.
        builder.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
    }
    final XMPPTCPConnectionConfiguration configuration = builder.build();
    final AbstractXMPPConnection connection = new XMPPTCPConnection(configuration);
    connection.setParsingExceptionCallback(new ExceptionLoggingCallback());
    try {
        connection.connect();
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
    return connection;
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SparkSSLSocketFactory(org.jivesoftware.sparkimpl.certificates.SparkSSLSocketFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) DnsName(org.minidns.dnsname.DnsName) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) ExceptionLoggingCallback(org.jivesoftware.smack.parsing.ExceptionLoggingCallback) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) NoSuchProviderException(java.security.NoSuchProviderException) InetAddress(java.net.InetAddress)

Example 39 with LocalPreferences

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

the class LoginDialog method startSpark.

/**
 * Initializes Spark and initializes all plugins.
 */
private void startSpark() {
    // Invoke the MainWindow.
    try {
        EventQueue.invokeLater(() -> {
            final MainWindow mainWindow = MainWindow.getInstance();
            /*
             if (tray != null) {
                 // Remove trayIcon
                 tray.removeTrayIcon(trayIcon);
             }
             */
            // Creates the Spark  Workspace and add to MainWindow
            Workspace workspace = Workspace.getInstance();
            LayoutSettings settings = LayoutSettingsManager.getLayoutSettings();
            LocalPreferences pref = SettingsManager.getLocalPreferences();
            if (pref.isDockingEnabled()) {
                JSplitPane splitPane = mainWindow.getSplitPane();
                workspace.getCardPanel().setMinimumSize(null);
                splitPane.setLeftComponent(workspace.getCardPanel());
                SparkManager.getChatManager().getChatContainer().setMinimumSize(null);
                splitPane.setRightComponent(SparkManager.getChatManager().getChatContainer());
                int dividerLoc = settings.getSplitPaneDividerLocation();
                if (dividerLoc != -1) {
                    mainWindow.getSplitPane().setDividerLocation(dividerLoc);
                } else {
                    mainWindow.getSplitPane().setDividerLocation(240);
                }
                mainWindow.getContentPane().add(splitPane, BorderLayout.CENTER);
            } else {
                mainWindow.getContentPane().add(workspace.getCardPanel(), BorderLayout.CENTER);
            }
            final Rectangle mainWindowBounds = settings.getMainWindowBounds();
            if (mainWindowBounds == null || mainWindowBounds.width <= 0 || mainWindowBounds.height <= 0) {
                // Use Default size
                mainWindow.setSize(310, 520);
                // Center Window on Screen
                GraphicUtils.centerWindowOnScreen(mainWindow);
            } else {
                mainWindow.setBounds(mainWindowBounds);
            }
            if (loginDialog.isVisible()) {
                mainWindow.setVisible(true);
            }
            loginDialog.setVisible(false);
            // Build the layout in the workspace
            workspace.buildLayout();
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : LayoutSettings(org.jivesoftware.sparkimpl.plugin.layout.LayoutSettings) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) LoginException(javax.security.auth.login.LoginException) NamingException(javax.naming.NamingException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DocumentException(org.dom4j.DocumentException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoSuchProviderException(java.security.NoSuchProviderException) Workspace(org.jivesoftware.spark.Workspace)

Example 40 with LocalPreferences

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

the class SipCodecsPreference method load.

@Override
public void load() {
    SwingWorker thread = new SwingWorker() {

        LocalPreferences localPreferences;

        public Object construct() {
            localPreferences = SettingsManager.getLocalPreferences();
            return localPreferences;
        }

        public void finished() {
            String sel = localPreferences.getSelectedCodecs();
            String avail = localPreferences.getAvailableCodecs();
            panel.setAvailable(avail);
            panel.setSelected(sel);
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

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