Very minor cleanups
[gc-dialer] / src / dialcentral / gc_dialer.py
index b0eb0d6..fc8c85a 100755 (executable)
@@ -40,11 +40,6 @@ except ImportError:
 
 
 
-gtk.gdk.threads_init()
-#This changes the default, system wide, socket timeout so that a hung server will not completly
-#hork the application
-
-
 def make_ugly(prettynumber):
        """
        function to take a phone number and strip out all non-numeric
@@ -121,7 +116,7 @@ def make_idler(func):
                except StopIteration:
                        del a[:]
                        return False
-       
+
        decorated_func.__name__ = func.__name__
        decorated_func.__doc__ = func.__doc__
        decorated_func.__dict__.update(func.__dict__)
@@ -139,7 +134,7 @@ class DummyAddressBook(object):
                @returns Iterable of (Address Book Factory, Book Id, Book Name)
                """
                yield self, "", "None"
-       
+
        def open_addressbook(self, bookId):
                return self
 
@@ -180,7 +175,7 @@ class MergedAddressBook(object):
                @returns Iterable of (Address Book Factory, Book Id, Book Name)
                """
                yield self, "", ""
-       
+
        def open_addressbook(self, bookId):
                return self
 
@@ -273,7 +268,7 @@ class PhoneTypeSelector(object):
                self._typeviewselection.unselect_all()
                self._dialog.hide()
                return phoneNumber
-       
+
        def _on_phonetype_select(self, *args):
                self._dialog.response(gtk.RESPONSE_OK)
 
@@ -289,9 +284,9 @@ class Dialpad(object):
        __app_magic__ = 0xdeadbeef
 
        _glade_files = [
-               './gc_dialer.glade',
-               '../lib/gc_dialer.glade',
                '/usr/lib/dialcentral/gc_dialer.glade',
+               os.path.join(os.path.dirname(__file__), "gc_dialer.glade"),
+               os.path.join(os.path.dirname(__file__), "../lib/gc_dialer.glade"),
        ]
 
        def __init__(self):
@@ -313,7 +308,7 @@ class Dialpad(object):
                self._contactsviewselection = None
 
                self._clearall_id = None
-               
+
                for path in Dialpad._glade_files:
                        if os.path.isfile(path):
                                self._widgetTree = gtk.glade.XML(path)
@@ -404,7 +399,7 @@ class Dialpad(object):
                """
                If something can be done after the UI loads, push it here so it's not blocking the UI
                """
-               
+
                import gc_backend
                import evo_backend
                import gmail_backend
@@ -450,14 +445,14 @@ class Dialpad(object):
                self._addressBookFactories.insert(0, mergedBook)
                self._addressBook = None
                self.open_addressbook(*self.get_addressbooks().next()[0][0:2])
-       
+
                gtk.gdk.threads_enter()
                self._booksList = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
                gtk.gdk.threads_leave()
 
                for (factoryId, bookId), (factoryName, bookName) in self.get_addressbooks():
                        if factoryName and bookName:
-                               entryName = "%s: %s" % (factoryName, bookName) 
+                               entryName = "%s: %s" % (factoryName, bookName)
                        elif factoryName:
                                entryName = factoryName
                        elif bookName:
@@ -583,6 +578,7 @@ class Dialpad(object):
                return False
 
        def _idly_populate_contactsview(self):
+               #@todo Add a lock so only one code path can be in here at a time
                self._contactstime = time.time()
                self._contactsmodel.clear()
 
@@ -591,8 +587,9 @@ class Dialpad(object):
                contactsview.freeze_child_notify()
                contactsview.set_model(None)
 
-               for contactId, contactName in self._addressBook.get_contacts():
-                       contactType = (self._addressBook.contact_source_short_name(contactId),)
+               addressBook = self._addressBook
+               for contactId, contactName in addressBook.get_contacts():
+                       contactType = (addressBook.contact_source_short_name(contactId),)
                        self._contactsmodel.append(contactType + (contactName, "", contactId) + ("",))
 
                # restart the treeview data rendering
@@ -612,7 +609,7 @@ class Dialpad(object):
 
                if self._gcBackend.is_authed():
                        return True
-               
+
                for x in xrange(numOfAttempts):
                        gtk.gdk.threads_enter()
 
@@ -654,7 +651,7 @@ class Dialpad(object):
                for i, factory in enumerate(self._addressBookFactories):
                        for bookFactory, bookId, bookName in factory.get_addressbooks():
                                yield (i, bookId), (factory.factory_name(), bookName)
-       
+
        def open_addressbook(self, bookFactoryId, bookId):
                self._addressBook = self._addressBookFactories[bookFactoryId].open_addressbook(bookId)
                self._contactstime = 0
@@ -716,7 +713,7 @@ class Dialpad(object):
                        self._isFullScreen = True
                else:
                        self._isFullScreen = False
-       
+
        def _on_key_press(self, widget, event, *args):
                """
                @note Hildon specific
@@ -851,7 +848,7 @@ class Dialpad(object):
                self.set_number("")
 
        def _on_digit_clicked(self, widget):
-               self.set_number(self._phonenumber + widget.get_name()[5])
+               self.set_number(self._phonenumber + widget.get_name()[-1])
 
        def _on_backspace(self, widget):
                self.set_number(self._phonenumber[:-1])
@@ -878,7 +875,7 @@ class Dialpad(object):
                dlg.set_authors(["<z2n@merctech.com>", "Eric Warnke <ericew@gmail.com>", "Ed Page <edpage@byu.net>"])
                dlg.run()
                dlg.destroy()
-       
+
 
 def run_doctest():
        import doctest