Skip to content

Commit

Permalink
Emit a signal when an account is updated in the controller
Browse files Browse the repository at this point in the history
The preferences dialog connects to it and update the last update
datetime
  • Loading branch information
chuchiperriman committed Jan 16, 2010
1 parent 99cca92 commit d919c25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Milestone 3
Milestone 2
===========
[X] Check the accounts in a different thread
[ ] Update the last check data in the preferences dialog correctly with the threads
[X] Update the last check data in the preferences dialog correctly with the threads
[X] Do not run two instances of cloudsn
[X] Add option to start the application with the session
[ ] cloudsn doesn't check the first time it starts with the session
Expand Down
20 changes: 14 additions & 6 deletions src/cloudsn/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import gobject
import gettext
from threading import Thread
import syslog

class Controller:
class Controller (gobject.GObject):

__default = None

__gtype_name__ = "Controller"

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

timeout_id = -1
interval = 60

Expand All @@ -30,14 +35,15 @@ def __init__(self):
print "Another instance is already running, quitting."
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.am = account.AccountManager.get_instance()
self.am.connect("account-added", self._account_added_cb)
self.am.connect("account-deleted", self._account_deleted_cb)
self.checker = CheckerThread()
self.checker = CheckerThread(self)

@staticmethod
def get_instance():
Expand Down Expand Up @@ -101,21 +107,22 @@ def create_indicator(self, acc):

def update_account(self, acc):
if self.checker is None or not self.checker.is_alive():
self.checker = CheckerThread(acc)
self.checker = CheckerThread(self, acc)
self.checker.start()
else:
print 'The checker is running'

def update_accounts(self, data=None):
if self.checker is None or not self.checker.is_alive():
self.checker = CheckerThread()
self.checker = CheckerThread(self)
self.checker.start()
else:
print 'The checker is running'
#For the timeout_add_seconds
return True

def _start_idle(self):
syslog.syslog('Starting cloudsn')
gtk.gdk.threads_enter()
self.init_indicator_server()
for provider in self.prov_manager.get_providers():
Expand All @@ -142,9 +149,10 @@ def start(self):
print 'keyboardInterrupt'

class CheckerThread (Thread):
def __init__(self, acc = None):
def __init__(self, controller, acc = None):
Thread.__init__ (self)
self.am = account.AccountManager.get_instance()
self.controller = controller
self.acc = acc

def run(self):
Expand All @@ -154,11 +162,11 @@ def run(self):
acc.update()
acc.indicator.set_property_int("count", acc.get_unread())
if acc.get_provider().has_notifications() and acc.get_new_unread() > 0:
pass
self.notify(acc.get_name(),
_("New messages: ") + str(acc.get_new_unread()),
acc.get_provider().get_icon())
#account.indicator.set_property('draw-attention', 'true');
self.controller.emit("account-checked", account)
except Exception as e:
print "Error trying to update the account " , acc.get_name() , ": " , e

Expand Down
12 changes: 9 additions & 3 deletions src/cloudsn/ui/preferences.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import gtk
import os
import shutil
from cloudsn.core import config
from cloudsn.core import provider
from cloudsn.core import account
from cloudsn.core import config, provider, account

STOP_RESPONSE = 1

Expand Down Expand Up @@ -100,8 +98,14 @@ def __get_account_date(self, acc):
last_update = dt.strftime("%Y-%m-%d %H:%M:%S")

return last_update

def __on_account_checked_cb(self, widget, acc):
for row in self.store:
if row[1] == acc.get_name():
row[2] = self.__get_account_date(acc)

def load_window(self):
from cloudsn.core.controller import Controller
builder=gtk.Builder()
builder.set_translation_domain("cloudsn")
builder.add_from_file(config.add_data_prefix("preferences.ui"))
Expand Down Expand Up @@ -131,6 +135,8 @@ def load_window(self):
self.startup_check.set_active(True)
else:
self.startup_check.set_active(False)
#Update the last check date
Controller.get_instance().connect ("account-checked", self.__on_account_checked_cb)

def run(self):
if self.window is None:
Expand Down

0 comments on commit d919c25

Please sign in to comment.