online-desktop r7265 - in trunk/weblogindriver: . weblogindriver



Author: marinaz
Date: Tue Sep  2 22:15:56 2008
New Revision: 7265
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7265&view=rev

Log:
Get the list of supported online account types from the server and add them to the ONLINE_ACCOUNT_TYPES dictionary.


Added:
   trunk/weblogindriver/weblogindriver/ddm_util.py
Modified:
   trunk/weblogindriver/web-login-driver
   trunk/weblogindriver/weblogindriver/accounts_dialog.py

Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver	(original)
+++ trunk/weblogindriver/web-login-driver	Tue Sep  2 22:15:56 2008
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
-import os,sys,re,logging,urlparse,base64,gconf,copy
+import os,sys,re,logging,urlparse,base64,gconf,copy,urllib2
+import xml.dom, xml.dom.minidom
 
 import gobject, dbus, gnomevfs, gobject
 import dbus,dbus.service,dbus.glib
@@ -12,6 +13,7 @@
 import weblogindriver.keyring as keyring
 import weblogindriver.accounts_dialog as accounts_dialog
 from weblogindriver.gutil import *
+import weblogindriver.ddm_util as ddm_util
 
 _logger = logging.getLogger("WebLoginDriver")
 
@@ -306,11 +308,8 @@
     return self.__signons[signon]
 
 TYPE_GOOGLE = "google"
-TYPE_TWITTER = "twitter"
-TYPE_RTM = "rtm"
-TYPE_LIBRARY_THING = "library"
 
-ONLINE_ACCOUNT_TYPES = {TYPE_GOOGLE : "Google", TYPE_TWITTER : "Twitter", TYPE_RTM : "Remember The Milk", TYPE_LIBRARY_THING : "LibraryThing"}
+ONLINE_ACCOUNT_TYPES = {TYPE_GOOGLE : "Google"}
 
 class OnlineAccount(dbus.service.Object):
   def __init__(self, account_id, bus_name, account_type, username, password='', enabled=True, gconf_dir=None):
@@ -647,7 +646,30 @@
     i = gconf_key.rfind('/')
     return gconf_key[i+1:]
 
+  def __download_online_account_types(self):
+    url = urlparse.urljoin(ddm_util.get_baseurl(), "/xml/supportedOnlineAccountTypes")
+    _logger.debug("Sending http request for %s" % url)
+    try:
+      data = urllib2.urlopen(url).read()
+      doc = xml.dom.minidom.parseString(data) 
+      resp = doc.documentElement
+      reply_root = resp.childNodes[0]
+      expected_name = 'onlineAccountTypes'
+      if not reply_root.nodeName == expected_name:
+        _logger.warn("invalid root node, expected %s", expected_name)
+      else:
+        for node in reply_root.childNodes:
+          if not (node.nodeType == xml.dom.Node.ELEMENT_NODE):
+            continue
+          name = node.getAttribute("name")
+          full_name = node.getAttribute("fullName")
+          _logger.debug("parsing online account type name=%s full_name=%s" % (name, full_name))
+          ONLINE_ACCOUNT_TYPES[name]= full_name     
+    except urllib2.HTTPError, e:
+      _logger.error("Failed to load %s : %s" % (url, e))
+
   def __on_ready(self):
+    self.__download_online_account_types()
     if self.__model.self_resource != None:
       _logger.debug("will get online desktop accounts")
       # TODO: get all gnomeExternalAccounts here later, googleEnabledEmails is just one case

Modified: trunk/weblogindriver/weblogindriver/accounts_dialog.py
==============================================================================
--- trunk/weblogindriver/weblogindriver/accounts_dialog.py	(original)
+++ trunk/weblogindriver/weblogindriver/accounts_dialog.py	Tue Sep  2 22:15:56 2008
@@ -2,8 +2,7 @@
 
 import gobject, gtk, dbus
 
-import gutil
-from ddm import DataModel
+import gutil, ddm_util
 
 _logger = logging.getLogger("weblogindriver.AccountsDialog")
 
@@ -222,7 +221,7 @@
         self.__connections.add(self.__onlineaccounts_proxy, id)
 
     def __open_account_page(self, l):
-        gnome.url_show(urlparse.urljoin(get_baseurl(), "/account"))
+        gnome.url_show(urlparse.urljoin(ddm_util.get_baseurl(), "/account"))
       
     def __on_account_added(self, a_path):
         # TODO: check for account type when we have a per-account dialog
@@ -427,23 +426,3 @@
         if hand and self.__enabled:
             cursor = gtk.gdk.Cursor(display, gtk.gdk.HAND2)
         self.window.set_cursor(cursor)
-
-def get_baseurl():
-    ## first we prefer the base url from the model we're actually using.
-    ## this happens when we just connect to "org.freedesktop.od.Engine"
-    ## and don't know in advance whether a dogfood or production or whatever
-    ## server instance owns that bus name.
-    ## Note that this is _supposed_ to work offline as well - the od.Engine
-    ## is supposed to have an offline mode.
-    model = DataModel()
-    if model.global_resource:
-        try:
-            return model.global_resource.webBaseUrl
-        except AttributeError:
-            pass
-
-    ## we fall back to a hardcoded URL, since it's probably better
-    ## than crashing and would normally be right in production, but never
-    ## right when testing on dogfood.
-    return "http://online.gnome.org";
-

Added: trunk/weblogindriver/weblogindriver/ddm_util.py
==============================================================================
--- (empty file)
+++ trunk/weblogindriver/weblogindriver/ddm_util.py	Tue Sep  2 22:15:56 2008
@@ -0,0 +1,21 @@
+from ddm import DataModel
+
+def get_baseurl():
+    ## first we prefer the base url from the model we're actually using.
+    ## this happens when we just connect to "org.freedesktop.od.Engine"
+    ## and don't know in advance whether a dogfood or production or whatever
+    ## server instance owns that bus name.
+    ## Note that this is _supposed_ to work offline as well - the od.Engine
+    ## is supposed to have an offline mode.
+    model = DataModel()
+    if model.global_resource:
+        try:
+            return model.global_resource.webBaseUrl
+        except AttributeError:
+            pass
+
+    ## we fall back to a hardcoded URL, since it's probably better
+    ## than crashing and would normally be right in production, but never
+    ## right when testing on dogfood.
+    return "http://online.gnome.org";
+



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