From c5e679a0783a586418001b22786c9a97a85221c5 Mon Sep 17 00:00:00 2001 From: js Date: Tue, 22 Jul 2008 21:08:52 +0000 Subject: [PATCH] Show mood in chat window. --- data/glade/message_window.glade | 67 +++++++++++++++++++++++++-------- src/chat_control.py | 41 +++++++++++++++++++- src/common/config.py | 2 + src/common/configpaths.py | 4 +- src/common/gajim.py | 1 + src/common/helpers.py | 6 +++ src/common/pep.py | 11 ++++++ src/dialogs.py | 15 +------- src/gtkgui_helpers.py | 9 ++++- 9 files changed, 123 insertions(+), 33 deletions(-) diff --git a/data/glade/message_window.glade b/data/glade/message_window.glade index f1025f95a..641389567 100644 --- a/data/glade/message_window.glade +++ b/data/glade/message_window.glade @@ -63,6 +63,42 @@ 1 + + + True + 2 + + + True + gtk-missing-image + + + + + True + gtk-missing-image + + + 1 + + + + + True + gtk-missing-image + + + 2 + + + + + False + False + 15 + 2 + + True @@ -77,7 +113,7 @@ False False - 2 + 3 @@ -111,23 +147,22 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - GTK_RELIEF_NONE - False - 0 - - - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-dialog-authentication - 1 - - - + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + GTK_RELIEF_NONE + False + 0 + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-dialog-authentication + 1 + + + False - 0 diff --git a/src/chat_control.py b/src/chat_control.py index c60b80d6c..072648a0e 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -45,7 +45,9 @@ from common.contacts import GC_Contact from common.logger import Constants constants = Constants() from common.rst_xhtml_generator import create_xhtml -from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC, NS_RECEIPTS, NS_ESESSION +from common.pep import MOODS +from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC, NS_RECEIPTS +from common.xmpp.protocol import NS_ESESSION try: import gtkspell @@ -1083,6 +1085,12 @@ class ChatControl(ChatControlBase): self.update_toolbar() + self._mood_image = self.xml.get_widget('mood_image') + self._activity_image = self.xml.get_widget('activity_image') + self._tune_image = self.xml.get_widget('tune_image') + + self.update_mood() + # keep timeout id and window obj for possible big avatar # it is on enter-notify and leave-notify so no need to be # per jid @@ -1186,6 +1194,37 @@ class ChatControl(ChatControlBase): else: self._convert_to_gc_button.set_sensitive(False) + def update_mood(self): + if self.contact.mood.has_key('mood'): + mood = gobject.markup_escape_text( + self.contact.mood['mood']) + else: + mood = None + + if self.contact.mood.has_key('text'): + text = gobject.markup_escape_text( + self.contact.mood['text']) + else: + text = '' + + if mood is not None: + if mood in MOODS: + self._mood_image.set_from_pixbuf( + gtkgui_helpers.load_mood_icon( + mood).get_pixbuf()) + # Translate standard moods + mood = _(mood) + else: + self._mood_image.set_from_pixbuf( + gtkgui_helpers.load_mood_icon( + 'unknown').get_pixbuf()) + + self._mood_image.set_tooltip_markup('%s%s%s' % + (mood, '\n' if text is not '' else '', text)) + self._mood_image.show() + else: + self._mood_image.hide() + def on_avatar_eventbox_enter_notify_event(self, widget, event): ''' we enter the eventbox area so we under conditions add a timeout diff --git a/src/common/config.py b/src/common/config.py index a991046d6..7b5307a8c 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -51,6 +51,7 @@ opt_treat_incoming_messages = ['', 'chat', 'normal'] class Config: DEFAULT_ICONSET = 'dcraven' + DEFAULT_MOOD_ICONSET = 'default' if sys.platform == 'darwin': DEFAULT_OPENWITH = 'open' DEFAULT_BROWSER = 'open -a Safari' @@ -92,6 +93,7 @@ class Config: 'last_status_msg_offline': [ opt_str, '' ], 'trayicon': [ opt_bool, True, '', True ], 'iconset': [ opt_str, DEFAULT_ICONSET, '', True ], + 'mood_iconset': [ opt_str, DEFAULT_MOOD_ICONSET, '', True ], 'use_transports_iconsets': [ opt_bool, True, '', True ], 'inmsgcolor': [ opt_color, '#a34526', '', True ], 'outmsgcolor': [ opt_color, '#164e6f', '', True ], diff --git a/src/common/configpaths.py b/src/common/configpaths.py index 516d849ef..12215ce31 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -79,9 +79,9 @@ class ConfigPaths: # LOG is deprecated k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS', - 'MY_ICONSETS', 'MY_CACERTS') + 'MY_ICONSETS', 'MY_MOOD_ICONSETS', 'MY_CACERTS') v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons', - u'iconsets', u'cacerts.pem') + u'iconsets', u'moods', u'cacerts.pem') if os.name == 'nt': v = map(lambda x: x.capitalize(), v) diff --git a/src/common/gajim.py b/src/common/gajim.py index bc9228f23..2bf00ceb8 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -81,6 +81,7 @@ VCARD_PATH = gajimpaths['VCARD'] AVATAR_PATH = gajimpaths['AVATAR'] MY_EMOTS_PATH = gajimpaths['MY_EMOTS'] MY_ICONSETS_PATH = gajimpaths['MY_ICONSETS'] +MY_MOOD_ICONSETS_PATH = gajimpaths['MY_MOOD_ICONSETS'] MY_CACERTS = gajimpaths['MY_CACERTS'] TMP = gajimpaths['TMP'] DATA_DIR = gajimpaths['DATA'] diff --git a/src/common/helpers.py b/src/common/helpers.py index 27ba1a093..26d54aa68 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -1179,6 +1179,12 @@ def get_iconset_path(iconset): elif os.path.isdir(os.path.join(gajim.MY_ICONSETS_PATH, iconset)): return os.path.join(gajim.MY_ICONSETS_PATH, iconset) +def get_mood_iconset_path(iconset): + if os.path.isdir(os.path.join(gajim.DATA_DIR, 'moods', iconset)): + return os.path.join(gajim.DATA_DIR, 'moods', iconset) + elif os.path.isdir(os.path.join(gajim.MY_MOOD_ICONSETS_PATH, iconset)): + return os.path.join(gajim.MY_MOOD_ICONSETS_PATH, iconset) + def get_transport_path(transport): if os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', 'transports', transport)): diff --git a/src/common/pep.py b/src/common/pep.py index c16d9a9ad..feb62e149 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -1,5 +1,16 @@ from common import gajim, xmpp +MOODS = ['None', 'afraid', 'amazed', 'angry', 'annoyed', 'anxious', 'aroused', + 'ashamed', 'bored', 'brave', 'calm', 'cold', 'confused', 'contented', + 'cranky', 'curious', 'depressed', 'disappointed', 'disgusted', + 'distracted', 'embarrassed', 'excited', 'flirtatious', 'frustrated', + 'grumpy', 'guilty', 'happy', 'hot', 'humbled', 'humiliated', 'hungry', + 'hurt', 'impressed', 'in_awe', 'in_love', 'indignant', 'interested', + 'intoxicated', 'invincible', 'jealous', 'lonely', 'mean', 'moody', + 'nervous', 'neutral', 'offended', 'playful', 'proud', 'relieved', + 'remorseful', 'restless', 'sad', 'sarcastic', 'serious', 'shocked', + 'shy', 'sick', 'sleepy', 'stressed', 'surprised', 'thirsty', 'worried'] + def user_mood(items, name, jid): has_child = False retract = False diff --git a/src/dialogs.py b/src/dialogs.py index 1747483c5..83b80e7d7 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -37,6 +37,7 @@ import message_control import dataforms_widget from random import randrange +from common.pep import MOODS try: import gtkspell @@ -442,19 +443,7 @@ class ChangeActivityDialog: self.window.destroy() class ChangeMoodDialog: - moods = ['None', 'afraid', 'amazed', 'angry', 'annoyed', 'anxious', - 'aroused', 'ashamed', 'bored', 'brave', 'calm', - 'cold', 'confused', 'contented', 'cranky', 'curious', - 'depressed', 'disappointed', 'disgusted', 'distracted', - 'embarrassed', 'excited', 'flirtatious', 'frustrated', - 'grumpy', 'guilty', 'happy', 'hot', 'humbled', - 'humiliated', 'hungry', 'hurt', 'impressed', 'in_awe', - 'in_love', 'indignant', 'interested', 'intoxicated', - 'invincible', 'jealous', 'lonely', 'mean', 'moody', - 'nervous', 'neutral', 'offended', 'playful', 'proud', - 'relieved', 'remorseful', 'restless', 'sad', 'sarcastic', - 'serious', 'shocked', 'shy', 'sick', 'sleepy', - 'stressed', 'surprised', 'thirsty', 'worried'] + moods = MOODS def __init__(self, account): self.account = account self.xml = gtkgui_helpers.get_glade('change_mood_dialog.glade') diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 6b388a0f4..824a77d0d 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -882,7 +882,14 @@ def load_iconset(path, pixbuf2 = None, transport = False): def load_icon(icon_name): '''load an icon from the iconset in 16x16''' iconset = gajim.config.get('iconset') - path = os.path.join(helpers.get_iconset_path(iconset), '16x16' + '/') + path = os.path.join(helpers.get_iconset_path(iconset), '16x16', '') + icon_list = _load_icon_list([icon_name], path) + return icon_list[icon_name] + +def load_mood_icon(icon_name): + '''load an icon from the mood iconset in 16x16''' + iconset = gajim.config.get('mood_iconset') + path = os.path.join(helpers.get_mood_iconset_path(iconset), '') icon_list = _load_icon_list([icon_name], path) return icon_list[icon_name]