def update(self, lock): """ Check if an error sound has to be played or if a watch has to be flagged updated. """ #play error sound if self.error == True and self.specto.specto_gconf.get_entry( "use_problem_sound"): problem_sound = self.specto.specto_gconf.get_entry("problem_sound") gnome.sound_play(problem_sound) pop_toast = self.specto.specto_gconf.get_entry("pop_toast") if (pop_toast == True) and (self.specto.GTK): NotificationToast( self.specto, _("The watch, <b>%s</b>, has a problem. You may need to check the error log." ) % self.name, self.specto.icon_theme.load_icon("error", 64, 0), urgency="critical" ) #fixme: not sure if that's possible, but this has no self.tray_x, self.tray_y, because we cannot be sure that the tray icon is actually displayed already #call update function if watch was updated if self.actually_updated: #we want to notify, but ONLY if it has not been marked as updated already try: self.specto.toggle_updated( self.id ) #call the main function to update the notifier entry. We need to use a try statement in case the watch was already toggled in the notifier entry. except: if self.specto.DEBUG: self.specto.logger.log( _("Watch \"%s\" is already marked as updated in the notifier" ) % self.name, "info", self.__class__) else: pass self.specto.count_updated_watches() self.notify() self.updated = True self.actually_updated = False self.timer_id = gobject.timeout_add(self.refresh, self.thread_update) lock.release()
def __init__(self, specto): """ In this init we are going to display the main notifier window. """ self.specto = specto uifile = os.path.join(self.specto.PATH, "uis/notifier.ui") windowname = "notifier" self.builder = gtk.Builder() self.builder.set_translation_domain("specto") self.builder.add_from_file(uifile) self.notifier = self.builder.get_object("notifier") if INDICATOR: self.indicator = Indicator(specto) self.tray = None else: self.tray = Tray(specto, self) self.indicator = None if SOUND: self.sound = Sound() else: self.sound = None self.balloon = NotificationToast(specto, self) self.preferences_initialized = False #create tree self.iter = {} self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, pango.Weight) #catch some events dic = { "on_add_activate": self.show_add_watch_menu, "on_edit_activate": self.show_edit_watch, "on_clear_all_activate": self.mark_all_as_read, "on_preferences_activate": self.show_preferences, "on_refresh_activate": self.refresh_all_watches, "on_close_activate": self.close_event, "on_quit_activate": self.delete_event, "on_import_watches_activate": self.import_watches, "on_export_watches_activate": self.export_watches, "on_error_log_activate": self.show_error_log, "on_display_all_watches_activate": self.toggle_show_deactivated_watches, "on_display_toolbar_activate": self.toggle_display_toolbar, "on_help_activate": self.show_help, "on_about_activate": self.show_about, "on_treeview_row_activated": self.open_watch_callback, "on_btnOpen_clicked": self.open_watch_callback, "on_btnClear_clicked": self.mark_watch_as_read, "on_treeview_cursor_changed": self.show_watch_info, "on_btnEdit_clicked": self.show_edit_watch, "on_by_watch_type_activate": self.sort_type, "on_by_name_activate": self.sort_name, "on_by_watch_active_activate": self.sort_active, "on_remove_clicked": self.remove_watch, "on_clear_activate": self._mark_watch_as_read, "on_remove_activate": self.remove_watch } self.builder.connect_signals(dic) self.notifier.set_icon_from_file(self.specto.LOGO_PATH) self.specto.notifier_initialized = True self.create_notifier_gui() self.stop_refresh = False
def notify(self): """ Notify the user when a watch was updated. """ global _ if self.specto.DEBUG or not self.specto.GTK: self.specto.logger.log( _("Watch \"%s\" updated!") % self.name, "info", self.__class__) #play a sound update_sound = self.specto.specto_gconf.get_entry("update_sound") if self.specto.specto_gconf.get_entry("use_update_sound"): gnome.sound_play(update_sound) #determine if libnotify support is to be used pop_toast = self.specto.specto_gconf.get_entry("pop_toast") if (pop_toast == True) and (self.specto.GTK): sleep( 0.5 ) #this is an important hack :) the reason why there is a sleep of half a second is to leave time for the tray icon to appear before getting its coordinates self.tray_x = self.specto.tray.get_x() self.tray_y = self.specto.tray.get_y() if self.type == 0: #web NotificationToast( self.specto, _("The website, <b>%s</b>, has been updated.") % str(self.name), self.specto.icon_theme.load_icon("applications-internet", 64, 0), self.tray_x, self.tray_y, name=self.name) elif self.type == 1: #email if self.prot == 0: #pop3 account notification_toast = i18n._translation.ungettext(\ # English singular form: (_("Your email account, <b>%s</b>, has <b>%d</b> new mail.") % (self.name, self.newMsg)),\ # English plural form: (_("Your email account, <b>%s</b>, has <b>%d</b> new unread mails, totalling %s") % (self.name, self.newMsg, self.oldMsg)),\ self.oldMsg) elif self.prot == 1: #imap account notification_toast = _( "Your email account, <b>%s</b>, has new mail.") % str( self.name) elif self.prot == 2: #gmail notification_toast = i18n._translation.ungettext(\ # English singular form: (_("Your email account, <b>%s</b>, has <b>%d</b> new mail.") % (self.name, self.newMsg)),\ # English plural form: (_("Your email account, <b>%s</b>, has <b>%d</b> new unread mails, totalling %s") % (self.name, self.newMsg, self.oldMsg)),\ self.oldMsg) if notification_toast: NotificationToast(self.specto, notification_toast, self.specto.icon_theme.load_icon( "emblem-mail", 64, 0), self.tray_x, self.tray_y, name=self.name) elif self.type == 2: #folder NotificationToast( self.specto, _("The file/folder, <b>%s</b>, has been updated.") % self.name, self.specto.icon_theme.load_icon("folder", 64, 0), self.tray_x, self.tray_y, name=self.name) elif self.type == 3: #process if self.running == False: NotificationToast( self.specto, _("The process, <b>%s</b>, has stopped.") % self.name, self.specto.icon_theme.load_icon( "applications-system", 64, 0), self.tray_x, self.tray_y) elif self.running == True: NotificationToast( self.specto, _("The process, <b>%s</b>, has started.") % self.name, self.specto.icon_theme.load_icon( "applications-system", 64, 0), self.tray_x, self.tray_y) else: self.specto.logger.log( ("This is a bug. The watch" + str(self.name) + "'s value for self.running is" + str(self.running)), "debug", self.__class__) elif self.type == 4: #port if self.running == False: NotificationToast( self.specto, _("The connection, <b>%s</b>, was closed.") % self.name, self.specto.icon_theme.load_icon( "network-offline", 64, 0), self.tray_x, self.tray_y) elif self.running == True: NotificationToast( self.specto, _("The connection, <b>%s</b>, was established.") % self.name, self.specto.icon_theme.load_icon( "network-transmit-receive", 64, 0), self.tray_x, self.tray_y) else: self.specto.logger.log( ("This is a bug. The watch" + str(self.name) + "'s value for self.running is" + str(self.running)), "debug", self.__class__) elif self.type == 5: #google reader notification_toast = i18n._translation.ungettext(\ # English singular form: (_("Your Google Reader watch, <b>%s</b>, has <b>%d</b> new message.") % (self.name, self.newMsg)),\ # English plural form: (_("Your Google Reader watch, <b>%s</b>, has <b>%d</b> new messages, totalling %s") % (self.name, self.newMsg, self.oldMsg)),\ self.oldMsg) if notification_toast: NotificationToast(self.specto, notification_toast, self.specto.icon_theme.load_icon( "applications-internet", 64, 0), self.tray_x, self.tray_y, name=self.name) else: self.specto.logger.log( _("Not implemented yet"), "warning", self.__class__) #TODO: implement other notifications