bigboard r7271 - trunk/bigboard
- From: marinaz svn gnome org
- To: svn-commits-list gnome org
- Subject: bigboard r7271 - trunk/bigboard
- Date: Thu, 20 Mar 2008 23:19:59 +0000 (GMT)
Author: marinaz
Date: Thu Mar 20 23:19:59 2008
New Revision: 7271
URL: http://svn.gnome.org/viewvc/bigboard?rev=7271&view=rev
Log:
Make sure copy.deepcopy() for Account objects works correctly.
Initial changes to the layout of the accounts dialog to contain
a dropdown box with accounts, rather than entries for all the accounts
at the same time.
Modified:
trunk/bigboard/accounts.py
trunk/bigboard/accounts_dialog.py
Modified: trunk/bigboard/accounts.py
==============================================================================
--- trunk/bigboard/accounts.py (original)
+++ trunk/bigboard/accounts.py Thu Mar 20 23:19:59 2008
@@ -13,30 +13,36 @@
_accounts_schema_dir = "/schemas/apps/bigboard/accounts/TEMPLATE"
+# This class is immutable. Make sure to change the __copy__ and __deepcopy__ methods, and add an __eq__ method
+# if you add setters to the class.
class AccountKind(object):
- def __init__(self, id, provided_by_server):
+ def __init__(self, account_id, name, provided_by_server):
super(AccountKind, self).__init__()
- self.__id = id
+ self.__id = account_id
+ self.__name = name
self.__provided_by_server = provided_by_server
def __copy__(self):
- return AccountKind(self.__id, self.__provided_by_server)
+ return self
def __deepcopy__(self, memo):
- return AccountKind(copy.deepcopy(self.__id, memo), copy.deepcopy(self.__provided_by_server, memo))
+ return self
def get_id(self):
return self.__id
+ def get_name(self):
+ return self.__name
+
def get_provided_by_server(self):
return self.__provided_by_server
def __str__(self):
return "<AccountKind:%s, provided_by_server:%s>" % (self.get_id(), self.get_provided_by_server())
-KIND_GOOGLE = AccountKind("google", True)
-KIND_TWITTER = AccountKind("twitter", True)
-KIND_RTM = AccountKind("rtm", False) # RTM = Remember The Milk
+KIND_GOOGLE = AccountKind("google", "Google", True)
+KIND_TWITTER = AccountKind("twitter", "Twitter", True)
+KIND_RTM = AccountKind("rtm", "Remember The Milk", False)
def kind_from_string(s):
for kind in [KIND_GOOGLE, KIND_TWITTER, KIND_RTM]:
@@ -65,8 +71,8 @@
return Account(self.__kind, self.__username, self.__password, self.__url, self.__enabled, self.__gconf_dir)
def __deepcopy__(self, memo):
- return Account(copy.deepcopy(self.__kind, memo), copy.deepcopy(self.__username, memo), copy.deepcopy(self.__password, memo), \
- copy.deepcopy(self.__url, memo), copy.deepcopy(self.__enabled, memo), copy.deepcopy(self.__gconf_dir, memo))
+ return Account(copy.deepcopy(self.__kind, memo), copy.deepcopy(self.__username, memo), copy.deepcopy(self.__password, memo), \
+ copy.deepcopy(self.__url, memo), copy.deepcopy(self.__enabled, memo), copy.deepcopy(self.__gconf_dir, memo))
def get_kind(self):
return self.__kind
@@ -193,7 +199,7 @@
def __find_weblogin_account(self, kind, username, url = None):
for a in self.__weblogin_accounts:
- _logger.debug("comparing to a weblogin account %s" % a)
+ _logger.debug("comparing to a weblogin account %s bool %s a.get_kind() %s kind %s" % (a, a.get_kind() == kind, a.get_kind(), kind))
if a.get_kind() == kind and a.get_username() == username \
and (url == None or a.get_url() == url or
(a.get_kind() == KIND_GOOGLE and url == "gmail.com" and (a.get_url() == None or a.get_url() == ''))):
@@ -414,15 +420,11 @@
break
if not account_found:
- # TODO: decide if we want to check if account is among weblogin_accounts
- # TODO: should use the deepcopy account, but right now it doesn't work for some reason
new_account_to_add = copy.deepcopy(new_account)
- _logger.debug("new account is %s" % new_account)
- _logger.debug("new account to add is %s" % new_account_to_add)
- self.__server_accounts.add(new_account)
+ self.__server_accounts.add(new_account_to_add)
# this will add the account to gconf and enabled accounts, and check if
# we have a password for it
- self.__update_account(new_account)
+ self.__update_account(new_account_to_add)
# clear out accounts that are no longer found in the list of accounts of this kind from the server
for existing_account in existing_accounts:
Modified: trunk/bigboard/accounts_dialog.py
==============================================================================
--- trunk/bigboard/accounts_dialog.py (original)
+++ trunk/bigboard/accounts_dialog.py Thu Mar 20 23:19:59 2008
@@ -10,6 +10,7 @@
_logger = logging.getLogger("bigboard.AccountsDialog")
+# this class will probably be removed since we are changing the layot of the accounts dialog
class AccountEditor(gtk.VBox):
def __init__(self, *args, **kwargs):
if 'account' in kwargs:
@@ -70,10 +71,11 @@
{ 'password' : text })
class Dialog(gtk.Dialog):
+ @log_except(_logger)
def __init__(self, *args, **kwargs):
super(Dialog, self).__init__(*args, **kwargs)
- self.set_title('Google Accounts')
+ self.set_title('Accounts')
self.connect('delete-event', self.__on_delete_event)
self.connect('response', self.__on_response)
@@ -82,7 +84,33 @@
gtk.RESPONSE_OK)
self.set_default_response(gtk.RESPONSE_OK)
- self.__editors_by_account = {}
+ # TODO: don't display the dropdown and password entry box if there are no accounts to edit
+ self.__password_entry = gtk.Entry()
+ self.__password_entry.set_visibility(False) # this sets a password mode
+ self.__password_entry.connect('activate',
+ self.__on_password_entry_changed)
+
+ password_vbox = gtk.VBox(spacing=2)
+ label = gtk.Label("Password:")
+ label.set_alignment(0.0, 0.5)
+ password_vbox.pack_start(label)
+ password_vbox.pack_end(self.__password_entry, False)
+ self.vbox.pack_end(password_vbox, padding=5)
+
+ self.__model = gtk.ListStore(gobject.TYPE_STRING)
+ self.__accounts_combo = gtk.ComboBox(self.__model)
+ self.vbox.pack_end(self.__accounts_combo)
+ textrender = gtk.CellRendererText()
+ self.__accounts_combo.pack_start(textrender, True)
+ self.__accounts_combo.add_attribute(textrender, 'text', 0)
+ self.__accounts_combo.connect('notify::active', self.__on_edited_account_changed)
+
+ self.__model_tree_iter_by_account = {}
+ self.__current_account = None
+
+ self.show_all()
+
+ self.__password_entry.set_activates_default(True)
self.__connections = gutil.DisconnectSet()
@@ -92,28 +120,61 @@
id = accts.connect('account-removed', self.__on_account_removed)
self.__connections.add(accts, id)
- google_accounts = accts.get_accounts_with_kind(accounts.KIND_GOOGLE)
- if len(google_accounts) == 0:
- accounts.get_accounts().create_account(accounts.KIND_GOOGLE)
+ # google_accounts = accts.get_accounts_with_kind(accounts.KIND_GOOGLE)
+ all_accounts = accts.get_accounts()
+ if len(all_accounts) == 0:
+ # do something else
+ pass
else:
- for a in google_accounts:
+ for a in all_accounts:
self.__on_account_added(accts, a)
## should be a destroy() that disconnects connections, but we never destroy anyway
+ @log_except(_logger)
def __on_account_added(self, accts, a):
- if a.get_kind() == accounts.KIND_GOOGLE and a not in self.__editors_by_account:
+ # TODO: check for account kind when we have a per-account dialog
+ if a not in self.__model_tree_iter_by_account:
_logger.debug("account added %s" % a)
- self.__editors_by_account[a] = AccountEditor(account=a)
- self.vbox.pack_end(self.__editors_by_account[a])
+ tree_iter = None
+ if a.get_url() and a.get_url() != '':
+ tree_iter = self.__model.append([a.get_kind().get_name() + ': ' + a.get_username() + '@' + a.get_url()])
+ else:
+ tree_iter = self.__model.append([a.get_kind().get_name() + ': ' + a.get_username()])
+
+ self.__model_tree_iter_by_account[a] = tree_iter
+
+ if len(self.__model_tree_iter_by_account) == 1:
+ self.__current_account = a
+ self.__accounts_combo.set_active(0)
+ @log_except(_logger)
def __on_account_removed(self, accts, a):
_logger.debug("account removed %s" % a)
- if a in self.__editors_by_account:
+ if a in self.__model_tree_iter_by_account:
_logger.debug("will remove")
- editor = self.__editors_by_account[a]
- del self.__editors_by_account[a]
- editor.destroy() ## should remove it from vbox
+ self.__model.remove(self.__model_tree_iter_by_account[a])
+ del self.__model_tree_iter_by_account[a]
+ #TODO: figure out how we update the current account here,
+ # possibly calling __on_edited_account_changed will do, but then
+ # but than it needs to check if self.__model_tree_iter_by_account is empty
+
+ def __on_edited_account_changed(self, *args):
+ new_iter = self.__accounts_combo.get_active_iter()
+ _logger.debug("account changed to %s" % self.__model.get_value(new_iter, 0))
+ for (a, tree_iter) in self.__model_tree_iter_by_account.items():
+ # this assumes that text for each entry in the drop down box is different, which it should be
+ if self.__model.get_value(tree_iter, 0) == self.__model.get_value(new_iter, 0):
+ self.__current_account = a
+ # TODO: this will trigger __on_password_entry_changed, make sure that is harmless
+ self.__password_entry.set_text(a.get_password())
+ return
+ _logger.error("new edited account was not found in self.__model_tree_iter_by_account")
+
+ def __on_password_entry_changed(self, entry):
+ text = entry.get_text()
+ accounts.get_accounts().save_account_changes(self.__current_account,
+ { 'password' : text })
def __on_delete_event(self, dialog, event):
self.hide()
@@ -125,6 +186,7 @@
__dialog = None
+ log_except(_logger)
def open_dialog():
global __dialog
if not __dialog:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]