Having the Contacts tab remember which was the last addressbook viewed
authorepage <eopage@byu.net>
Thu, 20 Aug 2009 01:57:36 +0000 (01:57 +0000)
committerepage <eopage@byu.net>
Thu, 20 Aug 2009 01:57:36 +0000 (01:57 +0000)
(Hopefully) stabalizing contacts
Removing the unused (and untested) Evolution addressbook backend

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

src/dc_glade.py
src/evo_backend.py [deleted file]
src/gc_views.py
support/builddeb.py

index 94d5406..19fcefb 100755 (executable)
@@ -244,7 +244,6 @@ class Dialcentral(object):
                        import gv_backend
                        import gc_backend
                        import file_backend
-                       import evo_backend
                        import gc_views
 
                        try:
@@ -303,7 +302,6 @@ class Dialcentral(object):
                                        ),
                                })
 
-                       evoBackend = evo_backend.EvolutionAddressBook()
                        fsContactsPath = os.path.join(constants._data_path_, "contacts")
                        fileBackend = file_backend.FilesystemAddressBookFactory(fsContactsPath)
                        for backendId in (self.GV_BACKEND, self.GC_BACKEND):
@@ -314,7 +312,6 @@ class Dialcentral(object):
 
                                addressBooks = [
                                        self._phoneBackends[backendId],
-                                       evoBackend,
                                        fileBackend,
                                ]
                                mergedBook = gc_views.MergedAddressBook(addressBooks, gc_views.MergedAddressBook.advanced_lastname_sorter)
diff --git a/src/evo_backend.py b/src/evo_backend.py
deleted file mode 100644 (file)
index 0b71ebf..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-#!/usr/bin/python
-
-"""
-DialCentral - Front end for Google's Grand Central service.
-Copyright (C) 2008  Eric Warnke ericew AT gmail DOT com
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Lesser General Public License for more details.
-
-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
-
-Evolution Contact Support
-
-@bug It seems the evolution contact API used is specific to the desktop.  evolution.ebook combined with abook is what is needed for Maemo.
-       http://maemo.org/maemo_release_documentation/maemo4.1.x/node8.html#SECTION00870000000000000000
-       https://garage.maemo.org/svn/pymaemo/packages/python-abook/trunk/tests/ especially contact_get_iter amd filter_model
-       http://pymaemo.garage.maemo.org/documentation/api/abook/index.html
-"""
-
-
-try:
-       import evolution
-except ImportError:
-       evolution = None
-
-
-class EvolutionAddressBook(object):
-       """
-       @note Combined the factory and the addressbook for "simplicity" and "cutting down" the number of allocations/deallocations
-       """
-
-       def __init__(self, bookId = None):
-               if not self.is_supported():
-                       return
-
-               self._phoneTypes = None
-               if bookId is not None:
-                       self._bookId = bookId
-               else:
-                       try:
-                               self._bookId = [
-                                       bookData[1]
-                                               for bookData in self.get_addressbooks()
-                               ][0]
-                       except IndexError:
-                               global evolution
-                               evolution = None
-                               return
-               self._book = evolution.ebook.open_addressbook(self._bookId)
-
-       @classmethod
-       def is_supported(cls):
-               return evolution is not None
-
-       def get_addressbooks(self):
-               """
-               @returns Iterable of (Address Book Factory, Book Id, Book Name)
-               """
-               if not self.is_supported():
-                       return
-
-               if len(evolution.ebook.list_addressbooks()) == 0 and evolution.ebook.open_addressbook('default') is not None:
-                       # It appears that Maemo's e-d-s does not always list the default addressbook, so we're faking it being listed
-                       yield self, "default", "Maemo"
-
-               for bookId in evolution.ebook.list_addressbooks():
-                       yield self, bookId[1], bookId[0]
-
-       def open_addressbook(self, bookId):
-               self._bookId = bookId
-               self._book = evolution.ebook.open_addressbook(self._bookId)
-               return self
-
-       @staticmethod
-       def contact_source_short_name(contactId):
-               return "Evo"
-
-       def clear_caches(self):
-               pass
-
-       @staticmethod
-       def factory_name():
-               return "Evolution"
-
-       def get_contacts(self):
-               """
-               @returns Iterable of (contact id, contact name)
-               """
-               if not self.is_supported():
-                       return
-
-               for contact in self._book.get_all_contacts():
-                       yield str(contact.get_uid()), contact.props.full_name
-
-       def get_contact_details(self, contactId):
-               """
-               @returns Iterable of (Phone Type, Phone Number)
-               """
-               contact = self._book.get_contact(int(contactId))
-
-               if self._phoneTypes is None and contact is not None:
-                       self._phoneTypes = [pt for pt in dir(contact.props) if "phone" in pt.lower()]
-
-               for phoneType in self._phoneTypes:
-                       phoneNumber = getattr(contact.props, phoneType)
-                       if isinstance(phoneNumber, str):
-                               yield phoneType, phoneNumber
-
-
-def print_evobooks():
-       """
-       Included here for debugging.
-
-       Either insert it into the code or launch python with the "-i" flag
-       """
-       if not EvolutionAddressBook.is_supported():
-               print "No Evolution Support"
-               return
-
-       eab = EvolutionAddressBook()
-       for book in eab.get_addressbooks():
-               eab = eab.open_addressbook(book[1])
-               print book
-               for contact in eab.get_contacts():
-                       print "\t", contact
-                       for details in eab.get_contact_details(contact[0]):
-                               print "\t\t", details
index dc96129..322a876 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 from __future__ import with_statement
 
+import ConfigParser
 import warnings
 
 import gobject
@@ -483,7 +484,7 @@ class Dialpad(object):
 
        def set_number(self, number):
                """
-               Set the callback phonenumber
+               Set the number to dial
                """
                try:
                        self._phonenumber = make_ugly(number)
@@ -742,8 +743,6 @@ class AccountInfo(object):
                number = make_ugly(text)
                self._set_callback_number(number)
 
-               self.save_everything()
-
        def _on_notify_toggled(self, *args):
                if self._applyAlarmTimeoutId is not None:
                        gobject.source_remove(self._applyAlarmTimeoutId)
@@ -1072,6 +1071,7 @@ class ContactsView(object):
                self._backend = backend
 
                self._addressBook = None
+               self._selectedComboIndex = 0
                self._addressBookFactories = [null_backend.NullAddressBook()]
 
                self._booksList = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
@@ -1135,11 +1135,12 @@ class ContactsView(object):
                cell = gtk.CellRendererText()
                self._booksSelectionBox.pack_start(cell, True)
                self._booksSelectionBox.add_attribute(cell, 'text', 2)
-               self._booksSelectionBox.set_active(0)
 
                self._onContactsviewRowActivatedId = self._contactsview.connect("row-activated", self._on_contactsview_row_activated)
                self._onAddressbookComboChangedId = self._booksSelectionBox.connect("changed", self._on_addressbook_combo_changed)
 
+               self._booksSelectionBox.set_active(self._selectedComboIndex)
+
        def disable(self):
                self._contactsview.disconnect(self._onContactsviewRowActivatedId)
                self._booksSelectionBox.disconnect(self._onAddressbookComboChangedId)
@@ -1163,11 +1164,16 @@ class ContactsView(object):
                """
                for i, factory in enumerate(self._addressBookFactories):
                        for bookFactory, bookId, bookName in factory.get_addressbooks():
-                               yield (i, bookId), (factory.factory_name(), bookName)
+                               yield (str(i), bookId), (factory.factory_name(), bookName)
 
        def open_addressbook(self, bookFactoryId, bookId):
-               self._addressBook = self._addressBookFactories[bookFactoryId].open_addressbook(bookId)
-               self.update(force=True)
+               bookFactoryIndex = int(bookFactoryId)
+               addressBook = self._addressBookFactories[bookFactoryIndex].open_addressbook(bookId)
+
+               forceUpdate = True if addressBook is not self._addressBook else False
+
+               self._addressBook = addressBook
+               self.update(force=forceUpdate)
 
        def update(self, force = False):
                if not force and self._isPopulated:
@@ -1192,25 +1198,23 @@ class ContactsView(object):
        def name():
                return "Contacts"
 
-       def load_settings(self, config, section):
-               pass
+       def load_settings(self, config, sectionName):
+               try:
+                       self._selectedComboIndex = config.getint(sectionName, "selectedAddressbook")
+               except ConfigParser.NoOptionError:
+                       self._selectedComboIndex = 0
 
-       def save_settings(self, config, section):
-               """
-               @note Thread Agnostic
-               """
-               pass
+       def save_settings(self, config, sectionName):
+               config.set(sectionName, "selectedAddressbook", str(self._selectedComboIndex))
 
        def _idly_populate_contactsview(self):
-               self.clear()
-               self._isPopulated = True
-
-               # completely disable updating the treeview while we populate the data
-               self._contactsview.freeze_child_notify()
-               try:
-                       self._contactsview.set_model(None)
-
+               addressBook = None
+               while addressBook is not self._addressBook:
                        addressBook = self._addressBook
+                       with gtk_toolbox.gtk_lock():
+                               self._contactsview.set_model(None)
+                               self.clear()
+
                        try:
                                contacts = addressBook.get_contacts()
                        except StandardError, e:
@@ -1221,19 +1225,20 @@ class ContactsView(object):
                                contactType = (addressBook.contact_source_short_name(contactId), )
                                self._contactsmodel.append(contactType + (contactName, "", contactId) + ("", ))
 
-                       # restart the treeview data rendering
-                       self._contactsview.set_model(self._contactsmodel)
-               finally:
-                       self._contactsview.thaw_child_notify()
+                       with gtk_toolbox.gtk_lock():
+                               self._contactsview.set_model(self._contactsmodel)
+
+               self._isPopulated = True
                return False
 
        def _on_addressbook_combo_changed(self, *args, **kwds):
                itr = self._booksSelectionBox.get_active_iter()
                if itr is None:
                        return
-               factoryId = int(self._booksList.get_value(itr, 0))
-               bookId = self._booksList.get_value(itr, 1)
-               self.open_addressbook(factoryId, bookId)
+               self._selectedComboIndex = self._booksSelectionBox.get_active()
+               selectedFactoryId = self._booksList.get_value(itr, 0)
+               selectedBookId = self._booksList.get_value(itr, 1)
+               self.open_addressbook(selectedFactoryId, selectedBookId)
 
        def _on_contactsview_row_activated(self, treeview, path, view_column):
                model, itr = self._contactsviewselection.get_selected()
index fbb13e1..53fd55d 100755 (executable)
@@ -19,6 +19,8 @@ __version__ = constants.__version__
 __build__ = 0
 __changelog__ = '''
 1.0.5
+* Feature: Contacts Tab remembers the last address book viewed on restart
+* Bug Fix: Not clearing the entered number on sending an SMS
 
 1.0.4
 * "Back" button and tabs now visually indicate when they've entered a "hold" state