From 2c68be7262fc392ad0cff7a86044a4abe6ef4b47 Mon Sep 17 00:00:00 2001
From: Denis Fomin <fominde@gmail.com>
Date: Sat, 2 Oct 2010 21:24:24 +0400
Subject: [PATCH] juick.fix typo Chat State Notifications plugin. init

---
 chatstate/__init__.py      |   1 +
 chatstate/chatstate.py     | 103 ++++++++++++++++++++++++
 chatstate/config_dialog.ui | 159 +++++++++++++++++++++++++++++++++++++
 chatstate/manifest.ini     |  12 +++
 juick/manifest.ini         |   2 +-
 5 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 chatstate/__init__.py
 create mode 100644 chatstate/chatstate.py
 create mode 100644 chatstate/config_dialog.ui
 create mode 100644 chatstate/manifest.ini

diff --git a/chatstate/__init__.py b/chatstate/__init__.py
new file mode 100644
index 00000000..2e0e6b68
--- /dev/null
+++ b/chatstate/__init__.py
@@ -0,0 +1 @@
+from chatstate import ChatstatePlugin
diff --git a/chatstate/chatstate.py b/chatstate/chatstate.py
new file mode 100644
index 00000000..2fd4c8b5
--- /dev/null
+++ b/chatstate/chatstate.py
@@ -0,0 +1,103 @@
+# -*- coding: utf-8 -*-
+##
+
+import gtk
+import gobject
+import pango
+
+from plugins.gui import GajimPluginConfigDialog
+from plugins import GajimPlugin
+from plugins.helpers import log_calls, log
+from common import ged
+from common import gajim
+from common import helpers
+import gtkgui_helpers
+
+
+class ChatstatePlugin(GajimPlugin):
+
+    @log_calls('ChatstatePlugin')
+    def init(self):
+        self.config_dialog = ChatstatePluginConfigDialog(self)
+        self.events_handlers = {'raw-message-received' :
+                                    (ged.POSTCORE, self.raw_pres_received),}
+        self.config_default_values = {
+            'active': ('darkblue',''),
+            'composing': ('darkred', ''),
+            'inactive': ('#675B5B',''),
+            'paused': ('darkgreen', ''),}
+        self.compose = ('active', 'composing', 'gone', 'inactive', 'paused')
+
+
+    def raw_pres_received(self, event_object):
+        jid = str(event_object.xmpp_msg.getFrom())
+        account = event_object.account
+        contact = gajim.contacts.get_contact_from_full_jid(account, jid)
+        if not contact:
+            return
+
+        for compose in self.compose:
+            state = event_object.xmpp_msg.getTag(compose)
+            if state:
+                break
+        if not state:
+            return
+
+        self.model = gajim.interface.roster.model
+        child_iters = gajim.interface.roster._get_contact_iter(
+                jid.split('/')[0], account, contact, self.model)
+
+        for child_iter in child_iters:
+            name = gobject.markup_escape_text(contact.get_shown_name())
+            if compose != 'gone':
+                name = '<span foreground="%s">%s</span>' % (
+                        self.config[compose], name)
+            if contact.status and gajim.config.get('show_status_msgs_in_roster'):
+                status = contact.status.strip()
+                if status != '':
+                    status = helpers.reduce_chars_newlines(status,
+                            max_lines = 1)
+                    color = gtkgui_helpers.get_fade_color(
+                            gajim.interface.roster.tree, False, False)
+                    colorstring = '#%04x%04x%04x' % (color.red, color.green,
+                            color.blue)
+                    name += '\n<span size="small" style="italic" ' \
+                            'foreground="%s">%s</span>' % (colorstring,
+                            gobject.markup_escape_text(status))
+            self.model[child_iter][1] = name
+
+    @log_calls('ChatstatePlugin')
+    def activate(self):
+        pass
+
+    @log_calls('ChatstatePlugin')
+    def deactivate(self):
+        pass
+
+
+class ChatstatePluginConfigDialog(GajimPluginConfigDialog):
+    def init(self):
+        self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
+                'config_dialog.ui')
+        self.xml = gtk.Builder()
+        self.xml.set_translation_domain('gajim')
+        self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH,
+                ['vbox1'])
+        vbox1 = self.xml.get_object('vbox1')
+        self.child.pack_start(vbox1)
+        self.xml.connect_signals(self)
+        self.connect('hide', self.on_hide)
+
+    def on_run(self):
+        for name in self.plugin.config_default_values:
+            widget = self.xml.get_object(name)
+            widget.set_color(gtk.gdk.color_parse(self.plugin.config[name]))
+
+    def changed(self, entry):
+        name = gtk.Buildable.get_name(entry)
+        self.plugin.config[name] = entry.get_text()
+
+    def on_hide(self, widget):
+        for name in self.plugin.config_default_values:
+            widget = self.xml.get_object(name)
+            self.plugin.config[name] = widget.get_color().to_string()
diff --git a/chatstate/config_dialog.ui b/chatstate/config_dialog.ui
new file mode 100644
index 00000000..57efc751
--- /dev/null
+++ b/chatstate/config_dialog.ui
@@ -0,0 +1,159 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkWindow" id="window1">
+    <child>
+      <object class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkHBox" id="hbox3">
+            <property name="visible">True</property>
+            <property name="border_width">3</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">is doing something else</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="inactive">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="color">#000000000000</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox2">
+            <property name="visible">True</property>
+            <property name="border_width">3</property>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">is composing a message...</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="composing">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="color">#000000000000</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox4">
+            <property name="visible">True</property>
+            <property name="border_width">3</property>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">paused composing a message</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="paused">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="focus_on_click">False</property>
+                <property name="xalign">0</property>
+                <property name="color">#000000000000</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="border_width">3</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">is paying attention to the conversation</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="active">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="color">#000000000000</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/chatstate/manifest.ini b/chatstate/manifest.ini
new file mode 100644
index 00000000..9def70dc
--- /dev/null
+++ b/chatstate/manifest.ini
@@ -0,0 +1,12 @@
+[info]
+name: Chatstate in roster
+short_name: chatstate
+version: 0.1
+description: Chat State Notifications in roster.
+ Font color of the contact varies depending on the chat state.
+ The plugin does not work if you use custom font color for contacts in roster.
+ http://trac.gajim.org/ticket/3628.
+ http://xmpp.org/extensions/xep-0085.html
+authors = Denis Fomin <fominde@gmail.com>
+homepage = http://trac-plugins.gajim.org/wiki
+
diff --git a/juick/manifest.ini b/juick/manifest.ini
index 1c19bd61..5f674590 100644
--- a/juick/manifest.ini
+++ b/juick/manifest.ini
@@ -4,6 +4,6 @@ short_name: Juick
 version: 0.2
 description: Clickable juick links , juick nics, preview juick picturs.
 	The key combination alt + up in the textbox allow insert the number of last message (comment or topic).
-authors: Denis Fomin <fominde@gmail.com>>, evgen <drujebober@gmail.com>
+authors: Denis Fomin <fominde@gmail.com>, evgen <drujebober@gmail.com>
 homepage: http://trac-plugins.gajim.org/wiki/JuickPlugin
 
-- 
GitLab