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