def activate (self):
     #Hack for gmail domains like mail.quiter.com
     #TODO check this when the user change the configuration too
     domain = None
     try:
         user, tmp, domain = self.get_credentials().username.partition('@')
     except Exception, e:
         logger.exception("Cannot load credentials for account "+acc.get_name()+", continue: %s", e)
def show_url(url):
    """Open any @url with default viewer"""
    #from Gtk import show_uri, get_current_event_time
    #from Gtk.gdk import screen_get_default
    #from glib import GError
    try:
        Gtk.show_uri(Gdk.Screen.get_default(), url, Gtk.get_current_event_time())
    except:
        logger.exception("Error in Gtk.show_uri: %s")
Exemple #3
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 show_url(url):
    """Open any @url with default viewer"""
    from gtk import show_uri, get_current_event_time
    from gtk.gdk import screen_get_default
    from glib import GError
    try:
        show_uri(screen_get_default(), url, get_current_event_time())
    except GError, e:
        logger.exception("Error in gtk.show_uri: %s", e)
Exemple #5
0
def show_url(url):
    """Open any @url with default viewer"""
    #from Gtk import show_uri, get_current_event_time
    #from Gtk.gdk import screen_get_default
    #from glib import GError
    try:
        Gtk.show_uri(Gdk.Screen.get_default(), url,
                     Gtk.get_current_event_time())
    except:
        logger.exception("Error in Gtk.show_uri: %s")
Exemple #6
0
 def activate(self):
     #Hack for gmail domains like mail.quiter.com
     #TODO check this when the user change the configuration too
     domain = None
     try:
         user, tmp, domain = self.get_credentials().username.partition('@')
     except Exception, e:
         logger.exception(
             "Cannot load credentials for account " + acc.get_name() +
             ", continue: %s", e)
Exemple #7
0
    def edit_action_activate_cb(self, widget, data=None):

        acc, citer = self.get_main_account_selected()

        if not acc:
            return

        self.new_dialog = self.builder.get_object("account_new_dialog")
        account_name_entry = self.builder.get_object("account_name_entry")
        account_name_entry.set_text(acc.get_name())
        #TODO the name cannot be modified by the moment
        account_name_entry.set_sensitive(False)
        self.provider_content = self.builder.get_object("provider_content")
        self.activate_command_entry = self.builder.get_object(
            "activate_command_entry")
        self.provider_content.account = acc
        self.new_dialog.set_transient_for(self.window)
        self.new_dialog.set_destroy_with_parent(True)

        #Select the provider and disable item
        providers_combo = self.builder.get_object("providers_combo")
        providers_combo.set_active(-1)
        self.select_provider_combo(providers_combo,
                                   acc.get_provider().get_name())

        providers_combo.set_sensitive(False)

        end = False
        while not end:
            response = self.new_dialog.run()
            if response == 0:
                try:
                    acc_name = account_name_entry.get_text()
                    if acc_name == '':
                        raise Exception(_("You must fill the account name"))

                    custom_widget = self.provider_content.get_children()[0]

                    acc = acc.get_provider().set_account_data_from_widget(
                        acc_name, custom_widget, acc)
                    acc.set_activate_command(
                        self.activate_command_entry.get_text())
                    self.am.save_account(acc)
                    end = True
                except Exception, e:
                    logger.exception('Error editing the account: %s', e)
                    md = gtk.MessageDialog(
                        self.window, gtk.DIALOG_DESTROY_WITH_PARENT,
                        gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                        _('Error editing the account: ') + str(e))
                    md.run()
                    md.destroy()
            else:
                end = True
Exemple #8
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)
    def __init__(self):
        if KeyringManager.__default:
            raise KeyringManager.__default

        #TODO control errors to disable providers
        self.config = config.SettingsController.get_instance()
        from keyrings.plainkeyring import PlainKeyring
        self.__add_manager (PlainKeyring())
        try:
            from keyrings.base64keyring import Base64Keyring
            self.__add_manager (Base64Keyring())
        except Exception, e:
            logger.exception("Cannot load base64 keyring: %s", e)
Exemple #10
0
    def __init__(self):
        if KeyringManager.__default:
            raise KeyringManager.__default

        #TODO control errors to disable providers
        self.config = config.SettingsController.get_instance()
        from keyrings.plainkeyring import PlainKeyring
        self.__add_manager(PlainKeyring())
        try:
            from keyrings.base64keyring import Base64Keyring
            self.__add_manager(Base64Keyring())
        except Exception, e:
            logger.exception("Cannot load base64 keyring: %s", e)
    def edit_action_activate_cb(self, widget, data=None):

        acc, citer = self.get_main_account_selected()

        if not acc:
            return

        self.new_dialog = self.builder.get_object("account_new_dialog")
        account_name_entry = self.builder.get_object("account_name_entry");
        account_name_entry.set_text(acc.get_name())
        #TODO the name cannot be modified by the moment
        account_name_entry.set_sensitive (False)
        self.provider_content = self.builder.get_object("provider_content")
        self.activate_command_entry = self.builder.get_object("activate_command_entry")
        self.provider_content.account = acc
        self.new_dialog.set_transient_for(self.window)
        self.new_dialog.set_destroy_with_parent (True)

        #Select the provider and disable item
        providers_combo = self.builder.get_object("providers_combo")
        providers_combo.set_active(-1)
        self.select_provider_combo (providers_combo, acc.get_provider().get_name())

        providers_combo.set_sensitive (False)

        end = False
        while not end:
            response = self.new_dialog.run()
            if response == 0:
                try:
                    acc_name = account_name_entry.get_text()
                    if acc_name == '':
                        raise Exception(_("You must fill the account name"))

                    custom_widget = self.provider_content.get_children()[0]

                    acc = acc.get_provider().set_account_data_from_widget(acc_name, custom_widget, acc)
                    acc.set_activate_command (self.activate_command_entry.get_text())
                    self.am.save_account(acc)
                    end = True
                except Exception, e:
                    logger.exception ('Error editing the account: %s', e)
                    md = Gtk.MessageDialog(self.window,
                        Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR,
                        Gtk.ButtonsType.CLOSE,
                        _('Error editing the account: ') + str(e))
                    md.run()
                    md.destroy()
            else:
                end = True
Exemple #12
0
 def _start_idle(self):
     try:
         check_auth_configuration()
         self.nm.set_statechange_callback(self.on_nm_state_changed)
         self.set_active (True)
         self.update_accounts()
         self.started = True
     except Exception, e:
         logger.exception ("Error starting the application: %s", e)
         try:
             notification.notify(_("Application Error"),
                 _("Error starting the application: %s") % (str(e)),
                 utils.get_error_pixbuf())
         except Exception, e:
             logger.exception ("Error notifying the error: %s", e)
 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 __init__(self):
        if IndicatorManager.__default:
           raise IndicatorManager.__default

        self.indicator= None
        self.indicators = {}
        #TODO Use the correct indicator
        from cloudsn.ui.indicators import statusicon
        statusindi = statusicon.StatusIconIndicator()
        self.indicators[statusindi.get_name()] = statusindi
        try:
            from cloudsn.ui.indicators import indicatorapplet
            indi = indicatorapplet.IndicatorApplet()
            self.indicators[indi.get_name()] = indi
        except Exception,e:
            logger.exception("The indicator applet provider cannot be loaded: %s", e)
    def __init__(self):
        if IndicatorManager.__default:
            raise IndicatorManager.__default

        self.indicator= None
        self.indicators = {}
        from cloudsn.ui.indicators import statusicon
        indi_statusicon = statusicon.StatusIconIndicator()
        self.indicators[indi_statusicon.get_name()] = indi_statusicon
        indi_indicator = None
        try:
            from cloudsn.ui.indicators import indicatorapplet
            indi_indicator = indicatorapplet.IndicatorApplet()
            self.indicators[indi_indicator.get_name()] = indi_indicator
        except Exception,e:
            logger.exception("The indicator applet provider cannot be loaded: %s", e)
class IndicatorManager():

    __default = None

    def __init__(self):
        if IndicatorManager.__default:
            raise IndicatorManager.__default

        self.indicator = None
        self.indicators = {}
        from cloudsn.ui.indicators import statusicon
        indi_statusicon = statusicon.StatusIconIndicator()
        self.indicators[indi_statusicon.get_name()] = indi_statusicon
        indi_indicator = None
        try:
            from cloudsn.ui.indicators import indicatorapplet
            indi_indicator = indicatorapplet.IndicatorApplet()
            self.indicators[indi_indicator.get_name()] = indi_indicator
        except Exception, e:
            logger.exception(
                "The indicator applet provider cannot be loaded: %s", e)

        indi_messagingmenu = None
        try:
            from cloudsn.ui.indicators import messagingmenu
            indi_messagingmenu = messagingmenu.IndicatorApplet()
            self.indicators[indi_messagingmenu.get_name()] = indi_messagingmenu
        except Exception, e:
            logger.exception(
                "The message menu applet provider cannot be loaded: %s", e)
Exemple #17
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)
Exemple #18
0
    def __init__(self):
        if IndicatorManager.__default:
            raise IndicatorManager.__default

        self.indicator = None
        self.indicators = {}
        #TODO Use the correct indicator
        from cloudsn.ui.indicators import statusicon
        statusindi = statusicon.StatusIconIndicator()
        self.indicators[statusindi.get_name()] = statusindi
        try:
            from cloudsn.ui.indicators import indicatorapplet
            indi = indicatorapplet.IndicatorApplet()
            self.indicators[indi.get_name()] = indi
        except Exception, e:
            logger.exception(
                "The indicator applet provider cannot be loaded: %s", e)
 def load_accounts(self):
     accs_conf = self.sc.get_accounts_config()
     for conf in accs_conf.values():
         provider = self.pm.get_provider(conf['provider_name'])
         if provider:
             try:
                 acc = provider.load_account (conf)
                 if acc.has_credentials():
                     credentials = Credentials("","")
                     try:
                         credentials = keyring.get_keyring().get_credentials(acc)
                     except Exception, e:
                         logger.exception("Cannot load credentials for account "+conf["name"]+": %s", e)
                     acc.set_credentials (credentials)
                 self.add_account(acc)
             except Exception, e:
                 logger.exception("Cannot load the account "+conf["name"]+": %s", e)
Exemple #20
0
 def load_accounts(self):
     accs_conf = self.sc.get_accounts_config()
     for conf in accs_conf.values():
         provider = self.pm.get_provider(conf['provider_name'])
         if provider:
             try:
                 acc = provider.load_account(conf)
                 if acc.has_credentials():
                     credentials = Credentials("", "")
                     try:
                         credentials = keyring.get_keyring(
                         ).get_credentials(acc)
                     except Exception, e:
                         logger.exception(
                             "Cannot load credentials for account " +
                             conf["name"] + ": %s", e)
                     acc.set_credentials(credentials)
                 self.add_account(acc)
             except Exception, e:
                 logger.exception(
                     "Cannot load the account " + conf["name"] + ": %s", e)
 def get_message_icon(self, m):
     icon = None
     try:
         icon = utils.download_image_to_pixbuf(m.user.profile_image_url)
     except Exception, e:
         logger.exception("Error loading the user avatar")
 def get_message_icon(self,m):
     icon = None
     try:
         icon = utils.download_image_to_pixbuf(m.user.profile_image_url)
     except Exception, e:
         logger.exception("Error loading the user avatar")
Exemple #23
0
class Controller (gobject.GObject):

    __default = None

    __gtype_name__ = "Controller"

    __gsignals__ = { "account-checked" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
                     "account-check-error" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))}

    timeout_id = -1
    interval = 60

    def __init__(self):
        if Controller.__default:
           raise Controller.__default

        #Prevent various instances
        import os, fcntl, sys, tempfile, getpass
        self.lockfile = os.path.normpath(tempfile.gettempdir() + '/cloudsn-'+getpass.getuser()+'.lock')
        self.fp = open(self.lockfile, 'w')
        try:
            fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
        except IOError:
            message = _("Another instance is already running, close it first.")
            logger.warn (message)
            print message
            sys.exit(-1)

        gobject.GObject.__init__(self)
        self.started = False
        self.config = config.SettingsController.get_instance()
        self.config.connect("value-changed", self._settings_changed)
        self.prov_manager = ProviderManager.get_instance()
        self.im = indicator.IndicatorManager.get_instance()
        self.am = account.AccountManager.get_instance()
        self.am.connect("account-added", self._account_added_cb)
        self.am.connect("account-deleted", self._account_deleted_cb)
        self.am.connect("account-changed", self._account_changed_cb)
        self.am.connect("account-active-changed", self._account_active_cb)
        self.am.load_accounts()
        self.accounts_checking = []
        self.nm = networkmanager.NetworkManager()

    @staticmethod
    def get_instance():
        if not Controller.__default:
            Controller.__default = Controller()
        return Controller.__default

    def _account_added_cb(self, am, acc):
        indi = self.im.get_indicator()
        if indi and acc.get_active():
            indi.create_indicator(acc)

        if self.started:
            self.update_account(acc)

    def _account_deleted_cb(self, am, acc):
        self.im.get_indicator().remove_indicator(acc)

    def _account_active_cb(self, am, acc):
        if acc.get_active():
            self.im.get_indicator().create_indicator(acc)
            self.update_account(acc)
        else:
            self.im.get_indicator().remove_indicator(acc)

    def _account_changed_cb (self, am, acc):
        self.update_account(acc)

    def _settings_changed(self, config, section, key, value):
        if section == "preferences" and key == "minutes":
            self._update_interval()

    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)

    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")

    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


    def get_active(self):
        return self.timeout_id > -1

    def update_account(self, acc):
        if not self.get_active():
            return
        """acc=None will check all accounts"""
        if self.nm.offline():
            logger.warn ("The network is not connected, the account cannot be updated")
            return

        #TODO Check if the updater is running
        if acc is None:
            for acc in self.am.get_accounts():
                thread.start_new_thread(self.__real_update_account, (acc,))
        else:
            thread.start_new_thread(self.__real_update_account, (acc,))

        #self.__real_update_account(acc)

    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)
        except Exception, e:
            logger.exception("Error trying to update the account %s: %s", acc.get_name(), e)
            if not acc.error_notified:
                acc.error_notified = True
                notification.notify (_("Error checking account %s") % (acc.get_name()),
                    str(e),
                    acc.get_icon())
                self.im.get_indicator().update_error(acc)
            self.emit("account-check-error", acc)
from cloudsn.core import config
from datetime import datetime

notifications = []
disable = True
notifying = False
last_notify = tstart = datetime.now()

try:
    import pynotify
    if pynotify.init("Cloud Services Notifications"):
        disable = False
    else:
        logger.error("Cannot initialize libnotify")
except Exception, e:
    logger.exception ("there was a problem initializing the pynotify module: %s" % (e))


def notify_closed_cb (n, data=None):
    global notifications, notifying
    notifying = False
    if n in notifications:
        notifications.remove (n)
    n = None
    notify_process()

def notify_process ():
    global notifications, notifying, last_notify

    if len(notifications) == 0:
        return;
from cloudsn.core import config
from datetime import datetime

notifications = []
disable = True
notifying = False
last_notify = tstart = datetime.now()

try:
    from gi.repository import Notify
    if Notify.init("Cloud Services Notifications"):
        disable = False
    else:
        logger.error("Cannot initialize libnotify")
except Exception, e:
    logger.exception("there was a problem initializing the Notify module: %s" %
                     (e))

#def notify_closed_cb (n, data=None):
#    global notifications, notifying
#    notifying = False
#    if n in notifications:
#        notifications.remove (n)
#    n = None
#    notify_process()


def notify_process():
    global notifications, notifying, last_notify

    if len(notifications) == 0:
        return