--- /dev/null
+__pretty_app_name__ = "DialCentral"
+__app_name__ = "dialcentral"
+__version__ = "0.9.8"
+__app_magic__ = 0xdeadbeef
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
"""
except ImportError:
hildon = None
+import constants
import gtk_toolbox
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"),
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,
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:
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)
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"
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)
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):
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)
@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 = (
"""
@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(),
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):
"""
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/")
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()
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: ",
import gtk
import gtk_toolbox
+import null_backend
def make_ugly(prettynumber):
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
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")
+++ /dev/null
-#!/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
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")
) if messageGroups else ()
yield {
- "id": id.strip(),
+ "id": messageId.strip(),
"time": exactTime,
"relTime": relativeTime,
"prettyNumber": prettyNumber,
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")
messageParts = itertools.izip(fromParts, textParts, timeParts)
yield {
- "id": id.strip(),
+ "id": messageId.strip(),
"time": exactTime,
"relTime": relativeTime,
"prettyNumber": prettyNumber,
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: ",
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 []