Ticket #1106: donotnotifywhenV2.patch

File donotnotifywhenV2.patch, 18.6 kB (added by Jim++, 3 years ago)
  • src/roster_window.py

     
    4040import cell_renderer_image 
    4141import tooltips 
    4242import message_control 
     43import notify 
    4344 
    4445from common import gajim 
    4546from common import helpers 
     
    18561857                        path = None 
    18571858                autopopup = gajim.config.get('autopopup') 
    18581859                autopopupaway = gajim.config.get('autopopupaway') 
     1860                do_not_notify_when = gajim.config.get('do_not_notify_when') 
    18591861 
    18601862                # Do we have a queue? 
    18611863                qs = gajim.awaiting_events[account] 
     
    18631865                if qs.has_key(jid): 
    18641866                        no_queue = False 
    18651867                popup = False 
    1866                 if autopopup and (autopopupaway or gajim.connections[account].connected \ 
    1867                         in (1, 2)): 
     1868                if autopopup and notify.want_notify(gajim.connections[account].connected): 
    18681869                        popup = True 
    18691870 
    18701871                if msg_type == 'normal' and popup: # it's single message to be autopopuped 
     
    23682369                self.make_jabber_state_images() 
    23692370                # Update the roster 
    23702371                self.draw_roster() 
     2372                print "reload" 
    23712373                # Update the status combobox 
    23722374                model = self.status_combobox.get_model() 
    23732375                iter = model.get_iter_root() 
  • src/config.py

     
    7272                        'notify_on_signin_checkbutton') 
    7373                self.notify_on_signout_checkbutton = self.xml.get_widget( 
    7474                        'notify_on_signout_checkbutton') 
    75                 self.auto_popup_away_checkbutton = self.xml.get_widget( 
    76                         'auto_popup_away_checkbutton') 
    7775                self.auto_away_checkbutton = self.xml.get_widget('auto_away_checkbutton') 
    7876                self.auto_away_time_spinbutton = self.xml.get_widget( 
    7977                        'auto_away_time_spinbutton') 
     
    169167                model = gtk.ListStore(str) 
    170168                theme_combobox.set_model(model) 
    171169 
     170                # Do not notify when 
     171                do_not_notify_when_combobox = self.xml.get_widget('do_not_notify_when_combobox') 
     172                cell = gtk.CellRendererText() 
     173                do_not_notify_when_combobox.pack_start(cell, True) 
     174                do_not_notify_when_combobox.add_attribute(cell, 'text', 0) 
     175                model = gtk.ListStore(str) 
     176                do_not_notify_when_combobox.set_model(model) 
     177 
    172178                #use speller 
    173179                if os.name == 'nt': 
    174180                        self.xml.get_widget('speller_checkbutton').set_no_show_all(True) 
     
    257263                st = gajim.config.get('notify_on_signout') 
    258264                self.notify_on_signout_checkbutton.set_active(st) 
    259265 
    260                 #autopopupaway 
    261                 st = gajim.config.get('autopopupaway') 
    262                 self.auto_popup_away_checkbutton.set_active(st) 
    263  
    264266                #Ignore messages from unknown contacts 
    265267                self.xml.get_widget('ignore_events_from_unknown_contacts_checkbutton').\ 
    266268                        set_active(gajim.config.get('ignore_unknown_contacts')) 
     
    443445                        i += 1 
    444446                self.on_theme_combobox_changed(theme_combobox) 
    445447                 
     448                #Do not notify when 
     449                do_not_notify_when_combobox = self.xml.get_widget('do_not_notify_when_combobox') 
     450                model = do_not_notify_when_combobox.get_model() 
     451                model.clear() 
     452                 
     453                do_not_notify_when_list = ['dnd','away xa dnd invisible'] 
     454                custom = True 
     455                always_text = _('Always notify') 
     456                 
     457                #Always notify part, config option is empty 
     458                model.append([always_text]) 
     459                if gajim.config.get('do_not_notify_when') == '': 
     460                        do_not_notify_when_combobox.set_active(0) 
     461                        custom = False 
     462         
     463                i = 1 # line 0 was just before           
     464                for config_do_not_notify_when in do_not_notify_when_list: 
     465                        model.append([config_do_not_notify_when]) 
     466                        if gajim.config.get('do_not_notify_when') == config_do_not_notify_when: 
     467                                do_not_notify_when_combobox.set_active(i) 
     468                                custom = False 
     469                        i += 1 
     470                if custom: 
     471                        custom_text = _('Custom') 
     472                        model.append([custom_text]) 
     473                        do_not_notify_when_combobox.set_active(i) 
     474                         
     475                self.on_do_not_notify_when_combobox_changed(do_not_notify_when_combobox) 
     476                 
    446477                # Notify user of new gmail e-mail messages, 
    447478                # only show checkbox if user has a gtalk account 
    448479                self.xml.get_widget('notify_gmail_checkbutton').hide() 
     
    548579                gajim.interface.roster.repaint_themed_widgets() 
    549580                gajim.interface.roster.change_roster_style(None) 
    550581                gajim.interface.save_config() 
     582                 
     583        def on_do_not_notify_when_combobox_changed(self, widget): 
     584                model = widget.get_model() 
     585                active = widget.get_active() 
     586                config_do_not_notify_when = model[active][0].decode('utf-8') 
     587                 
     588                custom_text = _('Custom') 
     589                if config_do_not_notify_when <> custom_text: 
     590                #Do not save "Custom", don't touch anything 
     591                        always_text = _('Always notify') 
     592                        if config_do_not_notify_when == always_text: 
     593                        #Always notify : empty status list 
     594                                config_do_not_notify_when='' 
     595                        gajim.config.set('do_not_notify_when', config_do_not_notify_when) 
     596                        gajim.interface.save_config()    
    551597 
    552598        def on_one_window_type_combo_changed(self, widget): 
    553599                active = widget.get_active() 
     
    681727                gajim.interface.save_config() 
    682728 
    683729        def on_notify_on_new_message_radiobutton_toggled(self, widget): 
    684                 self.on_checkbutton_toggled(widget, 'notify_on_new_message', 
    685                                         [self.auto_popup_away_checkbutton]) 
     730                self.on_checkbutton_toggled(widget, 'notify_on_new_message') 
    686731 
    687732        def on_popup_new_message_radiobutton_toggled(self, widget): 
    688                 self.on_checkbutton_toggled(widget, 'autopopup', 
    689                                         [self.auto_popup_away_checkbutton]) 
     733                self.on_checkbutton_toggled(widget, 'autopopup') 
    690734 
    691         def on_only_in_roster_radiobutton_toggled(self, widget): 
    692                 if widget.get_active(): 
    693                         self.auto_popup_away_checkbutton.set_sensitive(False) 
    694  
    695735        def on_notify_on_signin_checkbutton_toggled(self, widget): 
    696736                self.on_checkbutton_toggled(widget, 'notify_on_signin') 
    697737 
    698738        def on_notify_on_signout_checkbutton_toggled(self, widget): 
    699739                self.on_checkbutton_toggled(widget, 'notify_on_signout') 
    700740 
    701         def on_auto_popup_away_checkbutton_toggled(self, widget): 
    702                 self.on_checkbutton_toggled(widget, 'autopopupaway') 
    703  
    704741        def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget): 
    705742                self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts') 
    706743 
  • src/notify.py

     
    4747                import dbus.glib 
    4848                import dbus.service 
    4949 
     50STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', 
     51        'invisible'] 
     52         
    5053def notify(event_type, jid, account, msg_type = '', path_to_image = None, 
    5154        text = None): 
    5255        '''Notifies a user of an event. It first tries to a valid implementation of 
     
    6568                        gajim.log.debug(str(e)) 
    6669        instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, text) 
    6770        gajim.interface.roster.popup_notification_windows.append(instance) 
     71         
     72         
     73def want_notify(status): 
     74        '''Tell if we want to be notified by sounds/popup and want to auto open  
     75        messages depending of our status (and config)''' 
     76        do_not_notify_when = gajim.config.get('do_not_notify_when').split(' ')  
     77        if STATUS_LIST[status] not in do_not_notify_when: 
     78                return True 
     79        else:  
     80                return False 
     81         
    6882 
    6983class NotificationResponseManager: 
    7084        '''Collects references to pending DesktopNotifications and manages there 
  • src/gtkgui.glade

     
    48624862                              <property name="fill">True</property> 
    48634863                            </packing> 
    48644864                          </child> 
    4865  
     4865                           
    48664866                          <child> 
    4867                             <widget class="GtkCheckButton" id="auto_popup_away_checkbutton"> 
     4867                            <widget class="GtkHBox" id="hbox2957"> 
    48684868                              <property name="visible">True</property> 
    4869                               <property name="can_focus">True</property> 
    4870                               <property name="label" translatable="yes">Allow popup/notifications when I'm _away/na/busy/invisible</property> 
    4871                               <property name="use_underline">True</property> 
    4872                               <property name="relief">GTK_RELIEF_NORMAL</property> 
    4873                               <property name="focus_on_click">True</property> 
    4874                               <property name="active">False</property> 
    4875                               <property name="inconsistent">False</property> 
    4876                               <property name="draw_indicator">True</property> 
    4877                               <signal name="toggled" handler="on_auto_popup_away_checkbutton_toggled" last_modification_time="Wed, 06 Apr 2005 12:46:30 GMT"/> 
     4869                              <property name="homogeneous">False</property> 
     4870                              <property name="spacing">12</property> 
     4871 
     4872                              <child> 
     4873                                <widget class="GtkLabel" id="label250"> 
     4874                                  <property name="visible">True</property> 
     4875                                  <property name="label" translatable="yes">Do not disturb me with popups/sounds/auto open when I'm :</property> 
     4876                                  <property name="use_underline">False</property> 
     4877                                  <property name="use_markup">False</property> 
     4878                                  <property name="justify">GTK_JUSTIFY_LEFT</property> 
     4879                                  <property name="wrap">False</property> 
     4880                                  <property name="selectable">False</property> 
     4881                                  <property name="xalign">0.5</property> 
     4882                                  <property name="yalign">0.5</property> 
     4883                                  <property name="xpad">0</property> 
     4884                                  <property name="ypad">0</property> 
     4885                                  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> 
     4886                                  <property name="width_chars">-1</property> 
     4887                                  <property name="single_line_mode">False</property> 
     4888                                  <property name="angle">0</property> 
     4889                                </widget> 
     4890                                <packing> 
     4891                                  <property name="padding">0</property> 
     4892                                  <property name="expand">False</property> 
     4893                                  <property name="fill">False</property> 
     4894                                </packing> 
     4895                              </child> 
     4896 
     4897                              <child> 
     4898                                <widget class="GtkComboBox" id="do_not_notify_when_combobox"> 
     4899                                  <property name="visible">True</property> 
     4900                                  <property name="add_tearoffs">False</property> 
     4901                                  <property name="focus_on_click">True</property> 
     4902                                  <signal name="changed" handler="on_do_not_notify_when_combobox_changed" last_modification_time="Fri, 29 Apr 2005 11:44:52 GMT"/> 
     4903                                </widget> 
     4904                                <packing> 
     4905                                  <property name="padding">0</property> 
     4906                                  <property name="expand">False</property> 
     4907                                  <property name="fill">True</property> 
     4908                                </packing> 
     4909                              </child> 
     4910 
    48784911                            </widget> 
    4879                             <packing> 
    4880                               <property name="padding">0</property> 
    4881                               <property name="expand">False</property> 
    4882                               <property name="fill">False</property> 
    4883                             </packing> 
     4912                         
    48844913                          </child> 
    4885                         </widget> 
     4914                    </widget> 
    48864915                      </child> 
    48874916                    </widget> 
    48884917                  </child> 
  • src/gajim.py

     
    387387                        if array[1] in ('offline', 'error'): 
    388388                                contact1.our_chatstate = contact1.chatstate = None 
    389389                        self.roster.chg_contact_status(contact1, array[1], array[2], account) 
    390                         # play sound 
    391390                        if old_show < 2 and new_show > 1: 
    392                                 if gajim.config.get_per('soundevents', 'contact_connected', 
    393                                         'enabled') and gajim.allow_notifications[account]: 
    394                                         helpers.play_sound('contact_connected') 
    395                                 if not gajim.interface.msg_win_mgr.has_window(jid, account) and \ 
    396                                         not gajim.awaiting_events[account].has_key(jid) and \ 
    397                                         gajim.config.get('notify_on_signin') and \ 
    398                                         gajim.allow_notifications[account]: 
    399                                         show_notification = False 
    400                                         # check OUR status and if we allow notifications for that status 
    401                                         if gajim.config.get('autopopupaway'): # always notify 
    402                                                 show_notification = True 
    403                                         elif gajim.connections[account].connected in (2, 3): 
    404                                                 # we're online or chat 
    405                                                 show_notification = True 
    406                                         if show_notification: 
     391                                # check OUR status and if we allow notifications for that status 
     392                                if notify.want_notify(gajim.connections[account].connected): 
     393                                        # play sound                                     
     394                                        if gajim.config.get_per('soundevents', 'contact_connected', 
     395                                                'enabled') and gajim.allow_notifications[account]: 
     396                                                helpers.play_sound('contact_connected') 
     397                                        if not gajim.interface.msg_win_mgr.has_window(jid, account) and \ 
     398                                                not gajim.awaiting_events[account].has_key(jid) and \ 
     399                                                gajim.config.get('notify_on_signin') and \ 
     400                                                gajim.allow_notifications[account]: 
     401         
    407402                                                transport_name = gajim.get_transport_name_from_jid(jid) 
    408403                                                img = None 
    409404                                                if transport_name: 
     
    424419                                                (account, array)) 
    425420                                 
    426421                        elif old_show > 1 and new_show < 2: 
    427                                 if gajim.config.get_per('soundevents', 'contact_disconnected', 
    428                                                 'enabled'): 
    429                                         helpers.play_sound('contact_disconnected') 
    430                                 if not gajim.interface.msg_win_mgr.has_window(jid, account) and \ 
    431                                         not gajim.awaiting_events[account].has_key(jid) and \ 
    432                                         gajim.config.get('notify_on_signout'): 
    433                                         show_notification = False 
    434                                         # check OUR status and if we allow notifications for that status 
    435                                         if gajim.config.get('autopopupaway'): # always notify 
    436                                                 show_notification = True 
    437                                         elif gajim.connections[account].connected in (2, 3): 
    438                                                 # we're online or chat 
    439                                                 show_notification = True 
    440                                         if show_notification: 
     422                                # check OUR status and if we allow notifications for that status 
     423                                if notify.want_notify(gajim.connections[account].connected): 
     424                                        # play sound                                     
     425                                        if gajim.config.get_per('soundevents', 'contact_disconnected', 
     426                                                        'enabled'): 
     427                                                helpers.play_sound('contact_disconnected') 
     428                                        if not gajim.interface.msg_win_mgr.has_window(jid, account) and \ 
     429                                                not gajim.awaiting_events[account].has_key(jid) and \ 
     430                                                gajim.config.get('notify_on_signout'): 
     431 
    441432                                                transport_name = gajim.get_transport_name_from_jid(jid) 
    442433                                                img = None 
    443434                                                if transport_name: 
     
    473464                if jid.find('@') <= 0: 
    474465                        jid = jid.replace('@', '') 
    475466 
    476                 show_notification = False 
    477                 if gajim.config.get('notify_on_new_message'): 
    478                         # check OUR status and if we allow notifications for that status 
    479                         if gajim.config.get('autopopupaway'): # always show notification 
    480                                 show_notification = True 
    481                         elif gajim.connections[account].connected in (2, 3): # we're online or chat 
    482                                 show_notification = True 
     467                # check OUR status and if we allow notifications for that status 
     468                show_notification = notify.want_notify(gajim.connections[account].connected) 
    483469 
    484470                chat_control = gajim.interface.msg_win_mgr.get_control(jid, account) 
    485471                if chat_control and chat_control.type_id == message_control.TYPE_GC: 
     
    488474                        fjid = array[0] 
    489475                        if not gajim.interface.msg_win_mgr.has_window(fjid, account) and \ 
    490476                                not gajim.awaiting_events[account].has_key(fjid): 
    491                                 if show_notification: 
     477                                if gajim.config.get('notify_on_new_message') and show_notification: 
    492478                                        room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid) 
    493479                                        room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid) 
    494480                                        txt = _('%(nickname)s in room %(room_name)s has sent you a new message.')\ 
     
    531517                not gajim.awaiting_events[account].has_key(jid): 
    532518                        first = True 
    533519                        if gajim.config.get('notify_on_new_message'): 
    534                                 show_notification = False 
    535                                 # check OUR status and if we allow notifications for that status 
    536                                 if gajim.config.get('autopopupaway'): # always show notification 
    537                                         show_notification = True 
    538                                 elif gajim.connections[account].connected in (2, 3): # we're online or chat 
    539                                         show_notification = True 
    540520                                if show_notification: 
    541521                                        txt = _('%s has sent you a new message.') % gajim.get_name_from_jid(account, jid) 
    542522                                        if msg_type == 'normal': # single message 
     
    556536                self.roster.on_message(jid, array[1], array[2], account, array[3], 
    557537                        msg_type, array[5], resource) 
    558538                if gajim.config.get_per('soundevents', 'first_message_received', 
    559                         'enabled') and first: 
     539                        'enabled') and show_notification and first: 
    560540                        helpers.play_sound('first_message_received') 
    561                 if gajim.config.get_per('soundevents', 'next_message_received', 
    562                         'enabled') and not first: 
     541                elif gajim.config.get_per('soundevents', 'next_message_received', 
     542                        'enabled') and show_notification and not first: 
    563543                        helpers.play_sound('next_message_received') 
    564544                if self.remote_ctrl: 
    565545                        self.remote_ctrl.raise_signal('NewMessage', (account, array)) 
    566  
     546                         
    567547        def handle_event_msgerror(self, account, array): 
    568548                #('MSGERROR', account, (jid, error_code, error_msg, msg, time)) 
    569549                fjid = array[0] 
     
    606586                #('MSGSENT', account, (jid, msg, keyID)) 
    607587                msg = array[1] 
    608588                # do not play sound when standalone chatstate message (eg no msg) 
    609                 if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'): 
     589                if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled')\ 
     590                and notify.want_notify(gajim.connections[account].connected): 
    610591                        helpers.play_sound('message_sent') 
    611592                 
    612593        def handle_event_subscribe(self, account, array): 
     
    11201101                        txt = '' 
    11211102 
    11221103                if gajim.config.get('notify_on_file_complete') and \ 
    1123                         (gajim.config.get('autopopupaway') or \ 
    1124                         gajim.connections[account].connected in (2, 3)): 
    1125                         # we want to be notified and we are online/chat or we don't mind 
    1126                         # bugged when away/na/busy 
     1104                        notify.want_notify(gajim.connections[account].connected): 
     1105                        # want_notify() tell us if we want to be notified depending on our status 
    11271106                        notify.notify(event_type, jid, account, msg_type, path_to_image = path, text = txt) 
    11281107 
    11291108        def handle_event_stanza_arrived(self, account, stanza): 
  • src/groupchat_control.py

     
    3535import cell_renderer_image 
    3636import history_window 
    3737import tooltips 
     38import notify 
    3839 
    3940from common import gajim 
    4041from common import helpers 
     
    415416 
    416417                # Do we play a sound on every muc message? 
    417418                if gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'): 
    418                         if gajim.config.get('notify_on_all_muc_messages'): 
     419                        if gajim.config.get('notify_on_all_muc_messages') \ 
     420                        and notify.want_notify(gajim.connections[self.account].connected): 
    419421                                sound = 'received' 
    420422 
    421423                # Are any of the defined highlighting words in the text? 
    422424                if self.needs_visual_notification(text): 
    423425                        highlight = True 
    424                         if gajim.config.get_per('soundevents', 'muc_message_highlight', 
    425                                                                         'enabled'): 
     426                        if gajim.config.get_per('soundevents', 'muc_message_highlight', 'enabled')\ 
     427                        and notify.want_notify(gajim.connections[self.account].connected): 
    426428                                sound = 'highlight' 
    427429 
    428430                # Is it a history message? Don't want sound-floods when we join. 
  • src/common/config.py

     
    5252                'notify_on_signout': [ opt_bool, False ], 
    5353                'notify_on_new_message': [ opt_bool, True ], 
    5454                'autopopupaway': [ opt_bool, False ], 
     55                'do_not_notify_when': [ opt_str, '' , _('List of all status for which we don\'t want popups/sounds/auto open new messages, separated with a space (online chat away xa dnd invisible)')],        
    5556                'use_notif_daemon': [ opt_bool, True , _('Use DBus and Notification-Daemon to show notifications') ], 
    5657                'ignore_unknown_contacts': [ opt_bool, False ], 
    5758                'showoffline': [ opt_bool, False ],