Search in sources :

Example 6 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() {

        @Override
        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
            }
        }

        @Override
        public void windowDeactivated(WindowEvent windowEvent) {
        }

        @Override
        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 7 with LocalPreferences

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

the class ContactItem method updatePresenceIcon.

/**
 * Updates the icon of the user based on their presence.
 *
 * @param presence the users presence.
 */
public void updatePresenceIcon(Presence presence) {
    ChatManager chatManager = SparkManager.getChatManager();
    boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
    if (handled) {
        return;
    }
    String status = presence.getStatus();
    Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    boolean isAvailable = false;
    if (status == null && presence.isAvailable()) {
        Presence.Mode mode = presence.getMode();
        if (mode == Presence.Mode.available) {
            status = Res.getString("status.online");
            isAvailable = true;
        } else if (mode == Presence.Mode.away) {
            status = Res.getString("status.away");
            statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
        } else if (mode == Presence.Mode.chat) {
            status = Res.getString("status.free.to.chat");
        } else if (mode == Presence.Mode.dnd) {
            status = Res.getString("status.do.not.disturb");
            statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
        } else if (mode == Presence.Mode.xa) {
            status = Res.getString("status.extended.away");
            statusIcon = SparkRes.getImageIcon(SparkRes.IM_XA);
        }
    }
    if (presence.isAvailable() && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) {
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
    } else if (presence.isAvailable()) {
        isAvailable = true;
    } else if (!presence.isAvailable()) {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));
        RosterEntry entry = Roster.getInstanceFor(SparkManager.getConnection()).getEntry(getJid());
        if (entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from) && entry.isSubscriptionPending()) {
            // Do not move out of group.
            setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
            getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
            setStatusText(Res.getString("status.pending"));
        } else {
            // We should keep the offline bullet (not available) instead of putting icon null.
            setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
            setFont(new Font("Dialog", Font.PLAIN, fontSize));
            getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
            setAvailable(false);
            if (ModelUtil.hasLength(status)) {
                setStatusText(status);
            } else {
                setStatusText("");
            }
        }
        sideIcon.setIcon(null);
        setAvailable(false);
        return;
    }
    Icon sIcon = PresenceManager.getIconFromPresence(presence);
    if (sIcon != null) {
        setIcon(sIcon);
    } else {
        setIcon(statusIcon);
    }
    if (status != null) {
        setStatus(status);
    }
    if (PresenceManager.isOnPhone(presence)) {
        statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
        setIcon(statusIcon);
    }
    // Always change nickname label to black.
    getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));
    if (isAvailable) {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        if (Res.getString("status.online").equals(status) || Res.getString("available").equalsIgnoreCase(status)) {
            setStatusText("");
        } else {
            setStatusText(status);
        }
    } else if (presence.isAvailable()) {
        LocalPreferences pref = SettingsManager.getLocalPreferences();
        if (pref.isGrayingOutEnabled()) {
            getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
            getNicknameLabel().setForeground(Color.gray);
        } else {
            getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
            getNicknameLabel().setForeground(Color.black);
        }
        if (status != null) {
            setStatusText(status);
        }
    }
    setAvailable(true);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ChatManager(org.jivesoftware.spark.ChatManager) Font(java.awt.Font)

Example 8 with LocalPreferences

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

the class TranscriptWindow method saveTranscript.

/**
 * Persist a current transcript.
 *
 * @param fileName   the name of the file to save the transcript as. Note: This can be modified by the user.
 * @param transcript the collection of transcript.
 * @param headerData the string to prepend to the transcript.
 * @see ChatRoom#getTranscripts()
 */
public void saveTranscript(String fileName, List<Message> transcript, String headerData) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    try {
        SimpleDateFormat formatter;
        File defaultSaveFile = new File(Spark.getSparkUserHome() + "/" + fileName);
        final JFileChooser fileChooser = new JFileChooser(defaultSaveFile);
        fileChooser.setSelectedFile(defaultSaveFile);
        // Show save dialog; this method does not return until the dialog is closed
        int result = fileChooser.showSaveDialog(this);
        final File selFile = fileChooser.getSelectedFile();
        if (selFile != null && result == JFileChooser.APPROVE_OPTION) {
            final StringBuilder buf = new StringBuilder();
            final Iterator<Message> transcripts = transcript.iterator();
            buf.append("<html><body>");
            if (headerData != null) {
                buf.append(headerData);
            }
            buf.append("<table width=600>");
            while (transcripts.hasNext()) {
                final Message message = transcripts.next();
                String from = null;
                if (message.getFrom() != null) {
                    from = message.getFrom().toString();
                }
                if (from == null) {
                    from = pref.getNickname().toString();
                }
                if (Message.Type.groupchat == message.getType()) {
                    if (ModelUtil.hasLength(XmppStringUtils.parseResource(from))) {
                        from = XmppStringUtils.parseResource(from);
                    }
                }
                final String body = message.getBody();
                final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
                Date insertionDate = null;
                if (extension != null) {
                    insertionDate = (Date) extension.getProperty("insertionDate");
                }
                formatter = new SimpleDateFormat("hh:mm:ss");
                String value = "";
                if (insertionDate != null) {
                    value = "(" + formatter.format(insertionDate) + ") ";
                }
                buf.append("<tr><td nowrap><font size=2>").append(value).append("<strong>").append(from).append(":</strong>&nbsp;").append(body).append("</font></td></tr>");
            }
            buf.append("</table></body></html>");
            final BufferedWriter writer = new BufferedWriter(new FileWriter(selFile));
            writer.write(buf.toString());
            writer.close();
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Chat transcript has been saved.", "Chat Transcript Saved", JOptionPane.INFORMATION_MESSAGE);
        }
    } catch (Exception ex) {
        Log.error("Unable to save chat transcript.", ex);
        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
        JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Could not save transcript.", "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) FileWriter(java.io.FileWriter) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) BufferedWriter(java.io.BufferedWriter) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 9 with LocalPreferences

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

the class LookAndFeelManager method loadPreferredLookAndFeel.

/**
 * Handles the Loading of the Look And Feel, as defined as the prefered Look
 * And Feel in the local settings.
 */
public static void loadPreferredLookAndFeel() {
    final LocalPreferences preferences = SettingsManager.getLocalPreferences();
    final String laf = getLookandFeel(preferences);
    if (laf.toLowerCase().contains("substance")) {
        EventQueue.invokeLater(() -> doSetLookAndFeel(laf));
    } else {
        doSetLookAndFeel(laf);
    }
// if ( laf.contains( "jtattoo" ) )
// {
// Properties props = new Properties();
// String menubar = Default.getString( Default.MENUBAR_TEXT ) == null ? ""
// : Default.getString( Default.MENUBAR_TEXT );
// props.put( "logoString", menubar );
// try
// {
// Class<?> c = Thread.currentThread().getContextClassLoader().loadClass( laf );
// Method m = c.getMethod( "setCurrentTheme", Properties.class );
// m.invoke( c.newInstance(), props );
// }
// catch ( Exception e )
// {
// Log.error( "Error Setting JTattoo ", e );
// }
// }
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 10 with LocalPreferences

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

the class ChatRoomImpl method loadHistory.

protected void loadHistory() {
    // Add VCard Panel
    vcardPanel = new VCardPanel(participantJID.asBareJid());
    getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 2), 0, 0));
    if (!Default.getBoolean(Default.HISTORY_DISABLED) && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) {
        final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
        if (!localPreferences.isChatHistoryEnabled()) {
            return;
        }
        if (!localPreferences.isPrevChatHistoryEnabled()) {
            return;
        }
        final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(getParticipantJID());
        final String personalNickname = SparkManager.getUserManager().getNickname();
        for (HistoryMessage message : chatTranscript.getMessages()) {
            String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom().asBareJid());
            String messageBody = message.getBody();
            if (nickname.equals(message.getFrom().toString()) || nickname.equals(message.getFrom().asBareJid().toString())) {
                BareJid otherJID = message.getFrom().asBareJid();
                EntityBareJid myJID = SparkManager.getSessionManager().getUserBareAddress();
                if (otherJID.equals(myJID)) {
                    nickname = personalNickname;
                } else {
                    Resourcepart resourcepart = message.getFrom().getResourceOrNull();
                    if (resourcepart == null) {
                        Localpart localpart = message.getFrom().getLocalpartOrNull();
                        if (localpart != null) {
                            nickname = localpart.toString();
                        }
                    } else {
                        nickname = resourcepart.toString();
                    }
                }
            }
            if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) {
                messageBody = messageBody.replaceFirst("/me", nickname);
            }
            final Date messageDate = message.getDate();
            getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate);
        }
        if (0 < chatTranscript.getMessages().size()) {
            // Check if we have history mesages
            getTranscriptWindow().insertHorizontalLine();
        }
        chatTranscript.release();
    }
}
Also used : ChatTranscript(org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscript) Localpart(org.jxmpp.jid.parts.Localpart) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) HistoryMessage(org.jivesoftware.sparkimpl.plugin.transcripts.HistoryMessage) Date(java.util.Date) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

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