From 4c754a00eae12ba76b13540b3d4fe1bd5aa4454d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 12 Apr 2009 18:13:37 +0000 Subject: [PATCH] add activity / mood in change status dialog. Fixes #4419 --- data/glade/change_status_message_dialog.glade | 604 +++++++++--------- src/common/helpers.py | 53 +- src/common/pep.py | 117 ++-- src/dialogs.py | 165 +++-- src/gajim.py | 9 +- src/roster_window.py | 110 ++-- src/systray.py | 4 +- 7 files changed, 600 insertions(+), 462 deletions(-) diff --git a/data/glade/change_status_message_dialog.glade b/data/glade/change_status_message_dialog.glade index 704c0d0fb..b5be94445 100644 --- a/data/glade/change_status_message_dialog.glade +++ b/data/glade/change_status_message_dialog.glade @@ -1,312 +1,296 @@ - - - + + + - - - 6 - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 270 - 175 - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - True - - - - - True - False - 6 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - False - GTK_PACK_END - - - - - - True - 0 - 0.5 - GTK_SHADOW_NONE - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - 6 - True - False - 6 - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - True - True - True - True - False - True - GTK_JUSTIFY_LEFT - GTK_WRAP_WORD - True - 0 - 0 - 0 - 0 - 0 - 0 - - - - - - 0 - True - True - - - - - - True - GTK_BUTTONBOX_END - 0 - - - - True - False - True - True - GTK_RELIEF_NORMAL - True - - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-save-as - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Save as Preset... - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - 0 - False - False - - - - - - True - False - 6 - - - - True - Preset messages: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - False - True - - - - 0 - True - True - - - - - 0 - False - True - - - - - - - - - - True - <b>Type your new status message</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - 0 - True - True - - - - - - + + 6 + 270 + 175 + GDK_WINDOW_TYPE_HINT_DIALOG + + + + True + 6 + + + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + 6 + 6 + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + + + True + True + True + GTK_WRAP_WORD + + + + + + + True + GTK_BUTTONBOX_END + + + True + False + True + True + 0 + + + + True + 0 + 0 + + + True + 2 + + + True + gtk-save-as + + + False + False + + + + + True + Save as Preset... + True + + + False + False + 1 + + + + + + + + + + + False + False + 1 + + + + + True + 3 + 2 + 6 + 6 + + + True + True + True + 0 + + + + True + 6 + + + True + gtk-missing-image + + + False + + + + + True + 0 + True + + + 1 + + + + + + + 1 + 2 + 2 + 3 + + + + + True + True + True + 0 + + + + True + 6 + + + True + gtk-missing-image + + + False + + + + + True + 0 + True + + + 1 + + + + + + + 1 + 2 + 1 + 2 + + + + + True + 0 + Mood: + + + 2 + 3 + GTK_FILL + + + + + True + 0 + Activity: + + + 1 + 2 + GTK_FILL + + + + + True + + + + 1 + 2 + + + + + True + 0 + Preset messages: + + + GTK_FILL + + + + + False + 2 + + + + + + + + + True + <b>Type your new status message</b> + True + + + label_item + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + False + GTK_PACK_END + + + + + diff --git a/src/common/helpers.py b/src/common/helpers.py index 258863040..82e73afdf 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -45,6 +45,7 @@ from encodings.punycode import punycode_encode from i18n import Q_ from i18n import ngettext import xmpp +import pep try: import winsound # windows-only built-in module for playing wav @@ -800,7 +801,7 @@ def get_global_show(): maxi = 0 for account in gajim.connections: if not gajim.config.get_per('accounts', account, - 'sync_with_global_status'): + 'sync_with_global_status'): continue connected = gajim.connections[account].connected if connected > maxi: @@ -811,7 +812,7 @@ def get_global_status(): maxi = 0 for account in gajim.connections: if not gajim.config.get_per('accounts', account, - 'sync_with_global_status'): + 'sync_with_global_status'): continue connected = gajim.connections[account].connected if connected > maxi: @@ -819,6 +820,54 @@ def get_global_status(): status = gajim.connections[account].status return status +def get_pep_dict(account): + pep_dict = {} + con = gajim.connections[account] + # activity + if 'activity' in con.activity and con.activity['activity'] in pep.ACTIVITIES: + activity = con.activity['activity'] + if 'subactivity' in con.activity and con.activity['subactivity'] in \ + pep.ACTIVITIES[activity]: + subactivity = con.activity['subactivity'] + else: + subactivity = 'other' + else: + activity = '' + subactivity = '' + if 'text' in con.activity: + text = con.activity['text'] + else: + text = '' + pep_dict['activity'] = activity + pep_dict['subactivity'] = subactivity + pep_dict['activity_text'] = text + + # mood + if 'mood' in con.mood and con.mood['mood'] in pep.MOODS: + mood = con.mood['mood'] + else: + mood = '' + if 'text' in con.mood: + text = con.mood['text'] + else: + text = '' + pep_dict['mood'] = mood + pep_dict['mood_text'] = text + return pep_dict + +def get_global_pep(): + maxi = 0 + pep_dict = {'activity': '', 'mood': ''} + for account in gajim.connections: + if not gajim.config.get_per('accounts', account, + 'sync_with_global_status'): + continue + connected = gajim.connections[account].connected + if connected > maxi: + maxi = connected + pep_dict = get_pep_dict(account) + return pep_dict + def statuses_unified(): '''testing if all statuses are the same.''' reference = None diff --git a/src/common/pep.py b/src/common/pep.py index d7d2cc489..54012514f 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -5,7 +5,7 @@ ## Copyright (C) 2007-2008 Yann Leboulanger ## Copyright (C) 2008 Brendan Taylor ## Jean-Marie Traissard -## Jonathan Schleifer +## Jonathan Schleifer ## Stephan Erb ## ## This file is part of Gajim. @@ -23,7 +23,8 @@ ## along with Gajim. If not, see . ## -from common import gajim, xmpp +import common.gajim +from common import xmpp MOODS = { 'afraid': _('Afraid'), @@ -208,8 +209,8 @@ def user_mood(items, name, jid): if items.getTag('retract') is not None: retract = True - if jid == gajim.get_jid_from_account(name): - acc = gajim.connections[name] + if jid == common.gajim.get_jid_from_account(name): + acc = common.gajim.connections[name] if has_child: if 'mood' in acc.mood: del acc.mood['mood'] @@ -225,8 +226,8 @@ def user_mood(items, name, jid): if 'text' in acc.mood: del acc.mood['text'] - (user, resource) = gajim.get_room_and_nick_from_fjid(jid) - for contact in gajim.contacts.get_contacts(name, user): + (user, resource) = common.gajim.get_room_and_nick_from_fjid(jid) + for contact in common.gajim.contacts.get_contacts(name, user): if has_child: if 'mood' in contact.mood: del contact.mood['mood'] @@ -242,10 +243,10 @@ def user_mood(items, name, jid): if 'text' in contact.mood: del contact.mood['text'] - if jid == gajim.get_jid_from_account(name): - gajim.interface.roster.draw_account(name) - gajim.interface.roster.draw_mood(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + if jid == common.gajim.get_jid_from_account(name): + common.gajim.interface.roster.draw_account(name) + common.gajim.interface.roster.draw_mood(user, name) + ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_mood() @@ -276,8 +277,8 @@ def user_tune(items, name, jid): if items.getTag('retract') is not None: retract = True - if jid == gajim.get_jid_from_account(name): - acc = gajim.connections[name] + if jid == common.gajim.get_jid_from_account(name): + acc = common.gajim.connections[name] if has_child: if 'artist' in acc.tune: del acc.tune['artist'] @@ -311,8 +312,8 @@ def user_tune(items, name, jid): if 'length' in acc.tune: del acc.tune['length'] - user = gajim.get_room_and_nick_from_fjid(jid)[0] - for contact in gajim.contacts.get_contacts(name, user): + user = common.gajim.get_room_and_nick_from_fjid(jid)[0] + for contact in common.gajim.contacts.get_contacts(name, user): if has_child: if 'artist' in contact.tune: del contact.tune['artist'] @@ -346,10 +347,10 @@ def user_tune(items, name, jid): if 'length' in contact.tune: del contact.tune['length'] - if jid == gajim.get_jid_from_account(name): - gajim.interface.roster.draw_account(name) - gajim.interface.roster.draw_tune(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + if jid == common.gajim.get_jid_from_account(name): + common.gajim.interface.roster.draw_account(name) + common.gajim.interface.roster.draw_tune(user, name) + ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_tune() @@ -377,8 +378,8 @@ def user_activity(items, name, jid): if items.getTag('retract') is not None: retract = True - if jid == gajim.get_jid_from_account(name): - acc = gajim.connections[name] + if jid == common.gajim.get_jid_from_account(name): + acc = common.gajim.connections[name] if has_child: if 'activity' in acc.activity: del acc.activity['activity'] @@ -400,8 +401,8 @@ def user_activity(items, name, jid): if 'text' in acc.activity: del acc.activity['text'] - user = gajim.get_room_and_nick_from_fjid(jid)[0] - for contact in gajim.contacts.get_contacts(name, user): + user = common.gajim.get_room_and_nick_from_fjid(jid)[0] + for contact in common.gajim.contacts.get_contacts(name, user): if has_child: if 'activity' in contact.activity: del contact.activity['activity'] @@ -423,10 +424,10 @@ def user_activity(items, name, jid): if 'text' in contact.activity: del contact.activity['text'] - if jid == gajim.get_jid_from_account(name): - gajim.interface.roster.draw_account(name) - gajim.interface.roster.draw_activity(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + if jid == common.gajim.get_jid_from_account(name): + common.gajim.interface.roster.draw_account(name) + common.gajim.interface.roster.draw_activity(user, name) + ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_activity() @@ -445,21 +446,21 @@ def user_nickname(items, name, jid): if items.getTag('retract') is not None: retract = True - if jid == gajim.get_jid_from_account(name): + if jid == common.gajim.get_jid_from_account(name): if has_child: - gajim.nicks[name] = nick + common.gajim.nicks[name] = nick if retract: - gajim.nicks[name] = gajim.config.get_per('accounts', + common.gajim.nicks[name] = common.gajim.config.get_per('accounts', name, 'name') - user = gajim.get_room_and_nick_from_fjid(jid)[0] + user = common.gajim.get_room_and_nick_from_fjid(jid)[0] if has_child: if nick is not None: - for contact in gajim.contacts.get_contacts(name, user): + for contact in common.gajim.contacts.get_contacts(name, user): contact.contact_name = nick - gajim.interface.roster.draw_contact(user, name) + common.gajim.interface.roster.draw_contact(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_ui() win = ctrl.parent_win @@ -469,7 +470,7 @@ def user_nickname(items, name, jid): contact.contact_name = '' def user_send_mood(account, mood, message=''): - if not gajim.connections[account].pep_supported: + if not common.gajim.connections[account].pep_supported: return item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD}) if mood != '': @@ -478,10 +479,11 @@ def user_send_mood(account, mood, message=''): i = item.addChild('text') i.addData(message) - gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, '0') + common.gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, + '0') def user_send_activity(account, activity, subactivity='', message=''): - if not gajim.connections[account].pep_supported: + if not common.gajim.connections[account].pep_supported: return item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY}) if activity != '': @@ -492,12 +494,13 @@ def user_send_activity(account, activity, subactivity='', message=''): i = item.addChild('text') i.addData(message) - gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, '0') + common.gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, + '0') def user_send_tune(account, artist='', title='', source='', track=0, length=0, items=None): - if not (gajim.config.get_per('accounts', account, 'publish_tune') and \ - gajim.connections[account].pep_supported): + if not (common.gajim.config.get_per('accounts', account, 'publish_tune') and\ + common.gajim.connections[account].pep_supported): return item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE}) if artist != '': @@ -518,33 +521,35 @@ items=None): if items is not None: item.addChild(payload=items) - gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0') + common.gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, + '0') def user_send_nickname(account, nick): - if not gajim.connections[account].pep_supported: + if not common.gajim.connections[account].pep_supported: return item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) item.addData(nick) - gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, '0') + common.gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, + '0') def user_retract_mood(account): - gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0') + common.gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0') def user_retract_activity(account): - gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0') + common.gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0') def user_retract_tune(account): - gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0') + common.gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0') def user_retract_nickname(account): - gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0') + common.gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0') def delete_pep(jid, name): - user = gajim.get_room_and_nick_from_fjid(jid)[0] + user = common.gajim.get_room_and_nick_from_fjid(jid)[0] - if jid == gajim.get_jid_from_account(name): - acc = gajim.connections[name] + if jid == common.gajim.get_jid_from_account(name): + acc = common.gajim.connections[name] del acc.activity acc.activity = {} user_send_tune(name) @@ -553,7 +558,7 @@ def delete_pep(jid, name): del acc.mood acc.mood = {} - for contact in gajim.contacts.get_contacts(name, user): + for contact in common.gajim.contacts.get_contacts(name, user): del contact.activity contact.activity = {} del contact.tune @@ -561,13 +566,13 @@ def delete_pep(jid, name): del contact.mood contact.mood = {} - if jid == gajim.get_jid_from_account(name): - gajim.interface.roster.draw_account(name) + if jid == common.gajim.get_jid_from_account(name): + common.gajim.interface.roster.draw_account(name) - gajim.interface.roster.draw_activity(user, name) - gajim.interface.roster.draw_tune(user, name) - gajim.interface.roster.draw_mood(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + common.gajim.interface.roster.draw_activity(user, name) + common.gajim.interface.roster.draw_tune(user, name) + common.gajim.interface.roster.draw_mood(user, name) + ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_activity() ctrl.update_tune() diff --git a/src/dialogs.py b/src/dialogs.py index e5fbc24ef..bfb334998 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -323,8 +323,11 @@ class ChangeActivityDialog: 'having_appointment', 'inactive', 'relaxing', 'talking', 'traveling', 'working'] - def __init__(self, account): - self.account = account + def __init__(self, on_response, activity=None, subactivity=None, text=''): + self.on_response = on_response + self.activity = activity + self.subactivity = subactivity + self.text = text self.xml = gtkgui_helpers.get_glade( 'change_activity_dialog.glade') self.window = self.xml.get_widget('change_activity_dialog') @@ -334,9 +337,6 @@ class ChangeActivityDialog: self.notebook = self.xml.get_widget('notebook') self.entry = self.xml.get_widget('description_entry') - self.activity = 'working' - self.subactivity = 'other' - rbtns = {} group = None @@ -394,30 +394,24 @@ class ChangeActivityDialog: rbtns[act].add(hbox) vbox.pack_start(rbtns[act], False, False, 0) - rbtns['working_other'].set_active(True) - con = gajim.connections[account] + if self.activity in pep.ACTIVITIES: + if not self.subactivity in pep.ACTIVITIES[self.activity]: + self.subactivity = 'other' - if 'activity' in con.activity \ - and con.activity['activity'] in pep.ACTIVITIES: - if 'subactivity' in con.activity \ - and con.activity['subactivity'] in pep.ACTIVITIES[con.activity['activity']]: - subactivity = con.activity['subactivity'] - else: - subactivity = 'other' - - rbtns[con.activity['activity'] + '_' + subactivity]. \ - set_active(True) + rbtns[self.activity + '_' + self.subactivity].set_active(True) self.checkbutton.set_active(True) self.notebook.set_sensitive(True) self.entry.set_sensitive(True) self.notebook.set_current_page( - self.PAGELIST.index(con.activity['activity'])) + self.PAGELIST.index(self.activity)) - if 'text' in con.activity: - self.entry.set_text(con.activity['text']) + self.entry.set_text(text) + + else: + self.checkbutton.set_active(False) self.xml.signal_autoconnect(self) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) @@ -437,11 +431,16 @@ class ChangeActivityDialog: Return activity and messsage (None if no activity selected) ''' if self.checkbutton.get_active(): - pep.user_send_activity(self.account, self.activity, - self.subactivity, + self.on_response(self.activity, self.subactivity, self.entry.get_text().decode('utf-8')) else: - pep.user_send_activity(self.account, '') + self.on_response(None, None, '') +# if self.checkbutton.get_active(): +# pep.user_send_activity(self.account, self.activity, +# self.subactivity, +# self.entry.get_text().decode('utf-8')) +# else: +# pep.user_send_activity(self.account, '') self.window.destroy() def on_cancel_button_clicked(self, widget): @@ -450,10 +449,11 @@ class ChangeActivityDialog: class ChangeMoodDialog: COLS = 11 - def __init__(self, account): - self.account = account + def __init__(self, on_response, mood=None, text=''): + self.on_response = on_response + self.mood = mood + self.text = text self.xml = gtkgui_helpers.get_glade('change_mood_dialog.glade') - self.mood = None self.window = self.xml.get_widget('change_mood_dialog') self.window.set_transient_for(gajim.interface.roster.window) @@ -494,23 +494,17 @@ class ChangeMoodDialog: x = 0 y += 1 - con = gajim.connections[account] - if 'mood' in con.mood: - self.mood = con.mood['mood'] - if self.mood in pep.MOODS: - self.mood_buttons[self.mood].set_active(True) - self.label.set_text(pep.MOODS[self.mood]) - else: - self.label.set_text(self.mood) - - if self.mood: + if self.mood in pep.MOODS: + self.mood_buttons[self.mood].set_active(True) + self.label.set_text(pep.MOODS[self.mood]) self.entry.set_sensitive(True) + if self.text: + self.entry.set_text(self.text) else: + self.label.set_text(_('None')) + self.entry.set_text('') self.entry.set_sensitive(False) - if 'text' in con.mood: - self.entry.set_text(con.mood['text']) - self.xml.signal_autoconnect(self) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.window.show_all() @@ -528,25 +522,29 @@ class ChangeMoodDialog: def on_ok_button_clicked(self, widget): '''Return mood and messsage (None if no mood selected)''' message = self.entry.get_text().decode('utf-8') - if self.mood is None: - pep.user_send_mood(self.account, '') - else: - pep.user_send_mood(self.account, self.mood, message) + self.on_response(self.mood, message) +# if self.mood is None: +# pep.user_send_mood(self.account, '') +# else: +# pep.user_send_mood(self.account, self.mood, message) self.window.destroy() def on_cancel_button_clicked(self, widget): self.window.destroy() class ChangeStatusMessageDialog: - def __init__(self, on_response, show=None): + def __init__(self, on_response, show=None, pep_dict=None): self.show = show + self.pep_dict = pep_dict self.on_response = on_response self.xml = gtkgui_helpers.get_glade('change_status_message_dialog.glade') self.window = self.xml.get_widget('change_status_message_dialog') self.window.set_transient_for(gajim.interface.roster.window) + msg = None if show: uf_show = helpers.get_uf_show(show) self.title_text = _('%s Status Message') % uf_show + msg = gajim.config.get('last_status_msg_' + show) else: self.title_text = _('Status Message') self.window.set_title(self.title_text) @@ -555,9 +553,6 @@ class ChangeStatusMessageDialog: self.message_buffer = message_textview.get_buffer() self.message_buffer.connect('changed', self.toggle_sensitiviy_of_save_as_preset) - msg = None - if show: - msg = gajim.config.get('last_status_msg_' + show) if not msg: msg = '' msg = helpers.from_one_line(msg) @@ -571,8 +566,8 @@ class ChangeStatusMessageDialog: self.preset_messages_dict[msg_name] = msg_text sorted_keys_list = helpers.get_sorted_keys(self.preset_messages_dict) - self.countdown_time = gajim.config.get('change_status_window_timeout') - self.countdown_left = self.countdown_time + countdown_time = gajim.config.get('change_status_window_timeout') + self.countdown_left = countdown_time self.countdown_enabled = True self.message_liststore = gtk.ListStore(str) # msg_name @@ -583,14 +578,63 @@ class ChangeStatusMessageDialog: self.message_combobox.add_attribute(cellrenderertext, 'text', 0) for msg_name in sorted_keys_list: self.message_liststore.append((msg_name,)) + + if pep_dict: + self.draw_activity() + self.draw_mood() + else: + # remove acvtivity / mood lines + self.xml.get_widget('activity_label').set_no_show_all(True) + self.xml.get_widget('activity_button').set_no_show_all(True) + self.xml.get_widget('mood_label').set_no_show_all(True) + self.xml.get_widget('mood_button').set_no_show_all(True) + self.xml.get_widget('activity_label').hide() + self.xml.get_widget('activity_button').hide() + self.xml.get_widget('mood_label').hide() + self.xml.get_widget('mood_button').hide() + self.xml.signal_autoconnect(self) - if self.countdown_time > 0: + if countdown_time > 0: self.countdown() gobject.timeout_add(1000, self.countdown) self.window.connect('response', self.on_dialog_response) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.window.show_all() + def draw_activity(self): + '''Set activity button''' + img = self.xml.get_widget('activity_image') + label = self.xml.get_widget('activity_button_label') + if 'activity' in self.pep_dict and self.pep_dict['activity'] in \ + pep.ACTIVITIES: + if 'subactivity' in self.pep_dict and self.pep_dict['subactivity'] in \ + pep.ACTIVITIES[self.pep_dict['activity']]: + img.set_from_pixbuf(gtkgui_helpers.load_activity_icon( + self.pep_dict['activity'], self.pep_dict['subactivity']).\ + get_pixbuf()) + else: + img.set_from_pixbuf(gtkgui_helpers.load_activity_icon( + self.pep_dict['activity']).get_pixbuf()) +# gtk.Tooltips().set_tip(item, pep.ACTIVITIES[category]['category']) + if self.pep_dict['activity_text']: + label.set_text(self.pep_dict['activity_text']) + else: + img.set_from_pixbuf(None) + label.set_text('') + + def draw_mood(self): + '''Set mood button''' + img = self.xml.get_widget('mood_image') + label = self.xml.get_widget('mood_button_label') + if self.pep_dict['mood'] in pep.MOODS: + img.set_from_pixbuf(gtkgui_helpers.load_mood_icon( + self.pep_dict['mood']).get_pixbuf()) + if self.pep_dict['mood_text']: + label.set_text(self.pep_dict['mood_text']) + else: + img.set_from_pixbuf(None) + label.set_text('') + def countdown(self): if self.countdown_enabled: if self.countdown_left <= 0: @@ -618,7 +662,7 @@ class ChangeStatusMessageDialog: else: message = None # user pressed Cancel button or X wm button self.window.destroy() - self.on_response(message) + self.on_response(message, self.pep_dict) def on_message_combobox_changed(self, widget): self.countdown_enabled = False @@ -675,6 +719,25 @@ class ChangeStatusMessageDialog: _('Please type a name for this status message'), is_modal=False, ok_handler=on_ok) + def on_activity_button_clicked(self, widget): + self.countdown_enabled = False + def on_response(activity, subactivity, text): + self.pep_dict['activity'] = activity + self.pep_dict['subactivity'] = subactivity + self.pep_dict['activity_text'] = text + self.draw_activity() + ChangeActivityDialog(on_response, self.pep_dict['activity'], + self.pep_dict['subactivity'], self.pep_dict['activity_text']) + + def on_mood_button_clicked(self, widget): + self.countdown_enabled = False + def on_response(mood, text): + self.pep_dict['mood'] = mood + self.pep_dict['mood_text'] = text + self.draw_mood() + ChangeMoodDialog(on_response, self.pep_dict['mood'], + self.pep_dict['mood_text']) + class AddNewContactWindow: '''Class for AddNewContactWindow''' uid_labels = {'jabber': _('Jabber ID:'), diff --git a/src/gajim.py b/src/gajim.py index b1ed0a9be..445932621 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -3014,13 +3014,18 @@ class Interface: shows[show] = [a] else: shows[show].append(a) - def on_message(message): + def on_message(message, pep_dict): if message is None: return for a in shows[show]: self.roster.send_status(a, show, message) + self.roster.send_pep(a, pep_dict) for show in shows: - message = self.roster.get_status_message(show, on_message) + if len(shows[show]) == 1: + pep_dict = helpers.get_pep_dict(shows[show][0]) + else: + pep_dict = helpers.get_global_pep() + message = self.roster.get_status_message(show, pep_dict, on_message) return False def show_systray(self): diff --git a/src/roster_window.py b/src/roster_window.py index 5fed49968..5135bcf72 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1932,6 +1932,37 @@ class RosterWindow: self.send_status_continue(account, status, txt, auto, to) + def send_pep(self, account, pep_dict=None): + '''Sends pep information (activity, mood)''' + if not pep_dict: + return + # activity + if 'activity' in pep_dict and pep_dict['activity'] in pep.ACTIVITIES: + activity = pep_dict['activity'] + if 'subactivity' in pep_dict and \ + pep_dict['subactivity'] in pep.ACTIVITIES[activity]: + subactivity = pep_dict['subactivity'] + else: + subactivity = 'other' + if 'activity_text' in pep_dict: + activity_text = pep_dict['activity_text'] + else: + activity_text = '' + pep.user_send_activity(account, activity, subactivity, activity_text) + else: + pep.user_send_activity(account, '') + + # mood + if 'mood' in pep_dict and pep_dict['mood'] in pep.MOODS: + mood = pep_dict['mood'] + if 'mood_text' in pep_dict: + mood_text = pep_dict['mood_text'] + else: + mood_text = '' + pep.user_send_mood(account, mood, mood_text) + else: + pep.user_send_mood(account, '') + def send_status_continue(self, account, status, txt, auto, to): if gajim.account_is_connected(account) and not to: if status == 'online' and gajim.interface.sleeper.getState() != \ @@ -2060,34 +2091,37 @@ class RosterWindow: if sys.platform == 'darwin': self.make_menu(force=True) - def get_status_message(self, show, on_response, always_ask=False): + def get_status_message(self, show, pep_dict, on_response, always_ask=False): ''' get the status message by: 1/ looking in default status message 2/ asking to user if needed depending on ask_on(ff)line_status and always_ask + pep_dict can be None to hide pep things from status message or a dict ''' if show in gajim.config.get_per('defaultstatusmsg'): if gajim.config.get_per('defaultstatusmsg', show, 'enabled'): on_response(gajim.config.get_per('defaultstatusmsg', show, - 'message')) + 'message'), pep_dict) return if not always_ask and ((show == 'online' and not gajim.config.get( 'ask_online_status')) or (show in ('offline', 'invisible') and not \ gajim.config.get('ask_offline_status'))): - on_response('') + on_response('', pep_dict) return - dlg = dialogs.ChangeStatusMessageDialog(on_response, show) + dlg = dialogs.ChangeStatusMessageDialog(on_response, show, pep_dict) dlg.window.present() # show it on current workspace def change_status(self, widget, account, status): def change(account, status): - def on_response(message): + def on_response(message, pep_dict): if message is None: # user pressed Cancel to change status message dialog return self.send_status(account, status, message) - self.get_status_message(status, on_response) + self.send_pep(account, pep_dict) + pep_dict = helpers.get_pep_dict(account) + self.get_status_message(status, pep_dict, on_response) if status == 'invisible' and self.connected_rooms(account): dialogs.ConfirmationDialog( @@ -2217,7 +2251,7 @@ class RosterWindow: get_msg = True break - def on_continue2(message): + def on_continue2(message, pep_dict): self.quit_on_next_offline = 0 accounts_to_disconnect = [] for acct in accounts: @@ -2227,11 +2261,12 @@ class RosterWindow: for acct in accounts_to_disconnect: self.send_status(acct, 'offline', message) + self.send_pep(acct, pep_dict) if not self.quit_on_next_offline: self.quit_gtkgui_interface() - def on_continue(message): + def on_continue(message, pep_dict): if message is None: # user pressed Cancel to change status message dialog return @@ -2259,12 +2294,12 @@ class RosterWindow: dialogs.ConfirmationDialog(_('You have unread messages'), _('Messages will only be available for reading them later if you' ' have history enabled and contact is in your roster.'), - on_response_ok=(on_continue2, message)) + on_response_ok=(on_continue2, message, pep_dict)) return - on_continue2(message) + on_continue2(message, pep_dict) if get_msg: - self.get_status_message('offline', on_continue) + self.get_status_message('offline', None, on_continue) else: on_continue('') @@ -2514,7 +2549,7 @@ class RosterWindow: def on_block(self, widget, list_, group=None): ''' When clicked on the 'block' button in context menu. list_ is a list of (contact, account)''' - def on_continue(msg): + def on_continue(msg, pep_dict): if msg is None: # user pressed Cancel to change status message dialog return @@ -2556,7 +2591,7 @@ class RosterWindow: connection.set_default_list('block') connection.get_privacy_list('block') - self.get_status_message('offline', on_continue) + self.get_status_message('offline', None, on_continue) def on_unblock(self, widget, list_, group=None): ''' When clicked on the 'unblock' button in context menu. ''' @@ -2907,18 +2942,15 @@ class RosterWindow: if url: helpers.launch_browser_mailer('url', url) - def on_change_activity_activate(self, widget, account): - dialogs.ChangeActivityDialog(account) - - def on_change_mood_activate(self, widget, account): - dialogs.ChangeMoodDialog(account) - def on_change_status_message_activate(self, widget, account): show = gajim.SHOW_LIST[gajim.connections[account].connected] - def on_response(message): - if message is not None: # None is if user pressed Cancel - self.send_status(account, show, message) - dialogs.ChangeStatusMessageDialog(on_response, show) + pep_dict = helpers.get_pep_dict(account) + def on_response(message, pep_dict): + if message is None: # None is if user pressed Cancel + return + self.send_status(account, show, message) + self.send_pep(account, pep_dict) + dialogs.ChangeStatusMessageDialog(on_response, show, pep_dict) def on_add_to_roster(self, widget, contact, account): dialogs.AddNewContactWindow(account, contact.jid, contact.name) @@ -3023,7 +3055,8 @@ class RosterWindow: show = helpers.get_global_show() if show == 'offline': return True - def on_response(message): + pep_dict = helpers.get_global_pep() + def on_response(message, pep_dict): if message is None: return True for acct in gajim.connections: @@ -3033,7 +3066,8 @@ class RosterWindow: current_show = gajim.SHOW_LIST[gajim.connections[acct].\ connected] self.send_status(acct, current_show, message) - dialogs.ChangeStatusMessageDialog(on_response, show) + self.send_pep(acct, pep_dict) + dialogs.ChangeStatusMessageDialog(on_response, show, pep_dict) return True elif event.button == 1: # Left click @@ -3135,7 +3169,7 @@ class RosterWindow: def on_send_custom_status(self, widget, contact_list, show, group=None): '''send custom status''' # contact_list has only one element except if group != None - def on_response(message): + def on_response(message, pep_dict): if message is None: # None if user pressed Cancel return account_list = [] @@ -3168,7 +3202,7 @@ class RosterWindow: jid += '/' + contact.resource self.send_status(account, show, message, to=jid) - self.get_status_message(show, on_response, always_ask=True) + self.get_status_message(show, None, on_response, always_ask=True) def on_status_combobox_changed(self, widget): '''When we change our status via the combobox''' @@ -3192,7 +3226,8 @@ class RosterWindow: # 'Change status message' selected: # do not change show, just show change status dialog status = model[self.previous_status_combobox_active][2].decode('utf-8') - def on_response(message): + pep_dict = helpers.get_global_pep() + def on_response(message, pep_dict): if message is not None: # None if user pressed Cancel for account in accounts: if not gajim.config.get_per('accounts', account, @@ -3201,11 +3236,12 @@ class RosterWindow: current_show = gajim.SHOW_LIST[ gajim.connections[account].connected] self.send_status(account, current_show, message) + self.send_pep(account, pep_dict) self.combobox_callback_active = False self.status_combobox.set_active( self.previous_status_combobox_active) self.combobox_callback_active = True - dialogs.ChangeStatusMessageDialog(on_response, status) + dialogs.ChangeStatusMessageDialog(on_response, status, pep_dict) return # we are about to change show, so save this new show so in case # after user chooses "Change status message" menuitem @@ -3213,7 +3249,7 @@ class RosterWindow: self.previous_status_combobox_active = active connected_accounts = gajim.get_number_of_connected_accounts() - def on_continue(message): + def on_continue(message, pep_dict): if message is None: # user pressed Cancel to change status message dialog self.update_status_combobox() @@ -3236,6 +3272,7 @@ class RosterWindow: if not global_sync_connected_accounts > 0 or \ gajim.connections[account].connected > 0: self.send_status(account, status, message) + self.send_pep(account, pep_dict) self.update_status_combobox() if status == 'invisible': @@ -3251,7 +3288,7 @@ class RosterWindow: break if bug_user: def on_ok(): - self.get_status_message(status, on_continue) + self.get_status_message(status, None, on_continue) def on_cancel(): self.update_status_combobox() @@ -3264,7 +3301,8 @@ class RosterWindow: on_response_cancel=on_cancel) return - self.get_status_message(status, on_continue) + pep_dict = helpers.get_global_pep() + self.get_status_message(status, pep_dict, on_continue) def on_preferences_menuitem_activate(self, widget): if 'preferences' in gajim.interface.instances: @@ -4907,14 +4945,6 @@ class RosterWindow: else: item.set_active(have_tune) item.connect('toggled', self.on_publish_tune_toggled, account) - item = gtk.CheckMenuItem(_('Mood')) - pep_submenu.append(item) - item.set_active(len(gajim.connections[account].mood) > 0) - item.connect('activate', self.on_change_mood_activate, account) - item = gtk.CheckMenuItem(_('Activity')) - pep_submenu.append(item) - item.set_active(len(gajim.connections[account].activity) > 0) - item.connect('activate', self.on_change_activity_activate, account) pep_config = gtk.ImageMenuItem(_('Configure Services...')) item = gtk.SeparatorMenuItem() diff --git a/src/systray.py b/src/systray.py index cf90fa876..d55332dfe 100644 --- a/src/systray.py +++ b/src/systray.py @@ -38,6 +38,7 @@ import gtkgui_helpers from common import gajim from common import helpers +from common import pep HAS_SYSTRAY_CAPABILITIES = True @@ -385,7 +386,7 @@ class Systray: model = gajim.interface.roster.status_combobox.get_model() active = gajim.interface.roster.status_combobox.get_active() status = model[active][2].decode('utf-8') - def on_response(message): + def on_response(message, pep_dict): if message is None: # None if user press Cancel return accounts = gajim.connections.keys() @@ -395,6 +396,7 @@ class Systray: continue show = gajim.SHOW_LIST[gajim.connections[acct].connected] gajim.interface.roster.send_status(acct, show, message) + gajim.interface.roster.send_pep(acct, pep_dict) dlg = dialogs.ChangeStatusMessageDialog(on_response, status) dlg.window.present()