use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ChatTranscriptPlugin method persistChatRoom.
public void persistChatRoom(final ChatRoom room) {
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (!pref.isChatHistoryEnabled()) {
return;
}
final String jid = room.getRoomname();
final List<Message> transcripts = room.getTranscripts();
ChatTranscript transcript = new ChatTranscript();
int count = 0;
int i = 0;
if (lastMessage.get(jid) != null) {
count = transcripts.indexOf(lastMessage.get(jid)) + 1;
}
for (Message message : transcripts) {
if (i < count) {
i++;
continue;
}
lastMessage.put(jid, message);
HistoryMessage history = new HistoryMessage();
history.setTo(message.getTo());
history.setFrom(message.getFrom());
history.setBody(message.getBody());
final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
Date date = null;
if (extension != null) {
date = (Date) extension.getProperty("date");
}
history.setDate(date == null ? new Date() : date);
transcript.addHistoryMessage(history);
}
ChatTranscripts.appendToTranscript(jid, transcript);
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class ChatTranscriptPlugin method chatRoomOpened.
public void chatRoomOpened(final ChatRoom room) {
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (!pref.isChatHistoryEnabled()) {
return;
}
final String jid = room.getRoomname();
File transcriptFile = ChatTranscripts.getTranscriptFile(jid);
if (!transcriptFile.exists()) {
return;
}
if (room instanceof ChatRoomImpl) {
new ChatRoomDecorator(room);
}
}
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 = message.getFrom();
if (from == null) {
from = pref.getNickname();
}
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> ").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);
}
}
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_AWAY);
}
}
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) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// 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);
}
use of org.jivesoftware.sparkimpl.settings.local.LocalPreferences in project Spark by igniterealtime.
the class PasswordDialog method savePassword.
public void savePassword(String roomName, String password) {
File sparkProperties = new File(Spark.getSparkUserHome().concat(File.separator).concat(SettingsManager.getSettingsFile().getName()));
Properties props = new Properties();
try {
props.load(new FileInputStream(sparkProperties));
} catch (Exception e) {
Log.error("error with file" + e.getCause());
}
LocalPreferences preferences = new LocalPreferences(props);
try {
preferences.setGroupChatPassword(roomName, Encryptor.encrypt(password));
} catch (Exception ex) {
Log.error(ex.getCause());
}
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream(sparkProperties);
props.store(fileOut, "added room");
} catch (Exception ex) {
Log.error(ex.getCause());
}
}
Aggregations