bigboard r7406 - in trunk/bigboard/stocks: . twitter



Author: marinaz
Date: Thu Jun 26 00:26:26 2008
New Revision: 7406
URL: http://svn.gnome.org/viewvc/bigboard?rev=7406&view=rev

Log:
Add a simple Twitter stock that gets the user's Twitter account from the accounts system and displays it in the stock along with the button that opens an accounts dialog for Twitter. 


Added:
   trunk/bigboard/stocks/twitter/
   trunk/bigboard/stocks/twitter.xml
   trunk/bigboard/stocks/twitter/TwitterStock.py
   trunk/bigboard/stocks/twitter/stock.css
   trunk/bigboard/stocks/twitter/thumbnail.png   (contents, props changed)
Modified:
   trunk/bigboard/stocks/google_calendar.xml

Modified: trunk/bigboard/stocks/google_calendar.xml
==============================================================================
--- trunk/bigboard/stocks/google_calendar.xml	(original)
+++ trunk/bigboard/stocks/google_calendar.xml	Thu Jun 26 00:26:26 2008
@@ -5,9 +5,8 @@
                author_email="online-desktop-list gnome org"
                author_affiliation="Red Hat, Inc."
                author_location="Westford, MA"
-          	   screenshot="files.png"
                thumbnail="thumbnail.png"
                description="View your Google Calendar">
   </ModulePrefs>
   <Content type="online-desktop-builtin"></Content>  
-</Module>
\ No newline at end of file
+</Module>

Added: trunk/bigboard/stocks/twitter.xml
==============================================================================
--- (empty file)
+++ trunk/bigboard/stocks/twitter.xml	Thu Jun 26 00:26:26 2008
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+  <ModulePrefs title="Twitter"
+               author="Red Hat, Inc."
+               author_email="online-desktop-list gnome org"
+               author_affiliation="Red Hat, Inc."
+               author_location="Westford, MA"
+               thumbnail="thumbnail.png"
+               description="Update your Twitter status and see your friends Tweets">
+  </ModulePrefs>
+  <Content type="online-desktop-builtin"></Content>  
+</Module>

Added: trunk/bigboard/stocks/twitter/TwitterStock.py
==============================================================================
--- (empty file)
+++ trunk/bigboard/stocks/twitter/TwitterStock.py	Thu Jun 26 00:26:26 2008
@@ -0,0 +1,104 @@
+import logging, dbus
+import hippo
+from bigboard.stock import Stock
+import bigboard.accounts_dialog as accounts_dialog
+import bigboard.libbig.gutil as gutil
+from bigboard.libbig.logutil import log_except
+
+_logger = logging.getLogger('bigboard.stocks.TwitterStock')
+
+LOGIN_TO_TWITTER_STRING = "Login to Twitter"
+
+TWITTER_KIND = "twitter"
+
+class TwitterStock(Stock):
+
+    def __init__(self, *args, **kwargs):
+        Stock.__init__(self, *args, **kwargs)
+        _logger.debug("Hello Twitter")
+        self.__box = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL)
+
+        self.__login_button = hippo.CanvasButton(text=LOGIN_TO_TWITTER_STRING)
+        self.__login_button.connect('activated', lambda button: self.__open_login_dialog())
+        self.__box.append(self.__login_button)
+
+        # even though the account system can theoretically return multiple Twitter accounts, this stock
+        # only supports one -- the last one that was added
+        self.__twitter_account = None
+        self.__twitter_account_changed_signal_match = None
+
+        try:
+            onlineaccounts_proxy = dbus.SessionBus().get_object('org.gnome.WebLoginDriver', '/onlineaccounts')
+        except dbus.DBusException, e:
+            _logger.error("onlineaccounts DBus service not available, can't get twitter accounts")
+            return
+
+        all_twitter_account_paths = onlineaccounts_proxy.GetEnabledAccountsWithKinds([TWITTER_KIND])
+        for a_path in all_twitter_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)
+        self.__connections.add(onlineaccounts_proxy, id)
+
+    def _on_delisted(self):
+        if self.__twitter_account:
+            self.__on_account_removed(self.__twitter_account.GetObjectPath())
+        self.__connections.disconnect_all()
+
+    def get_content(self, size):
+        return self.__box
+
+    @log_except(_logger)
+    def __on_account_added(self, acct_path):
+        try:
+            _logger.debug("acct_path is %s" % acct_path)
+            acct = dbus.SessionBus().get_object('org.gnome.WebLoginDriver', acct_path)
+        except dbus.DBusException, e:
+            _logger.error("onlineaccount for path %s was not found" % acct_path)
+            return
+
+        if acct.GetKind() != TWITTER_KIND:
+            return
+       
+        _logger.debug("in __on_account_added for %s %s" % (str(acct), acct.GetUsername()))    
+  
+        if self.__twitter_account:
+            self.__on_account_removed(self.__twitter_account.GetObjectPath())
+       
+        self.__twitter_account = acct
+        self.__twitter_account_changed_signal_match = \
+            self.__twitter_account.connect_to_signal('Changed', self.__on_twitter_account_changed)
+        self.__on_twitter_account_changed()  
+   
+        # TODO: start the polling action here
+    
+    @log_except(_logger)
+    def __on_account_removed(self, acct_path):
+        _logger.debug("in on account removed")
+        if self.__twitter_account and self.__twitter_account.GetObjectPath() == acct_path: 
+            _logger.debug("in __on_account_removed for %s", acct_path)   
+            self.__twitter_account_changed_signal_match.remove()
+            self.__twitter_account_changed_signal_match = None 
+            self.__twitter_account = None
+            #TODO: will need to stop the polling action here
+            self.__box.remove_all() 
+            self.__login_button.set_property('text', LOGIN_TO_TWITTER_STRING) 
+            self.__box.append(self.__login_button)
+
+    @log_except(_logger)
+    def __on_twitter_account_changed(self):
+        _logger.debug("will change stuff")
+        self.__box.remove_all()
+        hello_message = hippo.CanvasText(text="Hello Twitter User " + self.__twitter_account.GetUsername() , \
+                                         size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
+        self.__box.append(hello_message)
+        if self.__twitter_account.GetPassword() == "":
+            self.__box.append(self.__login_button)                    
+
+    def __open_login_dialog(self):
+        accounts_dialog.open_dialog(["twitter"])
+

Added: trunk/bigboard/stocks/twitter/stock.css
==============================================================================
--- (empty file)
+++ trunk/bigboard/stocks/twitter/stock.css	Thu Jun 26 00:26:26 2008
@@ -0,0 +1 @@
+/* nothing here */

Added: trunk/bigboard/stocks/twitter/thumbnail.png
==============================================================================
Binary file. No diff available.



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