Search in sources :

Example 41 with LocalPreferences

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();
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 42 with LocalPreferences

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Message(org.jivesoftware.smack.packet.Message) EntityJid(org.jxmpp.jid.EntityJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 43 with LocalPreferences

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());
            }
        }
    }
}
Also used : SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) Message(org.jivesoftware.smack.packet.Message) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 44 with LocalPreferences

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();
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 45 with LocalPreferences

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);
        }
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) XMPPException(org.jivesoftware.smack.XMPPException)

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