def on_account_add_button_clicked (self, widget, data=None):
     response = self.dialog_new.run()
     self.dialog_new.hide()
     if response == 0:
         citer = self.providers_combo.get_active_iter()
         provider_name = self.providers_store.get_value (citer, 1)
         provider = self.pm.get_provider(provider_name)
         account_name = self.account_name_entry.get_text()
         if account_name != "":
             try:
                 self.am.validate_account(account_name)
                 account = provider.create_account_dialog(account_name, self.window)
                 if account is not None:
                     self.am.add_account(account)
                     self.am.save_account(account)
                     self.store.append([account.get_icon(),
                             account.get_name(),self.__get_account_date(account),
                             account.get_active()])
             except Exception, e:
                 logger.error ('Error adding a new account: ' + str(e))
                 md = gtk.MessageDialog(self.window,
                     gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
                     gtk.BUTTONS_CLOSE,
                     'Error adding a new account: ' + str(e))
                 md.run()
                 md.destroy()
    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)
    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 #4
0
    def new_action_activate_cb(self, widget, data=None):
        self.new_dialog = self.builder.get_object("account_new_dialog")
        account_name_entry = self.builder.get_object("account_name_entry")
        self.provider_content = self.builder.get_object("provider_content")
        self.activate_command_entry = self.builder.get_object(
            "activate_command_entry")
        self.provider_content.account = None
        self.new_dialog.set_transient_for(self.window)
        self.new_dialog.set_destroy_with_parent(True)
        account_name_entry.set_text("")
        account_name_entry.set_sensitive(True)
        self.providers_combo.set_sensitive(True)
        self.providers_combo.set_active(-1)
        for c in self.provider_content.get_children():
            if c:
                self.provider_content.remove(c)
                c.destroy()
        end = False
        while not end:
            response = self.new_dialog.run()
            if response == 0:
                try:
                    if len(self.provider_content.get_children()) == 0:
                        raise Exception(
                            _("You must select a provider and fill the data"))

                    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]
                    citer = self.providers_combo.get_active_iter()
                    provider_name = self.providers_store.get_value(citer, 1)
                    provider = self.pm.get_provider(provider_name)
                    acc = provider.set_account_data_from_widget(
                        acc_name, custom_widget)
                    acc.set_activate_command(
                        self.activate_command_entry.get_text())
                    self.am.add_account(acc)
                    self.am.save_account(acc)
                    self.main_store.append([
                        acc.get_icon(),
                        acc.get_name(),
                        self.__get_account_date(acc),
                        acc.get_active(),
                        acc.get_total_unread()
                    ])
                    end = True
                except Exception, e:
                    logger.error('Error adding a new account: %s', e)
                    md = gtk.MessageDialog(
                        self.window, gtk.DIALOG_DESTROY_WITH_PARENT,
                        gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                        _('Error adding a new account: ') + str(e))
                    md.run()
                    md.destroy()
            else:
                end = True
 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:
             acc = provider.load_account (conf)
             self.add_account(acc)
         else:
             logger.error("Error in account %s: The provider %s doesn't exists" % (conf['name'], conf['provider_name']))
 def __connect(self):
     try:
         if not self.ssl:
             self.mbox = poplib.POP3(self.host, self.port)
         else:
             self.mbox = poplib.POP3_SSL(self.host, self.port)
     except Exception, e:
         logger.error("Error connecting the POP3 account: " + str(e))
         raise PopBoxConnectionError()
    def new_action_activate_cb(self, widget, data=None):
        self.new_dialog = self.builder.get_object("account_new_dialog")
        account_name_entry = self.builder.get_object("account_name_entry");
        self.provider_content = self.builder.get_object("provider_content")
        self.activate_command_entry = self.builder.get_object("activate_command_entry")
        self.provider_content.account = None
        self.new_dialog.set_transient_for(self.window)
        self.new_dialog.set_destroy_with_parent (True)
        account_name_entry.set_text("")
        account_name_entry.set_sensitive (True)
        self.providers_combo.set_sensitive (True)
        self.providers_combo.set_active(-1)
        for c in self.provider_content.get_children():
            if c:
                self.provider_content.remove(c)
                c.destroy()
        end = False
        while not end:
            response = self.new_dialog.run()
            if response == 0:
                try:
                    if len(self.provider_content.get_children())==0:
                        raise Exception(_("You must select a provider and fill the data"))

                    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]
                    citer = self.providers_combo.get_active_iter()
                    provider_name = self.providers_store.get_value (citer, 1)
                    provider = self.pm.get_provider(provider_name)
                    acc = provider.set_account_data_from_widget(acc_name, custom_widget)
                    acc.set_activate_command (self.activate_command_entry.get_text())
                    self.am.add_account(acc)
                    self.am.save_account(acc)
                    self.main_store.append([acc.get_icon(),
                            acc.get_name(),self.__get_account_date(acc),
                            acc.get_active(), acc.get_total_unread()])
                    end = True
                except Exception, e:
                    logger.error ('Error adding a new account: %s', e)
                    md = Gtk.MessageDialog(self.window,
                        Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR,
                        Gtk.ButtonsType.CLOSE,
                        _('Error adding a new account: ') + str(e))
                    md.run()
                    md.destroy()
            else:
                end = True
 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.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)
                 self.am.save_account(acc)
                 end = True
             except Exception, e:
                 logger.error ('Error editing an account: ' + str(e))
                 md = gtk.MessageDialog(self.window,
                     gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
                     gtk.BUTTONS_CLOSE,
                     _('Error editing an account: ') + str(e))
                 md.run()
                 md.destroy()
         else:
             end = True
 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 #10
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
    def get_mails(self):
        self.__connect()

        messages = []
        msgs = self.mbox.list()[1]
        for msg in msgs:
            try:
                msgNum = int(msg.split(" ")[0])
                msgSize = int(msg.split(" ")[1])

                # retrieve only the header
                st = "\n".join(self.mbox.top(msgNum, 0)[1])
                #print st
                #print "----------------------------------------"
                msg = self.parser.parsestr(st, True) # header only
                sub = utils.mime_decode(msg.get("Subject"))
                msgid = msg.get("Message-Id")
                if not msgid:
                    msgid = hash(msg.get("Received") + sub)
                fr = utils.mime_decode(msg.get("From"))
                messages.append( [msgid, sub, fr] )
            except Exception, e:
                logger.error("Error reading pop3 box: " + str(e))
Beispiel #12
0
class IndicatorManager():

    __default = None

    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)

        self.config = config.SettingsController.get_instance()
        indicator_conf = self.config.get_prefs()["indicator"]
        if indicator_conf:
            for name in self.indicators:
                if name == indicator_conf:
                    self.indicator = self.indicators[name]
                    break
            if not self.indicator:
                logger.error(
                    "The indicator named %s is configured but it cannot be found"
                    % (indicator_conf))
                notification.notify(
                    _("Indicator error"),
                    _("The indicator named %s is configured but it cannot be found"
                      ) % (indicator_conf), utils.get_error_pixbuf())
        if not self.indicator:
            self.indicator = statusindi

        self.indicator.set_active(True)
            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)

        self.config = config.SettingsController.get_instance()
        indicator_conf = self.config.get_prefs()["indicator"]
        if indicator_conf:
            for name in self.indicators:
                if name == indicator_conf:
                    self.indicator = self.indicators[name]
                    break
            if not self.indicator:
                logger.error(
                    "The indicator named %s is configured but it cannot be found"
                    % (indicator_conf))
                notification.notify(
                    _("Indicator error"),
                    _("The indicator named %s is configured but it cannot be found"
                      ) % (indicator_conf), utils.get_error_pixbuf())
        if not self.indicator:
            if "DESKTOP_SESSION" in os.environ and os.environ[
                    "DESKTOP_SESSION"] == 'ubuntu':
                indi_fin = indi_messagingmenu if indi_messagingmenu else indi_indicator
                if not indi_fin:
                    notification.notify(
                        _("Indicator error"),
                        _("The indicator for ubuntu cannot be loaded "),
                        utils.get_error_pixbuf())
                    raise Error(
        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)

        self.config = config.SettingsController.get_instance()
        indicator_conf = self.config.get_prefs()["indicator"]
        if indicator_conf:
            for name in self.indicators:
                if name == indicator_conf:
                    self.indicator = self.indicators[name]
                    break
            if not self.indicator:
                logger.error("The indicator named %s is configured but it cannot be found" % (indicator_conf))
                notification.notify (_("Indicator error"),
                                     _("The indicator named %s is configured but it cannot be found") % (indicator_conf),
                                     utils.get_error_pixbuf())
        if not self.indicator:
            if "DESKTOP_SESSION" in os.environ and os.environ["DESKTOP_SESSION"] == 'ubuntu':
                indi_fin = indi_messagingmenu if indi_messagingmenu else indi_indicator
                if not indi_fin:
                    notification.notify (_("Indicator error"),
                                         _("The indicator for ubuntu cannot be loaded "),
                                         utils.get_error_pixbuf())
                    raise Error(_("The indicator for ubuntu cannot be loaded "))
                self.indicator = indi_fin
            else:
                self.indicator = indi_statusicon
Beispiel #15
0
                        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)

            else:
                logger.error(
                    "Error in account %s: The provider %s doesn't exists" %
                    (conf['name'], conf['provider_name']))

    def validate_account(self, account_name):
        if account_name in self.accounts:
            error = _('The account %s already exists' % (account_name))
            raise Exception(error)

    def add_account(self, acc):
        self.validate_account(acc.get_name())
        self.accounts[acc.get_name()] = acc

        self.emit("account-added", acc)

    def set_account_active(self, acc, active):
        if acc.get_active() != active:
from cloudsn import logger
from cloudsn.core.sound import Sound
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 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)

            else:
                logger.error("Error in account %s: The provider %s doesn't exists" % (conf['name'], conf['provider_name']))

    def validate_account(self, account_name):
        if account_name in self.accounts:
            error = _('The account %s already exists' % (account_name))
            raise Exception(error)

    def add_account(self, acc):
        self.validate_account(acc.get_name())
        self.accounts[acc.get_name()] = acc

        self.emit("account-added", acc)

    def set_account_active (self, acc, active):
        if acc.get_active() != active:
            acc.error_notified = False
from cloudsn import logger
from cloudsn.core.sound import Sound
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
Beispiel #19
0
from cloudsn.providers.providersbase import ProviderUtilsBuilder
from cloudsn.core.provider import Provider
from cloudsn.core import utils, indicator, config
from cloudsn import logger
from os.path import join
import os
from gi.repository import Gtk, GdkPixbuf
import urllib2
import csv

import_error = None

try:
    import feedparser
except Exception, e:
    logger.error("Error loading the FeedsProvider: %s", e)
    import_error = Exception(_("You need install the python-feedparser module to use this provider"))

class FeedsProvider(ProviderUtilsBuilder):

    __default = None

    def __init__(self):
        if FeedsProvider.__default:
            raise FeedsProvider.__default
        ProviderUtilsBuilder.__init__(self, _("RSS news"), 'rss')

    @staticmethod
    def get_instance():
        if not FeedsProvider.__default:
            FeedsProvider.__default = FeedsProvider()
from cloudsn.providers.providersbase import ProviderUtilsBuilder
from cloudsn.core.provider import Provider
from cloudsn.core import utils, indicator, config
from cloudsn import logger
from os.path import join
import os
from gi.repository import Gtk, GdkPixbuf
import urllib2
import csv

import_error = None

try:
    import feedparser
except Exception, e:
    logger.error("Error loading the FeedsProvider: %s", e)
    import_error = Exception(_("You need install the python-feedparser module to use this provider"))

class FeedsProvider(ProviderUtilsBuilder):

    __default = None

    def __init__(self):
        if FeedsProvider.__default:
           raise FeedsProvider.__default
        ProviderUtilsBuilder.__init__(self, _("RSS news"), 'rss')

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