From b330917676268bbcf498f63b971dabff32eaa6ac Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Wed, 11 Sep 2013 17:50:11 +0300 Subject: [PATCH] Adds message when otr session is enabled whether chat logging history is on or off and an option to open menu to change this settings. --- resources/languages/resources.properties | 2 + .../chat/toolBars/HistorySelectorBox.java | 18 +++++++ .../otr/KnownFingerprintsTableModel.java | 13 +---- .../communicator/plugin/otr/OtrActivator.java | 24 +++++++++ .../plugin/otr/ScOtrEngineImpl.java | 54 +++++++++++++++++++ 5 files changed, 100 insertions(+), 11 deletions(-) diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index e17968e27..afe6b33a9 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -1541,6 +1541,8 @@ plugin.otr.activator.unverifiedsessionstared=Unverified private conversat plugin.otr.activator.sessionstared=Private conversation with {0} started. plugin.otr.activator.sessionfinished={0} has ended his/her private conversation with you; you should do the same. plugin.otr.activator.sessionlost=Private conversation with {0} lost. +plugin.otr.activator.historyon={0} is recording this conversation on your device. You can turn off chat history here. +plugin.otr.activator.historyoff={0} is NOT recording this conversation. You can activate chat history here. # global proxy plugin plugin.globalproxy.GLOBAL_PROXY_CONFIG=Global Proxy diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java index f87d641f6..21a5786ab 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java @@ -12,6 +12,7 @@ import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.msghistory.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.skin.*; @@ -22,6 +23,7 @@ import java.awt.event.*; import java.beans.*; import java.io.*; +import java.net.*; /** * The HistorySelectorBox is the component where user could choose a @@ -35,6 +37,7 @@ public class HistorySelectorBox implements ActionListener, PropertyChangeListener, ChatChangeListener, + ChatLinkClickedListener, Skinnable { /** @@ -346,5 +349,20 @@ public void dispose() public void chatChanged(ChatPanel panel) { changeHistoryIcon(); + + panel.addChatLinkClickedListener(this); + } + + /** + * If a link is clicked with certain action to open the history popup menu. + * @param url The URI of the link that was clicked. + */ + @Override + public void chatLinkClicked(URI url) + { + if(url.getPath().equals("/showHistoryPopupMenu")) + { + this.doClick(); + } } } diff --git a/src/net/java/sip/communicator/plugin/otr/KnownFingerprintsTableModel.java b/src/net/java/sip/communicator/plugin/otr/KnownFingerprintsTableModel.java index becc4a5fc..c158d0f1e 100644 --- a/src/net/java/sip/communicator/plugin/otr/KnownFingerprintsTableModel.java +++ b/src/net/java/sip/communicator/plugin/otr/KnownFingerprintsTableModel.java @@ -58,16 +58,6 @@ public KnownFingerprintsTableModel() || protocolProviderRefs.length < 1) return; - // Get the metacontactlist service. - ServiceReference ref = - OtrActivator.bundleContext - .getServiceReference(MetaContactListService.class - .getName()); - - MetaContactListService service - = (MetaContactListService) OtrActivator - .bundleContext.getService(ref); - // Populate contacts. for (int i = 0; i < protocolProviderRefs.length; i++) { @@ -77,7 +67,8 @@ public KnownFingerprintsTableModel() .getService(protocolProviderRefs[i]); Iterator metaContacts = - service.findAllMetaContactsForProvider(provider); + OtrActivator.getContactListService() + .findAllMetaContactsForProvider(provider); while (metaContacts.hasNext()) { MetaContact metaContact = metaContacts.next(); diff --git a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java index 3b10939b2..5898f866d 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java @@ -8,6 +8,7 @@ import java.util.*; +import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.resources.*; @@ -95,6 +96,11 @@ public class OtrActivator */ public static UIService uiService; + /** + * The MetaContactListService reference. + */ + private static MetaContactListService metaCListService; + /** * Gets an {@link AccountID} by its UID. * @@ -422,4 +428,22 @@ public void stop(BundleContext bc) throws Exception } } } + + /** + * Returns the MetaContactListService obtained from the bundle + * context. + * @return the MetaContactListService obtained from the bundle + * context + */ + public static MetaContactListService getContactListService() + { + if (metaCListService == null) + { + metaCListService + = ServiceUtils.getService( + bundleContext, + MetaContactListService.class); + } + return metaCListService; + } } diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java index 8ddc98ecf..7c2355938 100644 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java @@ -14,6 +14,7 @@ import net.java.otr4j.session.*; import net.java.sip.communicator.service.browserlauncher.*; +import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -208,6 +209,42 @@ public void sessionStatusChanged(SessionID sessionID) OperationSetBasicInstantMessaging.HTML_MIME_TYPE); } + + // show info whether history is on or off + String otrAndHistoryMessage; + if(!ConfigurationUtils.isHistoryLoggingEnabled() + || !isHistoryLoggingEnabled(contact)) + { + otrAndHistoryMessage = + OtrActivator.resourceService.getI18NString( + "plugin.otr.activator.historyoff", + new String[]{ + OtrActivator.resourceService + .getSettingsString( + "service.gui.APPLICATION_NAME"), + this.getClass().getName(), + "showHistoryPopupMenu" + }); + } + else + { + otrAndHistoryMessage = + OtrActivator.resourceService.getI18NString( + "plugin.otr.activator.historyon", + new String[]{ + OtrActivator.resourceService + .getSettingsString( + "service.gui.APPLICATION_NAME"), + this.getClass().getName(), + "showHistoryPopupMenu" + }); + } + OtrActivator.uiService.getChat(contact).addMessage( + contact.getDisplayName(), + new Date(), Chat.SYSTEM_MESSAGE, + otrAndHistoryMessage, + OperationSetBasicInstantMessaging.HTML_MIME_TYPE); + message = OtrActivator.resourceService.getI18NString( OtrActivator.scOtrKeyManager.isVerified(contact) @@ -243,6 +280,23 @@ public void sessionStatusChanged(SessionID sessionID) }); } + /** + * Checks whether history is enabled for the metacontact containing + * the contact. + * @param contact the contact to check. + * @return whether chat logging is enabled while chatting + * with contact. + */ + private boolean isHistoryLoggingEnabled(Contact contact) + { + MetaContact metaContact = OtrActivator + .getContactListService().findMetaContactByContact(contact); + if(metaContact != null) + return ConfigurationUtils.isHistoryLoggingEnabled(metaContact); + else + return true; + } + public void addListener(ScOtrEngineListener l) { synchronized (listeners)