bigboard r7398 - in trunk/bigboard: . libbig



Author: marinaz
Date: Tue Jun 24 17:17:12 2008
New Revision: 7398
URL: http://svn.gnome.org/viewvc/bigboard?rev=7398&view=rev

Log:
Allow opening accounts dialog that only includes specific account types.

Add support for disconnecting DBus signals to the gutil DisconnectSet.


Modified:
   trunk/bigboard/accounts_dialog.py
   trunk/bigboard/google_stock.py
   trunk/bigboard/libbig/gutil.py

Modified: trunk/bigboard/accounts_dialog.py
==============================================================================
--- trunk/bigboard/accounts_dialog.py	(original)
+++ trunk/bigboard/accounts_dialog.py	Tue Jun 24 17:17:12 2008
@@ -11,7 +11,7 @@
 
 class Dialog(gtk.Window):
     @log_except(_logger)      
-    def __init__(self, *args, **kwargs):
+    def __init__(self, account_kinds, *args, **kwargs):
         super(Dialog, self).__init__(*args, **kwargs)        
         
         try:
@@ -20,6 +20,7 @@
             _logger.error("onlineaccounts DBus service not available, can't manage accounts")
             return
 
+        self.__account_kinds = account_kinds
         self.set_title('Accounts')
         self.set_position(gtk.WIN_POS_CENTER)
 
@@ -47,6 +48,7 @@
         self.add(self.__notebook)
 
         self.connect('delete-event', self.__on_delete_event)
+        self.connect('destroy', self.__on_destroy)
 
         # stuff below gets added to the "Existing Accounts" tab
 
@@ -177,9 +179,9 @@
             self.__add_link_box.pack_end(self.__add_link, expand=False, fill=False)
             self.__outer_new_account_vbox.pack_end(self.__add_link_box, False, False)
         else:  
-            if len(self.__all_account_kinds) == 1 and \
-               "google" in self.__all_account_kinds.keys():           
-                self.__add_link.set_text("Add Google accounts online")
+            if self.__account_kinds and len(self.__account_kinds) == 1 and \
+               self.__account_kinds[0] in self.__all_account_kinds.keys():           
+                self.__add_link.set_text("Add " + self.__all_account_kinds[self.__account_kinds[0]] + " accounts online")
             else:
                 self.__add_link.set_text("Add accounts online")
             self.__add_link_box.pack_start(self.__add_link)
@@ -217,8 +219,6 @@
                                                            self.__on_account_removed)
         self.__connections.add(self.__onlineaccounts_proxy, id)
 
-    ## should be a destroy() that disconnects connections, but we never destroy anyway
-
     def __open_account_page(self, l):
         libbig.show_url(urlparse.urljoin(globals.get_baseurl(), "/account"))
    
@@ -232,6 +232,9 @@
                 _logger.error("onlineaccount for path %s was not found" % a_path)
                 return
 
+            if self.__account_kinds and a.GetKind() not in self.__account_kinds:
+                return 
+
             _logger.debug("account added %s" % a) 
             tree_iter = self.__model.append([self.__all_account_kinds[a.GetKind()] + ': ' + a.GetUsername()])
                 
@@ -362,6 +365,10 @@
     def __on_delete_event(self, dialog, event):
         self.hide()
         return True
+
+    def __on_destroy(self, dialog):
+        self.hide()
+        self.__connections.disconnect_all()
         
 class Link(gtk.EventBox):
     __gsignals__ = {
@@ -426,12 +433,15 @@
 __dialog = None
 
 @log_except(_logger)      
-def open_dialog():
+def open_dialog(accountKinds=None):
     global __dialog
-    if not __dialog:
-        __dialog = Dialog()
+    # TODO: Right now we just destroy the dialog each time a new dialog is opened, but we still keep it around
+    # when it is closed. We can re-use the same dialog when the set of account kinds is the same as it was in 
+    # the previous dialog we showed.
+    if __dialog:
+        __dialog.destroy()
+    __dialog = Dialog(accountKinds)    
     __dialog.present()
-    
 
 if __name__ == '__main__':
 

Modified: trunk/bigboard/google_stock.py
==============================================================================
--- trunk/bigboard/google_stock.py	(original)
+++ trunk/bigboard/google_stock.py	Tue Jun 24 17:17:12 2008
@@ -46,8 +46,6 @@
         for a_path in all_google_account_paths:
             self.__on_account_added(a_path)
 
-        self.__connections = gutil.DisconnectSet()
-
         id = onlineaccounts_proxy.connect_to_signal('AccountEnabled', self.__on_account_added)
         self.__connections.add(onlineaccounts_proxy, id)
         id = onlineaccounts_proxy.connect_to_signal('AccountDisabled', self.__on_account_removed)
@@ -112,7 +110,7 @@
         return False
 
     def __open_login_dialog(self):
-        accounts_dialog.open_dialog()
+        accounts_dialog.open_dialog(["google"])
 
     def _checking_google_auth(self, gobj):
         self._login_button.set_property("text", CHECKING_LOGIN_STRING)

Modified: trunk/bigboard/libbig/gutil.py
==============================================================================
--- trunk/bigboard/libbig/gutil.py	(original)
+++ trunk/bigboard/libbig/gutil.py	Tue Jun 24 17:17:12 2008
@@ -1,4 +1,4 @@
-import os, sys, logging, weakref, functools
+import os, sys, logging, weakref, functools, dbus
 from StringIO import StringIO
 
 import gobject
@@ -22,7 +22,10 @@
         to_remove = []        
         for (object, id) in self.__connections:
             if object == object_to_disconnect:
-                object.disconnect(id)
+                if type(id) == dbus.connection.SignalMatch:
+                    id.remove()
+                else:
+                    object.disconnect(id)
                 to_remove.append((object, id))
 
         for (object, id) in to_remove:
@@ -30,7 +33,10 @@
                 
     def disconnect_all(self):
         for (object, id) in self.__connections:
-            object.disconnect(id)
+            if type(id) == dbus.connection.SignalMatch:
+                id.remove()
+            else:
+                object.disconnect(id)
 
 def call_timeout(timeout, func, *args, **kwargs):
     if 'logger' in kwargs:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]