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