changeset 6b094611322a in /home/hg/repos/gajim-plugins

author: lovetox <[email protected]>
branches: 
details:gajim-plugins?cmd=changeset;node=6b094611322a
description: Option to disable accounts for OMEMO

diffstat:

 omemo/__init__.py      |   78 ++++++++++++++++++-------
 omemo/config_dialog.ui |  146 +++++++++++++++++++++++++++++++++++++++++++++++-
 omemo/ui.py            |  111 +++++++++++++++++++++++++++++++-----
 3 files changed, 293 insertions(+), 42 deletions(-)

diffs (truncated from 526 to 300 lines):

diff -r d0fcde466a48 -r 6b094611322a omemo/__init__.py
--- a/omemo/__init__.py Sun Sep 18 18:13:01 2016 +0200
+++ b/omemo/__init__.py Mon Sep 19 20:08:04 2016 +0200
@@ -127,6 +127,12 @@
         self.plugin = self
         self.announced = []
         self.query_for_bundles = []
+        self.disabled_accounts = []
+
+        self.config_default_values = {'DISABLED_ACCOUNTS': ([], ''), }
+
+        for account in self.plugin.config['DISABLED_ACCOUNTS']:
+            self.disabled_accounts.append(account)
 
     def migrate_dbpath(self, account, my_jid):
         old_dbpath = os.path.join(DB_DIR_OLD, 'omemo_' + account + '.db')
@@ -157,6 +163,8 @@
             -------
             OmemoState
         """
+        if account in self.disabled_accounts:
+            return
         if account not in self.omemo_states:
             self.deactivate_gajim_e2e(account)
             my_jid = gajim.get_jid_from_account(account)
@@ -186,6 +194,8 @@
             event : SignedInEvent
         """
         account = event.conn.name
+        if account in self.disabled_accounts:
+            return
         log.debug(account +
                   ' => Announce Support after Sign In')
         self.query_for_bundles = []
@@ -199,11 +209,15 @@
         """ Method called when the Plugin is activated in the PluginManager
         """
         self.query_for_bundles = []
-        if NS_NOTIFY not in gajim.gajim_common_features:
-            gajim.gajim_common_features.append(NS_NOTIFY)
-        self._compute_caps_hash()
-        # Publish bundle information
+        # Publish bundle information and Entity Caps
         for account in gajim.connections:
+            if account in self.disabled_accounts:
+                log.debug(account +
+                          ' => Account is disabled')
+                continue
+            if NS_NOTIFY not in gajim.gajim_optional_features[account]:
+                gajim.gajim_optional_features[account].append(NS_NOTIFY)
+            self._compute_caps_hash(account)
             if account not in self.announced:
                 if gajim.account_is_connected(account):
                     log.debug(account +
@@ -218,23 +232,25 @@
 
             Removes OMEMO from the Entity Capabilities list
         """
-        if NS_NOTIFY in gajim.gajim_common_features:
-            gajim.gajim_common_features.remove(NS_NOTIFY)
-        self._compute_caps_hash()
+        for account in gajim.connections:
+            if account in self.disabled_accounts:
+                continue
+            if NS_NOTIFY in gajim.gajim_optional_features[account]:
+                gajim.gajim_optional_features[account].remove(NS_NOTIFY)
+            self._compute_caps_hash(account)
 
     @staticmethod
-    def _compute_caps_hash():
+    def _compute_caps_hash(account):
         """ Computes the hash for Entity Capabilities and publishes it """
-        for acc in gajim.connections:
-            gajim.caps_hash[acc] = caps_cache.compute_caps_hash(
-                [gajim.gajim_identity],
-                gajim.gajim_common_features +
-                gajim.gajim_optional_features[acc])
-            # re-send presence with new hash
-            connected = gajim.connections[acc].connected
-            if connected > 1 and gajim.SHOW_LIST[connected] != 'invisible':
-                gajim.connections[acc].change_status(
-                    gajim.SHOW_LIST[connected], gajim.connections[acc].status)
+        gajim.caps_hash[account] = caps_cache.compute_caps_hash(
+            [gajim.gajim_identity],
+            gajim.gajim_common_features +
+            gajim.gajim_optional_features[account])
+        # re-send presence with new hash
+        connected = gajim.connections[account].connected
+        if connected > 1 and gajim.SHOW_LIST[connected] != 'invisible':
+            gajim.connections[account].change_status(
+                gajim.SHOW_LIST[connected], gajim.connections[account].status)
 
     @log_calls('OmemoPlugin')
     def mam_message_received(self, msg):
@@ -251,12 +267,15 @@
             -------
             Return means that the Event is passed on to Gajim
         """
+        account = msg.conn.name
+        if account in self.disabled_accounts:
+            return
+
         if msg.msg_.getTag('openpgp', namespace=NS_PGP):
             return
 
         omemo_encrypted_tag = msg.msg_.getTag('encrypted', namespace=NS_OMEMO)
         if omemo_encrypted_tag:
-            account = msg.conn.name
             log.debug(account + ' => OMEMO MAM msg received')
 
             state = self.get_omemo_state(account)
@@ -309,12 +328,15 @@
             -------
             Return means that the Event is passed on to Gajim
         """
+        account = msg.conn.name
+        if account in self.disabled_accounts:
+            return
+
         if msg.stanza.getTag('openpgp', namespace=NS_PGP):
             return
 
         if msg.stanza.getTag('encrypted', namespace=NS_OMEMO) and \
                 msg.mtype == 'chat':
-            account = msg.conn.name
             log.debug(account + ' => OMEMO msg received')
 
             state = self.get_omemo_state(account)
@@ -379,6 +401,8 @@
             Return if encryption is not activated
         """
         account = event.account
+        if account in self.disabled_accounts:
+            return
         state = self.get_omemo_state(account)
 
         if not state.encryption.is_active(event.jid):
@@ -401,11 +425,13 @@
             Return if encryption is not activated or any other
             exception or error occurs
         """
+        account = event.conn.name
+        if account in self.disabled_accounts:
+            return
         try:
             if not event.msg_iq.getTag('body'):
                 return
 
-            account = event.conn.name
             state = self.get_omemo_state(account)
             full_jid = str(event.msg_iq.getAttr('to'))
             to_jid = gajim.get_jid_without_resource(full_jid)
@@ -479,6 +505,11 @@
             4.2 Discovering peer support
                 
http://conversations.im/xeps/multi-end.html#usecases-discovering
         """
+
+        account = event.conn.name
+        if account in self.disabled_accounts:
+            return False
+
         if event.pep_type != 'headline':
             return False
 
@@ -486,7 +517,6 @@
                                                           event.conn.name)))
         if len(devices_list) == 0:
             return False
-        account = event.conn.name
         contact_jid = gajim.get_jid_without_resource(event.fjid)
         state = self.get_omemo_state(account)
         my_jid = gajim.get_jid_from_account(account)
@@ -573,6 +603,8 @@
                 Gajim ChatControl object
         """
         account = chat_control.contact.account.name
+        if account in self.disabled_accounts:
+            return
         contact_jid = chat_control.contact.jid
         if account not in self.ui_list:
             self.ui_list[account] = {}
@@ -604,6 +636,8 @@
         """
         contact_jid = chat_control.contact.jid
         account = chat_control.contact.account.name
+        if account in self.disabled_accounts:
+            return
         self.ui_list[account][contact_jid].removeUi()
 
     def are_keys_missing(self, account, contact_jid):
diff -r d0fcde466a48 -r 6b094611322a omemo/config_dialog.ui
--- a/omemo/config_dialog.ui    Sun Sep 18 18:13:01 2016 +0200
+++ b/omemo/config_dialog.ui    Mon Sep 19 20:08:04 2016 +0200
@@ -4,7 +4,7 @@
   <!-- interface-naming-policy toplevel-contextual -->
   <object class="GtkListStore" id="account_store">
     <columns>
-      <!-- column-name accountname -->
+      <!-- column-name accounts -->
       <column type="gchararray"/>
     </columns>
   </object>
@@ -14,6 +14,12 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="disabled_account_store">
+    <columns>
+      <!-- column-name accounts -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkListStore" id="fingerprint_store">
     <columns>
       <!-- column-name id -->
@@ -106,7 +112,6 @@
               <object class="GtkLabel" id="fingerprint_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label">&lt;tt&gt;-------- -------- -------- 
-------- --------  &lt;/tt&gt;</property>
                 <property name="use_markup">True</property>
                 <property name="selectable">True</property>
               </object>
@@ -149,7 +154,6 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="xalign">0</property>
-                <property name="label" translatable="yes">0</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -417,6 +421,142 @@
         <property name="tab_fill">False</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkHBox" id="hbox6">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">12</property>
+        <property name="spacing">5</property>
+        <child>
+          <object class="GtkVBox" id="vbox5">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow3">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <child>
+                  <object class="GtkTreeView" id="active_accounts_view">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">account_store</property>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                        <property name="title" translatable="yes">Active 
Accounts</property>
+                        <property name="alignment">0.5</property>
+                        <child>
+                          <object class="GtkCellRendererText" 
id="cellrenderertext5"/>
+                          <attributes>
+                            <attribute name="text">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="disable_accounts_btn">
+                <property name="label" translatable="yes">Disable 
Account</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <signal name="clicked" handler="disable_accounts_btn_clicked" 
swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkVBox" id="vbox2">
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to