From 07f5b39e581729d81b70ab0080d060bd89e2f3a7 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 22 Aug 2006 14:40:19 +0000 Subject: [PATCH] default status message are now used (if enabled) instead of asking status message. Fixes #2069 --- data/glade/preferences_window.glade | 70 +++++++++++++++++++++++++++-- src/common/config.py | 19 ++++++++ src/config.py | 57 +++++++++++++++++++++++ src/roster_window.py | 3 ++ 4 files changed, 145 insertions(+), 4 deletions(-) diff --git a/data/glade/preferences_window.glade b/data/glade/preferences_window.glade index 5f31793a4..2b408d9d0 100644 --- a/data/glade/preferences_window.glade +++ b/data/glade/preferences_window.glade @@ -18,6 +18,7 @@ GDK_WINDOW_TYPE_HINT_NORMAL GDK_GRAVITY_NORTH_WEST True + False @@ -2537,6 +2538,68 @@ Disabled + + + True + True + False + 0 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + + + + True + <b>Default Status Messages</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + False + True + + + True @@ -3128,7 +3191,7 @@ Custom - True + True True Display _extra email details True @@ -3137,7 +3200,7 @@ Custom False False True - + 0 @@ -3179,7 +3242,7 @@ Custom False - + True @@ -3245,7 +3308,6 @@ Custom False - diff --git a/src/common/config.py b/src/common/config.py index d5cfd34ea..2ff2833b1 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -249,6 +249,10 @@ class Config: 'statusmsg': ({ 'message': [ opt_str, '' ], }, {}), + 'defaultstatusmsg': ({ + 'enabled': [ opt_bool, False ], + 'message': [ opt_str, '' ], + }, {}), 'soundevents': ({ 'enabled': [ opt_bool, True ], 'path': [ opt_str, '' ], @@ -321,6 +325,16 @@ class Config: _('Out'): _("I'm out enjoying life"), } + defaultstatusmsg_default = { + 'online': [ False, _("I'm avavilable") ], + 'chat': [ False, _("I'm free for chat") ], + 'away': [ False, _('Be right back') ], + 'xa': [ False, _("I'm not available") ], + 'dnd': [ False, _('Do not disturb') ], + 'invisible': [ False, _('Bye !') ], + 'offline': [ False, _('Bye !') ], + } + soundevents_default = { 'first_message_received': [ True, '../data/sounds/message1.wav' ], 'next_message_received': [ True, '../data/sounds/message2.wav' ], @@ -534,3 +548,8 @@ class Config: self.set_per('soundevents', event, 'enabled', default[0]) self.set_per('soundevents', event, 'path', default[1]) + for status in self.defaultstatusmsg_default: + default = self.defaultstatusmsg_default[status] + self.add_per('defaultstatusmsg', status) + self.set_per('defaultstatusmsg', status, 'enabled', default[0]) + self.set_per('defaultstatusmsg', status, 'message', default[1]) diff --git a/src/config.py b/src/config.py index 09671fd33..93c8c6716 100644 --- a/src/config.py +++ b/src/config.py @@ -376,6 +376,32 @@ class PreferencesWindow: self.xml.get_widget('prompt_offline_status_message_checkbutton').\ set_active(st) + # Default Status messages + self.default_msg_tree = self.xml.get_widget('default_msg_treeview') + # (status, translated_status, message, enabled) + model = gtk.ListStore(str, str, str, bool) + self.default_msg_tree.set_model(model) + col = gtk.TreeViewColumn('Status') + self.default_msg_tree.append_column(col) + renderer = gtk.CellRendererText() + col.pack_start(renderer, False) + col.set_attributes(renderer, text = 1) + col = gtk.TreeViewColumn('Message') + self.default_msg_tree.append_column(col) + renderer = gtk.CellRendererText() + col.pack_start(renderer, True) + col.set_attributes(renderer, text = 2) + renderer.connect('edited', self.on_default_msg_cell_edited) + renderer.set_property('editable', True) + col = gtk.TreeViewColumn('Enabled') + self.default_msg_tree.append_column(col) + renderer = gtk.CellRendererToggle() + col.pack_start(renderer, False) + col.set_attributes(renderer, active = 3) + renderer.set_property('activatable', True) + renderer.connect('toggled', self.default_msg_toggled_cb) + self.fill_default_msg_treeview() + #Status messages self.msg_tree = self.xml.get_widget('msg_treeview') model = gtk.ListStore(str, str) @@ -456,6 +482,8 @@ class PreferencesWindow: self.on_msg_treemodel_row_changed) self.msg_tree.get_model().connect('row-deleted', self.on_msg_treemodel_row_deleted) + self.default_msg_tree.get_model().connect('row-changed', + self.on_default_msg_treemodel_row_changed) self.theme_preferences = None @@ -789,6 +817,35 @@ class PreferencesWindow: def on_auto_xa_message_entry_changed(self, widget): gajim.config.set('autoxa_message', widget.get_text().decode('utf-8')) + def fill_default_msg_treeview(self): + model = self.default_msg_tree.get_model() + model.clear() + status = [] + for status_ in gajim.config.get_per('defaultstatusmsg'): + status.append(status_) + status.sort() + for status_ in status: + msg = gajim.config.get_per('defaultstatusmsg', status_, 'message') + enabled = gajim.config.get_per('defaultstatusmsg', status_, 'enabled') + iter = model.append() + model.set(iter, 0, status_, 1, _(status_), 2, msg, 3, enabled) + + def on_default_msg_cell_edited(self, cell, row, new_text): + model = self.default_msg_tree.get_model() + iter = model.get_iter_from_string(row) + model.set_value(iter, 2, new_text) + + def default_msg_toggled_cb(self, cell, path): + model = self.default_msg_tree.get_model() + model[path][3] = not model[path][3] + + def on_default_msg_treemodel_row_changed(self, model, path, iter): + status = model[iter][0] + message = model[iter][2].decode('utf-8') + gajim.config.set_per('defaultstatusmsg', status, 'enabled', + model[iter][3]) + gajim.config.set_per('defaultstatusmsg', status, 'message', message) + def save_status_messages(self, model): for msg in gajim.config.get_per('statusmsg'): gajim.config.del_per('statusmsg', msg) diff --git a/src/roster_window.py b/src/roster_window.py index dc64a9dd5..67422325b 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -2221,6 +2221,9 @@ _('If "%s" accepts this request you will know his or her status.') % jid) gajim.connections[account].change_status(status, txt, auto) def get_status_message(self, show): + if show in gajim.config.get_per('defaultstatusmsg'): + if gajim.config.get_per('defaultstatusmsg', show, 'enabled'): + return gajim.config.get_per('defaultstatusmsg', show, 'message') if (show == 'online' and not gajim.config.get('ask_online_status')) or \ (show == 'offline' and not gajim.config.get('ask_offline_status')) or \ show == 'invisible':