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