def __init__(self):
        self.state = STATE_UNKNOWN
        self.statechange_callback = None

        try:
            # get an event loop
            loop = DBusGMainLoop()

            # get the NetworkManager object from D-Bus
            logger.debug("Connecting to Network Manager via D-Bus")
            bus = dbus.SystemBus(mainloop=loop)
            nmobj = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
            nm = dbus.Interface(nmobj, 'org.freedesktop.NetworkManager')

            # connect the signal handler to the bus
            bus.add_signal_receiver(self.handler, None,
                            'org.freedesktop.NetworkManager',
                            'org.freedesktop.NetworkManager',
                            '/org/freedesktop/NetworkManager')

            # get the current status of the network manager
            self.state = nm.state()
            logger.debug("Current Network Manager status is %d" % self.state)
        except Exception, msg:
            logger.error("Could not connect to the Network Manager: %s" % msg )
Beispiel #2
0
    def update_account(self, account):
        account.new_unread = []
        notifications = {}
        all_inbox = []
        credentials = account.get_credentials()

        #Main inbox
        all_inbox.append(
            ImapBox(account["host"], credentials.username,
                    credentials.password, account["port"],
                    utils.get_boolean(account["ssl"])))

        if 'labels' in account.get_properties():
            labels = []
            labels += [l.strip() for l in account["labels"].split(",")]
            for l in labels:
                if l != '':
                    all_inbox.append(
                        ImapBox(account["host"], credentials.username,
                                credentials.password, account["port"],
                                utils.get_boolean(account["ssl"]), False, l))

        for g in all_inbox:
            mails = g.get_mails()
            logger.debug("Checking label %s: %i" % (g.mbox_dir, len(mails)))
            for mail_id, sub, fr in mails:
                notifications[mail_id] = sub
                if mail_id not in account.notifications:
                    n = Notification(mail_id, sub, fr)
                    account.new_unread.append(n)

        account.notifications = notifications
Beispiel #3
0
    def get_credentials(self, acc):
        self.lock.acquire()
        try:
            logger.debug(
                "Getting credentials with gnome keyring for account %s" %
                (acc.get_name()))
            attrs = gk.Attribute.list_new()
            gk.Attribute.list_append_string(attrs, 'account_name',
                                            acc.get_name())
            try:
                (result,
                 items) = gk.find_items_sync(gk.ItemType.NETWORK_PASSWORD,
                                             attrs)
            except gk.NoMatchError, e:
                items = list()

            if len(items) < 1:
                raise KeyringException(
                    "Cannot find the keyring data for the account %s" %
                    (acc.get_name()))

            logger.debug("items ok")

            username = ''
            for attr in gk.Attribute.list_to_glist(items[0].attributes):
                if attr.name == 'username':
                    username = attr.get_string()
            return Credentials(username, items[0].secret)
    def update_account (self, account):
        account.new_unread = []
        notifications = {}
        all_inbox = []
        credentials = account.get_credentials()

        #Main inbox
        all_inbox.append(ImapBox (account["host"], credentials.username,
            credentials.password, account["port"],
            utils.get_boolean(account["ssl"])))

        if 'labels' in account.get_properties():
            labels = []
            labels += [l.strip() for l in account["labels"].split(",")]
            for l in labels:
                if l != '':
                    all_inbox.append(ImapBox (account["host"], credentials.username,
                        credentials.password, account["port"],
                        utils.get_boolean(account["ssl"]),
                        False, l))

        for g in all_inbox:
            mails = g.get_mails()
            logger.debug("Checking label %s: %i" %(g.mbox_dir, len(mails)))
            for mail_id, sub, fr in mails:
                notifications[mail_id] = sub
                if mail_id not in account.notifications:
                    n = Notification(mail_id, sub, fr)
                    account.new_unread.append (n)

        account.notifications = notifications
Beispiel #5
0
 def on_nm_state_changed (self):
     if self.nm.state == networkmanager.STATE_CONNECTED:
         logger.debug("Network connected")
         #Force update
         self.update_accounts()
     else:
         logger.debug("Network disconnected")
Beispiel #6
0
 def remove_indicator(self, acc):
     logger.debug("remove indicator")
     #If the account is disabled, there is not an indicator
     if acc.indicator:
         self.indmenu.remove(acc.indicator)
     acc.indicator = None
     acc.total_label = None
 def remove_indicator(self, acc):
     logger.debug("remove indicator")
     # If the account is disabled, there is not an indicator
     if acc.indicator:
         self.indmenu.remove(acc.indicator)
     acc.indicator = None
     acc.total_label = None
    def __init__(self):
        self.state = STATE_UNKNOWN
        self.statechange_callback = None

        try:
            # get an event loop
            loop = DBusGMainLoop()

            # get the NetworkManager object from D-Bus
            logger.debug("Connecting to Network Manager via D-Bus")
            bus = dbus.SystemBus(mainloop=loop)
            nmobj = bus.get_object('org.freedesktop.NetworkManager',
                                   '/org/freedesktop/NetworkManager')
            nm = dbus.Interface(nmobj, 'org.freedesktop.NetworkManager')

            # connect the signal handler to the bus
            bus.add_signal_receiver(self.handler, None,
                                    'org.freedesktop.NetworkManager',
                                    'org.freedesktop.NetworkManager',
                                    '/org/freedesktop/NetworkManager')

            # get the current status of the network manager
            self.state = nm.state()
            logger.debug("Current Network Manager status is %d" % self.state)
        except Exception, msg:
            logger.error("Could not connect to the Network Manager: %s" % msg)
Beispiel #9
0
 def store_credentials(self, acc, credentials):
     try:
         logger.debug("Storing base64 credentials for account: %s" % (acc.get_name()))
         acc["username"] = base64.encodestring(credentials.username)
         acc["password"] = base64.encodestring(credentials.password)
     except Exception, e:
         raise KeyringException("Cannot encode the base64 username password for account %s" % (acc.get_name()), e)
 def activate (self):
     if "activate_command" in self.properties and self.properties["activate_command"] != "":
         logger.debug ("Executing the activate command")
         utils.execute_command (self, self.properties["activate_command"])
     elif "activate_url" in self.properties :
         utils.show_url (self.properties["activate_url"])
     else:
         logger.warn('This account type has not an activate action')
Beispiel #11
0
 def __init__(self):
     self._protocol = "network"
     self._key = gk.ITEM_NETWORK_PASSWORD
     if not gk.is_available():
         raise KeyringException("The Gnome keyring is not available")
     logger.debug("default keyring ok")
     self.loaded = False
     self.lock = threading.RLock()
Beispiel #12
0
 def set_active(self, active):
     if active and not self.get_active():
         self.timeout_id = gobject.timeout_add_seconds(self.interval,
                             self.update_accounts, None)
         logger.debug("activated source: "+str(self.timeout_id))
     elif not active and self.get_active():
         gobject.source_remove(self.timeout_id)
         logger.debug("deactivated source "+str(self.timeout_id))
         self.timeout_id = -1
Beispiel #13
0
 def activate(self):
     if "activate_command" in self.properties and self.properties[
             "activate_command"] != "":
         logger.debug("Executing the activate command")
         utils.execute_command(self, self.properties["activate_command"])
     elif "activate_url" in self.properties:
         utils.show_url(self.properties["activate_url"])
     else:
         logger.warn('This account type has not an activate action')
Beispiel #14
0
 def __check_keyring (self):
     if not self.loaded:
         try:
             gk.list_item_ids_sync(self._KEYRING_NAME)
         except Exception, e:
             logger.exception("Error getting the gnome keyring. We'll try to create it: %s",e)
             logger.debug("Creating keyring " + self._KEYRING_NAME)
             gk.create_sync(self._KEYRING_NAME, None)
         self.loaded = True
 def on_indicator_display_cb(self, mmapp, source_id):
     """
     call back when user clicked on sources
     """
     logger.debug("on_indicator_display_cb called")
     for acc in self.am.get_accounts():
         if acc.get_active() and acc.indicator == source_id:
             acc.activate()
             #we also clear the source in account
             acc.indicator = None
Beispiel #16
0
 def on_indicator_display_cb(self, mmapp, source_id):
     """
     call back when user clicked on sources
     """
     logger.debug("on_indicator_display_cb called")
     for acc in self.am.get_accounts():
         if acc.get_active() and acc.indicator == source_id:
             acc.activate()
             #we also clear the source in account
             acc.indicator = None
    def handler(self,signal=None):
        if isinstance(signal, dict):
            state = signal.get('State')
            if state != None:
                logger.debug("Network Manager change state %d => %d" % (self.state, state) );
                self.state = state

                # notify about state change
                if self.statechange_callback != None:
                    self.statechange_callback()
 def create_indicator(self, acc):
     indicator = Indicate.Indicator()
     indicator.set_property("name", acc.get_name())
     indicator.set_property("count", str(acc.get_total_unread()))
     #TODO indicator.set_property_icon("icon", acc.get_icon())
     indicator.show()
     indicator.connect("user-display", self.on_indicator_display_cb)
     acc.indicator = indicator
     indicator.account = acc
     acc.is_error_icon = False
     logger.debug("Indicator created")
 def create_indicator(self, acc):
     indicator = Indicate.Indicator()
     indicator.set_property("name", acc.get_name())
     indicator.set_property("count", str(acc.get_total_unread()))
     #TODO indicator.set_property_icon("icon", acc.get_icon())
     indicator.show()
     indicator.connect("user-display", self.on_indicator_display_cb)
     acc.indicator = indicator
     indicator.account = acc
     acc.is_error_icon = False
     logger.debug("Indicator created")
 def set_active(self, active):
     if active:
         self.server = indicate.indicate_server_ref_default()
         self.server.set_type("message.im")
         self.server.connect("server-display", self.on_server_display_cb)
         self.server.set_desktop_file(config.add_apps_prefix("cloudsn.desktop"))
         self.server.show()
         logger.debug("Indicator server created")
     else:
         #TODO Disable the indicators
         logger.debug("deactivate Not implemented")
    def handler(self, signal=None):
        if isinstance(signal, dict):
            state = signal.get('State')
            if state != None:
                logger.debug("Network Manager change state %d => %d" %
                             (self.state, state))
                self.state = state

                # notify about state change
                if self.statechange_callback != None:
                    self.statechange_callback()
Beispiel #22
0
 def set_active(self, active):
     if active:
         self.server = indicate.indicate_server_ref_default()
         self.server.set_type("message.im")
         self.server.connect("server-display", self.on_server_display_cb)
         self.server.set_desktop_file(
             config.add_apps_prefix("cloudsn.desktop"))
         self.server.show()
         logger.debug("Indicator server created")
     else:
         #TODO Disable the indicators
         logger.debug("deactivate Not implemented")
Beispiel #23
0
 def get_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Getting credentials with gnome keyring for account %s" % (acc.get_name()))
         attrs = {"account_name": acc.get_name()}
         try:
             items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, attrs)
         except gk.NoMatchError, e:
             items = list()
         if len(items) < 1:
             raise KeyringException("Cannot find the keyring data for the account %s" % (acc.get_name()))
         
         logger.debug("items ok")
         return Credentials (items[0].attributes["username"], items[0].secret)
 def __init__(self):
     self._protocol = "network"
     self._key = gk.ItemType.NETWORK_PASSWORD
     if not gk.is_available():
         raise KeyringException("The Gnome keyring is not available")
     logger.debug("GnomeKeyring is available")
     self.loaded = False
     self.lock = threading.RLock()
     
     if not self.loaded:
         (result, keyring_names) = gk.list_keyring_names_sync()
         if self._KEYRING_NAME not in keyring_names:
             logger.error("Error getting the gnome keyring. We'll try to create it: %s")
             logger.debug("Creating keyring " + self._KEYRING_NAME)
             gk.create_sync(self._KEYRING_NAME, None)
         self.loaded = True
Beispiel #25
0
 def store_credentials(self, acc, credentials):
     self.lock.acquire()
     try:
         logger.debug("Storing credentials with gnome keyring for account %s" % (acc.get_name()))
         self.__check_keyring()
         #Remove the old info and create a new item with the new info
         self.remove_credentials(acc)
         attrs = {
             "account_name": acc.get_name(),
             "username": credentials.username,
             }
         id = gk.item_create_sync(self._KEYRING_NAME, \
              gk.ITEM_NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
         logger.debug("credentials stored with id: %i" % (id))
     finally:
         self.lock.release()
Beispiel #26
0
 def set_manager(self, manager):
     #The same manager, we don't need do nothing
     if manager == self.current:
         logger.debug("Setting the keyring manager but it is the same")
         return
     logger.info("Setting the keyring manager: %s" % (manager.get_name()))
     from cloudsn.core import account
     old = self.current
     for acc in account.AccountManager.get_instance().get_accounts():
         try:
             credentials = acc.get_credentials()
             old.remove_credentials(acc)
             manager.store_credentials(acc, credentials)
         except Exception, e:
             logger.exception("Cannot change the keyring for the account "\
                 + acc.get_name() + ": %s" , e)
    def set_active(self, active):
        if active:
            self.statusIcon = gtk.StatusIcon()
            self.statusIcon.set_from_pixbuf(config.get_cloudsn_icon())
            self.statusIcon.set_visible(True)
            self.statusIcon.set_tooltip(APP_LONG_NAME)
            self.statusIcon.connect("activate", self.main_cb, self.statusIcon)

            self.menu = self.create_pref_menu()
            self.indmenu = self.create_main_menu()

            self.statusIcon.connect("popup-menu", self.popup_menu_cb, self.menu)
            self.statusIcon.set_visible(1)
        else:
            # TODO Discable the indicators
            logger.debug("deactivate Not implemented")
Beispiel #28
0
    def set_active(self, active):
        if active:
            self.statusIcon = gtk.StatusIcon()
            self.statusIcon.set_from_pixbuf(config.get_cloudsn_icon())
            self.statusIcon.set_visible(True)
            self.statusIcon.set_tooltip(APP_LONG_NAME)
            self.statusIcon.connect('activate', self.main_cb, self.statusIcon)

            self.menu = self.create_pref_menu()
            self.indmenu = self.create_main_menu()

            self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
            self.statusIcon.set_visible(1)
        else:
            #TODO Discable the indicators
            logger.debug("deactivate Not implemented")
 def set_manager(self, manager):
     #The same manager, we don't need do nothing
     if manager == self.current:
         logger.debug("Setting the keyring manager but it is the same")
         return
     logger.info("Setting the keyring manager: %s" % (manager.get_name()))
     from cloudsn.core import account
     old = self.current
     for acc in account.AccountManager.get_instance().get_accounts():
         try:
             credentials = acc.get_credentials()
             old.remove_credentials(acc)
             manager.store_credentials(acc, credentials)
         except Exception, e:
             logger.exception("Cannot change the keyring for the account "\
                 + acc.get_name() + ": %s" , e)
 def create_indicator(self, acc):
     """
     create a source and add binds it to the account.
     There is one source section for each account.
     and each account also holds a reference to the source.
     """
     source_name = acc.get_name()
     count = acc.get_total_unread()
     source_id = acc.get_name()
     self.mmapp.append_source_with_count(source_id, None, source_name, count)
     self.mmapp.connect("activate-source", self.on_indicator_display_cb)
     #now indicator is not an object as in indicatorapplet, we can keep
     #the id of it instead
     acc.indicator = source_id
     logger.debug("add new source to account "+acc.get_name())
     acc.is_error_icon = False
     logger.debug("new source created")
Beispiel #31
0
    def __init__(self):
        self._protocol = "network"
        self._key = gk.ItemType.NETWORK_PASSWORD
        if not gk.is_available():
            raise KeyringException("The Gnome keyring is not available")
        logger.debug("GnomeKeyring is available")
        self.loaded = False
        self.lock = threading.RLock()

        if not self.loaded:
            (result, keyring_names) = gk.list_keyring_names_sync()
            if self._KEYRING_NAME not in keyring_names:
                logger.error(
                    "Error getting the gnome keyring. We'll try to create it: %s"
                )
                logger.debug("Creating keyring " + self._KEYRING_NAME)
                gk.create_sync(self._KEYRING_NAME, None)
            self.loaded = True
Beispiel #32
0
 def create_indicator(self, acc):
     """
     create a source and add binds it to the account.
     There is one source section for each account.
     and each account also holds a reference to the source.
     """
     source_name = acc.get_name()
     count = acc.get_total_unread()
     source_id = acc.get_name()
     self.mmapp.append_source_with_count(source_id, None, source_name,
                                         count)
     self.mmapp.connect("activate-source", self.on_indicator_display_cb)
     #now indicator is not an object as in indicatorapplet, we can keep
     #the id of it instead
     acc.indicator = source_id
     logger.debug("add new source to account " + acc.get_name())
     acc.is_error_icon = False
     logger.debug("new source created")
    def store_credentials(self, acc, credentials):
        self.lock.acquire()
        try:
            logger.debug("Storing credentials with gnome keyring for account %s" % (acc.get_name()))
            #Remove the old info and create a new item with the new info
            self.remove_credentials(acc)

            attrs = gk.Attribute.list_new()
            gk.Attribute.list_append_string(attrs, 'account_name', acc.get_name())
            gk.Attribute.list_append_string(attrs, 'username', credentials.username)
            
            (result, id) = gk.item_create_sync(self._KEYRING_NAME, \
                 gk.ItemType.NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
            if result != gk.Result.OK:
                raise Exception("Gnome Keyring return the error code: %i" % result)
            logger.debug("credentials stored with id: %i" % (id))
        finally:
            self.lock.release()
def check_auth_configuration():
    try:
        import gnomekeyring as gk
        from ..core.keyrings import gkeyring
    except Exception:
        logger.debug("Gnome keyring is not available")
        return

    conf = SettingsController.get_instance()
    prefs = conf.get_prefs()
    if AUTH_DONT_ASK_KEY in prefs and get_boolean(
            prefs[AUTH_DONT_ASK_KEY]) == True:
        return

    if get_keyring().get_id() == gkeyring.GNOME_KEYRING_ID:
        return

    label = Gtk.Label()
    label.set_markup(
        _("""<b>Security warning</b>

You have gnome-keyring installed but your are using plain text encryption
to store your passwords. You can select the encryption method
in the preferences dialog.

"""))
    dialog = Gtk.Dialog(
        APP_LONG_NAME, None,
        Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
        (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
    dialog.set_icon(get_cloudsn_icon())
    dialog.vbox.pack_start(label, False, False, 10)
    checkbox = Gtk.CheckButton(_("Don't ask me again"))
    checkbox.show()
    dialog.vbox.pack_end(checkbox, False, False, 0)
    label.show()
    response = dialog.run()
    dialog.destroy()
    if checkbox.get_active():
        conf.set_pref(AUTH_DONT_ASK_KEY, True)
        conf.save_prefs()
def notify_process ():
    global notifications, notifying, last_notify

    if len(notifications) == 0:
        return;
        
    if notifying == True:
        #See Bug #622021 on gnome
        diff = datetime.now() - last_notify
        if diff.seconds > 30:
            logger.debug("30 seconds from the last notification, reactivating")
            notifying = False
        else:
            return
        
    n = notifications[0]
    n.connect("closed", notify_closed_cb)
    n.show()
    
    notifying= True
    last_notify = datetime.now()
 def get_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Getting credentials with gnome keyring for account %s" % (acc.get_name()))
         attrs = gk.Attribute.list_new()
         gk.Attribute.list_append_string(attrs, 'account_name', acc.get_name())
         try:
             (result, items) = gk.find_items_sync(gk.ItemType.NETWORK_PASSWORD, attrs)
         except gk.NoMatchError, e:
             items = list()
             
         if len(items) < 1:
             raise KeyringException("Cannot find the keyring data for the account %s" % (acc.get_name()))
         
         logger.debug("items ok")
         
         username = ''
         for attr in gk.Attribute.list_to_glist(items[0].attributes):
             if attr.name == 'username':
                 username = attr.get_string()
         return Credentials (username, items[0].secret)
def check_auth_configuration():
    try:
        import gnomekeyring as gk
        from ..core.keyrings import gkeyring
    except Exception:
        logger.debug("Gnome keyring is not available")
        return

    conf = SettingsController.get_instance()
    prefs = conf.get_prefs()
    if AUTH_DONT_ASK_KEY in prefs and get_boolean(prefs[AUTH_DONT_ASK_KEY]) == True:
        return

    if get_keyring().get_id() == gkeyring.GNOME_KEYRING_ID:
        return

    label = Gtk.Label()
    label.set_markup(_("""<b>Security warning</b>

You have gnome-keyring installed but your are using plain text encryption
to store your passwords. You can select the encryption method
in the preferences dialog.

"""))
    dialog = Gtk.Dialog(APP_LONG_NAME,
                       None,
                       Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                       (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
    dialog.set_icon(get_cloudsn_icon())
    dialog.vbox.pack_start(label, False, False, 10)
    checkbox = Gtk.CheckButton(_("Don't ask me again"))
    checkbox.show()
    dialog.vbox.pack_end(checkbox, False, False, 0)
    label.show()
    response = dialog.run()
    dialog.destroy()
    if checkbox.get_active():
        conf.set_pref (AUTH_DONT_ASK_KEY, True)
        conf.save_prefs()
Beispiel #38
0
    def store_credentials(self, acc, credentials):
        self.lock.acquire()
        try:
            logger.debug(
                "Storing credentials with gnome keyring for account %s" %
                (acc.get_name()))
            #Remove the old info and create a new item with the new info
            self.remove_credentials(acc)

            attrs = gk.Attribute.list_new()
            gk.Attribute.list_append_string(attrs, 'account_name',
                                            acc.get_name())
            gk.Attribute.list_append_string(attrs, 'username',
                                            credentials.username)

            (result, id) = gk.item_create_sync(self._KEYRING_NAME, \
                 gk.ItemType.NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
            if result != gk.Result.OK:
                raise Exception("Gnome Keyring return the error code: %i" %
                                result)
            logger.debug("credentials stored with id: %i" % (id))
        finally:
            self.lock.release()
 def set_active(self, active):
     logger.debug("set_active called")
     if active:
         self.mmapp = MessagingMenu.App(desktop_id="cloudsn.desktop")
         self.mmapp.register()
         logger.debug("MessagingMenuAPP created")
     else:
         #TODO Disable the indicators
         logger.debug("deactivate Not implemented")
Beispiel #40
0
 def set_active(self, active):
     logger.debug("set_active called")
     if active:
         self.mmapp = MessagingMenu.App(desktop_id="cloudsn.desktop")
         self.mmapp.register()
         logger.debug("MessagingMenuAPP created")
     else:
         #TODO Disable the indicators
         logger.debug("deactivate Not implemented")
Beispiel #41
0
def notify_process():
    global notifications, notifying, last_notify

    if len(notifications) == 0:
        return

    if notifying == True:
        #See Bug #622021 on gnome
        diff = datetime.now() - last_notify
        if diff.seconds > 30:
            logger.debug("30 seconds from the last notification, reactivating")
            notifying = False
        else:
            return

    n = notifications[0]
    n.connect("closed", notify_closed_cb)
    n.show()

    notifying = True
    last_notify = datetime.now()
    #TODO Do it better and configuable
    sound = Sound()
    sound.play(config.add_data_prefix("drip.ogg"))
def notify_process ():
    global notifications, notifying, last_notify

    if len(notifications) == 0:
        return;

    if notifying == True:
        #See Bug #622021 on gnome
        diff = datetime.now() - last_notify
        if diff.seconds > 30:
            logger.debug("30 seconds from the last notification, reactivating")
            notifying = False
        else:
            return

    n = notifications[0]
    n.connect("closed", notify_closed_cb)
    n.show()

    notifying= True
    last_notify = datetime.now()
    #TODO Do it better and configuable
    sound = Sound()
    sound.play(config.add_data_prefix("drip.ogg"))
 def remove_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Removing credentias from gnome keyring for the account: %s" % (acc.get_name()))
         if hasattr(acc, "keyringid"):
             gk.item_delete_sync(self._KEYRING_NAME, int(acc.keyringid))
             logger.debug("Credentials removed")
         else:
             logger.debug("The account has not credentials asigned, continue")
     finally:
         self.lock.release()
Beispiel #44
0
 def remove_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Removing credentias from gnome keyring for the account: %s" % (acc.get_name()))
         if hasattr(acc, "keyringid"):
             gk.item_delete_sync(self._KEYRING_NAME, int(acc.keyringid))
             logger.debug("Credentials removed")
         else:
             logger.debug("The account has not credentials asigned, continue")
     finally:
         self.lock.release()
Beispiel #45
0
    def __real_update_account(self, acc):
        if acc in self.accounts_checking:
            logger.warn("The account %s is being checked" % (acc.get_name()))
            return

        logger.debug("Starting checker")
        if not acc.get_active():
            logger.debug("The account %s is not active, it will not be updated" % (acc.get_name()))
            return

        self.accounts_checking.append(acc)
        max_notifications = int(float(self.config.get_prefs()["max_notifications"]))
        try:
            logger.debug('Updating account: ' + acc.get_name())

            #Process events to show the main icon
            while gtk.events_pending():
                gtk.main_iteration(False)

            self.am.update_account(acc)

            acc.error_notified = False

            if hasattr(acc, "indicator"):
                self.im.get_indicator().update_account(acc)


            #Process events to show the indicator menu
            while gtk.events_pending():
                gtk.main_iteration(False)

            if acc.get_provider().has_notifications() and \
                    acc.get_show_notifications():
                nots = acc.get_new_unread_notifications()
                message = None
                if len(nots) > max_notifications:
                    notification.notify(acc.get_name(),
                        _("New messages: ") + str(len(nots)),
                        acc.get_icon())

                if len(nots) > 0 and len(nots) <= max_notifications:
                    for n in nots:
                        if n.icon:
                            icon = n.icon
                        else:
                            icon = acc.get_icon()
                        notification.notify(acc.get_name() + ": " + n.sender,
                            n.message,
                            icon)

            self.emit("account-checked", acc)
        except notification.NotificationError, ne:
            logger.exception("Error trying to notify with libnotify: %s", e)
Beispiel #46
0
    def _update_interval(self):
        old = self.interval
        self.interval = int(float(self.config.get_prefs()["minutes"]) * 60)

        if not self.get_active():
            return

        if self.timeout_id < 0:
            logger.debug("new source: "+str(self.timeout_id))
            self.timeout_id = gobject.timeout_add_seconds(self.interval,
                                self.update_accounts, None)
        elif self.interval != old:
            logger.debug("removed source: "+str(self.timeout_id))
            gobject.source_remove(self.timeout_id)
            logger.debug("restart source: "+str(self.timeout_id))
            self.timeout_id = gobject.timeout_add_seconds(self.interval,
                                self.update_accounts, None)
Beispiel #47
0
 def remove_indicator(self, acc):
     logger.debug("remove_indicator called")
     if self._has_source(acc):
         self.mmapp.remove_source(acc.indicator)
         acc.indicator = None
Beispiel #48
0
 def update_account(self, acc):
     logger.debug("update_account called")
     logger.debug("get_total_unread " + str(acc.get_total_unread()))
     logger.debug("get_new_unread_notifications " +
                  str(acc.get_new_unread_notifications()))
     if acc.is_error_icon:
         acc.is_error_icon = False
     else:
         if self._has_source(acc):
             logger.debug("acc.indicator is not None")
             #user didn't click on the source
             if acc.get_total_unread() < 1:
                 logger.debug("acc get_total_unread is 0")
                 #but user has checked the email
                 self.mmapp.remove_attention(acc.indicator)
                 self.mmapp.remove_source(acc.indicator)
                 acc.indicator = None
             else:
                 if len(acc.get_new_unread_notifications()) > 0:
                     #whether user checks or not, the number changed
                     self.mmapp.draw_attention(acc.indicator)
                     self.mmapp.set_source_count(acc.indicator,
                                                 acc.get_total_unread())
         else:
             logger.debug("acc.indicator is None")
             #user clicked on the source, which causes that the source is removed
             #recreate the indicator/source
             if len(acc.get_new_unread_notifications()) > 0:
                 self.create_indicator(acc)
                 self.mmapp.draw_attention(acc.indicator)
                 self.mmapp.set_source_count(acc.indicator,
                                             acc.get_total_unread())
Beispiel #49
0
    def preferences_action_activate_cb(self, widget, data=None):
        self.pref_dialog = self.builder.get_object("preferences_dialog")
        self.pref_dialog.set_transient_for(self.window)
        self.pref_dialog.set_destroy_with_parent(True)
        indicator_combo = self.builder.get_object("indicator_combo")
        indicators_store = self.builder.get_object("indicators_store")
        keyring_combo = self.builder.get_object("keyring_combo")
        keyring_store = self.builder.get_object("keyring_store")
        minutes = self.builder.get_object("minutes_spin")
        max_not_spin = self.builder.get_object("max_not_spin")
        startup_check = self.builder.get_object("startup_check")
        enable_sounds_check = self.builder.get_object("enable_sounds_check")

        minutes.set_value(float(self.config.get_prefs()["minutes"]))
        max_not_spin.set_value(
            float(self.config.get_prefs()["max_notifications"]))
        if os.path.exists(config.get_startup_file_path()):
            startup_check.set_active(True)
        else:
            startup_check.set_active(False)

        enable_sounds_check.set_active(
            coreutils.get_boolean(self.config.get_prefs()["enable_sounds"]))

        #Populate indicator combo
        i = 0
        indicator_name = self.config.get_prefs()["indicator"]
        indicators_store.clear()
        for indi in self.im.get_indicators():
            indicators_store.append([indi.get_name()])
            if indi.get_name() == indicator_name:
                indicator_combo.set_active(i)
            i += 1
        i = 0
        keyring_id = self.config.get_prefs()["keyring"]
        keyring_store.clear()
        for k in self.km.get_managers():
            keyring_store.append([k.get_name(), k.get_id()])
            if k.get_id() == keyring_id:
                keyring_combo.set_active(i)
            i += 1
        response = self.pref_dialog.run()
        self.pref_dialog.hide()
        self.config.set_pref("minutes", minutes.get_value())
        self.config.set_pref("max_notifications", max_not_spin.get_value())
        self.config.set_pref("enable_sounds", enable_sounds_check.get_active())
        iiter = indicator_combo.get_active_iter()
        if iiter:
            self.config.set_pref("indicator",
                                 indicators_store.get_value(iiter, 0))
        iiter = keyring_combo.get_active_iter()

        selected = keyring_store.get_value(iiter, 1)
        for m in self.km.get_managers():
            logger.debug("selected %s, current %s" % (selected, m.get_id()))
            if m.get_id() == selected:
                self.km.set_manager(m)
                break

        self.config.set_pref("keyring", selected)

        #Check startup checkbox
        if startup_check.get_active():
            if not os.path.exists(config.get_startup_file_path()):
                if not os.path.exists(config.get_startup_file_dir()):
                    os.makedirs(config.get_startup_file_dir())
                shutil.copyfile(config.add_data_prefix("cloudsn.desktop"),
                                config.get_startup_file_path())
        else:
            if os.path.exists(config.get_startup_file_path()):
                os.remove(config.get_startup_file_path())

        self.config.save_prefs()
    def preferences_action_activate_cb (self, widget, data=None):
        self.pref_dialog = self.builder.get_object("preferences_dialog")
        self.pref_dialog.set_transient_for(self.window)
        self.pref_dialog.set_destroy_with_parent (True)
        indicator_combo = self.builder.get_object("indicator_combo")
        indicators_store = self.builder.get_object("indicators_store");
        keyring_combo = self.builder.get_object("keyring_combo")
        keyring_store = self.builder.get_object("keyring_store");
        minutes=self.builder.get_object("minutes_spin")
        max_not_spin=self.builder.get_object("max_not_spin")
        startup_check = self.builder.get_object("startup_check")
        enable_sounds_check = self.builder.get_object("enable_sounds_check")

        minutes.set_value (float(self.config.get_prefs()["minutes"]))
        max_not_spin.set_value (float(self.config.get_prefs()["max_notifications"]))
        if os.path.exists(config.get_startup_file_path()):
            startup_check.set_active(True)
        else:
            startup_check.set_active(False)

        enable_sounds_check.set_active(coreutils.get_boolean(self.config.get_prefs()["enable_sounds"]))

        #Populate indicator combo
        i=0
        indicator_name = self.config.get_prefs()["indicator"]
        indicators_store.clear()
        for indi in self.im.get_indicators():
            indicators_store.append([indi.get_name()])
            if indi.get_name() == indicator_name:
                indicator_combo.set_active(i)
            i+=1
        i=0
        keyring_id = self.config.get_prefs()["keyring"]
        keyring_store.clear()
        for k in self.km.get_managers():
            keyring_store.append([k.get_name(), k.get_id()])
            if k.get_id() == keyring_id:
                keyring_combo.set_active(i)
            i+=1
        response = self.pref_dialog.run()
        self.pref_dialog.hide()
        self.config.set_pref ("minutes", minutes.get_value())
        self.config.set_pref ("max_notifications", max_not_spin.get_value())
        self.config.set_pref ("enable_sounds", enable_sounds_check.get_active())
        iiter = indicator_combo.get_active_iter()
        if iiter:
            self.config.set_pref ("indicator", indicators_store.get_value(iiter,0))
        iiter = keyring_combo.get_active_iter()

        selected = keyring_store.get_value(iiter,1)
        for m in self.km.get_managers():
            logger.debug("selected %s, current %s" % (selected, m.get_id()))
            if m.get_id() == selected:
                self.km.set_manager(m)
                break

        self.config.set_pref ("keyring", selected)

        #Check startup checkbox
        if startup_check.get_active():
            if not os.path.exists(config.get_startup_file_path()):
                if not os.path.exists(config.get_startup_file_dir()):
                    os.makedirs(config.get_startup_file_dir())
                shutil.copyfile(config.add_data_prefix("cloudsn.desktop"),
                    config.get_startup_file_path())
        else:
            if os.path.exists(config.get_startup_file_path()):
                os.remove (config.get_startup_file_path())

        self.config.save_prefs()
 def store_credentials(self, acc, credentials):
     logger.debug("Storing plain credentials for account: %s" % (acc.get_name()))
     acc["username"] = credentials.username
     acc["password"] = credentials.password