* Getting more of the login outside of the UI thread
authorepage <eopage@byu.net>
Thu, 28 May 2009 00:13:04 +0000 (00:13 +0000)
committerepage <eopage@byu.net>
Thu, 28 May 2009 00:13:04 +0000 (00:13 +0000)
* Lint cleanup
* Single sourcing the tracking of the version
* Removing dead code

git-svn-id: file:///svnroot/gc-dialer/trunk@330 c39d3808-3fe2-4d86-a59f-b7f623ee9f21

src/constants.py [new file with mode: 0644]
src/dc_glade.py
src/gc_backend.py
src/gc_views.py
src/gdata_backend.py [deleted file]
src/gv_backend.py
src/null_backend.py

diff --git a/src/constants.py b/src/constants.py
new file mode 100644 (file)
index 0000000..131e69e
--- /dev/null
@@ -0,0 +1,4 @@
+__pretty_app_name__ = "DialCentral"
+__app_name__ = "dialcentral"
+__version__ = "0.9.8"
+__app_magic__ = 0xdeadbeef
index 2fd9e8d..8159eb8 100755 (executable)
@@ -18,11 +18,10 @@ You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-@bug SMS Dialog issues on Hildon
+@bug Need to add unit tests
 @bug Session timeouts are bad, possible solutions:
        @li For every X minutes, if logged in, attempt login
        @li Restructure so code handling login/dial/sms is beneath everything else and login attempts are made if those fail
-@todo Force login on connect if not already done
 @todo Can't text from dialpad (so can't do any arbitrary number texts)
 @todo Add logging support to make debugging issues for people a lot easier
 """
@@ -47,6 +46,7 @@ try:
 except ImportError:
        hildon = None
 
+import constants
 import gtk_toolbox
 
 
@@ -68,11 +68,6 @@ def display_error_message(msg):
 
 class Dialcentral(object):
 
-       __pretty_app_name__ = "DialCentral"
-       __app_name__ = "dialcentral"
-       __version__ = "0.9.8"
-       __app_magic__ = 0xdeadbeef
-
        _glade_files = [
                '/usr/lib/dialcentral/dialcentral.glade',
                os.path.join(os.path.dirname(__file__), "dialcentral.glade"),
@@ -154,7 +149,7 @@ class Dialcentral(object):
                if hildon is not None:
                        self._window.set_title("Keypad")
                else:
-                       self._window.set_title("%s - Keypad" % self.__pretty_app_name__)
+                       self._window.set_title("%s - Keypad" % constants.__pretty_app_name__)
 
                callbackMapping = {
                        "on_dialpad_quit": self._on_close,
@@ -199,7 +194,7 @@ class Dialcentral(object):
                        osso = None
                self._osso = None
                if osso is not None:
-                       self._osso = osso.Context(Dialcentral.__app_name__, Dialcentral.__version__, False)
+                       self._osso = osso.Context(constants.__app_name__, constants.__version__, False)
                        device = osso.DeviceState(self._osso)
                        device.set_device_state_callback(self._on_device_state_change, 0)
                else:
@@ -213,7 +208,7 @@ class Dialcentral(object):
                self._connection = None
                if conic is not None:
                        self._connection = conic.Connection()
-                       self._connection.connect("connection-event", self._on_connection_change, Dialcentral.__app_magic__)
+                       self._connection.connect("connection-event", self._on_connection_change, constants.__app_magic__)
                        self._connection.request_connection(conic.CONNECT_FLAG_NONE)
                else:
                        pass # warnings.warn("No Internet Connectivity API ", UserWarning)
@@ -319,6 +314,8 @@ class Dialcentral(object):
        def attempt_login(self, numOfAttempts = 10, force = False):
                """
                @todo Handle user notification better like attempting to login and failed login
+
+               @note This must be run outside of the UI lock
                """
                try:
                        assert 0 <= numOfAttempts, "That was pointless having 0 or less login attempts"
@@ -337,8 +334,7 @@ class Dialcentral(object):
                                        pass
 
                        if not loggedIn:
-                               with gtk_toolbox.gtk_lock():
-                                       loggedIn, serviceId = self._login_by_user(numOfAttempts)
+                               loggedIn, serviceId = self._login_by_user(numOfAttempts)
 
                        with gtk_toolbox.gtk_lock():
                                self._change_loggedin_status(serviceId)
@@ -381,6 +377,9 @@ class Dialcentral(object):
                return loggedIn
 
        def _login_by_user(self, numOfAttempts):
+               """
+               @note This must be run outside of the UI lock
+               """
                loggedIn, (username, password) = False, self._credentials
                tmpServiceId = self.NULL_BACKEND
                for attemptCount in xrange(numOfAttempts):
@@ -390,9 +389,10 @@ class Dialcentral(object):
                                self.GV_BACKEND: "Google Voice",
                                self.GC_BACKEND: "Grand Central",
                        }
-                       credentials = self._credentialsDialog.request_credentials_from(
-                               availableServices, defaultCredentials = self._credentials
-                       )
+                       with gtk_toolbox.gtk_lock():
+                               credentials = self._credentialsDialog.request_credentials_from(
+                                       availableServices, defaultCredentials = self._credentials
+                               )
                        tmpServiceId, username, password = credentials
                        loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
 
@@ -448,9 +448,9 @@ class Dialcentral(object):
                @note UI Thread
                """
                try:
-                       self._defaultBackendId = int(config.get(self.__pretty_app_name__, "active"))
+                       self._defaultBackendId = int(config.get(constants.__pretty_app_name__, "active"))
                        blobs = (
-                               config.get(self.__pretty_app_name__, "bin_blob_%i" % i)
+                               config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
                                for i in xrange(len(self._credentials))
                        )
                        creds = (
@@ -490,11 +490,11 @@ class Dialcentral(object):
                """
                @note Thread Agnostic
                """
-               config.add_section(self.__pretty_app_name__)
-               config.set(self.__pretty_app_name__, "active", str(self._selectedBackendId))
+               config.add_section(constants.__pretty_app_name__)
+               config.set(constants.__pretty_app_name__, "active", str(self._selectedBackendId))
                for i, value in enumerate(self._credentials):
                        blob = base64.b64encode(value)
-                       config.set(self.__pretty_app_name__, "bin_blob_%i" % i, blob)
+                       config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
                for backendId, view in itertools.chain(
                        self._dialpads.iteritems(),
                        self._accountViews.iteritems(),
@@ -617,7 +617,7 @@ class Dialcentral(object):
                if hildon is not None:
                        self._window.set_title(tabTitle)
                else:
-                       self._window.set_title("%s - %s" % (self.__pretty_app_name__, tabTitle))
+                       self._window.set_title("%s - %s" % (constants.__pretty_app_name__, tabTitle))
 
        def _on_sms_clicked(self, number, message):
                """
@@ -693,8 +693,8 @@ class Dialcentral(object):
 
        def _on_about_activate(self, *args):
                dlg = gtk.AboutDialog()
-               dlg.set_name(self.__pretty_app_name__)
-               dlg.set_version(self.__version__)
+               dlg.set_name(constants.__pretty_app_name__)
+               dlg.set_version(constants.__version__)
                dlg.set_copyright("Copyright 2008 - LGPL")
                dlg.set_comments("Dialer is designed to interface with your Google Grandcentral account.  This application is not affiliated with Google or Grandcentral in any way")
                dlg.set_website("http://gc-dialer.garage.maemo.org/")
@@ -717,7 +717,7 @@ def run_doctest():
 def run_dialpad():
        gtk.gdk.threads_init()
        if hildon is not None:
-               gtk.set_application_name(Dialcentral.__pretty_app_name__)
+               gtk.set_application_name(constants.__pretty_app_name__)
        handle = Dialcentral()
        gtk.main()
 
index a12c77d..f8d09b8 100644 (file)
@@ -346,7 +346,7 @@ def test_backend(username, password):
        print "Authenticated: ", backend.is_authed()
        print "Login?: ", backend.login(username, password)
        print "Authenticated: ", backend.is_authed()
-       print "Token: ", backend._accessToken
+       # print "Token: ", backend._accessToken
        print "Account: ", backend.get_account_number()
        print "Callback: ", backend.get_callback_number()
        # print "All Callback: ",
index 11d982c..630e213 100644 (file)
@@ -28,6 +28,7 @@ import gobject
 import gtk
 
 import gtk_toolbox
+import null_backend
 
 
 def make_ugly(prettynumber):
@@ -93,69 +94,6 @@ def make_pretty(phonenumber):
        return prettynumber
 
 
-def make_idler(func):
-       """
-       Decorator that makes a generator-function into a function that will continue execution on next call
-       """
-       a = []
-
-       def decorated_func(*args, **kwds):
-               if not a:
-                       a.append(func(*args, **kwds))
-               try:
-                       a[0].next()
-                       return True
-               except StopIteration:
-                       del a[:]
-                       return False
-
-       decorated_func.__name__ = func.__name__
-       decorated_func.__doc__ = func.__doc__
-       decorated_func.__dict__.update(func.__dict__)
-
-       return decorated_func
-
-
-class DummyAddressBook(object):
-       """
-       Minimal example of both an addressbook factory and an addressbook
-       """
-
-       def clear_caches(self):
-               pass
-
-       def get_addressbooks(self):
-               """
-               @returns Iterable of (Address Book Factory, Book Id, Book Name)
-               """
-               yield self, "", "None"
-
-       def open_addressbook(self, bookId):
-               return self
-
-       @staticmethod
-       def contact_source_short_name(contactId):
-               return ""
-
-       @staticmethod
-       def factory_name():
-               return ""
-
-       @staticmethod
-       def get_contacts():
-               """
-               @returns Iterable of (contact id, contact name)
-               """
-               return []
-
-       @staticmethod
-       def get_contact_details(contactId):
-               """
-               @returns Iterable of (Phone Type, Phone Number)
-               """
-               return []
-
-
 class MergedAddressBook(object):
        """
        Merger of all addressbooks
@@ -971,7 +909,7 @@ class ContactsView(object):
                self._backend = backend
 
                self._addressBook = None
-               self._addressBookFactories = [DummyAddressBook()]
+               self._addressBookFactories = [null_backend.NullAddressBook()]
 
                self._booksList = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
                self._booksSelectionBox = widgetTree.get_widget("addressbook_combo")
diff --git a/src/gdata_backend.py b/src/gdata_backend.py
deleted file mode 100644 (file)
index 8560ab3..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/python
-
-import sys
-sys.path.insert(0,"../gdata/src/")
-
-
-try:
-       import atom
-       import gdata
-       gdata.contacts
-except (ImportError, AttributeError):
-       atom = None
-       gdata = None
-
-
-class GDataAddressBook(object):
-       """
-       """
-
-       def __init__(self, client, id = None):
-               self._client = client
-               self._id = id
-               self._contacts = []
-
-       def clear_caches(self):
-               del self._contacts[:]
-
-       @staticmethod
-       def factory_name():
-               return "GData"
-
-       @staticmethod
-       def contact_source_short_name(contactId):
-               return "gd"
-
-       def get_contacts(self):
-               """
-               @returns Iterable of (contact id, contact name)
-               """
-               return []
-
-       def get_contact_details(self, contactId):
-               """
-               @returns Iterable of (Phone Type, Phone Number)
-               """
-               return []
-
-       def _get_contacts(self):
-               if len(self._contacts) != 0:
-                       return self._contacts
-               feed = self._get_feed()
-               for entry in feed:
-                       name = entry.title.text
-                       print name
-                       for extendedProperty in entry.extended_property:
-                               if extendedProperty.value:
-                                       print extendedProperty.value
-                               else:
-                                       print extendedProperty.GetXmlBlobString()
-
-       def _get_feed(self):
-               if self._id is None:
-                       return self._client.GetContactsFeed()
-               else:
-                       pass
-
-
-class GDataAddressBookFactory(object):
-
-       def __init__(self, username, password):
-               self._username = username
-               self._password = password
-               self._client = None
-
-               if gdata is None:
-                       return
-               self._client = gdata.contacts.service.ContactsService()
-               self._client.email = username
-               self._client.password = password
-               self._client.source = "DialCentra"
-               self._client.ProgrammaticLogin()
-
-       def clear_caches(self):
-               if gdata is None:
-                       return
-
-       def get_addressbooks(self):
-               """
-               @returns Iterable of (Address Book Factory, Book Id, Book Name)
-               """
-               if gdata is None:
-                       return
-               feed = self._client.GetGroupsFeed()
-               for entry in feed:
-                       id = entry.id.text
-                       name = entry.title.text
-                       yield self, id, name
-               yield self, "all", "All"
-
-       def open_addressbook(self, bookId):
-               if gdata is None:
-                       return
-               if bookId == "all":
-                       return GDataAddressBook(self._client)
-               else:
-                       return GDataAddressBook(self._client, bookId)
-
-       @staticmethod
-       def factory_name():
-               return "GData"
-
-
-def print_gbooks(username, password):
-       """
-       Included here for debugging.
-
-       Either insert it into the code or launch python with the "-i" flag
-       """
-       abf = GDataAddressBookFactory(username, password)
-       for book in abf.get_addressbooks():
-               ab = abf.open_addressbook(book[1])
-               print book
-               for contact in ab.get_contacts():
-                       print "\t", contact
-                       for details in ab.get_contact_details(contact[0]):
-                               print "\t\t", details
index a1233b0..514626a 100644 (file)
@@ -515,7 +515,7 @@ class GVDialer(object):
 
        def _parse_voicemail(self, voicemailHtml):
                splitVoicemail = self._seperateVoicemailsRegex.split(voicemailHtml)
-               for id, messageHtml in itergroup(splitVoicemail[1:], 2):
+               for messageId, messageHtml in itergroup(splitVoicemail[1:], 2):
                        exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
                        exactTime = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
                        exactTime = datetime.datetime.strptime(exactTime, "%m/%d/%y %I:%M %p")
@@ -536,7 +536,7 @@ class GVDialer(object):
                        ) if messageGroups else ()
 
                        yield {
-                               "id": id.strip(),
+                               "id": messageId.strip(),
                                "time": exactTime,
                                "relTime": relativeTime,
                                "prettyNumber": prettyNumber,
@@ -568,7 +568,7 @@ class GVDialer(object):
 
        def _parse_sms(self, smsHtml):
                splitSms = self._seperateVoicemailsRegex.split(smsHtml)
-               for id, messageHtml in itergroup(splitSms[1:], 2):
+               for messageId, messageHtml in itergroup(splitSms[1:], 2):
                        exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
                        exactTime = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
                        exactTime = datetime.datetime.strptime(exactTime, "%m/%d/%y %I:%M %p")
@@ -590,7 +590,7 @@ class GVDialer(object):
                        messageParts = itertools.izip(fromParts, textParts, timeParts)
 
                        yield {
-                               "id": id.strip(),
+                               "id": messageId.strip(),
                                "time": exactTime,
                                "relTime": relativeTime,
                                "prettyNumber": prettyNumber,
@@ -619,7 +619,7 @@ def test_backend(username, password):
        print "Authenticated: ", backend.is_authed()
        print "Login?: ", backend.login(username, password)
        print "Authenticated: ", backend.is_authed()
-       print "Token: ", backend._token
+       # print "Token: ", backend._token
        print "Account: ", backend.get_account_number()
        print "Callback: ", backend.get_callback_number()
        # print "All Callback: ",
index 07222cd..c07f724 100644 (file)
@@ -92,3 +92,43 @@ class NullDialer(object):
 
        def get_messages(self):
                return ()
+
+
+class NullAddressBook(object):
+       """
+       Minimal example of both an addressbook factory and an addressbook
+       """
+
+       def clear_caches(self):
+               pass
+
+       def get_addressbooks(self):
+               """
+               @returns Iterable of (Address Book Factory, Book Id, Book Name)
+               """
+               yield self, "", "None"
+
+       def open_addressbook(self, bookId):
+               return self
+
+       @staticmethod
+       def contact_source_short_name(contactId):
+               return ""
+
+       @staticmethod
+       def factory_name():
+               return ""
+
+       @staticmethod
+       def get_contacts():
+               """
+               @returns Iterable of (contact id, contact name)
+               """
+               return []
+
+       @staticmethod
+       def get_contact_details(contactId):
+               """
+               @returns Iterable of (Phone Type, Phone Number)
+               """
+               return []