use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class SipCodecsPreference method commit.
@Override
public void commit() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
pref.setSelectedCodecs(panel.getSelected());
pref.setAvailableCodecs(panel.getAvailable());
SettingsManager.saveSettings();
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ChatContainer method groupChatMessageCheck.
/**
* Performs several group chat checks
*
* chatRoom the chat room that needs to be passed customMsg whether or not
* this is a custom message customMsgText if any custom message should
* appear in the popup customMsgTitle whether or not the toaster should have
* any popup
*/
private void groupChatMessageCheck(ChatRoom chatRoom, boolean customMsg, String customMsgText, String customMsgTitle) {
// predefine if this is a group chat message or not
LocalPreferences localPref = SettingsManager.getLocalPreferences();
boolean isGroupChat = chatRoom.getChatType() == Message.Type.groupchat;
int size = chatRoom.getTranscripts().size();
// is this a group chat message and is my name in it?
if (isGroupChat) {
// is a group chat, perform some functions
String fromNickName = "";
Message lastChatMessage = new Message();
Jid mucNickNameT;
String finalRoomName = "";
if (size > 0) {
lastChatMessage = chatRoom.getTranscripts().get(size - 1);
mucNickNameT = lastChatMessage.getFrom();
String[] mucNickName = mucNickNameT.toString().split("/");
finalRoomName = chatRoom.getRoomTitle();
if (mucNickName.length < 2) {
// We have no name after "/" in mucNickNameT (must be like: test@conference.jabber.kg/kos)
// Res.getString("label.message");
fromNickName = finalRoomName;
} else {
fromNickName = mucNickName[1];
}
}
String myNickName = chatRoom.getNickname().toString();
if (!myNickName.equals(fromNickName)) {
if (localPref.isMucHighToastEnabled()) {
// allowed to check for new messages containing name
String myUserName = SparkManager.getSessionManager().getUsername();
Pattern usernameMatch = Pattern.compile(myUserName, Pattern.CASE_INSENSITIVE);
Pattern nicknameMatch = Pattern.compile(myNickName, Pattern.CASE_INSENSITIVE);
if (usernameMatch.matcher(lastChatMessage.getBody()).find() || nicknameMatch.matcher(lastChatMessage.getBody()).find()) {
// match, send new message
String customMsgTextS = Res.getString("group.chat.name.match") + " " + finalRoomName + " by " + fromNickName + " (" + lastChatMessage.getBody() + ")";
String customMsgTitleS = Res.getString("group.chat.name.notification");
startFlashing(chatRoom, true, customMsgTextS, customMsgTitleS);
} else {
// regular group message
String customMsgTextS = fromNickName + " says: " + lastChatMessage.getBody();
startFlashing(chatRoom, true, customMsgTextS, finalRoomName);
}
} else {
// regular group message
String customMsgTextS = fromNickName + " says: " + lastChatMessage.getBody();
startFlashing(chatRoom, true, customMsgTextS, finalRoomName);
}
}
} else if (customMsg) {
// probably a file transfer request
startFlashing(chatRoom, true, customMsgText, customMsgTitle);
} else {
// normal personal chat
Message lastChatMessage = null;
if (size > 0) {
lastChatMessage = chatRoom.getTranscripts().get(size - 1);
}
String finalRoomName = chatRoom.getRoomTitle();
String customMsgTextS = "";
if (lastChatMessage != null) {
customMsgTextS = lastChatMessage.getBody();
}
startFlashing(chatRoom, true, customMsgTextS, finalRoomName);
}
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ChatContainer method checkNotificationPreferences.
/**
* Handles Notification preferences for incoming messages and rooms.
*
* @param room the chat room.
*/
private void checkNotificationPreferences(final ChatRoom room, boolean customMsg, String customMsgText, String customMsgTitle) {
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (pref.getWindowTakesFocus()) {
chatFrame.setState(Frame.NORMAL);
chatFrame.setVisible(true);
}
if (pref.getShowToasterPopup()) {
SparkToaster toaster = new SparkToaster();
toaster.setCustomAction(new AbstractAction() {
private static final long serialVersionUID = -2759404307378067515L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
chatFrame.setState(Frame.NORMAL);
chatFrame.setVisible(true);
int tabLocation = indexOfComponent(room);
if (tabLocation != -1) {
setSelectedIndex(tabLocation);
}
}
});
toaster.setDisplayTime(5000);
toaster.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
String nickname = room.getRoomTitle();
toaster.setToasterHeight(150);
toaster.setToasterWidth(200);
int size = room.getTranscripts().size();
if (customMsg) {
toaster.setTitle(customMsgTitle);
toaster.showToaster(room.getTabIcon(), customMsgText);
} else {
toaster.setTitle(nickname);
if (size > 0) {
Message message = room.getTranscripts().get(size - 1);
toaster.showToaster(room.getTabIcon(), message.getBody());
}
}
}
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class FileTransferPreference method commit.
@Override
public void commit() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
pref.setFileTransferIbbOnly(ui.getIbbOnly());
pref.setAutoAcceptFileTransferFromContacts(ui.getAutoAccept());
String downloadDir = ui.getDownloadDirectory();
if (ModelUtil.hasLength(downloadDir)) {
pref.setDownloadDir(downloadDir);
}
String timeout = ui.getTimeout();
if (ModelUtil.hasLength(timeout)) {
int tout = 1;
try {
tout = Integer.parseInt(timeout);
} catch (NumberFormatException e) {
// Nothing to do
}
pref.setFileTransferTimeout(tout);
final int timeOutMs = tout * (60 * 1000);
OutgoingFileTransfer.setResponseTimeout(timeOutMs);
}
SettingsManager.saveSettings();
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ChatPreference method commit.
@Override
public void commit() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
pref.setTimeDisplayedInChat(panel.getShowTime());
if (panel.getShowTime()) {
pref.setTimeFormat(panel.getFormatTime());
}
pref.setChatRoomNotifications(panel.isGroupChatNotificationsOn());
pref.setChatHistoryEnabled(!panel.isChatHistoryHidden());
pref.setPrevChatHistoryEnabled(!panel.isPrevChatHistoryHidden());
pref.setChatLengthDefaultTimeout(panel.getChatTimeoutTime());
pref.setTabsOnTop(panel.isTabsOnTop());
pref.setBuzzEnabled(panel.isBuzzEnabled());
pref.setChatHistoryAscending(panel.isSortChatHistoryAscending());
SettingsManager.saveSettings();
// Do not commit if not changed.
if (ModelUtil.hasLength(panel.getPassword()) && ModelUtil.hasLength(panel.getConfirmationPassword())) {
try {
AccountManager.getInstance(SparkManager.getConnection()).changePassword(panel.getPassword());
} catch (XMPPException | SmackException | InterruptedException passwordEx) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.unable.to.save.password"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
Log.error("Unable to change password", passwordEx);
}
}
}
Aggregations