online-desktop r7274 - trunk/weblogindriver
- From: marinaz svn gnome org
- To: svn-commits-list gnome org
- Subject: online-desktop r7274 - trunk/weblogindriver
- Date: Thu, 23 Oct 2008 22:51:07 +0000 (UTC)
Author: marinaz
Date: Thu Oct 23 22:51:07 2008
New Revision: 7274
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7274&view=rev
Log:
Disconnect from updates from the server and don't send account additions and removals to the server when we are not saving accounts online.
Enter a special merge mode if saving accounts online becomes enabled or we don't receive data model's self resource on the accounts service start up, but receive it after a while (e.g. the user was not initially signed in on the website). In the merge mode, we sync accounts on the server and on the client by keeping a combined set of the accounts in both places.
Modified:
trunk/weblogindriver/web-login-driver
Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver (original)
+++ trunk/weblogindriver/web-login-driver Thu Oct 23 22:51:07 2008
@@ -402,7 +402,7 @@
self.Changed()
def __str__(self):
- return "<Account userame:%s, type:%s, gconf_dir:%s, enabled:%s, resource_id:%s>" % (self.GetUsername(), self.GetType(), self._get_gconf_dir(), self.GetEnabled(), self._get_resource_id())
+ return "<Account username:%s, type:%s, gconf_dir:%s, enabled:%s, resource_id:%s>" % (self.GetUsername(), self.GetType(), self._get_gconf_dir(), self.GetEnabled(), self._get_resource_id())
_dialog = None
@@ -410,7 +410,7 @@
def __init__(self, bus_name):
dbus.service.Object.__init__(self, bus_name, '/onlineaccounts')
self.__bus_name = bus_name
- self.__received_response_from_server = set()
+ self.__received_response_from_server = False
#TODO: do we need to pass in the server name, and if so how do we know here what to pass in?
self.__model = DataModel()
@@ -444,8 +444,12 @@
self.__gconf = gconf.client_get_default()
self.__gconf.add_dir(GCONF_BASE_DIR, gconf.CLIENT_PRELOAD_RECURSIVE)
self.__gconf.notify_add(GCONF_BASE_DIR, self.__on_gconf_change)
- self.__save_online_flag = False
- self.__reload_save_online_flag_from_gconf()
+ # merge_mode can be set to True in two cases: if self.__save_online_flag got explicitly
+ # enabled by the user and if we initially didn't get the self resource for the user,
+ # but then got it later
+ self.__merge_mode = False
+ self.__save_online_flag = None
+ self.__reload_save_online_flag_from_gconf()
## a dict from gconf directory name underneath GCONF_BASE_DIR to
## a dict of the gconf values underneath that account directory
@@ -526,7 +530,7 @@
if account in self.__server_accounts:
self.__ensure_account_in_gconf(account)
- elif account.GetType() in self.__received_response_from_server:
+ elif self.__received_response_from_server:
#remove gconf dir if one exists
if gconf_dir:
self.__remove_gconf_dir(gconf_dir)
@@ -675,20 +679,23 @@
_logger.error("Failed to load %s : %s" % (url, e))
def __on_ready(self):
+ _logger.debug("__on_ready got called")
self.__download_online_account_types()
# we can only reload stuff from gconf after we know the account types and we use the data model
# in self.__download_online_account_types() to determine the base site link
self.__reload_from_gconf()
- if self.__model.self_resource != None:
+ self.__get_online_accounts()
+
+ def __get_online_accounts(self):
+ if self.__model.self_resource != None and self.__save_online_flag:
_logger.debug("will get online desktop accounts")
query = self.__model.query_resource(self.__model.self_resource, "googleEnabledEmails; lovedAccounts +")
query.add_handler(self.__on_datamodel_response)
query.add_error_handler(self.__on_datamodel_error)
query.execute()
-
- # query = self.__model.query_resource(self.__model.self_resource, "lovedAccounts +")
- # query.add_handler(self.__on_loved_accounts)
- # query.execute()
+ elif self.__model.self_resource == None:
+ # we will want to use the merge mode once we do get the self resource
+ self.__merge_mode = True
def __on_datamodel_error(self, code, str):
_logger.error("datamodel error %s: %s", code, str)
@@ -699,6 +706,9 @@
myself.connect(self.__update_loved_accounts, 'lovedAccounts')
self.__update_google_enabled_emails(myself)
self.__update_loved_accounts(myself)
+ if self.__save_online_flag:
+ self.__merge_mode = False
+ self.__received_response_from_server = True
# def __on_loved_accounts(self, myself):
# _logger.debug("received some loved accounts")
@@ -706,6 +716,10 @@
# self.__update_loved_accounts(myself)
def __update_google_enabled_emails(self, myself):
+ if not self.__save_online_flag:
+ _logger.warn("got into __update_google_enabled_emails when self.__save_online_flag is False")
+ return
+
new_google_accounts = set()
if not hasattr(myself, 'googleEnabledEmails'):
_logger.debug("No googleEnabledEmails in DDM identity")
@@ -719,7 +733,22 @@
self.update_accounts_from_server(TYPE_GOOGLE, new_google_accounts)
+ if self.__merge_mode:
+ existing_accounts_in_gconf = self.__get_gconf_accounts_by_type(TYPE_GOOGLE)
+ for gconf_account in existing_accounts_in_gconf:
+ if gconf_account not in self.__server_accounts:
+ # add the account on the server
+ query = self.__model.update(("http://mugshot.org/p/accounts", "addOnlineAccount"), accountType=gconf_account.GetType(), username=gconf_account.GetUsername())
+ # TODO: add eror handler that would display a message, possibe a note one for
+ # Google on success too
+ # query.add_error_handler(self.__on_server_account_add_failed)
+ query.execute()
+
def __update_loved_accounts(self, myself):
+ if not self.__save_online_flag:
+ _logger.warn("got into __update_google_enabled_emails when self.__save_online_flag is False")
+ return
+
new_accounts_by_type = {}
new_loved_data_model_accounts = set()
if not hasattr(myself, 'lovedAccounts'):
@@ -747,18 +776,26 @@
for (key, value) in new_accounts_by_type.items():
self.update_accounts_from_server(key, value)
-
- # make sure we remove accounts for types which we no longer are getting from the server,
- # this will do it repeatedly since we never reset what's in self.__received_response_from_server,
- # but that's ok
- for key in self.__received_response_from_server:
- if key != TYPE_GOOGLE and key not in new_accounts_by_type.keys():
- self.update_accounts_from_server(key, set())
+
+ gconf_accounts = copy.copy(self.__gconf_accounts)
+ _logger.debug("will go through existing accounts")
+ for gconf_account in gconf_accounts:
+ if gconf_account.GetType() != TYPE_GOOGLE and gconf_account not in self.__server_accounts:
+ if self.__merge_mode:
+ # add the account on the server
+ query = self.__model.update(("http://mugshot.org/p/accounts", "addOnlineAccount"), accountType=gconf_account.GetType(), username=gconf_account.GetUsername())
+ # TODO: add eror handler that would display a message, possibly a note one for
+ # Google on success too
+ # query.add_error_handler(self.__on_server_account_add_failed)
+ query.execute()
+ else:
+ # remove the account locally
+ self.__update_account(gconf_account)
for account in self.__loved_data_model_accounts:
if account not in new_loved_data_model_accounts:
_logger.debug("Some old account is not in new accounts %s" % account.resource_id)
- account.disconnect(self.__update_loved_accounts)
+ account.disconnect(self.__update_loved_account)
self.__loved_data_model_accounts = new_loved_data_model_accounts
@@ -772,7 +809,7 @@
query.add_error_handler(self.__on_datamodel_error)
query.execute()
- def update_accounts_from_server(self, account_type, new_accounts):
+ def update_accounts_from_server(self, account_type, new_accounts):
existing_accounts = self.__get_server_accounts_by_type(account_type)
for new_account in new_accounts:
@@ -802,20 +839,20 @@
# we have a password for it
self.__update_account(new_account_to_add)
- self.__received_response_from_server.add(account_type)
-
- # clear out accounts that are no longer found in the list of accounts of this type from the server
- for existing_account in existing_accounts:
- self.__server_accounts.remove(existing_account)
- # this should remove the account from gconf and gconf_accounts
- self.__update_account(existing_account)
-
- # make sure that all accounts in gconf correspond to the ones returned from the server;
- # this will remove old accounts from gconf
- existing_accounts_in_gconf = self.__get_gconf_accounts_by_type(account_type)
- _logger.debug("existing_accounts_in_gconf of type %s: %d" % (account_type, len(existing_accounts_in_gconf)))
- for gconf_account in existing_accounts_in_gconf:
- self.__update_account(gconf_account)
+ _logger.debug("merge mode is %s" % self.__merge_mode)
+ if not self.__merge_mode:
+ # clear out accounts that are no longer found in the list of accounts of this type from the server
+ for existing_account in existing_accounts:
+ self.__server_accounts.remove(existing_account)
+ # this should remove the account from gconf and gconf_accounts
+ self.__update_account(existing_account)
+
+ # make sure that all accounts in gconf correspond to the ones returned from the server;
+ # this will remove old accounts from gconf
+ existing_accounts_in_gconf = self.__get_gconf_accounts_by_type(account_type)
+ _logger.debug("existing_accounts_in_gconf of type %s: %d" % (account_type, len(existing_accounts_in_gconf)))
+ for gconf_account in existing_accounts_in_gconf:
+ self.__update_account(gconf_account)
def __get_gconf_info(self, gconf_dir):
base_key = GCONF_BASE_DIR + "/" + gconf_dir
@@ -839,12 +876,30 @@
def __reload_save_online_flag_from_gconf(self):
try:
new_save_online_flag = self.__gconf.get_value(GCONF_BASE_DIR + "/save_online")
+ if self.__save_online_flag is None:
+ self.__save_online_flag = new_save_online_flag
+ return
+
if new_save_online_flag != self.__save_online_flag:
self.__save_online_flag = new_save_online_flag
self.SaveOnlineFlagChanged(self.__save_online_flag)
- # TODO: do everything else here
+ if self.__save_online_flag:
+ _logger.debug("will enter the merge mode")
+ self.__merge_mode = True
+ self.__get_online_accounts()
+ #do merge if have self resource
+ else:
+ self.__server_accounts.clear()
+ self.__received_response_from_server = False
+ if self.__model.self_resource != None:
+ self.__model.self_resource.disconnect(self.__update_google_enabled_emails)
+ self.__model.self_resource.disconnect(self.__update_loved_accounts)
+ for account in self.__loved_data_model_accounts:
+ account.disconnect(self.__update_loved_account)
+ self.__loved_data_model_accounts.clear()
except ValueError:
- self.__set_save_online_flag_in_gconf(self.__save_online_flag)
+ self.__save_online_flag = False
+ self.__set_save_online_flag_in_gconf(False)
def __set_save_online_flag_in_gconf(self, save_online_flag):
self.__gconf.set_bool(GCONF_BASE_DIR + "/save_online", save_online_flag)
@@ -1106,12 +1161,18 @@
account = self.__find_account_in_gconf(account_type, username)
if account:
return_cb((account.GetObjectPath(), False, None))
-
- query = self.__model.update(("http://mugshot.org/p/accounts", "addOnlineAccount"), accountType=account_type, username=username)
- query.add_handler(on_server_account_added)
- query.add_error_handler(on_server_account_add_failed)
- query.execute()
-
+
+ if self.__save_online_flag:
+ query = self.__model.update(("http://mugshot.org/p/accounts", "addOnlineAccount"), accountType=account_type, username=username)
+ query.add_handler(on_server_account_added)
+ query.add_error_handler(on_server_account_add_failed)
+ query.execute()
+ else:
+ account = self.__create_online_account(account_type, username)
+ self.__ensure_account_in_gconf(account)
+ self.__update_account(account) # this will try to find a password for the account, and emit AccountEnabled signal
+ return_cb((account.GetObjectPath(), True, ""))
+
def get_existing_account(self, account_object_path):
if self.__all_accounts.has_key(account_object_path):
return self.__all_accounts[account_object_path]
@@ -1144,7 +1205,7 @@
if account_type == TYPE_GOOGLE:
resource_id = account.GetUsername()
- if resource_id is not None:
+ if resource_id is not None and self.__save_online_flag:
query = self.__model.update(("http://mugshot.org/p/accounts", "removeOnlineAccount"), accountType=account_type, resourceId=resource_id)
query.add_handler(on_server_account_removed)
query.add_error_handler(on_server_account_remove_failed)
@@ -1152,7 +1213,7 @@
else:
self.__remove_gconf_dir(account._get_gconf_dir())
if account in self.__server_accounts:
- _logger.warn("Account %s was in self.__server_accounts, but did not have a resource_id" % str(account))
+ _logger.warn("Account %s was in self.__server_accounts, but did not have a resource_id or we were in the mode when we should not be kepping track of server accounts" % str(account))
self.__server_accounts.remove(account)
self.__update_account(account) # this will remove the account from self.__all_accounts
return_cb()
@@ -1162,9 +1223,9 @@
def GetEnabledAccounts(self):
object_paths_list = [a.GetObjectPath() for a in self.__enabled_accounts]
return object_paths_list
-
+
@dbus.service.method(OA_BUS_IFACE_STR,
- in_signature="as",
+ in_signature="as",
out_signature="ao")
def GetEnabledAccountsWithTypes(self, account_types):
object_paths_list = [a.GetObjectPath() for a in \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]