Search in sources :

Example 1 with LocalPreferences

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

the class BroadcastPlugin method userToUserBroadcast.

/**
 * Handles Broadcasts made from a user to another user
 *
 * @param message
 *            the message
 * @param type
 *            the message type
 * @param from
 *            the sender
 */
private void userToUserBroadcast(Message message, Type type, String from) {
    String jid = XmppStringUtils.parseBareJid(from);
    String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(jid);
    } catch (ChatRoomNotFoundException e) {
        chatRoom = new ChatRoomImpl(jid, nickname, nickname);
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    Message m = new Message();
    m.setBody(message.getBody());
    m.setTo(message.getTo());
    String broadcasttype = type == Message.Type.normal ? Res.getString("broadcast") : Res.getString("message.alert.notify");
    // m.setFrom(name +" "+broadcasttype);
    m.setFrom(nickname + " - " + broadcasttype);
    chatRoom.getTranscriptWindow().insertMessage(m.getFrom(), message, ChatManager.FROM_COLOR);
    chatRoom.addToTranscript(m, true);
    chatRoom.increaseUnreadMessageCount();
    broadcastRooms.add(chatRoom);
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (pref.getShowToasterPopup()) {
        SparkToaster toaster = new SparkToaster();
        toaster.setDisplayTime(30000);
        toaster.setBorder(BorderFactory.createBevelBorder(0));
        toaster.setTitle(nickname + " - " + broadcasttype);
        toaster.showToaster(message.getBody());
    }
    SparkManager.getChatManager().fireGlobalMessageReceievedListeners(chatRoom, message);
    DelayInformation inf = message.getExtension("delay", "urn:xmpp:delay");
    if (inf == null) {
        SoundPreference soundPreference = (SoundPreference) SparkManager.getPreferenceManager().getPreference(new SoundPreference().getNamespace());
        SoundPreferences preferences = soundPreference.getPreferences();
        if (preferences.isPlayIncomingSound()) {
            File incomingFile = new File(preferences.getIncomingSound());
            SparkManager.getSoundManager().playClip(incomingFile);
        }
    }
    chatRoom.addMessageListener(new MessageListener() {

        boolean waiting = true;

        public void messageReceived(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        public void messageSent(ChatRoom room, Message message) {
            removeAsBroadcast(room);
        }

        private void removeAsBroadcast(ChatRoom room) {
            if (waiting) {
                broadcastRooms.remove(room);
                // Notify decorators
                SparkManager.getChatManager().notifySparkTabHandlers(room);
                waiting = false;
            }
        }
    });
}
Also used : SoundPreference(org.jivesoftware.sparkimpl.preference.sounds.SoundPreference) Message(org.jivesoftware.smack.packet.Message) SoundPreferences(org.jivesoftware.sparkimpl.preference.sounds.SoundPreferences) MessageListener(org.jivesoftware.spark.ui.MessageListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ChatManager(org.jivesoftware.spark.ChatManager) File(java.io.File)

Example 2 with LocalPreferences

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

the class ChatContainer method createFrameIfNeeded.

private void createFrameIfNeeded() {
    if (chatFrame != null) {
        return;
    }
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (pref.isDockingEnabled()) {
        chatFrame = MainWindow.getInstance();
    } else {
        chatFrame = new ChatFrame();
    }
    if (SparkManager.getMainWindow().isActive() || pref.getWindowTakesFocus()) {
        chatFrame.setState(Frame.NORMAL);
    } else {
        chatFrame.setAutoRequestFocus(false);
        chatFrame.setState(Frame.ICONIFIED);
    }
    chatFrame.setVisible(true);
    chatFrame.addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent windowEvent) {
            stopFlashing();
            int sel = getSelectedIndex();
            if (sel == -1) {
                return;
            }
            final ChatRoom room;
            try {
                room = getChatRoom(sel);
                focusChat();
                // Set the title of the room.
                chatFrame.setTitle(room.getRoomTitle());
            } catch (ChatRoomNotFoundException e1) {
            // Nothing to do
            }
        }

        public void windowDeactivated(WindowEvent windowEvent) {
        }

        public void windowClosing(WindowEvent windowEvent) {
            SparkManager.getChatManager().getChatContainer().closeAllChatRooms();
        }
    });
    // Start timer
    handleStaleChats();
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 3 with LocalPreferences

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

the class ChatContainer method closeAllChatRooms.

/**
 * Close all chat rooms.
 */
public void closeAllChatRooms() {
    LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (MainWindow.getInstance().isDocked() || !pref.isAutoCloseChatRoomsEnabled()) {
        return;
    }
    for (ChatRoom chatRoom : new ArrayList<>(chatRoomList)) {
        closeTab(chatRoom);
        chatRoom.closeChatRoom();
    }
    for (int i = 0; i < getTabCount(); i++) {
        Component comp = getComponentAt(i);
        if (comp instanceof ContainerComponent) {
            ((ContainerComponent) comp).closing();
        }
        closeTab(comp);
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 4 with LocalPreferences

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

the class ChatContainer method getStaleChatRooms.

/**
 * Returns a Collection of stale chat rooms.
 *
 * @return a collection of stale chat rooms.
 */
public Collection<ChatRoom> getStaleChatRooms() {
    final List<ChatRoom> staleRooms = new ArrayList<>();
    for (ChatRoom chatRoom : getChatRooms()) {
        long lastActivity = chatRoom.getLastActivity();
        long currentTime = System.currentTimeMillis();
        long diff = currentTime - lastActivity;
        int minutes = (int) (diff / (60 * 1000F));
        LocalPreferences pref = SettingsManager.getLocalPreferences();
        int timeoutMinutes = pref.getChatLengthDefaultTimeout();
        int unreadCount = chatRoom.getUnreadMessageCount();
        if (timeoutMinutes <= minutes && unreadCount == 0) {
            staleRooms.add(chatRoom);
        }
    }
    return staleRooms;
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 5 with LocalPreferences

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

the class JoinConferenceRoomDialog method joinRoom.

public void joinRoom(final String roomJID, final String roomName) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    // Set default nickname
    nicknameField.setText(pref.getNickname());
    // Enable password field if a password is required
    passwordField.setVisible(false);
    passwordLabel.setVisible(false);
    roomNameDescription.setText(roomName);
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.join.conference.room"), Res.getString("message.specify.information.for.conference"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("join"), Res.getString("cancel") };
    pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    final JOptionPane p = new JOptionPane();
    final JDialog dlg = p.createDialog(SparkManager.getMainWindow(), Res.getString("title.conference.rooms"));
    dlg.setModal(false);
    dlg.pack();
    dlg.setSize(350, 250);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(SparkManager.getMainWindow());
    PropertyChangeListener changeListener = e -> {
        String value = (String) pane.getValue();
        if (Res.getString("cancel").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        } else if (Res.getString("join").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
            ConferenceUtils.joinConferenceOnSeperateThread(roomName, roomJID, null);
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    SwingWorker worker = new SwingWorker() {

        boolean requiresPassword;

        public Object construct() {
            requiresPassword = ConferenceUtils.isPasswordRequired(roomJID);
            return requiresPassword;
        }

        public void finished() {
            passwordField.setVisible(requiresPassword);
            passwordLabel.setVisible(requiresPassword);
        }
    };
    worker.start();
}
Also used : Insets(java.awt.Insets) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) SparkRes(org.jivesoftware.resource.SparkRes) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) SwingWorker(org.jivesoftware.spark.util.SwingWorker) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) JPasswordField(javax.swing.JPasswordField) PropertyChangeListener(java.beans.PropertyChangeListener) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) PropertyChangeListener(java.beans.PropertyChangeListener) SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) JDialog(javax.swing.JDialog)

Aggregations

LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)48 SmackException (org.jivesoftware.smack.SmackException)9 XMPPException (org.jivesoftware.smack.XMPPException)8 SwingWorker (org.jivesoftware.spark.util.SwingWorker)8 File (java.io.File)7 Message (org.jivesoftware.smack.packet.Message)5 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)5 Form (org.jivesoftware.smackx.xdata.Form)5 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)5 ActionEvent (java.awt.event.ActionEvent)4 ArrayList (java.util.ArrayList)4 AbstractAction (javax.swing.AbstractAction)4 Action (javax.swing.Action)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Date (java.util.Date)3 JPopupMenu (javax.swing.JPopupMenu)3 ChatManager (org.jivesoftware.spark.ChatManager)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2