Ejemplo n.º 1
0
    def __init__(self):
        """
        Constructor.
        """
        # configuration manager
        self.config = Config(CONFIG_PATH)
        load = self.config.load()

        # systray icon
        self.tray = gtk.StatusIcon()
        self.tray.connect("popup-menu", self.show_menu)
        self.new_activities(False)

        self._create_menu()

        # window to show the activities
        self.box = NotificationBox(800, self.tray)

        # activities timer
        self.timer = gobject.timeout_add_seconds(self.config.get_or_set("i_delay", 60), self.check_for_activities)
        self.config.subscribe(self._on_delay_change, "i_delay")

        # create an account object
        self._account = Account(self.config.get_or_set("s_nick", ""), self.config.get_or_set("s_pass", ""))
        self.config.subscribe(self._on_nick_change, "s_nick")
        self.config.subscribe(self._on_pass_change, "_s_pass")

        self._taringa = TaringaSession(self._account)

        # TEST
        # ~ status = self._taringa.login()
        # ~ if status:
        # ~ print 'logged'

        # html templates
        self._templates = {
            "notification": """<head>
            <link type="text/css" href="http://o2.t26.net/img/style.css?0.2" rel="stylesheet">
            <link type="text/css" href="http://o2.t26.net/img/ui.css?0.1" rel="stylesheet">
            </head><body><div class="modal-wrapper rounded"><h3>Notificaciones</h3>
            <div class="list" id="notifications-list">%s</div><div class="view-more-list">
            <a style="margin-left:5px;padding:2px;" href="http://www.taringa.net/monitor">
            Ver más</a></div></div></body>"""
        }

        # initialize pynotify
        pynotify.init("Notifinga!")

        # contains the current html
        self._current_html = {"notification": "", "message": "", "shout": ""}
Ejemplo n.º 2
0
class Notifinga(object):
    """ """

    def __init__(self):
        """
        Constructor.
        """
        # configuration manager
        self.config = Config(CONFIG_PATH)
        load = self.config.load()

        # systray icon
        self.tray = gtk.StatusIcon()
        self.tray.connect("popup-menu", self.show_menu)
        self.new_activities(False)

        self._create_menu()

        # window to show the activities
        self.box = NotificationBox(800, self.tray)

        # activities timer
        self.timer = gobject.timeout_add_seconds(self.config.get_or_set("i_delay", 60), self.check_for_activities)
        self.config.subscribe(self._on_delay_change, "i_delay")

        # create an account object
        self._account = Account(self.config.get_or_set("s_nick", ""), self.config.get_or_set("s_pass", ""))
        self.config.subscribe(self._on_nick_change, "s_nick")
        self.config.subscribe(self._on_pass_change, "_s_pass")

        self._taringa = TaringaSession(self._account)

        # TEST
        # ~ status = self._taringa.login()
        # ~ if status:
        # ~ print 'logged'

        # html templates
        self._templates = {
            "notification": """<head>
            <link type="text/css" href="http://o2.t26.net/img/style.css?0.2" rel="stylesheet">
            <link type="text/css" href="http://o2.t26.net/img/ui.css?0.1" rel="stylesheet">
            </head><body><div class="modal-wrapper rounded"><h3>Notificaciones</h3>
            <div class="list" id="notifications-list">%s</div><div class="view-more-list">
            <a style="margin-left:5px;padding:2px;" href="http://www.taringa.net/monitor">
            Ver más</a></div></div></body>"""
        }

        # initialize pynotify
        pynotify.init("Notifinga!")

        # contains the current html
        self._current_html = {"notification": "", "message": "", "shout": ""}

    def _create_menu(self):
        """
        Create the pop-up menu.
        """
        self.menu = gtk.Menu()
        notifications = gtk.MenuItem("Notificaciones")
        notifications.connect("activate", self.show_notifications)
        self.menu.append(notifications)

        messages = gtk.MenuItem("Mensajes")
        messages.connect("activate", self.show_messages)
        self.menu.append(messages)

        shouts = gtk.MenuItem("Shouts")
        # shouts.connect('activate', lambda x: pass)
        self.menu.append(shouts)

        self.menu.append(gtk.SeparatorMenuItem())
        config = gtk.MenuItem("Configuración")
        config.connect("activate", self.show_configuration)
        self.menu.append(config)

        self.menu.append(gtk.SeparatorMenuItem())
        about = gtk.MenuItem("Acerca de")
        about.connect("activate", self.show_about)
        self.menu.append(about)

        exit_app = gtk.MenuItem("Salir")
        exit_app.connect("activate", gtk.main_quit)
        self.menu.append(exit_app)

    def _on_delay_change(self, value):
        """
        Change the activities verification delay.
        
        :param value: new delay
        """
        gobject.source_remove(self.timer)
        self.timer = gobject.timeout_add_seconds(self.config.get_or_set("i_delay", 60), self.check_for_activities)

    def _on_nick_change(self, value):
        """ 
        Change the nick of the account.
        
        :param value: new nick
        """
        self._account.nick = value

    def _on_pass_change(self, value):
        """ 
        Change the password of the account.
        
        :param value: new password
        """
        self._account.passw = value

    def check_for_activities(self):
        """
        """
        new_notif = self._taringa.get_notifications()
        # diff
        if self._current_html["notification"] != new_notif and new_notif != "":
            self._current_html["notification"] = new_notif

        new_msg = self._taringa.get_messages()

        if self._current_html["message"] != new_msg and new_msg != "":
            self._current_html["message"] = new_msg

        # notify new activities!

    def notify_activities(self, notif_num=0, msg_num=0, shout_num=0):
        """
        Crea una burbuja de notificacion mostrando el numero de mensajes,
        notificaciones o shouts nuevos.
        """
        # set body text
        if (notif_num * msg_num * shout_num) != 0:
            text = "Hay %s actividades nuevas!" % (notif_num + msg_num + shout_num)
        elif notif_num:
            text = "Tienes %s notificaciones nuevas!" % (notif_num)
        elif msg_num:
            text = "Tienes %s mensajes nuevos!" % (msg_num)

        bubble = pynotify.Notification("Nuevas actividades", text, "dialog-info")
        bubble.set_urgency(pynotify.URGENCY_NORMAL)
        bubble.set_timeout(self.config.get_or_set("i_bubble_timeout", 5))
        # bubble.attach_to_status_icon(self.tray)
        bubble.show()
        # set callback

        # chequea notif, msgs, shouts
        # si SUCCES -> hace un diff con el html anterior de cada categoria
        #
        #

    def new_activities(self, new):
        """
        Establece el icono y el tooltip de acuerdo a si hay nuevas actividades.

        :param new: numero de actividades nuevas
        """
        if new:
            self.tray.set_from_file(ICON_NEW_ACTIVITY)
            self.tray.set_tooltip("Hay nuevas actividades!")
        else:
            self.tray.set_from_file(ICON_NORMAL)
            self.tray.set_tooltip("No hay actividades nuevas")

    def show_menu(self, icon, event_button, event_time):
        """
        Shows the pop-up menu.

        :param icon:
        :param event_button:
        :param event_time:
        """
        self.menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray)

        self.menu.show_all()

    def show_notifications(self, widget, data=None):
        """
        """
        # ~ html_notif = self._taringa.get_notifications()
        html_notif = " "
        self.box.set_html(self._templates["notification"] % html_notif)
        self.box.resize_and_show(NOTIFICATION_SIZE[0], NOTIFICATION_SIZE[1])

    def show_messages(self, widget, data=None):
        """
        """
        self.box.set_html(message_html)
        self.box.resize_and_show(MESSAGE_SIZE[0], MESSAGE_SIZE[1])

    def show_configuration(self, widget, data=None):
        """
        Create and show the configuration window.

        :param widget:
        :param data:
        """
        config_w = ConfigWindow(self.config)
        config_w.show_all()

    def show_about(self, widget, data=None):
        """
        Create and show the about dialog.

        :param widget:
        :param data:
        """
        about = gtk.AboutDialog()
        about.set_border_width(10)
        about.set_destroy_with_parent(True)
        about.set_logo(gtk.gdk.pixbuf_new_from_file(LOGO))
        about.set_name(NAME)
        about.set_version(VERSION)
        about.set_copyright(COPYRIGHT)
        about.set_comments(DESCRIPTION)
        about.set_authors(AUTHORS)
        about.set_website(WEBSITE)
        about.set_license(LICENSE)
        about.run()
        about.destroy()