diff --git a/src/config.py b/src/config.py index 0e8eaeb7f..f7c9fd23b 100644 --- a/src/config.py +++ b/src/config.py @@ -913,43 +913,11 @@ class PreferencesWindow: if not iter: return path_to_snd_file = model[iter][2].decode('utf-8') - dialog = gtk.FileChooserDialog(_('Choose Sound'), None, - gtk.FILE_CHOOSER_ACTION_OPEN, - (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, - gtk.STOCK_OPEN, gtk.RESPONSE_OK)) - dialog.set_default_response(gtk.RESPONSE_OK) - last_sounds_dir = gajim.config.get('last_sounds_dir') - if last_sounds_dir and os.path.isdir('last_sounds_dir'): - dialog.set_current_folder(last_sounds_dir) - else: - dialog.set_current_folder(gajim.HOME_DIR) - - filter = gtk.FileFilter() - filter.set_name(_('All files')) - filter.add_pattern('*') - dialog.add_filter(filter) - - filter = gtk.FileFilter() - filter.set_name(_('Wav Sounds')) - filter.add_pattern('*.wav') - dialog.add_filter(filter) - dialog.set_filter(filter) - path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file) - dialog.set_filename(path_to_snd_file) - path_to_snd_file = '' - while True: - response = dialog.run() - if response != gtk.RESPONSE_OK: - break - path_to_snd_file = dialog.get_filename() - try: - path_to_snd_file = path_to_snd_file.decode(sys.getfilesystemencoding()) - except: - pass - if os.path.exists(path_to_snd_file): - break - dialog.destroy() + dlg_instance = dialogs.SoundChooserDialog(path_to_snd_file) + path_to_snd_file = dlg_instance.path_to_snd_file + dlg_instance.dialog.destroy() + if path_to_snd_file: directory = os.path.dirname(path_to_snd_file) gajim.config.set('last_sounds_dir', directory) diff --git a/src/dialogs.py b/src/dialogs.py index d2b616b57..9d50d9054 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1467,3 +1467,101 @@ class ProgressDialog: gobject.source_remove(self.read_from_queue_id) self.read_from_queue_and_update_textview() self.progressbar.set_fraction(1) + +class SoundChooserDialog: + def __init__(self, path_to_snd_file = ''): + '''optionally accepts path_to_snd_file so it has that as selected''' + self.dialog = gtk.FileChooserDialog(_('Choose Sound'), None, + gtk.FILE_CHOOSER_ACTION_OPEN, + (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, gtk.RESPONSE_OK)) + self.dialog.set_default_response(gtk.RESPONSE_OK) + last_sounds_dir = gajim.config.get('last_sounds_dir') + if last_sounds_dir and os.path.isdir('last_sounds_dir'): + self.dialog.set_current_folder(last_sounds_dir) + else: + self.dialog.set_current_folder(gajim.HOME_DIR) + + filter = gtk.FileFilter() + filter.set_name(_('All files')) + filter.add_pattern('*') + self.dialog.add_filter(filter) + + filter = gtk.FileFilter() + filter.set_name(_('Wav Sounds')) + filter.add_pattern('*.wav') + self.dialog.add_filter(filter) + self.dialog.set_filter(filter) + + self.path_to_snd_file = path_to_snd_file + self.dialog.set_filename(self.path_to_snd_file) + + self.path_to_snd_file = '' + while True: + response = self.dialog.run() + if response != gtk.RESPONSE_OK: + break + self.path_to_snd_file = self.dialog.get_filename() + try: + self.path_to_snd_file = path_to_snd_file.decode( + sys.getfilesystemencoding()) + except: + pass + if os.path.exists(self.path_to_snd_file): + break + + +class AddSpecialNotificationDialog: + def __init__(self, jid): + '''jid is the jid for which we want to add special notification + (sound and notification popups)''' + self.xml = gtk.glade.XML(GTKGUI_GLADE, 'add_special_notification_window', + APP) + self.window = self.xml.get_widget('add_special_notification_window') + self.condition_combobox = self.xml.get_widget('condition_combobox') + self.condition_combobox.set_active(0) + self.notification_popup_yes_no_combobox = self.xml.get_widget( + 'notification_popup_yes_no_combobox') + self.notification_popup_yes_no_combobox.set_active(0) + self.listen_sound_combobox = self.xml.get_widget('listen_sound_combobox') + self.listen_sound_combobox.set_active(0) + + + self.jid = jid + self.xml.get_widget('when_foo_becomes_label').set_text( + _('When %s becomes:') % self.jid) + + + self.window.set_title(_('Adding Special Notification for %s') % jid) + self.window.show_all() + self.xml.signal_autoconnect(self) + + def on_cancel_button_clicked(self, widget): + self.window.destroy() + + def on_add_special_notification_window_delete_event(self, widget, event): + self.window.destroy() + + def on_listen_sound_combobox_changed(self, widget): + model = widget.get_model() + active = widget.get_active() + if active == 1: # user selected 'choose sound' + dlg_instance = SoundChooserDialog() + path_to_snd_file = dlg_instance.path_to_snd_file + dlg_instance.dialog.destroy() + + if path_to_snd_file: + print path_to_snd_file + else: # user selected nothing (X button or Cancel) + widget.set_active(0) # go back to No Sound + #model[iter][0] = + + def on_ok_button_clicked(self, widget): + conditions = ('online', 'chat', 'online_and_chat', + 'away', 'xa', 'away_and_xa', 'dnd', 'xa_and_dnd', 'offline') + active = self.condition_combobox.get_active() + print conditions[active] + + active_iter = self.listen_sound_combobox.get_active_iter() + listen_sound_model = self.listen_sound_combobox.get_model() + print listen_sound_model[active_iter][0] diff --git a/src/gtkgui.glade b/src/gtkgui.glade index e1056317d..db8da05e1 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -15218,7 +15218,7 @@ Banner True - + True gtk-jump-to 1 @@ -15238,7 +15238,7 @@ Banner True - + True gtk-new 1 @@ -15257,7 +15257,7 @@ Banner True - + True gtk-refresh 1 @@ -15278,7 +15278,7 @@ Banner - + True @@ -15288,10 +15288,9 @@ Banner True Send File True - - + True gtk-file 1 @@ -15311,7 +15310,7 @@ Banner - + True gtk-dialog-authentication 1 @@ -15324,6 +15323,26 @@ Banner + + + True + Add Special _Notification + True + + + + True + gtk-info + 1 + 0.5 + 0.5 + 0 + 0 + + + + + True @@ -15336,7 +15355,7 @@ Banner True - + True gtk-dialog-question 1 @@ -15357,7 +15376,7 @@ Banner True - + True gtk-go-up 1 @@ -15377,7 +15396,7 @@ Banner True - + True gtk-go-down 1 @@ -15395,10 +15414,9 @@ Banner True Forbid him/her to see my status True - - + True gtk-stop 1 @@ -15421,7 +15439,7 @@ Banner True - + True gtk-add 1 @@ -15440,7 +15458,7 @@ Banner True - + True gtk-remove 1 @@ -15472,7 +15490,7 @@ Banner True - + True gtk-justify-fill 1 @@ -19290,4 +19308,254 @@ topic + + 6 + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + + + + + True + False + 6 + + + + True + <b>Please modify your special notification below</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + 3 + 2 + False + 6 + 12 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Available +Free for Chat +Available or Free for Chat +Away +Not Available +Away or Not Available +Busy +Not Available or Busy +Offline + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + True + I want a notification popup: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + I want to listen to: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + Nothing +Select Sound... + False + True + + + + 1 + 2 + 2 + 3 + fill + fill + + + + + + True + Yes +No + False + True + + + 1 + 2 + 1 + 2 + fill + fill + + + + + 0 + False + False + + + + + + True + GTK_BUTTONBOX_END + 6 + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + + + + + + 0 + False + False + + + + + + diff --git a/src/roster_window.py b/src/roster_window.py index 646b58f94..bc0940c6a 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1095,7 +1095,7 @@ class RosterWindow: gajim.interface.instances['logs'][contact.jid] = history_window.\ HistoryWindow(contact.jid, account) - def on_send_single_message_menuitem_activate(self, wiget, account, + def on_send_single_message_menuitem_activate(self, widget, account, contact = None): if contact is None: dialogs.SingleMessageWindow(account, action = 'send') @@ -1105,6 +1105,9 @@ class RosterWindow: def on_send_file_menuitem_activate(self, widget, account, contact): gajim.interface.instances['file_transfers'].show_file_send_request( account, contact) + + def on_add_special_notification_menuitem_activate(self, widget, jid): + dialogs.AddSpecialNotificationDialog(jid) def mk_menu_user(self, event, iter): '''Make contact's popup menu''' @@ -1118,25 +1121,28 @@ class RosterWindow: APP) roster_contact_context_menu = xml.get_widget( 'roster_contact_context_menu') - childs = roster_contact_context_menu.get_children() + #childs = roster_contact_context_menu.get_children() - start_chat_menuitem = childs[0] - send_single_message_menuitem = childs[1] - rename_menuitem = childs[2] - edit_groups_menuitem = childs[3] - # separator4 goes with assign_openpgp_key_menuitem - assign_openpgp_separator = childs[4] - send_file_menuitem = childs[5] - assign_openpgp_key_menuitem = childs[6] + start_chat_menuitem = xml.get_widget('start_chat_menuitem') + send_single_message_menuitem = xml.get_widget('send_single_message_menuitem') + rename_menuitem = xml.get_widget('rename_menuitem') + edit_groups_menuitem = xml.get_widget('edit_groups_menuitem') + # separator has with send file, assign_openpgp_key_menuitem, etc.. + above_send_file_separator = xml.get_widget('above_send_file_separator') + send_file_menuitem = xml.get_widget('send_file_menuitem') + assign_openpgp_key_menuitem = xml.get_widget('assign_openpgp_key_menuitem') + add_special_notification_menuitem = xml.get_widget( + 'add_special_notification_menuitem') #skip a seperator + subscription_menuitem = xml.get_widget('subscription_menuitem') send_auth_menuitem, ask_auth_menuitem, revoke_auth_menuitem =\ - childs[8].get_submenu().get_children() - add_to_roster_menuitem = childs[9] - remove_from_roster_menuitem = childs[10] + subscription_menuitem.get_submenu().get_children() + add_to_roster_menuitem = xml.get_widget('add_to_roster_menuitem') + remove_from_roster_menuitem = xml.get_widget('remove_from_roster_menuitem') #skip a seperator - information_menuitem = childs[12] - history_menuitem = childs[13] + information_menuitem = xml.get_widget('information_menuitem') + history_menuitem = xml.get_widget('history_menuitem') contacts = gajim.contacts.get_contact(account, jid) if len(contacts) > 1: # sevral resources @@ -1198,6 +1204,8 @@ class RosterWindow: send_auth_menuitem.connect('activate', self.authorize, jid, account) if contact.sub in ('to', 'both'): ask_auth_menuitem.set_sensitive(False) + add_special_notification_menuitem.connect('activate', + self.on_add_special_notification_menuitem_activate, jid) else: ask_auth_menuitem.connect('activate', self.req_sub, jid, _('I would like to add you to my roster'), account) @@ -1212,8 +1220,8 @@ class RosterWindow: edit_groups_menuitem.hide() edit_groups_menuitem.set_no_show_all(True) # hide first of the two consecutive separators - assign_openpgp_separator.hide() - assign_openpgp_separator.set_no_show_all(True) + above_send_file_separator.hide() + above_send_file_separator.set_no_show_all(True) assign_openpgp_key_menuitem.hide() assign_openpgp_key_menuitem.set_no_show_all(True)