Merging in files from skeleton
authorEd Page <eopage@byu.net>
Fri, 16 Jul 2010 01:47:06 +0000 (20:47 -0500)
committerEd Page <eopage@byu.net>
Fri, 16 Jul 2010 01:47:27 +0000 (20:47 -0500)
58 files changed:
Makefile
README
src/REPLACEME.py [deleted file]
src/REPLACEME_gtk.py [deleted file]
src/REPLACEME_qt.py [deleted file]
src/alarm_handler.py [new file with mode: 0644]
src/alarm_notify.py [new file with mode: 0755]
src/backends/__init__.py [new file with mode: 0644]
src/backends/browser_emu.py [new file with mode: 0644]
src/backends/file_backend.py [new file with mode: 0644]
src/backends/gv_backend.py [new file with mode: 0644]
src/backends/gvoice.py [new file with mode: 0755]
src/backends/merge_backend.py [new file with mode: 0644]
src/backends/null_backend.py [new file with mode: 0644]
src/constants.py
src/dc_glade.py [new file with mode: 0755]
src/dialcentral.glade [new file with mode: 0644]
src/dialcentral.py [new file with mode: 0755]
src/examples/log_notifier.py [new file with mode: 0644]
src/examples/sound_notifier.py [new file with mode: 0644]
src/gtk_toolbox.py
src/gv_views.py [new file with mode: 0644]
src/led_handler.py [new file with mode: 0755]
src/maeqt.py [deleted file]
src/null_views.py [new file with mode: 0644]
support/builddeb.py
support/dialcentral.desktop [new file with mode: 0644]
support/icons/hicolor/26x26/hildon/dialcentral.png [new file with mode: 0644]
support/icons/hicolor/64x64/hildon/dialcentral.png [new file with mode: 0644]
support/icons/hicolor/scalable/hildon/dialcentral.png [new file with mode: 0644]
tests/basic_data/basic.csv [new file with mode: 0644]
tests/basic_data/empty.csv [new file with mode: 0644]
tests/basic_data/google.csv [new file with mode: 0644]
tests/basic_data/grandcentral.csv [new file with mode: 0644]
tests/basic_data/settings.ini [new file with mode: 0644]
tests/dummy_hildon/__init__.py [new file with mode: 0644]
tests/dummy_hildon/hildon.py [new file with mode: 0644]
tests/gv_samples/__init__.py [new file with mode: 0644]
tests/gv_samples/generate_gv_samples.py [new file with mode: 0755]
tests/test_file_backend.py [new file with mode: 0644]
tests/test_gv_backend.py [new file with mode: 0644]
tests/test_startup.py [new file with mode: 0644]
www/dialcentral.deb [new file with mode: 0644]
www/download.html
www/images/Dialcentral - Accounts - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Accounts Callback - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Contacts - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Contacts Phone Select - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Contacts Response - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Messages - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Messages Response Down - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Messages Response Start - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Messages Response Up - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Recent - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/images/Dialcentral - Recent Response - 1.0.7-12 Fremantle.png [new file with mode: 0644]
www/index.html
www/screenshots.html

index 6b80980..15eff8c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-PROJECT_NAME=REPLACEME
+PROJECT_NAME=dialcentral
 SOURCE_PATH=src
 SOURCE=$(shell find $(SOURCE_PATH) -iname "*.py")
 PROGRAM=$(SOURCE_PATH)/$(PROJECT_NAME).py
@@ -25,7 +25,7 @@ CTAGS=ctags-exuberant
 all: test
 
 run: $(OBJ)
-       $(SOURCE_PATH)/$(PROJECT_NAME).py
+       $(SOURCE_PATH)/dc_glade.py
 
 profile: $(OBJ)
        $(PROFILE_GEN) $(PROGRAM)
diff --git a/README b/README
index ac2fe23..b87ce9c 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,37 @@
 Building a package
 ===================
 Run
-       make package
+       make PLATFORM=... package
+which will create a "./pkg-.../..." heirarchy.  Move this structure to somewhere on the tablet, then run pypackager. 
+
+Supported PLATFORMs include
+       desktop
+       os2007
+       os2008
+
+SDK Enviroment
+===================
+
+Native
+
+Follow install instructions
+       Ubuntu: http://www.linuxuk.org/node/38
+Install Nokia stuff (for each target)
+       fakeroot apt-get install maemo-explicit
+
+Userful commands
+Login
+       /scratchbox/login
+Change targets
+       sb-conf select DIABLO_ARMEL
+       sb-conf select DIABLO_X86
+Fixing it
+       fakeroot apt-get -f install
+
+Starting scratchbox
+       Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -extension Composite
+       scratchbox
+       export DISPLAY=:2
+       af-sb-init.sh start
+Then running a command in the "Maemo" terminal will launch it in the Xephyr session
+       Tip: run with "run-standalone.sh" for niceness?
diff --git a/src/REPLACEME.py b/src/REPLACEME.py
deleted file mode 100755 (executable)
index fee6217..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-Copyright (C) 2007 Christoph Würstle
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License version 2 as
-published by the Free Software Foundation.
-"""
-
-
-import os
-import sys
-import logging
-
-
-_moduleLogger = logging.getLogger(__name__)
-sys.path.append("/opt/REPLACEME/lib")
-
-
-import constants
-import REPLACEME_gtk
-
-
-if __name__ == "__main__":
-       try:
-               os.makedirs(constants._data_path_)
-       except OSError, e:
-               if e.errno != 17:
-                       raise
-
-       try:
-               os.makedirs(constants._cache_path_)
-       except OSError, e:
-               if e.errno != 17:
-                       raise
-
-       logFormat = '(%(asctime)s) %(levelname)-5s %(threadName)s.%(name)s: %(message)s'
-       logging.basicConfig(level=logging.DEBUG, filename=constants._user_logpath_, format=logFormat)
-       _moduleLogger.info("%s %s-%s" % (constants.__app_name__, constants.__version__, constants.__build__))
-       _moduleLogger.info("OS: %s" % (os.uname()[0], ))
-       _moduleLogger.info("Kernel: %s (%s) for %s" % os.uname()[2:])
-       _moduleLogger.info("Hostname: %s" % os.uname()[1])
-
-       REPLACEME_gtk.run()
diff --git a/src/REPLACEME_gtk.py b/src/REPLACEME_gtk.py
deleted file mode 100755 (executable)
index 4fa96ed..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-from __future__ import with_statement
-
-import gc
-import logging
-import ConfigParser
-
-import gobject
-import dbus
-import gtk
-
-try:
-       import osso
-except ImportError:
-       osso = None
-
-import constants
-import hildonize
-import util.misc as misc_utils
-
-
-_moduleLogger = logging.getLogger(__name__)
-PROFILE_STARTUP = False
-
-
-class REPLACEMEProgram(hildonize.get_app_class()):
-
-       def __init__(self):
-               super(REPLACEMEProgram, self).__init__()
-
-               if not hildonize.IS_HILDON_SUPPORTED:
-                       _moduleLogger.info("No hildonization support")
-
-               if osso is not None:
-                       self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
-                       self._deviceState = osso.DeviceState(self._osso_c)
-                       self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
-               else:
-                       _moduleLogger.info("No osso support")
-                       self._osso_c = None
-                       self._deviceState = None
-
-       def _save_settings(self):
-               config = ConfigParser.SafeConfigParser()
-
-               self._REPLACEME.save_settings(config, "Windows")
-
-               with open(constants._user_settings_, "wb") as configFile:
-                       config.write(configFile)
-
-       def _load_settings(self):
-               config = ConfigParser.SafeConfigParser()
-               config.read(constants._user_settings_)
-
-               self._REPLACEME.load_settings(config, "Windows")
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
-               """
-               For system_inactivity, we have no background tasks to pause
-
-               @note Hildon specific
-               """
-               if memory_low:
-                       gc.collect()
-
-               if save_unsaved_data or shutdown:
-                       self._save_settings()
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_destroy(self, widget = None, data = None):
-               try:
-                       self.quit()
-               finally:
-                       gtk.main_quit()
-
-       def quit(self):
-               try:
-                       self._save_settings()
-               except Exception:
-                       _moduleLogger.exception("Error saving settigns")
-
-               try:
-                       self._deviceState.close()
-               except AttributeError:
-                       pass # Either None or close was removed (in Fremantle)
-               except Exception:
-                       _moduleLogger.exception("Error closing device state")
-               try:
-                       self._osso_c.close()
-               except AttributeError:
-                       pass # Either None or close was removed (in Fremantle)
-               except Exception:
-                       _moduleLogger.exception("Error closing osso state")
-
-
-def run():
-       gobject.threads_init()
-       gtk.gdk.threads_init()
-       l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
-       # HACK Playback while silent on Maemo 5
-       hildonize.set_application_name("FMRadio")
-
-       app = REPLACEMElProgram()
-       if not PROFILE_STARTUP:
-               try:
-                       gtk.main()
-               except KeyboardInterrupt:
-                       app.quit()
-                       raise
-       else:
-               app.quit()
-
-
-if __name__ == "__main__":
-       logging.basicConfig(level=logging.DEBUG)
-       run()
diff --git a/src/REPLACEME_qt.py b/src/REPLACEME_qt.py
deleted file mode 100755 (executable)
index a66596e..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: UTF8 -*-
-
-from __future__ import with_statement
-
-import sys
-import os
-import simplejson
-import logging
-
-from PyQt4 import QtGui
-from PyQt4 import QtCore
-
-import constants
-import maeqt
-from util import misc as misc_utils
-import unit_data
-
-
-_moduleLogger = logging.getLogger(__name__)
-
-
-IS_MAEMO = True
-
-
-class REPLACEME(object):
-
-       _DATA_PATHS = [
-               os.path.dirname(__file__),
-               os.path.join(os.path.dirname(__file__), "../data"),
-               os.path.join(os.path.dirname(__file__), "../lib"),
-               '/usr/share/%s' % constants.__app_name__,
-               '/usr/lib/%s' % constants.__app_name__,
-       ]
-
-       def __init__(self, app):
-               self._dataPath = ""
-               for dataPath in self._DATA_PATHS:
-                       appIconPath = os.path.join(dataPath, "pixmaps", "%s.png" %  constants.__app_name__)
-                       if os.path.isfile(appIconPath):
-                               self._dataPath = dataPath
-                               break
-               else:
-                       raise RuntimeError("UI Descriptor not found!")
-               self._app = app
-               self._appIconPath = appIconPath
-               self._recent = []
-               self._hiddenCategories = set()
-               self._hiddenUnits = {}
-               self._clipboard = QtGui.QApplication.clipboard()
-
-               self._mainWindow = None
-
-               self._fullscreenAction = QtGui.QAction(None)
-               self._fullscreenAction.setText("Fullscreen")
-               self._fullscreenAction.setCheckable(True)
-               self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
-               self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen)
-
-               self._logAction = QtGui.QAction(None)
-               self._logAction.setText("Log")
-               self._logAction.setShortcut(QtGui.QKeySequence("CTRL+l"))
-               self._logAction.triggered.connect(self._on_log)
-
-               self._quitAction = QtGui.QAction(None)
-               self._quitAction.setText("Quit")
-               self._quitAction.setShortcut(QtGui.QKeySequence("CTRL+q"))
-               self._quitAction.triggered.connect(self._on_quit)
-
-               self._app.lastWindowClosed.connect(self._on_app_quit)
-               self.load_settings()
-
-       def load_settings(self):
-               try:
-                       with open(constants._user_settings_, "r") as settingsFile:
-                               settings = simplejson.load(settingsFile)
-               except IOError, e:
-                       _moduleLogger.info("No settings")
-                       settings = {}
-               except ValueError:
-                       _moduleLogger.info("Settings were corrupt")
-                       settings = {}
-
-               self._fullscreenAction.setChecked(settings.get("isFullScreen", False))
-
-       def save_settings(self):
-               settings = {
-                       "isFullScreen": self._fullscreenAction.isChecked(),
-               }
-               with open(constants._user_settings_, "w") as settingsFile:
-                       simplejson.dump(settings, settingsFile)
-
-       @property
-       def appIconPath(self):
-               return self._appIconPath
-
-       @property
-       def fullscreenAction(self):
-               return self._fullscreenAction
-
-       @property
-       def logAction(self):
-               return self._logAction
-
-       @property
-       def quitAction(self):
-               return self._quitAction
-
-       def _close_windows(self):
-               if self._mainWindow is not None:
-                       self._mainWindow.window.destroyed.disconnect(self._on_child_close)
-                       self._mainWindow.close()
-                       self._mainWindow = None
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_app_quit(self, checked = False):
-               self.save_settings()
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_child_close(self, obj = None):
-               self._mainWindow = None
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_toggle_fullscreen(self, checked = False):
-               for window in self._walk_children():
-                       window.set_fullscreen(checked)
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_log(self, checked = False):
-               with open(constants._user_logpath_, "r") as f:
-                       logLines = f.xreadlines()
-                       log = "".join(logLines)
-                       self._clipboard.setText(log)
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_quit(self, checked = False):
-               self._close_windows()
-
-
-class MainWindow(object):
-
-       def __init__(self, parent, app):
-               self._app = app
-
-               self._layout = QtGui.QVBoxLayout()
-
-               centralWidget = QtGui.QWidget()
-               centralWidget.setLayout(self._layout)
-
-               self._window = QtGui.QMainWindow(parent)
-               self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
-               maeqt.set_autorient(self._window, True)
-               maeqt.set_stackable(self._window, True)
-               self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
-               self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
-               self._window.setCentralWidget(centralWidget)
-
-               self._closeWindowAction = QtGui.QAction(None)
-               self._closeWindowAction.setText("Close")
-               self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
-               self._closeWindowAction.triggered.connect(self._on_close_window)
-
-               if IS_MAEMO:
-                       fileMenu = self._window.menuBar().addMenu("&File")
-
-                       viewMenu = self._window.menuBar().addMenu("&View")
-
-                       self._window.addAction(self._closeWindowAction)
-                       self._window.addAction(self._app.quitAction)
-                       self._window.addAction(self._app.fullscreenAction)
-               else:
-                       fileMenu = self._window.menuBar().addMenu("&Units")
-                       fileMenu.addAction(self._closeWindowAction)
-                       fileMenu.addAction(self._app.quitAction)
-
-                       viewMenu = self._window.menuBar().addMenu("&View")
-                       viewMenu.addAction(self._app.fullscreenAction)
-
-               self._window.addAction(self._app.logAction)
-
-               self.set_fullscreen(self._app.fullscreenAction.isChecked())
-               self._window.show()
-
-       @property
-       def window(self):
-               return self._window
-
-       def walk_children(self):
-               return ()
-
-       def show(self):
-               self._window.show()
-               for child in self.walk_children():
-                       child.show()
-
-       def hide(self):
-               for child in self.walk_children():
-                       child.hide()
-               self._window.hide()
-
-       def close(self):
-               for child in self.walk_children():
-                       child.window.destroyed.disconnect(self._on_child_close)
-                       child.close()
-               self._window.close()
-
-       def set_fullscreen(self, isFullscreen):
-               if isFullscreen:
-                       self._window.showFullScreen()
-               else:
-                       self._window.showNormal()
-               for child in self.walk_children():
-                       child.set_fullscreen(isFullscreen)
-
-       @misc_utils.log_exception(_moduleLogger)
-       def _on_close_window(self, checked = True):
-               self.close()
-
-
-def run():
-       app = QtGui.QApplication([])
-       handle = REPLACEME(app)
-       return app.exec_()
-
-
-if __name__ == "__main__":
-       logging.basicConfig(level = logging.DEBUG)
-       try:
-               os.makedirs(constants._data_path_)
-       except OSError, e:
-               if e.errno != 17:
-                       raise
-
-       val = run()
-       sys.exit(val)
diff --git a/src/alarm_handler.py b/src/alarm_handler.py
new file mode 100644 (file)
index 0000000..e0366ce
--- /dev/null
@@ -0,0 +1,323 @@
+#!/usr/bin/env python
+
+import os
+import time
+import datetime
+import ConfigParser
+
+import dbus
+
+
+_FREMANTLE_ALARM = "Fremantle"
+_DIABLO_ALARM = "Diablo"
+_NO_ALARM = "None"
+
+
+try:
+       import alarm
+       ALARM_TYPE = _FREMANTLE_ALARM
+except (ImportError, OSError):
+       try:
+               import osso.alarmd as alarmd
+               ALARM_TYPE = _DIABLO_ALARM
+       except (ImportError, OSError):
+               ALARM_TYPE = _NO_ALARM
+
+
+def _get_start_time(recurrence):
+       now = datetime.datetime.now()
+       startTimeMinute = now.minute + max(recurrence, 5) # being safe
+       startTimeHour = now.hour + int(startTimeMinute / 60)
+       startTimeMinute = startTimeMinute % 59
+       now.replace(minute=startTimeMinute)
+       timestamp = int(time.mktime(now.timetuple()))
+       return timestamp
+
+
+def _create_recurrence_mask(recurrence, base):
+       """
+       >>> bin(_create_recurrence_mask(60, 60))
+       '0b1'
+       >>> bin(_create_recurrence_mask(30, 60))
+       '0b1000000000000000000000000000001'
+       >>> bin(_create_recurrence_mask(2, 60))
+       '0b10101010101010101010101010101010101010101010101010101010101'
+       >>> bin(_create_recurrence_mask(1, 60))
+       '0b111111111111111111111111111111111111111111111111111111111111'
+       """
+       mask = 0
+       for i in xrange(base / recurrence):
+               mask |= 1 << (recurrence * i)
+       return mask
+
+
+def _unpack_minutes(recurrence):
+       """
+       >>> _unpack_minutes(0)
+       (0, 0, 0)
+       >>> _unpack_minutes(1)
+       (0, 0, 1)
+       >>> _unpack_minutes(59)
+       (0, 0, 59)
+       >>> _unpack_minutes(60)
+       (0, 1, 0)
+       >>> _unpack_minutes(129)
+       (0, 2, 9)
+       >>> _unpack_minutes(5 * 60 * 24 + 3 * 60 + 2)
+       (5, 3, 2)
+       >>> _unpack_minutes(12 * 60 * 24 + 3 * 60 + 2)
+       (5, 3, 2)
+       """
+       minutesInAnHour = 60
+       minutesInDay = 24 * minutesInAnHour
+       minutesInAWeek = minutesInDay * 7
+
+       days = recurrence / minutesInDay
+       daysOfWeek = days % 7
+       recurrence -= days * minutesInDay
+       hours = recurrence / minutesInAnHour
+       recurrence -= hours * minutesInAnHour
+       mins = recurrence % minutesInAnHour
+       recurrence -= mins
+       assert recurrence == 0, "Recurrence %d" % recurrence
+       return daysOfWeek, hours, mins
+
+
+class _FremantleAlarmHandler(object):
+
+       _INVALID_COOKIE = -1
+       _REPEAT_FOREVER = -1
+       _TITLE = "Dialcentral Notifications"
+       _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+
+       def __init__(self):
+               self._recurrence = 5
+
+               self._alarmCookie = self._INVALID_COOKIE
+               self._launcher = self._LAUNCHER
+
+       def load_settings(self, config, sectionName):
+               try:
+                       self._recurrence = config.getint(sectionName, "recurrence")
+                       self._alarmCookie = config.getint(sectionName, "alarmCookie")
+                       launcher = config.get(sectionName, "notifier")
+                       if launcher:
+                               self._launcher = launcher
+               except ConfigParser.NoOptionError:
+                       pass
+               except ConfigParser.NoSectionError:
+                       pass
+
+       def save_settings(self, config, sectionName):
+               config.set(sectionName, "recurrence", str(self._recurrence))
+               config.set(sectionName, "alarmCookie", str(self._alarmCookie))
+               launcher = self._launcher if self._launcher != self._LAUNCHER else ""
+               config.set(sectionName, "notifier", launcher)
+
+       def apply_settings(self, enabled, recurrence):
+               if recurrence != self._recurrence or enabled != self.isEnabled:
+                       if self.isEnabled:
+                               self._clear_alarm()
+                       if enabled:
+                               self._set_alarm(recurrence)
+               self._recurrence = int(recurrence)
+
+       @property
+       def recurrence(self):
+               return self._recurrence
+
+       @property
+       def isEnabled(self):
+               return self._alarmCookie != self._INVALID_COOKIE
+
+       def _set_alarm(self, recurrenceMins):
+               assert 1 <= recurrenceMins, "Notifications set to occur too frequently: %d" % recurrenceMins
+               alarmTime = _get_start_time(recurrenceMins)
+
+               event = alarm.Event()
+               event.appid = self._TITLE
+               event.alarm_time = alarmTime
+               event.recurrences_left = self._REPEAT_FOREVER
+
+               action = event.add_actions(1)[0]
+               action.flags |= alarm.ACTION_TYPE_EXEC | alarm.ACTION_WHEN_TRIGGERED
+               action.command = self._launcher
+
+               recurrence = event.add_recurrences(1)[0]
+               recurrence.mask_min |= _create_recurrence_mask(recurrenceMins, 60)
+               recurrence.mask_hour |= alarm.RECUR_HOUR_DONTCARE
+               recurrence.mask_mday |= alarm.RECUR_MDAY_DONTCARE
+               recurrence.mask_wday |= alarm.RECUR_WDAY_DONTCARE
+               recurrence.mask_mon |= alarm.RECUR_MON_DONTCARE
+               recurrence.special |= alarm.RECUR_SPECIAL_NONE
+
+               assert event.is_sane()
+               self._alarmCookie = alarm.add_event(event)
+
+       def _clear_alarm(self):
+               if self._alarmCookie == self._INVALID_COOKIE:
+                       return
+               alarm.delete_event(self._alarmCookie)
+               self._alarmCookie = self._INVALID_COOKIE
+
+
+class _DiabloAlarmHandler(object):
+
+       _INVALID_COOKIE = -1
+       _TITLE = "Dialcentral Notifications"
+       _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+       _REPEAT_FOREVER = -1
+
+       def __init__(self):
+               self._recurrence = 5
+
+               bus = dbus.SystemBus()
+               self._alarmdDBus = bus.get_object("com.nokia.alarmd", "/com/nokia/alarmd");
+               self._alarmCookie = self._INVALID_COOKIE
+               self._launcher = self._LAUNCHER
+
+       def load_settings(self, config, sectionName):
+               try:
+                       self._recurrence = config.getint(sectionName, "recurrence")
+                       self._alarmCookie = config.getint(sectionName, "alarmCookie")
+                       launcher = config.get(sectionName, "notifier")
+                       if launcher:
+                               self._launcher = launcher
+               except ConfigParser.NoOptionError:
+                       pass
+               except ConfigParser.NoSectionError:
+                       pass
+
+       def save_settings(self, config, sectionName):
+               config.set(sectionName, "recurrence", str(self._recurrence))
+               config.set(sectionName, "alarmCookie", str(self._alarmCookie))
+               launcher = self._launcher if self._launcher != self._LAUNCHER else ""
+               config.set(sectionName, "notifier", launcher)
+
+       def apply_settings(self, enabled, recurrence):
+               if recurrence != self._recurrence or enabled != self.isEnabled:
+                       if self.isEnabled:
+                               self._clear_alarm()
+                       if enabled:
+                               self._set_alarm(recurrence)
+               self._recurrence = int(recurrence)
+
+       @property
+       def recurrence(self):
+               return self._recurrence
+
+       @property
+       def isEnabled(self):
+               return self._alarmCookie != self._INVALID_COOKIE
+
+       def _set_alarm(self, recurrence):
+               assert 1 <= recurrence, "Notifications set to occur too frequently: %d" % recurrence
+               alarmTime = _get_start_time(recurrence)
+
+               #Setup the alarm arguments so that they can be passed to the D-Bus add_event method
+               _DEFAULT_FLAGS = (
+                       alarmd.ALARM_EVENT_NO_DIALOG |
+                       alarmd.ALARM_EVENT_NO_SNOOZE |
+                       alarmd.ALARM_EVENT_CONNECTED
+               )
+               action = []
+               action.extend(['flags', _DEFAULT_FLAGS])
+               action.extend(['title', self._TITLE])
+               action.extend(['path', self._launcher])
+               action.extend([
+                       'arguments',
+                       dbus.Array(
+                               [alarmTime, int(27)],
+                               signature=dbus.Signature('v')
+                       )
+               ])  #int(27) used in place of alarm_index
+
+               event = []
+               event.extend([dbus.ObjectPath('/AlarmdEventRecurring'), dbus.UInt32(4)])
+               event.extend(['action', dbus.ObjectPath('/AlarmdActionExec')])  #use AlarmdActionExec instead of AlarmdActionDbus
+               event.append(dbus.UInt32(len(action) / 2))
+               event.extend(action)
+               event.extend(['time', dbus.Int64(alarmTime)])
+               event.extend(['recurr_interval', dbus.UInt32(recurrence)])
+               event.extend(['recurr_count', dbus.Int32(self._REPEAT_FOREVER)])
+
+               self._alarmCookie = self._alarmdDBus.add_event(*event);
+
+       def _clear_alarm(self):
+               if self._alarmCookie == self._INVALID_COOKIE:
+                       return
+               deleteResult = self._alarmdDBus.del_event(dbus.Int32(self._alarmCookie))
+               self._alarmCookie = self._INVALID_COOKIE
+               assert deleteResult != -1, "Deleting of alarm event failed"
+
+
+class _NoneAlarmHandler(object):
+
+       def __init__(self):
+               self._alarmCookie = 0
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               pass
+
+       def apply_settings(self, enabled, recurrence):
+               pass
+
+       @property
+       def recurrence(self):
+               return 0
+
+       @property
+       def isEnabled(self):
+               return False
+
+
+AlarmHandler = {
+       _FREMANTLE_ALARM: _FremantleAlarmHandler,
+       _DIABLO_ALARM: _DiabloAlarmHandler,
+       _NO_ALARM: _NoneAlarmHandler,
+}[ALARM_TYPE]
+
+
+def main():
+       import constants
+       try:
+               import optparse
+       except ImportError:
+               return
+
+       parser = optparse.OptionParser()
+       parser.add_option("-x", "--display", action="store_true", dest="display", help="Display data")
+       parser.add_option("-e", "--enable", action="store_true", dest="enabled", help="Whether the alarm should be enabled or not", default=False)
+       parser.add_option("-d", "--disable", action="store_false", dest="enabled", help="Whether the alarm should be enabled or not", default=False)
+       parser.add_option("-r", "--recurrence", action="store", type="int", dest="recurrence", help="How often the alarm occurs", default=5)
+       (commandOptions, commandArgs) = parser.parse_args()
+
+       alarmHandler = AlarmHandler()
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._user_settings_)
+       alarmHandler.load_settings(config, "alarm")
+
+       if commandOptions.display:
+               print "Alarm (%s) is %s for every %d minutes" % (
+                       alarmHandler._alarmCookie,
+                       "enabled" if alarmHandler.isEnabled else "disabled",
+                       alarmHandler.recurrence,
+               )
+       else:
+               isEnabled = commandOptions.enabled
+               recurrence = commandOptions.recurrence
+               alarmHandler.apply_settings(isEnabled, recurrence)
+
+               alarmHandler.save_settings(config, "alarm")
+               configFile = open(constants._user_settings_, "wb")
+               try:
+                       config.write(configFile)
+               finally:
+                       configFile.close()
+
+
+if __name__ == "__main__":
+       main()
diff --git a/src/alarm_notify.py b/src/alarm_notify.py
new file mode 100755 (executable)
index 0000000..7b7e93f
--- /dev/null
@@ -0,0 +1,166 @@
+#!/usr/bin/env python
+
+import os
+import filecmp
+import ConfigParser
+import pprint
+import logging
+
+import constants
+from backends import gvoice
+
+
+def get_missed(backend):
+       missedPage = backend._browser.download(backend._XML_MISSED_URL)
+       missedJson = backend._grab_json(missedPage)
+       return missedJson
+
+
+def get_voicemail(backend):
+       voicemailPage = backend._browser.download(backend._XML_VOICEMAIL_URL)
+       voicemailJson = backend._grab_json(voicemailPage)
+       return voicemailJson
+
+
+def get_sms(backend):
+       smsPage = backend._browser.download(backend._XML_SMS_URL)
+       smsJson = backend._grab_json(smsPage)
+       return smsJson
+
+
+def remove_reltime(data):
+       for messageData in data["messages"].itervalues():
+               del messageData["relativeStartTime"]
+               del messageData["labels"]
+               del messageData["isRead"]
+               del messageData["isSpam"]
+               del messageData["isTrash"]
+               del messageData["star"]
+
+
+def is_type_changed(backend, type, get_material):
+       jsonMaterial = get_material(backend)
+       unreadCount = jsonMaterial["unreadCounts"][type]
+
+       previousSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.old.json" % type)
+       currentSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.json" % type)
+
+       try:
+               os.remove(previousSnapshotPath)
+       except OSError, e:
+               # check if failed purely because the old file didn't exist, which is fine
+               if e.errno != 2:
+                       raise
+       try:
+               os.rename(currentSnapshotPath, previousSnapshotPath)
+               previousExists = True
+       except OSError, e:
+               # check if failed purely because the new old file didn't exist, which is fine
+               if e.errno != 2:
+                       raise
+               previousExists = False
+
+       remove_reltime(jsonMaterial)
+       textMaterial = pprint.pformat(jsonMaterial)
+       currentSnapshot = file(currentSnapshotPath, "w")
+       try:
+               currentSnapshot.write(textMaterial)
+       finally:
+               currentSnapshot.close()
+
+       if unreadCount == 0 or not previousExists:
+               return False
+
+       seemEqual = filecmp.cmp(previousSnapshotPath, currentSnapshotPath)
+       return not seemEqual
+
+
+def create_backend(config):
+       gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
+       backend = gvoice.GVoiceBackend(gvCookiePath)
+
+       loggedIn = False
+
+       if not loggedIn:
+               loggedIn = backend.is_authed()
+
+       if not loggedIn:
+               import base64
+               try:
+                       blobs = (
+                               config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
+                               for i in xrange(2)
+                       )
+                       creds = (
+                               base64.b64decode(blob)
+                               for blob in blobs
+                       )
+                       username, password = tuple(creds)
+                       loggedIn = backend.login(username, password)
+               except ConfigParser.NoOptionError, e:
+                       pass
+               except ConfigParser.NoSectionError, e:
+                       pass
+
+       assert loggedIn
+       return backend
+
+
+def is_changed(config, backend):
+       try:
+               notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
+               notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
+               notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
+       except ConfigParser.NoOptionError, e:
+               notifyOnMissed = False
+               notifyOnVoicemail = False
+               notifyOnSms = False
+       except ConfigParser.NoSectionError, e:
+               notifyOnMissed = False
+               notifyOnVoicemail = False
+               notifyOnSms = False
+       logging.debug(
+               "Missed: %s, Voicemail: %s, SMS: %s" % (notifyOnMissed, notifyOnVoicemail, notifyOnSms)
+       )
+
+       notifySources = []
+       if notifyOnMissed:
+               notifySources.append(("missed", get_missed))
+       if notifyOnVoicemail:
+               notifySources.append(("voicemail", get_voicemail))
+       if notifyOnSms:
+               notifySources.append(("sms", get_sms))
+
+       notifyUser = False
+       for type, get_material in notifySources:
+               if is_type_changed(backend, type, get_material):
+                       notifyUser = True
+       return notifyUser
+
+
+def notify_on_change():
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._user_settings_)
+       backend = create_backend(config)
+       notifyUser = is_changed(config, backend)
+
+       if notifyUser:
+               logging.info("Changed")
+               import led_handler
+               led = led_handler.LedHandler()
+               led.on()
+       else:
+               logging.info("No Change")
+
+
+if __name__ == "__main__":
+       logging.basicConfig(level=logging.WARNING, filename=constants._notifier_logpath_)
+       logging.info("Notifier %s-%s" % (constants.__version__, constants.__build__))
+       logging.info("OS: %s" % (os.uname()[0], ))
+       logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])
+       logging.info("Hostname: %s" % os.uname()[1])
+       try:
+               notify_on_change()
+       except:
+               logging.exception("Error")
+               raise
diff --git a/src/backends/__init__.py b/src/backends/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/backends/browser_emu.py b/src/backends/browser_emu.py
new file mode 100644 (file)
index 0000000..b676a13
--- /dev/null
@@ -0,0 +1,198 @@
+"""
+@author:         Laszlo Nagy
+@copyright:   (c) 2005 by Szoftver Messias Bt.
+@licence:       BSD style
+
+Objects of the MozillaEmulator class can emulate a browser that is capable of:
+
+       - cookie management
+       - configurable user agent string
+       - GET and POST
+       - multipart POST (send files)
+       - receive content into file
+
+I have seen many requests on the python mailing list about how to emulate a browser. I'm using this class for years now, without any problems. This is how you can use it:
+
+       1. Use firefox
+       2. Install and open the livehttpheaders plugin
+       3. Use the website manually with firefox
+       4. Check the GET and POST requests in the livehttpheaders capture window
+       5. Create an instance of the above class and send the same GET and POST requests to the server.
+
+Optional steps:
+
+       - You can change user agent string in the build_opened method
+       - The "encode_multipart_formdata" function can be used alone to create POST data from a list of field values and files
+"""
+
+import urllib2
+import cookielib
+import logging
+
+import socket
+
+
+_moduleLogger = logging.getLogger(__name__)
+socket.setdefaulttimeout(45)
+
+
+class MozillaEmulator(object):
+
+       def __init__(self, trycount = 1):
+               """Create a new MozillaEmulator object.
+
+               @param trycount: The download() method will retry the operation if it
+               fails. You can specify -1 for infinite retrying.  A value of 0 means no
+               retrying. A value of 1 means one retry. etc."""
+               self.debug = False
+               self.trycount = trycount
+               self._cookies = cookielib.LWPCookieJar()
+               self._loadedFromCookies = False
+
+       def load_cookies(self, path):
+               assert not self._loadedFromCookies, "Load cookies only once"
+               if path is None:
+                       return
+
+               self._cookies.filename = path
+               try:
+                       self._cookies.load()
+               except cookielib.LoadError:
+                       _moduleLogger.exception("Bad cookie file")
+               except IOError:
+                       _moduleLogger.exception("No cookie file")
+               except Exception, e:
+                       _moduleLogger.exception("Unknown error with cookies")
+               self._loadedFromCookies = True
+
+               return self._loadedFromCookies
+
+       def save_cookies(self):
+               if self._loadedFromCookies:
+                       self._cookies.save()
+
+       def clear_cookies(self):
+               if self._loadedFromCookies:
+                       self._cookies.clear()
+
+       def download(self, url,
+                       postdata = None, extraheaders = None, forbidRedirect = False,
+                       trycount = None, only_head = False,
+               ):
+               """Download an URL with GET or POST methods.
+
+               @param postdata: It can be a string that will be POST-ed to the URL.
+                       When None is given, the method will be GET instead.
+               @param extraheaders: You can add/modify HTTP headers with a dict here.
+               @param forbidRedirect: Set this flag if you do not want to handle
+                       HTTP 301 and 302 redirects.
+               @param trycount: Specify the maximum number of retries here.
+                       0 means no retry on error. Using -1 means infinite retring.
+                       None means the default value (that is self.trycount).
+               @param only_head: Create the openerdirector and return it. In other
+                       words, this will not retrieve any content except HTTP headers.
+
+               @return: The raw HTML page data
+               """
+               _moduleLogger.debug("Performing download of %s" % url)
+
+               if extraheaders is None:
+                       extraheaders = {}
+               if trycount is None:
+                       trycount = self.trycount
+               cnt = 0
+
+               while True:
+                       try:
+                               req, u = self._build_opener(url, postdata, extraheaders, forbidRedirect)
+                               openerdirector = u.open(req)
+                               if self.debug:
+                                       _moduleLogger.info("%r - %r" % (req.get_method(), url))
+                                       _moduleLogger.info("%r - %r" % (openerdirector.code, openerdirector.msg))
+                                       _moduleLogger.info("%r" % (openerdirector.headers))
+                               self._cookies.extract_cookies(openerdirector, req)
+                               if only_head:
+                                       return openerdirector
+
+                               return self._read(openerdirector, trycount)
+                       except urllib2.URLError, e:
+                               _moduleLogger.debug("%s: %s" % (e, url))
+                               cnt += 1
+                               if (-1 < trycount) and (trycount < cnt):
+                                       raise
+
+                       # Retry :-)
+                       _moduleLogger.debug("MozillaEmulator: urllib2.URLError, retrying %d" % cnt)
+
+       def _build_opener(self, url, postdata = None, extraheaders = None, forbidRedirect = False):
+               if extraheaders is None:
+                       extraheaders = {}
+
+               txheaders = {
+                       'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png',
+                       'Accept-Language': 'en,en-us;q=0.5',
+                       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
+               }
+               for key, value in extraheaders.iteritems():
+                       txheaders[key] = value
+               req = urllib2.Request(url, postdata, txheaders)
+               self._cookies.add_cookie_header(req)
+               if forbidRedirect:
+                       redirector = HTTPNoRedirector()
+                       #_moduleLogger.info("Redirection disabled")
+               else:
+                       redirector = urllib2.HTTPRedirectHandler()
+                       #_moduleLogger.info("Redirection enabled")
+
+               http_handler = urllib2.HTTPHandler(debuglevel=self.debug)
+               https_handler = urllib2.HTTPSHandler(debuglevel=self.debug)
+
+               u = urllib2.build_opener(
+                       http_handler,
+                       https_handler,
+                       urllib2.HTTPCookieProcessor(self._cookies),
+                       redirector
+               )
+               u.addheaders = [(
+                       'User-Agent',
+                       'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)'
+               )]
+               if not postdata is None:
+                       req.add_data(postdata)
+               return (req, u)
+
+       def _read(self, openerdirector, trycount):
+               chunks = []
+
+               chunk = openerdirector.read()
+               chunks.append(chunk)
+               #while chunk and cnt < trycount:
+               #       time.sleep(1)
+               #       cnt += 1
+               #       chunk = openerdirector.read()
+               #       chunks.append(chunk)
+
+               data = "".join(chunks)
+
+               if "Content-Length" in openerdirector.info():
+                       assert len(data) == int(openerdirector.info()["Content-Length"]), "The packet header promised %s of data but only was able to read %s of data" % (
+                               openerdirector.info()["Content-Length"],
+                               len(data),
+                       )
+
+               return data
+
+
+class HTTPNoRedirector(urllib2.HTTPRedirectHandler):
+       """This is a custom http redirect handler that FORBIDS redirection."""
+
+       def http_error_302(self, req, fp, code, msg, headers):
+               e = urllib2.HTTPError(req.get_full_url(), code, msg, headers, fp)
+               if e.code in (301, 302):
+                       if 'location' in headers:
+                               newurl = headers.getheaders('location')[0]
+                       elif 'uri' in headers:
+                               newurl = headers.getheaders('uri')[0]
+                       e.newurl = newurl
+               _moduleLogger.info("New url: %s" % e.newurl)
+               raise e
diff --git a/src/backends/file_backend.py b/src/backends/file_backend.py
new file mode 100644 (file)
index 0000000..b373561
--- /dev/null
@@ -0,0 +1,171 @@
+#!/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
+
+Filesystem backend for contact support
+"""
+
+
+import os
+import re
+import csv
+
+
+class CsvAddressBook(object):
+       """
+       Currently supported file format
+       @li Has the first line as a header
+       @li Escapes with quotes
+       @li Comma as delimiter
+       @li Column 0 is name, column 1 is number
+       """
+
+       _nameRe = re.compile("name", re.IGNORECASE)
+       _phoneRe = re.compile("phone", re.IGNORECASE)
+       _mobileRe = re.compile("mobile", re.IGNORECASE)
+
+       def __init__(self, csvPath):
+               self.__csvPath = csvPath
+               self.__contacts = list(
+                       self.read_csv(csvPath)
+               )
+
+       @classmethod
+       def read_csv(cls, csvPath):
+               try:
+                       csvReader = iter(csv.reader(open(csvPath, "rU")))
+               except IOError, e:
+                       if e.errno != 2:
+                               raise
+                       return
+
+               header = csvReader.next()
+               nameColumn, phoneColumns = cls._guess_columns(header)
+
+               yieldCount = 0
+               for row in csvReader:
+                       contactDetails = []
+                       for (phoneType, phoneColumn) in phoneColumns:
+                               try:
+                                       if len(row[phoneColumn]) == 0:
+                                               continue
+                                       contactDetails.append((phoneType, row[phoneColumn]))
+                               except IndexError:
+                                       pass
+                       if len(contactDetails) != 0:
+                               yield str(yieldCount), row[nameColumn], contactDetails
+                               yieldCount += 1
+
+       @classmethod
+       def _guess_columns(cls, row):
+               names = []
+               phones = []
+               for i, item in enumerate(row):
+                       if cls._nameRe.search(item) is not None:
+                               names.append((item, i))
+                       elif cls._phoneRe.search(item) is not None:
+                               phones.append((item, i))
+                       elif cls._mobileRe.search(item) is not None:
+                               phones.append((item, i))
+               if len(names) == 0:
+                       names.append(("Name", 0))
+               if len(phones) == 0:
+                       phones.append(("Phone", 1))
+
+               return names[0][1], phones
+
+       def clear_caches(self):
+               pass
+
+       @staticmethod
+       def factory_name():
+               return "csv"
+
+       @staticmethod
+       def contact_source_short_name(contactId):
+               return "csv"
+
+       def get_contacts(self):
+               """
+               @returns Iterable of (contact id, contact name)
+               """
+               for contact in self.__contacts:
+                       yield contact[0:2]
+
+       def get_contact_details(self, contactId):
+               """
+               @returns Iterable of (Phone Type, Phone Number)
+               """
+               contactId = int(contactId)
+               return iter(self.__contacts[contactId][2])
+
+
+class FilesystemAddressBookFactory(object):
+
+       FILETYPE_SUPPORT = {
+               "csv": CsvAddressBook,
+       }
+
+       def __init__(self, path):
+               self.__path = path
+
+       def clear_caches(self):
+               pass
+
+       def get_addressbooks(self):
+               """
+               @returns Iterable of (Address Book Factory, Book Id, Book Name)
+               """
+               for root, dirs, filenames in os.walk(self.__path):
+                       for filename in filenames:
+                               try:
+                                       name, ext = filename.rsplit(".", 1)
+                               except ValueError:
+                                       continue
+
+                               if ext in self.FILETYPE_SUPPORT:
+                                       yield self, os.path.join(root, filename), name
+
+       def open_addressbook(self, bookId):
+               name, ext = bookId.rsplit(".", 1)
+               assert ext in self.FILETYPE_SUPPORT, "Unsupported file extension %s" % ext
+               return self.FILETYPE_SUPPORT[ext](bookId)
+
+       @staticmethod
+       def factory_name():
+               return "File"
+
+
+def print_filebooks(contactPath = None):
+       """
+       Included here for debugging.
+
+       Either insert it into the code or launch python with the "-i" flag
+       """
+       if contactPath is None:
+               contactPath = os.path.join(os.path.expanduser("~"), ".dialcentral", "contacts")
+
+       abf = FilesystemAddressBookFactory(contactPath)
+       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
diff --git a/src/backends/gv_backend.py b/src/backends/gv_backend.py
new file mode 100644 (file)
index 0000000..ace5243
--- /dev/null
@@ -0,0 +1,298 @@
+#!/usr/bin/python
+
+"""
+DialCentral - Front end for Google's GoogleVoice 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
+
+Google Voice backend code
+
+Resources
+       http://thatsmith.com/2009/03/google-voice-addon-for-firefox/
+       http://posttopic.com/topic/google-voice-add-on-development
+"""
+
+from __future__ import with_statement
+
+import itertools
+import logging
+
+import gvoice
+
+
+_moduleLogger = logging.getLogger("gv_backend")
+
+
+class GVDialer(object):
+
+       def __init__(self, cookieFile = None):
+               self._gvoice = gvoice.GVoiceBackend(cookieFile)
+
+               self._contacts = None
+
+       def is_quick_login_possible(self):
+               """
+               @returns True then is_authed might be enough to login, else full login is required
+               """
+               return self._gvoice.is_quick_login_possible()
+
+       def is_authed(self, force = False):
+               """
+               Attempts to detect a current session
+               @note Once logged in try not to reauth more than once a minute.
+               @returns If authenticated
+               """
+               return self._gvoice.is_authed(force)
+
+       def login(self, username, password):
+               """
+               Attempt to login to GoogleVoice
+               @returns Whether login was successful or not
+               """
+               return self._gvoice.login(username, password)
+
+       def logout(self):
+               return self._gvoice.logout()
+
+       def is_dnd(self):
+               return self._gvoice.is_dnd()
+
+       def set_dnd(self, doNotDisturb):
+               return self._gvoice.set_dnd(doNotDisturb)
+
+       def call(self, outgoingNumber):
+               """
+               This is the main function responsible for initating the callback
+               """
+               return self._gvoice.call(outgoingNumber)
+
+       def cancel(self, outgoingNumber=None):
+               """
+               Cancels a call matching outgoing and forwarding numbers (if given). 
+               Will raise an error if no matching call is being placed
+               """
+               return self._gvoice.cancel(outgoingNumber)
+
+       def send_sms(self, phoneNumbers, message):
+               self._gvoice.send_sms(phoneNumbers, message)
+
+       def search(self, query):
+               """
+               Search your Google Voice Account history for calls, voicemails, and sms
+               Returns ``Folder`` instance containting matching messages
+               """
+               return self._gvoice.search(query)
+
+       def get_feed(self, feed):
+               return self._gvoice.get_feed(feed)
+
+       def download(self, messageId, adir):
+               """
+               Download a voicemail or recorded call MP3 matching the given ``msg``
+               which can either be a ``Message`` instance, or a SHA1 identifier. 
+               Saves files to ``adir`` (defaults to current directory). 
+               Message hashes can be found in ``self.voicemail().messages`` for example. 
+               Returns location of saved file.
+               """
+               return self._gvoice.download(messageId, adir)
+
+       def is_valid_syntax(self, number):
+               """
+               @returns If This number be called ( syntax validation only )
+               """
+               return self._gvoice.is_valid_syntax(number)
+
+       def get_account_number(self):
+               """
+               @returns The GoogleVoice phone number
+               """
+               return self._gvoice.get_account_number()
+
+       def get_callback_numbers(self):
+               """
+               @returns a dictionary mapping call back numbers to descriptions
+               @note These results are cached for 30 minutes.
+               """
+               return self._gvoice.get_callback_numbers()
+
+       def set_callback_number(self, callbacknumber):
+               """
+               Set the number that GoogleVoice calls
+               @param callbacknumber should be a proper 10 digit number
+               """
+               return self._gvoice.set_callback_number(callbacknumber)
+
+       def get_callback_number(self):
+               """
+               @returns Current callback number or None
+               """
+               return self._gvoice.get_callback_number()
+
+       def get_recent(self):
+               """
+               @returns Iterable of (personsName, phoneNumber, exact date, relative date, action)
+               """
+               return self._gvoice.get_recent()
+
+       def get_contacts(self):
+               """
+               @returns Iterable of (contact id, contact name)
+               """
+               self._update_contacts_cache()
+               contactsToSort = [
+                       (contactDetails["name"], contactId)
+                       for contactId, contactDetails in self._contacts.iteritems()
+               ]
+               contactsToSort.sort()
+               return (
+                       (contactId, contactName)
+                       for (contactName, contactId) in contactsToSort
+               )
+
+       def get_contact_details(self, contactId):
+               """
+               @returns Iterable of (Phone Type, Phone Number)
+               """
+               if self._contacts is None:
+                       self._update_contacts_cache()
+               contactDetails = self._contacts[contactId]
+               # Defaulting phoneTypes because those are just things like faxes
+               return (
+                       (number.get("phoneType", ""), number["phoneNumber"])
+                       for number in contactDetails["numbers"]
+               )
+
+       def get_messages(self):
+               voicemails = self._gvoice.get_voicemails()
+               smss = self._gvoice.get_texts()
+               conversations = itertools.chain(voicemails, smss)
+               for conversation in conversations:
+                       messages = conversation.messages
+                       messageParts = (
+                               (message.whoFrom, self._format_message(message), message.when)
+                               for message in messages
+                       )
+
+                       messageDetails = {
+                               "id": conversation.id,
+                               "contactId": conversation.contactId,
+                               "name": conversation.name,
+                               "time": conversation.time,
+                               "relTime": conversation.relTime,
+                               "prettyNumber": conversation.prettyNumber,
+                               "number": conversation.number,
+                               "location": conversation.location,
+                               "messageParts": messageParts,
+                               "type": conversation.type,
+                               "isRead": conversation.isRead,
+                               "isTrash": conversation.isTrash,
+                               "isSpam": conversation.isSpam,
+                               "isArchived": conversation.isArchived,
+                       }
+                       yield messageDetails
+
+       def clear_caches(self):
+               pass
+
+       def get_addressbooks(self):
+               """
+               @returns Iterable of (Address Book Factory, Book Id, Book Name)
+               """
+               yield self, "", ""
+
+       def open_addressbook(self, bookId):
+               return self
+
+       @staticmethod
+       def contact_source_short_name(contactId):
+               return "GV"
+
+       @staticmethod
+       def factory_name():
+               return "Google Voice"
+
+       def _update_contacts_cache(self):
+               self._contacts = dict(self._gvoice.get_contacts())
+
+       def _format_message(self, message):
+               messagePartFormat = {
+                       "med1": "<i>%s</i>",
+                       "med2": "%s",
+                       "high": "<b>%s</b>",
+               }
+               return " ".join(
+                       messagePartFormat[text.accuracy] % text.text
+                       for text in message.body
+               )
+
+
+def sort_messages(allMessages):
+       sortableAllMessages = [
+               (message["time"], message)
+               for message in allMessages
+       ]
+       sortableAllMessages.sort(reverse=True)
+       return (
+               message
+               for (exactTime, message) in sortableAllMessages
+       )
+
+
+def decorate_recent(recentCallData):
+       """
+       @returns (personsName, phoneNumber, date, action)
+       """
+       contactId = recentCallData["contactId"]
+       if recentCallData["name"]:
+               header = recentCallData["name"]
+       elif recentCallData["prettyNumber"]:
+               header = recentCallData["prettyNumber"]
+       elif recentCallData["location"]:
+               header = recentCallData["location"]
+       else:
+               header = "Unknown"
+
+       number = recentCallData["number"]
+       relTime = recentCallData["relTime"]
+       action = recentCallData["action"]
+       return contactId, header, number, relTime, action
+
+
+def decorate_message(messageData):
+       contactId = messageData["contactId"]
+       exactTime = messageData["time"]
+       if messageData["name"]:
+               header = messageData["name"]
+       elif messageData["prettyNumber"]:
+               header = messageData["prettyNumber"]
+       else:
+               header = "Unknown"
+       number = messageData["number"]
+       relativeTime = messageData["relTime"]
+
+       messageParts = list(messageData["messageParts"])
+       if len(messageParts) == 0:
+               messages = ("No Transcription", )
+       elif len(messageParts) == 1:
+               messages = (messageParts[0][1], )
+       else:
+               messages = [
+                       "<b>%s</b>: %s" % (messagePart[0], messagePart[1])
+                       for messagePart in messageParts
+               ]
+
+       decoratedResults = contactId, header, number, relativeTime, messages
+       return decoratedResults
diff --git a/src/backends/gvoice.py b/src/backends/gvoice.py
new file mode 100755 (executable)
index 0000000..19275f8
--- /dev/null
@@ -0,0 +1,969 @@
+#!/usr/bin/python
+
+"""
+DialCentral - Front end for Google's GoogleVoice 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
+
+Google Voice backend code
+
+Resources
+       http://thatsmith.com/2009/03/google-voice-addon-for-firefox/
+       http://posttopic.com/topic/google-voice-add-on-development
+"""
+
+from __future__ import with_statement
+
+import os
+import re
+import urllib
+import urllib2
+import time
+import datetime
+import itertools
+import logging
+import inspect
+
+from xml.etree import ElementTree
+
+try:
+       import simplejson as _simplejson
+       simplejson = _simplejson
+except ImportError:
+       simplejson = None
+
+import browser_emu
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+class NetworkError(RuntimeError):
+       pass
+
+
+class MessageText(object):
+
+       ACCURACY_LOW = "med1"
+       ACCURACY_MEDIUM = "med2"
+       ACCURACY_HIGH = "high"
+
+       def __init__(self):
+               self.accuracy = None
+               self.text = None
+
+       def __str__(self):
+               return self.text
+
+       def to_dict(self):
+               return to_dict(self)
+
+       def __eq__(self, other):
+               return self.accuracy == other.accuracy and self.text == other.text
+
+
+class Message(object):
+
+       def __init__(self):
+               self.whoFrom = None
+               self.body = None
+               self.when = None
+
+       def __str__(self):
+               return "%s (%s): %s" % (
+                       self.whoFrom,
+                       self.when,
+                       "".join(str(part) for part in self.body)
+               )
+
+       def to_dict(self):
+               selfDict = to_dict(self)
+               selfDict["body"] = [text.to_dict() for text in self.body] if self.body is not None else None
+               return selfDict
+
+       def __eq__(self, other):
+               return self.whoFrom == other.whoFrom and self.when == other.when and self.body == other.body
+
+
+class Conversation(object):
+
+       TYPE_VOICEMAIL = "Voicemail"
+       TYPE_SMS = "SMS"
+
+       def __init__(self):
+               self.type = None
+               self.id = None
+               self.contactId = None
+               self.name = None
+               self.location = None
+               self.prettyNumber = None
+               self.number = None
+
+               self.time = None
+               self.relTime = None
+               self.messages = None
+               self.isRead = None
+               self.isSpam = None
+               self.isTrash = None
+               self.isArchived = None
+
+       def __cmp__(self, other):
+               cmpValue = cmp(self.contactId, other.contactId)
+               if cmpValue != 0:
+                       return cmpValue
+
+               cmpValue = cmp(self.time, other.time)
+               if cmpValue != 0:
+                       return cmpValue
+
+               cmpValue = cmp(self.id, other.id)
+               if cmpValue != 0:
+                       return cmpValue
+
+       def to_dict(self):
+               selfDict = to_dict(self)
+               selfDict["messages"] = [message.to_dict() for message in self.messages] if self.messages is not None else None
+               return selfDict
+
+
+class GVoiceBackend(object):
+       """
+       This class encapsulates all of the knowledge necessary to interact with the GoogleVoice servers
+       the functions include login, setting up a callback number, and initalting a callback
+       """
+
+       PHONE_TYPE_HOME = 1
+       PHONE_TYPE_MOBILE = 2
+       PHONE_TYPE_WORK = 3
+       PHONE_TYPE_GIZMO = 7
+
+       def __init__(self, cookieFile = None):
+               # Important items in this function are the setup of the browser emulation and cookie file
+               self._browser = browser_emu.MozillaEmulator(1)
+               self._loadedFromCookies = self._browser.load_cookies(cookieFile)
+
+               self._token = ""
+               self._accountNum = ""
+               self._lastAuthed = 0.0
+               self._callbackNumber = ""
+               self._callbackNumbers = {}
+
+               # Suprisingly, moving all of these from class to self sped up startup time
+
+               self._validateRe = re.compile("^\+?[0-9]{10,}$")
+
+               self._loginURL = "https://www.google.com/accounts/ServiceLoginAuth"
+
+               SECURE_URL_BASE = "https://www.google.com/voice/"
+               SECURE_MOBILE_URL_BASE = SECURE_URL_BASE + "mobile/"
+               self._forwardURL = SECURE_MOBILE_URL_BASE + "phones"
+               self._tokenURL = SECURE_URL_BASE + "m"
+               self._callUrl = SECURE_URL_BASE + "call/connect"
+               self._callCancelURL = SECURE_URL_BASE + "call/cancel"
+               self._sendSmsURL = SECURE_URL_BASE + "sms/send"
+
+               self._isDndURL = "https://www.google.com/voice/m/donotdisturb"
+               self._isDndRe = re.compile(r"""<input.*?id="doNotDisturb".*?checked="(.*?)"\s*/>""")
+               self._setDndURL = "https://www.google.com/voice/m/savednd"
+
+               self._downloadVoicemailURL = SECURE_URL_BASE + "media/send_voicemail/"
+               self._markAsReadURL = SECURE_URL_BASE + "m/mark"
+               self._archiveMessageURL = SECURE_URL_BASE + "m/archive"
+
+               self._XML_SEARCH_URL = SECURE_URL_BASE + "inbox/search/"
+               self._XML_ACCOUNT_URL = SECURE_URL_BASE + "contacts/"
+               # HACK really this redirects to the main pge and we are grabbing some javascript
+               self._XML_CONTACTS_URL = "http://www.google.com/voice/inbox/search/contact"
+               self._XML_RECENT_URL = SECURE_URL_BASE + "inbox/recent/"
+
+               self.XML_FEEDS = (
+                       'inbox', 'starred', 'all', 'spam', 'trash', 'voicemail', 'sms',
+                       'recorded', 'placed', 'received', 'missed'
+               )
+               self._XML_INBOX_URL = SECURE_URL_BASE + "inbox/recent/inbox"
+               self._XML_STARRED_URL = SECURE_URL_BASE + "inbox/recent/starred"
+               self._XML_ALL_URL = SECURE_URL_BASE + "inbox/recent/all"
+               self._XML_SPAM_URL = SECURE_URL_BASE + "inbox/recent/spam"
+               self._XML_TRASH_URL = SECURE_URL_BASE + "inbox/recent/trash"
+               self._XML_VOICEMAIL_URL = SECURE_URL_BASE + "inbox/recent/voicemail/"
+               self._XML_SMS_URL = SECURE_URL_BASE + "inbox/recent/sms/"
+               self._XML_RECORDED_URL = SECURE_URL_BASE + "inbox/recent/recorded/"
+               self._XML_PLACED_URL = SECURE_URL_BASE + "inbox/recent/placed/"
+               self._XML_RECEIVED_URL = SECURE_URL_BASE + "inbox/recent/received/"
+               self._XML_MISSED_URL = SECURE_URL_BASE + "inbox/recent/missed/"
+
+               self._galxRe = re.compile(r"""<input.*?name="GALX".*?value="(.*?)".*?/>""", re.MULTILINE | re.DOTALL)
+               self._tokenRe = re.compile(r"""<input.*?name="_rnr_se".*?value="(.*?)"\s*/>""")
+               self._accountNumRe = re.compile(r"""<b class="ms\d">(.{14})</b></div>""")
+               self._callbackRe = re.compile(r"""\s+(.*?):\s*(.*?)<br\s*/>\s*$""", re.M)
+
+               self._contactsBodyRe = re.compile(r"""gcData\s*=\s*({.*?});""", re.MULTILINE | re.DOTALL)
+               self._seperateVoicemailsRegex = re.compile(r"""^\s*<div id="(\w+)"\s* class=".*?gc-message.*?">""", re.MULTILINE | re.DOTALL)
+               self._exactVoicemailTimeRegex = re.compile(r"""<span class="gc-message-time">(.*?)</span>""", re.MULTILINE)
+               self._relativeVoicemailTimeRegex = re.compile(r"""<span class="gc-message-relative">(.*?)</span>""", re.MULTILINE)
+               self._voicemailNameRegex = re.compile(r"""<a class=.*?gc-message-name-link.*?>(.*?)</a>""", re.MULTILINE | re.DOTALL)
+               self._voicemailNumberRegex = re.compile(r"""<input type="hidden" class="gc-text gc-quickcall-ac" value="(.*?)"/>""", re.MULTILINE)
+               self._prettyVoicemailNumberRegex = re.compile(r"""<span class="gc-message-type">(.*?)</span>""", re.MULTILINE)
+               self._voicemailLocationRegex = re.compile(r"""<span class="gc-message-location">.*?<a.*?>(.*?)</a></span>""", re.MULTILINE)
+               self._messagesContactIDRegex = re.compile(r"""<a class=".*?gc-message-name-link.*?">.*?</a>\s*?<span .*?>(.*?)</span>""", re.MULTILINE)
+               self._voicemailMessageRegex = re.compile(r"""(<span id="\d+-\d+" class="gc-word-(.*?)">(.*?)</span>|<a .*? class="gc-message-mni">(.*?)</a>)""", re.MULTILINE)
+               self._smsFromRegex = re.compile(r"""<span class="gc-message-sms-from">(.*?)</span>""", re.MULTILINE | re.DOTALL)
+               self._smsTimeRegex = re.compile(r"""<span class="gc-message-sms-time">(.*?)</span>""", re.MULTILINE | re.DOTALL)
+               self._smsTextRegex = re.compile(r"""<span class="gc-message-sms-text">(.*?)</span>""", re.MULTILINE | re.DOTALL)
+
+       def is_quick_login_possible(self):
+               """
+               @returns True then is_authed might be enough to login, else full login is required
+               """
+               return self._loadedFromCookies or 0.0 < self._lastAuthed
+
+       def is_authed(self, force = False):
+               """
+               Attempts to detect a current session
+               @note Once logged in try not to reauth more than once a minute.
+               @returns If authenticated
+               """
+               isRecentledAuthed = (time.time() - self._lastAuthed) < 120
+               isPreviouslyAuthed = self._token is not None
+               if isRecentledAuthed and isPreviouslyAuthed and not force:
+                       return True
+
+               try:
+                       page = self._get_page(self._forwardURL)
+                       self._grab_account_info(page)
+               except Exception, e:
+                       _moduleLogger.exception(str(e))
+                       return False
+
+               self._browser.save_cookies()
+               self._lastAuthed = time.time()
+               return True
+
+       def _get_token(self):
+               tokenPage = self._get_page(self._tokenURL)
+
+               galxTokens = self._galxRe.search(tokenPage)
+               if galxTokens is not None:
+                       galxToken = galxTokens.group(1)
+               else:
+                       galxToken = ""
+                       _moduleLogger.debug("Could not grab GALX token")
+               return galxToken
+
+       def _login(self, username, password, token):
+               loginData = {
+                       'Email' : username,
+                       'Passwd' : password,
+                       'service': "grandcentral",
+                       "ltmpl": "mobile",
+                       "btmpl": "mobile",
+                       "PersistentCookie": "yes",
+                       "GALX": token,
+                       "continue": self._forwardURL,
+               }
+
+               loginSuccessOrFailurePage = self._get_page(self._loginURL, loginData)
+               return loginSuccessOrFailurePage
+
+       def login(self, username, password):
+               """
+               Attempt to login to GoogleVoice
+               @returns Whether login was successful or not
+               """
+               self.logout()
+               galxToken = self._get_token()
+               loginSuccessOrFailurePage = self._login(username, password, galxToken)
+
+               try:
+                       self._grab_account_info(loginSuccessOrFailurePage)
+               except Exception, e:
+                       # Retry in case the redirect failed
+                       # luckily is_authed does everything we need for a retry
+                       loggedIn = self.is_authed(True)
+                       if not loggedIn:
+                               _moduleLogger.exception(str(e))
+                               return False
+                       _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this")
+
+               self._browser.save_cookies()
+               self._lastAuthed = time.time()
+               return True
+
+       def logout(self):
+               self._browser.clear_cookies()
+               self._browser.save_cookies()
+               self._token = None
+               self._lastAuthed = 0.0
+
+       def is_dnd(self):
+               isDndPage = self._get_page(self._isDndURL)
+
+               dndGroup = self._isDndRe.search(isDndPage)
+               if dndGroup is None:
+                       return False
+               dndStatus = dndGroup.group(1)
+               isDnd = True if dndStatus.strip().lower() == "true" else False
+               return isDnd
+
+       def set_dnd(self, doNotDisturb):
+               dndPostData = {
+                       "doNotDisturb": 1 if doNotDisturb else 0,
+               }
+
+               dndPage = self._get_page_with_token(self._setDndURL, dndPostData)
+
+       def call(self, outgoingNumber):
+               """
+               This is the main function responsible for initating the callback
+               """
+               outgoingNumber = self._send_validation(outgoingNumber)
+               subscriberNumber = None
+               phoneType = guess_phone_type(self._callbackNumber) # @todo Fix this hack
+
+               callData = {
+                               'outgoingNumber': outgoingNumber,
+                               'forwardingNumber': self._callbackNumber,
+                               'subscriberNumber': subscriberNumber or 'undefined',
+                               'phoneType': str(phoneType),
+                               'remember': '1',
+               }
+               _moduleLogger.info("%r" % callData)
+
+               page = self._get_page_with_token(
+                       self._callUrl,
+                       callData,
+               )
+               self._parse_with_validation(page)
+               return True
+
+       def cancel(self, outgoingNumber=None):
+               """
+               Cancels a call matching outgoing and forwarding numbers (if given). 
+               Will raise an error if no matching call is being placed
+               """
+               page = self._get_page_with_token(
+                       self._callCancelURL,
+                       {
+                       'outgoingNumber': outgoingNumber or 'undefined',
+                       'forwardingNumber': self._callbackNumber or 'undefined',
+                       'cancelType': 'C2C',
+                       },
+               )
+               self._parse_with_validation(page)
+
+       def send_sms(self, phoneNumbers, message):
+               validatedPhoneNumbers = [
+                       self._send_validation(phoneNumber)
+                       for phoneNumber in phoneNumbers
+               ]
+               flattenedPhoneNumbers = ",".join(validatedPhoneNumbers)
+               page = self._get_page_with_token(
+                       self._sendSmsURL,
+                       {
+                               'phoneNumber': flattenedPhoneNumbers,
+                               'text': message
+                       },
+               )
+               self._parse_with_validation(page)
+
+       def search(self, query):
+               """
+               Search your Google Voice Account history for calls, voicemails, and sms
+               Returns ``Folder`` instance containting matching messages
+               """
+               page = self._get_page(
+                       self._XML_SEARCH_URL,
+                       {"q": query},
+               )
+               json, html = extract_payload(page)
+               return json
+
+       def get_feed(self, feed):
+               actualFeed = "_XML_%s_URL" % feed.upper()
+               feedUrl = getattr(self, actualFeed)
+
+               page = self._get_page(feedUrl)
+               json, html = extract_payload(page)
+
+               return json
+
+       def download(self, messageId, adir):
+               """
+               Download a voicemail or recorded call MP3 matching the given ``msg``
+               which can either be a ``Message`` instance, or a SHA1 identifier. 
+               Saves files to ``adir`` (defaults to current directory). 
+               Message hashes can be found in ``self.voicemail().messages`` for example. 
+               Returns location of saved file.
+               """
+               page = self._get_page(self._downloadVoicemailURL, {"id": messageId})
+               fn = os.path.join(adir, '%s.mp3' % messageId)
+               with open(fn, 'wb') as fo:
+                       fo.write(page)
+               return fn
+
+       def is_valid_syntax(self, number):
+               """
+               @returns If This number be called ( syntax validation only )
+               """
+               return self._validateRe.match(number) is not None
+
+       def get_account_number(self):
+               """
+               @returns The GoogleVoice phone number
+               """
+               return self._accountNum
+
+       def get_callback_numbers(self):
+               """
+               @returns a dictionary mapping call back numbers to descriptions
+               @note These results are cached for 30 minutes.
+               """
+               if not self.is_authed():
+                       return {}
+               return self._callbackNumbers
+
+       def set_callback_number(self, callbacknumber):
+               """
+               Set the number that GoogleVoice calls
+               @param callbacknumber should be a proper 10 digit number
+               """
+               self._callbackNumber = callbacknumber
+               _moduleLogger.info("Callback number changed: %r" % self._callbackNumber)
+               return True
+
+       def get_callback_number(self):
+               """
+               @returns Current callback number or None
+               """
+               return self._callbackNumber
+
+       def get_recent(self):
+               """
+               @returns Iterable of (personsName, phoneNumber, exact date, relative date, action)
+               """
+               for action, url in (
+                       ("Received", self._XML_RECEIVED_URL),
+                       ("Missed", self._XML_MISSED_URL),
+                       ("Placed", self._XML_PLACED_URL),
+               ):
+                       flatXml = self._get_page(url)
+
+                       allRecentHtml = self._grab_html(flatXml)
+                       allRecentData = self._parse_history(allRecentHtml)
+                       for recentCallData in allRecentData:
+                               recentCallData["action"] = action
+                               yield recentCallData
+
+       def get_contacts(self):
+               """
+               @returns Iterable of (contact id, contact name)
+               """
+               page = self._get_page(self._XML_CONTACTS_URL)
+               contactsBody = self._contactsBodyRe.search(page)
+               if contactsBody is None:
+                       raise RuntimeError("Could not extract contact information")
+               accountData = _fake_parse_json(contactsBody.group(1))
+               for contactId, contactDetails in accountData["contacts"].iteritems():
+                       # A zero contact id is the catch all for unknown contacts
+                       if contactId != "0":
+                               yield contactId, contactDetails
+
+       def get_voicemails(self):
+               voicemailPage = self._get_page(self._XML_VOICEMAIL_URL)
+               voicemailHtml = self._grab_html(voicemailPage)
+               voicemailJson = self._grab_json(voicemailPage)
+               parsedVoicemail = self._parse_voicemail(voicemailHtml)
+               voicemails = self._merge_conversation_sources(parsedVoicemail, voicemailJson)
+               return voicemails
+
+       def get_texts(self):
+               smsPage = self._get_page(self._XML_SMS_URL)
+               smsHtml = self._grab_html(smsPage)
+               smsJson = self._grab_json(smsPage)
+               parsedSms = self._parse_sms(smsHtml)
+               smss = self._merge_conversation_sources(parsedSms, smsJson)
+               return smss
+
+       def mark_message(self, messageId, asRead):
+               postData = {
+                       "read": 1 if asRead else 0,
+                       "id": messageId,
+               }
+
+               markPage = self._get_page(self._markAsReadURL, postData)
+
+       def archive_message(self, messageId):
+               postData = {
+                       "id": messageId,
+               }
+
+               markPage = self._get_page(self._archiveMessageURL, postData)
+
+       def _grab_json(self, flatXml):
+               xmlTree = ElementTree.fromstring(flatXml)
+               jsonElement = xmlTree.getchildren()[0]
+               flatJson = jsonElement.text
+               jsonTree = parse_json(flatJson)
+               return jsonTree
+
+       def _grab_html(self, flatXml):
+               xmlTree = ElementTree.fromstring(flatXml)
+               htmlElement = xmlTree.getchildren()[1]
+               flatHtml = htmlElement.text
+               return flatHtml
+
+       def _grab_account_info(self, page):
+               tokenGroup = self._tokenRe.search(page)
+               if tokenGroup is None:
+                       raise RuntimeError("Could not extract authentication token from GoogleVoice")
+               self._token = tokenGroup.group(1)
+
+               anGroup = self._accountNumRe.search(page)
+               if anGroup is not None:
+                       self._accountNum = anGroup.group(1)
+               else:
+                       _moduleLogger.debug("Could not extract account number from GoogleVoice")
+
+               self._callbackNumbers = {}
+               for match in self._callbackRe.finditer(page):
+                       callbackNumber = match.group(2)
+                       callbackName = match.group(1)
+                       self._callbackNumbers[callbackNumber] = callbackName
+               if len(self._callbackNumbers) == 0:
+                       _moduleLogger.debug("Could not extract callback numbers from GoogleVoice (the troublesome page follows):\n%s" % page)
+
+       def _send_validation(self, number):
+               if not self.is_valid_syntax(number):
+                       raise ValueError('Number is not valid: "%s"' % number)
+               elif not self.is_authed():
+                       raise RuntimeError("Not Authenticated")
+               return number
+
+       def _parse_history(self, historyHtml):
+               splitVoicemail = self._seperateVoicemailsRegex.split(historyHtml)
+               for messageId, messageHtml in itergroup(splitVoicemail[1:], 2):
+                       exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
+                       exactTime = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
+                       exactTime = google_strptime(exactTime)
+                       relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
+                       relativeTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
+                       locationGroup = self._voicemailLocationRegex.search(messageHtml)
+                       location = locationGroup.group(1).strip() if locationGroup else ""
+
+                       nameGroup = self._voicemailNameRegex.search(messageHtml)
+                       name = nameGroup.group(1).strip() if nameGroup else ""
+                       numberGroup = self._voicemailNumberRegex.search(messageHtml)
+                       number = numberGroup.group(1).strip() if numberGroup else ""
+                       prettyNumberGroup = self._prettyVoicemailNumberRegex.search(messageHtml)
+                       prettyNumber = prettyNumberGroup.group(1).strip() if prettyNumberGroup else ""
+                       contactIdGroup = self._messagesContactIDRegex.search(messageHtml)
+                       contactId = contactIdGroup.group(1).strip() if contactIdGroup else ""
+
+                       yield {
+                               "id": messageId.strip(),
+                               "contactId": contactId,
+                               "name": name,
+                               "time": exactTime,
+                               "relTime": relativeTime,
+                               "prettyNumber": prettyNumber,
+                               "number": number,
+                               "location": location,
+                       }
+
+       @staticmethod
+       def _interpret_voicemail_regex(group):
+               quality, content, number = group.group(2), group.group(3), group.group(4)
+               text = MessageText()
+               if quality is not None and content is not None:
+                       text.accuracy = quality
+                       text.text = content
+                       return text
+               elif number is not None:
+                       text.accuracy = MessageText.ACCURACY_HIGH
+                       text.text = number
+                       return text
+
+       def _parse_voicemail(self, voicemailHtml):
+               splitVoicemail = self._seperateVoicemailsRegex.split(voicemailHtml)
+               for messageId, messageHtml in itergroup(splitVoicemail[1:], 2):
+                       conv = Conversation()
+                       conv.type = Conversation.TYPE_VOICEMAIL
+                       conv.id = messageId.strip()
+
+                       exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
+                       exactTimeText = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
+                       conv.time = google_strptime(exactTimeText)
+                       relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
+                       conv.relTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
+                       locationGroup = self._voicemailLocationRegex.search(messageHtml)
+                       conv.location = locationGroup.group(1).strip() if locationGroup else ""
+
+                       nameGroup = self._voicemailNameRegex.search(messageHtml)
+                       conv.name = nameGroup.group(1).strip() if nameGroup else ""
+                       numberGroup = self._voicemailNumberRegex.search(messageHtml)
+                       conv.number = numberGroup.group(1).strip() if numberGroup else ""
+                       prettyNumberGroup = self._prettyVoicemailNumberRegex.search(messageHtml)
+                       conv.prettyNumber = prettyNumberGroup.group(1).strip() if prettyNumberGroup else ""
+                       contactIdGroup = self._messagesContactIDRegex.search(messageHtml)
+                       conv.contactId = contactIdGroup.group(1).strip() if contactIdGroup else ""
+
+                       messageGroups = self._voicemailMessageRegex.finditer(messageHtml)
+                       messageParts = [
+                               self._interpret_voicemail_regex(group)
+                               for group in messageGroups
+                       ] if messageGroups else ((MessageText.ACCURACY_LOW, "No Transcription"), )
+                       message = Message()
+                       message.body = messageParts
+                       message.whoFrom = conv.name
+                       message.when = conv.time.strftime("%I:%M %p")
+                       conv.messages = (message, )
+
+                       yield conv
+
+       @staticmethod
+       def _interpret_sms_message_parts(fromPart, textPart, timePart):
+               text = MessageText()
+               text.accuracy = MessageText.ACCURACY_MEDIUM
+               text.text = textPart
+
+               message = Message()
+               message.body = (text, )
+               message.whoFrom = fromPart
+               message.when = timePart
+
+               return message
+
+       def _parse_sms(self, smsHtml):
+               splitSms = self._seperateVoicemailsRegex.split(smsHtml)
+               for messageId, messageHtml in itergroup(splitSms[1:], 2):
+                       conv = Conversation()
+                       conv.type = Conversation.TYPE_SMS
+                       conv.id = messageId.strip()
+
+                       exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
+                       exactTimeText = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
+                       conv.time = google_strptime(exactTimeText)
+                       relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
+                       conv.relTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
+                       conv.location = ""
+
+                       nameGroup = self._voicemailNameRegex.search(messageHtml)
+                       conv.name = nameGroup.group(1).strip() if nameGroup else ""
+                       numberGroup = self._voicemailNumberRegex.search(messageHtml)
+                       conv.number = numberGroup.group(1).strip() if numberGroup else ""
+                       prettyNumberGroup = self._prettyVoicemailNumberRegex.search(messageHtml)
+                       conv.prettyNumber = prettyNumberGroup.group(1).strip() if prettyNumberGroup else ""
+                       contactIdGroup = self._messagesContactIDRegex.search(messageHtml)
+                       conv.contactId = contactIdGroup.group(1).strip() if contactIdGroup else ""
+
+                       fromGroups = self._smsFromRegex.finditer(messageHtml)
+                       fromParts = (group.group(1).strip() for group in fromGroups)
+                       textGroups = self._smsTextRegex.finditer(messageHtml)
+                       textParts = (group.group(1).strip() for group in textGroups)
+                       timeGroups = self._smsTimeRegex.finditer(messageHtml)
+                       timeParts = (group.group(1).strip() for group in timeGroups)
+
+                       messageParts = itertools.izip(fromParts, textParts, timeParts)
+                       messages = [self._interpret_sms_message_parts(*parts) for parts in messageParts]
+                       conv.messages = messages
+
+                       yield conv
+
+       @staticmethod
+       def _merge_conversation_sources(parsedMessages, json):
+               for message in parsedMessages:
+                       jsonItem = json["messages"][message.id]
+                       message.isRead = jsonItem["isRead"]
+                       message.isSpam = jsonItem["isSpam"]
+                       message.isTrash = jsonItem["isTrash"]
+                       message.isArchived = "inbox" not in jsonItem["labels"]
+                       yield message
+
+       def _get_page(self, url, data = None, refererUrl = None):
+               headers = {}
+               if refererUrl is not None:
+                       headers["Referer"] = refererUrl
+
+               encodedData = urllib.urlencode(data) if data is not None else None
+
+               try:
+                       page = self._browser.download(url, encodedData, None, headers)
+               except urllib2.URLError, e:
+                       _moduleLogger.error("Translating error: %s" % str(e))
+                       raise NetworkError("%s is not accesible" % url)
+
+               return page
+
+       def _get_page_with_token(self, url, data = None, refererUrl = None):
+               if data is None:
+                       data = {}
+               data['_rnr_se'] = self._token
+
+               page = self._get_page(url, data, refererUrl)
+
+               return page
+
+       def _parse_with_validation(self, page):
+               json = parse_json(page)
+               validate_response(json)
+               return json
+
+
+def google_strptime(time):
+       """
+       Hack: Google always returns the time in the same locale.  Sadly if the
+       local system's locale is different, there isn't a way to perfectly handle
+       the time.  So instead we handle implement some time formatting
+       """
+       abbrevTime = time[:-3]
+       parsedTime = datetime.datetime.strptime(abbrevTime, "%m/%d/%y %I:%M")
+       if time[-2] == "PN":
+               parsedTime += datetime.timedelta(hours=12)
+       return parsedTime
+
+
+def itergroup(iterator, count, padValue = None):
+       """
+       Iterate in groups of 'count' values. If there
+       aren't enough values, the last result is padded with
+       None.
+
+       >>> for val in itergroup([1, 2, 3, 4, 5, 6], 3):
+       ...     print tuple(val)
+       (1, 2, 3)
+       (4, 5, 6)
+       >>> for val in itergroup([1, 2, 3, 4, 5, 6], 3):
+       ...     print list(val)
+       [1, 2, 3]
+       [4, 5, 6]
+       >>> for val in itergroup([1, 2, 3, 4, 5, 6, 7], 3):
+       ...     print tuple(val)
+       (1, 2, 3)
+       (4, 5, 6)
+       (7, None, None)
+       >>> for val in itergroup("123456", 3):
+       ...     print tuple(val)
+       ('1', '2', '3')
+       ('4', '5', '6')
+       >>> for val in itergroup("123456", 3):
+       ...     print repr("".join(val))
+       '123'
+       '456'
+       """
+       paddedIterator = itertools.chain(iterator, itertools.repeat(padValue, count-1))
+       nIterators = (paddedIterator, ) * count
+       return itertools.izip(*nIterators)
+
+
+def safe_eval(s):
+       _TRUE_REGEX = re.compile("true")
+       _FALSE_REGEX = re.compile("false")
+       s = _TRUE_REGEX.sub("True", s)
+       s = _FALSE_REGEX.sub("False", s)
+       return eval(s, {}, {})
+
+
+def _fake_parse_json(flattened):
+       return safe_eval(flattened)
+
+
+def _actual_parse_json(flattened):
+       return simplejson.loads(flattened)
+
+
+if simplejson is None:
+       parse_json = _fake_parse_json
+else:
+       parse_json = _actual_parse_json
+
+
+def extract_payload(flatXml):
+       xmlTree = ElementTree.fromstring(flatXml)
+
+       jsonElement = xmlTree.getchildren()[0]
+       flatJson = jsonElement.text
+       jsonTree = parse_json(flatJson)
+
+       htmlElement = xmlTree.getchildren()[1]
+       flatHtml = htmlElement.text
+
+       return jsonTree, flatHtml
+
+
+def validate_response(response):
+       """
+       Validates that the JSON response is A-OK
+       """
+       try:
+               assert 'ok' in response and response['ok']
+       except AssertionError:
+               raise RuntimeError('There was a problem with GV: %s' % response)
+
+
+def guess_phone_type(number):
+       if number.startswith("747") or number.startswith("1747") or number.startswith("+1747"):
+               return GVoiceBackend.PHONE_TYPE_GIZMO
+       else:
+               return GVoiceBackend.PHONE_TYPE_MOBILE
+
+
+def get_sane_callback(backend):
+       """
+       Try to set a sane default callback number on these preferences
+       1) 1747 numbers ( Gizmo )
+       2) anything with gizmo in the name
+       3) anything with computer in the name
+       4) the first value
+       """
+       numbers = backend.get_callback_numbers()
+
+       priorityOrderedCriteria = [
+               ("\+1747", None),
+               ("1747", None),
+               ("747", None),
+               (None, "gizmo"),
+               (None, "computer"),
+               (None, "sip"),
+               (None, None),
+       ]
+
+       for numberCriteria, descriptionCriteria in priorityOrderedCriteria:
+               numberMatcher = None
+               descriptionMatcher = None
+               if numberCriteria is not None:
+                       numberMatcher = re.compile(numberCriteria)
+               elif descriptionCriteria is not None:
+                       descriptionMatcher = re.compile(descriptionCriteria, re.I)
+
+               for number, description in numbers.iteritems():
+                       if numberMatcher is not None and numberMatcher.match(number) is None:
+                               continue
+                       if descriptionMatcher is not None and descriptionMatcher.match(description) is None:
+                               continue
+                       return number
+
+
+def set_sane_callback(backend):
+       """
+       Try to set a sane default callback number on these preferences
+       1) 1747 numbers ( Gizmo )
+       2) anything with gizmo in the name
+       3) anything with computer in the name
+       4) the first value
+       """
+       number = get_sane_callback(backend)
+       backend.set_callback_number(number)
+
+
+def _is_not_special(name):
+       return not name.startswith("_") and name[0].lower() == name[0] and "_" not in name
+
+
+def to_dict(obj):
+       members = inspect.getmembers(obj)
+       return dict((name, value) for (name, value) in members if _is_not_special(name))
+
+
+def grab_debug_info(username, password):
+       cookieFile = os.path.join(".", "raw_cookies.txt")
+       try:
+               os.remove(cookieFile)
+       except OSError:
+               pass
+
+       backend = GVoiceBackend(cookieFile)
+       browser = backend._browser
+
+       _TEST_WEBPAGES = [
+               ("forward", backend._forwardURL),
+               ("token", backend._tokenURL),
+               ("login", backend._loginURL),
+               ("isdnd", backend._isDndURL),
+               ("account", backend._XML_ACCOUNT_URL),
+               ("contacts", backend._XML_CONTACTS_URL),
+
+               ("voicemail", backend._XML_VOICEMAIL_URL),
+               ("sms", backend._XML_SMS_URL),
+
+               ("recent", backend._XML_RECENT_URL),
+               ("placed", backend._XML_PLACED_URL),
+               ("recieved", backend._XML_RECEIVED_URL),
+               ("missed", backend._XML_MISSED_URL),
+       ]
+
+       # Get Pages
+       print "Grabbing pre-login pages"
+       for name, url in _TEST_WEBPAGES:
+               try:
+                       page = browser.download(url)
+               except StandardError, e:
+                       print e.message
+                       continue
+               print "\tWriting to file"
+               with open("not_loggedin_%s.txt" % name, "w") as f:
+                       f.write(page)
+
+       # Login
+       print "Attempting login"
+       galxToken = backend._get_token()
+       loginSuccessOrFailurePage = backend._login(username, password, galxToken)
+       with open("loggingin.txt", "w") as f:
+               print "\tWriting to file"
+               f.write(loginSuccessOrFailurePage)
+       try:
+               backend._grab_account_info(loginSuccessOrFailurePage)
+       except Exception:
+               # Retry in case the redirect failed
+               # luckily is_authed does everything we need for a retry
+               loggedIn = backend.is_authed(True)
+               if not loggedIn:
+                       raise
+
+       # Get Pages
+       print "Grabbing post-login pages"
+       for name, url in _TEST_WEBPAGES:
+               try:
+                       page = browser.download(url)
+               except StandardError, e:
+                       print str(e)
+                       continue
+               print "\tWriting to file"
+               with open("loggedin_%s.txt" % name, "w") as f:
+                       f.write(page)
+
+       # Cookies
+       browser.save_cookies()
+       print "\tWriting cookies to file"
+       with open("cookies.txt", "w") as f:
+               f.writelines(
+                       "%s: %s\n" % (c.name, c.value)
+                       for c in browser._cookies
+               )
+
+
+def main():
+       import sys
+       logging.basicConfig(level=logging.DEBUG)
+       args = sys.argv
+       if 3 <= len(args):
+               username = args[1]
+               password = args[2]
+
+       grab_debug_info(username, password)
+
+
+if __name__ == "__main__":
+       main()
diff --git a/src/backends/merge_backend.py b/src/backends/merge_backend.py
new file mode 100644 (file)
index 0000000..476a616
--- /dev/null
@@ -0,0 +1,153 @@
+import logging
+
+
+_moduleLogger = logging.getLogger("merge_backend")
+
+
+class MergedAddressBook(object):
+       """
+       Merger of all addressbooks
+       """
+
+       def __init__(self, addressbookFactories, sorter = None):
+               self.__addressbookFactories = addressbookFactories
+               self.__addressbooks = None
+               self.__sort_contacts = sorter if sorter is not None else self.null_sorter
+
+       def clear_caches(self):
+               self.__addressbooks = None
+               for factory in self.__addressbookFactories:
+                       factory.clear_caches()
+
+       def get_addressbooks(self):
+               """
+               @returns Iterable of (Address Book Factory, Book Id, Book Name)
+               """
+               yield self, "", ""
+
+       def open_addressbook(self, bookId):
+               return self
+
+       def contact_source_short_name(self, contactId):
+               if self.__addressbooks is None:
+                       return ""
+               bookIndex, originalId = contactId.split("-", 1)
+               return self.__addressbooks[int(bookIndex)].contact_source_short_name(originalId)
+
+       @staticmethod
+       def factory_name():
+               return "All Contacts"
+
+       def get_contacts(self):
+               """
+               @returns Iterable of (contact id, contact name)
+               """
+               if self.__addressbooks is None:
+                       self.__addressbooks = list(
+                               factory.open_addressbook(id)
+                               for factory in self.__addressbookFactories
+                               for (f, id, name) in factory.get_addressbooks()
+                       )
+               contacts = (
+                       ("-".join([str(bookIndex), contactId]), contactName)
+                               for (bookIndex, addressbook) in enumerate(self.__addressbooks)
+                                       for (contactId, contactName) in addressbook.get_contacts()
+               )
+               sortedContacts = self.__sort_contacts(contacts)
+               return sortedContacts
+
+       def get_contact_details(self, contactId):
+               """
+               @returns Iterable of (Phone Type, Phone Number)
+               """
+               if self.__addressbooks is None:
+                       return []
+               bookIndex, originalId = contactId.split("-", 1)
+               return self.__addressbooks[int(bookIndex)].get_contact_details(originalId)
+
+       @staticmethod
+       def null_sorter(contacts):
+               """
+               Good for speed/low memory
+               """
+               return contacts
+
+       @staticmethod
+       def basic_firtname_sorter(contacts):
+               """
+               Expects names in "First Last" format
+               """
+               contactsWithKey = [
+                       (contactName.rsplit(" ", 1)[0], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def basic_lastname_sorter(contacts):
+               """
+               Expects names in "First Last" format
+               """
+               contactsWithKey = [
+                       (contactName.rsplit(" ", 1)[-1], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def reversed_firtname_sorter(contacts):
+               """
+               Expects names in "Last, First" format
+               """
+               contactsWithKey = [
+                       (contactName.split(", ", 1)[-1], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def reversed_lastname_sorter(contacts):
+               """
+               Expects names in "Last, First" format
+               """
+               contactsWithKey = [
+                       (contactName.split(", ", 1)[0], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def guess_firstname(name):
+               if ", " in name:
+                       return name.split(", ", 1)[-1]
+               else:
+                       return name.rsplit(" ", 1)[0]
+
+       @staticmethod
+       def guess_lastname(name):
+               if ", " in name:
+                       return name.split(", ", 1)[0]
+               else:
+                       return name.rsplit(" ", 1)[-1]
+
+       @classmethod
+       def advanced_firstname_sorter(cls, contacts):
+               contactsWithKey = [
+                       (cls.guess_firstname(contactName), (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @classmethod
+       def advanced_lastname_sorter(cls, contacts):
+               contactsWithKey = [
+                       (cls.guess_lastname(contactName), (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
diff --git a/src/backends/null_backend.py b/src/backends/null_backend.py
new file mode 100644 (file)
index 0000000..6909c7c
--- /dev/null
@@ -0,0 +1,146 @@
+#!/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
+"""
+
+
+class NullDialer(object):
+
+       def __init__(self):
+               pass
+
+       def is_quick_login_possible(self):
+               return False
+
+       def is_authed(self, force = False):
+               return False
+
+       def login(self, username, password):
+               return self.is_authed()
+
+       def logout(self):
+               self.clear_caches()
+
+       def call(self, number):
+               return True
+
+       def cancel(self, outgoingNumber=None):
+               pass
+
+       def send_sms(self, number, message):
+               raise NotImplementedError("SMS Is Not Supported")
+
+       def search(self, query):
+               return []
+
+       def get_feed(self, feed):
+               return {}
+
+       def download(self, messageId, adir):
+               return ""
+
+       def clear_caches(self):
+               pass
+
+       def is_valid_syntax(self, number):
+               """
+               @returns If This number be called ( syntax validation only )
+               """
+               return False
+
+       def get_account_number(self):
+               """
+               @returns The grand central phone number
+               """
+               return ""
+
+       def get_callback_numbers(self):
+               return {}
+
+       def set_callback_number(self, callbacknumber):
+               return True
+
+       def get_callback_number(self):
+               return ""
+
+       def get_recent(self):
+               return ()
+
+       def get_addressbooks(self):
+               return ()
+
+       def open_addressbook(self, bookId):
+               return self
+
+       @staticmethod
+       def contact_source_short_name(contactId):
+               return "ERROR"
+
+       @staticmethod
+       def factory_name():
+               return "ERROR"
+
+       def get_contacts(self):
+               return ()
+
+       def get_contact_details(self, contactId):
+               return ()
+
+       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 []
index 8be32c8..d41e7cd 100644 (file)
@@ -1,10 +1,12 @@
 import os
 
-__pretty_app_name__ = "REPLACEME"
-__app_name__ = "REPLACEME"
-__version__ = "0.1.0"
+__pretty_app_name__ = "DialCentral"
+__app_name__ = "dialcentral"
+__version__ = "1.1.8"
 __build__ = 0
 __app_magic__ = 0xdeadbeef
 _data_path_ = os.path.join(os.path.expanduser("~"), ".%s" % __app_name__)
 _user_settings_ = "%s/settings.ini" % _data_path_
+_custom_notifier_settings_ = "%s/notifier.ini" % _data_path_
 _user_logpath_ = "%s/%s.log" % (_data_path_, __app_name__)
+_notifier_logpath_ = "%s/notifier.log" % _data_path_
diff --git a/src/dc_glade.py b/src/dc_glade.py
new file mode 100755 (executable)
index 0000000..14ffb02
--- /dev/null
@@ -0,0 +1,1006 @@
+#!/usr/bin/env python
+
+"""
+DialCentral - Front end for Google's GoogleVoice service.
+Copyright (C) 2008  Mark Bergman bergman AT merctech 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
+"""
+
+
+from __future__ import with_statement
+
+import sys
+import gc
+import os
+import threading
+import base64
+import ConfigParser
+import itertools
+import shutil
+import logging
+
+import gtk
+import gtk.glade
+
+import constants
+import hildonize
+import gtk_toolbox
+
+
+_moduleLogger = logging.getLogger("dc_glade")
+PROFILE_STARTUP = False
+
+
+def getmtime_nothrow(path):
+       try:
+               return os.path.getmtime(path)
+       except Exception:
+               return 0
+
+
+def display_error_message(msg):
+       error_dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
+
+       def close(dialog, response):
+               dialog.destroy()
+       error_dialog.connect("response", close)
+       error_dialog.run()
+
+
+class Dialcentral(object):
+
+       _glade_files = [
+               os.path.join(os.path.dirname(__file__), "dialcentral.glade"),
+               os.path.join(os.path.dirname(__file__), "../lib/dialcentral.glade"),
+               '/usr/lib/dialcentral/dialcentral.glade',
+       ]
+
+       KEYPAD_TAB = 0
+       RECENT_TAB = 1
+       MESSAGES_TAB = 2
+       CONTACTS_TAB = 3
+       ACCOUNT_TAB = 4
+
+       NULL_BACKEND = 0
+       # 1 Was GrandCentral support so the gap was maintained for compatibility
+       GV_BACKEND = 2
+       BACKENDS = (NULL_BACKEND, GV_BACKEND)
+
+       def __init__(self):
+               self._initDone = False
+               self._connection = None
+               self._osso = None
+               self._deviceState = None
+               self._clipboard = gtk.clipboard_get()
+
+               self._credentials = ("", "")
+               self._selectedBackendId = self.NULL_BACKEND
+               self._defaultBackendId = self.GV_BACKEND
+               self._phoneBackends = None
+               self._dialpads = None
+               self._accountViews = None
+               self._messagesViews = None
+               self._historyViews = None
+               self._contactsViews = None
+               self._alarmHandler = None
+               self._ledHandler = None
+               self._originalCurrentLabels = []
+               self._fsContactsPath = os.path.join(constants._data_path_, "contacts")
+
+               for path in self._glade_files:
+                       if os.path.isfile(path):
+                               self._widgetTree = gtk.glade.XML(path)
+                               break
+               else:
+                       display_error_message("Cannot find dialcentral.glade")
+                       gtk.main_quit()
+                       return
+
+               self._window = self._widgetTree.get_widget("mainWindow")
+               self._notebook = self._widgetTree.get_widget("notebook")
+               errorBox = self._widgetTree.get_widget("errorEventBox")
+               errorDescription = self._widgetTree.get_widget("errorDescription")
+               errorClose = self._widgetTree.get_widget("errorClose")
+               self._errorDisplay = gtk_toolbox.ErrorDisplay(errorBox, errorDescription, errorClose)
+               self._credentialsDialog = gtk_toolbox.LoginWindow(self._widgetTree)
+               self._smsEntryWindow = None
+
+               self._isFullScreen = False
+               self.__isPortrait = False
+               self._app = hildonize.get_app_class()()
+               self._window = hildonize.hildonize_window(self._app, self._window)
+               hildonize.hildonize_text_entry(self._widgetTree.get_widget("usernameentry"))
+               hildonize.hildonize_password_entry(self._widgetTree.get_widget("passwordentry"))
+
+               for scrollingWidgetName in (
+                       'history_scrolledwindow',
+                       'message_scrolledwindow',
+                       'contacts_scrolledwindow',
+                       "smsMessages_scrolledwindow",
+               ):
+                       scrollingWidget = self._widgetTree.get_widget(scrollingWidgetName)
+                       assert scrollingWidget is not None, scrollingWidgetName
+                       hildonize.hildonize_scrollwindow(scrollingWidget)
+               for scrollingWidgetName in (
+                       "smsMessage_scrolledEntry",
+               ):
+                       scrollingWidget = self._widgetTree.get_widget(scrollingWidgetName)
+                       assert scrollingWidget is not None, scrollingWidgetName
+                       hildonize.hildonize_scrollwindow_with_viewport(scrollingWidget)
+
+               for buttonName in (
+                       "back",
+                       "addressbookSelectButton",
+                       "sendSmsButton",
+                       "dialButton",
+                       "callbackSelectButton",
+                       "minutesEntryButton",
+                       "clearcookies",
+                       "phoneTypeSelection",
+               ):
+                       button = self._widgetTree.get_widget(buttonName)
+                       assert button is not None, buttonName
+                       hildonize.set_button_thumb_selectable(button)
+
+               menu = hildonize.hildonize_menu(
+                       self._window,
+                       self._widgetTree.get_widget("dialpad_menubar"),
+               )
+               if not hildonize.GTK_MENU_USED:
+                       button = gtk.Button("New Login")
+                       button.connect("clicked", self._on_clearcookies_clicked)
+                       menu.append(button)
+
+                       button = gtk.Button("Refresh")
+                       button.connect("clicked", self._on_menu_refresh)
+                       menu.append(button)
+
+                       menu.show_all()
+
+               self._window.connect("key-press-event", self._on_key_press)
+               self._window.connect("window-state-event", self._on_window_state_change)
+               if not hildonize.IS_HILDON_SUPPORTED:
+                       _moduleLogger.warning("No hildonization support")
+
+               hildonize.set_application_name("%s" % constants.__pretty_app_name__)
+
+               self._window.connect("destroy", self._on_close)
+               self._window.set_default_size(800, 300)
+               self._window.show_all()
+
+               self._loginSink = gtk_toolbox.threaded_stage(
+                       gtk_toolbox.comap(
+                               self._attempt_login,
+                               gtk_toolbox.null_sink(),
+                       )
+               )
+
+               if not PROFILE_STARTUP:
+                       backgroundSetup = threading.Thread(target=self._idle_setup)
+                       backgroundSetup.setDaemon(True)
+                       backgroundSetup.start()
+               else:
+                       self._idle_setup()
+
+       def _idle_setup(self):
+               """
+               If something can be done after the UI loads, push it here so it's not blocking the UI
+               """
+               # Barebones UI handlers
+               try:
+                       from backends import null_backend
+                       import null_views
+
+                       self._phoneBackends = {self.NULL_BACKEND: null_backend.NullDialer()}
+                       with gtk_toolbox.gtk_lock():
+                               self._dialpads = {self.NULL_BACKEND: null_views.Dialpad(self._widgetTree)}
+                               self._accountViews = {self.NULL_BACKEND: null_views.AccountInfo(self._widgetTree)}
+                               self._historyViews = {self.NULL_BACKEND: null_views.CallHistoryView(self._widgetTree)}
+                               self._messagesViews = {self.NULL_BACKEND: null_views.MessagesView(self._widgetTree)}
+                               self._contactsViews = {self.NULL_BACKEND: null_views.ContactsView(self._widgetTree)}
+
+                               self._dialpads[self._selectedBackendId].enable()
+                               self._accountViews[self._selectedBackendId].enable()
+                               self._historyViews[self._selectedBackendId].enable()
+                               self._messagesViews[self._selectedBackendId].enable()
+                               self._contactsViews[self._selectedBackendId].enable()
+               except Exception, e:
+                       with gtk_toolbox.gtk_lock():
+                               self._errorDisplay.push_exception()
+
+               # Setup maemo specifics
+               try:
+                       try:
+                               import osso
+                       except (ImportError, OSError):
+                               osso = None
+                       self._osso = None
+                       self._deviceState = None
+                       if osso is not None:
+                               self._osso = osso.Context(constants.__app_name__, constants.__version__, False)
+                               self._deviceState = osso.DeviceState(self._osso)
+                               self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
+                       else:
+                               _moduleLogger.warning("No device state support")
+
+                       try:
+                               import alarm_handler
+                               if alarm_handler.AlarmHandler is not alarm_handler._NoneAlarmHandler:
+                                       self._alarmHandler = alarm_handler.AlarmHandler()
+                               else:
+                                       self._alarmHandler = None
+                       except (ImportError, OSError):
+                               alarm_handler = None
+                       except Exception:
+                               with gtk_toolbox.gtk_lock():
+                                       self._errorDisplay.push_exception()
+                               alarm_handler = None
+                       if alarm_handler is None:
+                               _moduleLogger.warning("No notification support")
+                       if hildonize.IS_HILDON_SUPPORTED:
+                               try:
+                                       import led_handler
+                                       self._ledHandler = led_handler.LedHandler()
+                               except Exception, e:
+                                       _moduleLogger.exception('LED Handling failed: "%s"' % str(e))
+                                       self._ledHandler = None
+                       else:
+                               self._ledHandler = None
+
+                       try:
+                               import conic
+                       except (ImportError, OSError):
+                               conic = None
+                       self._connection = None
+                       if conic is not None:
+                               self._connection = conic.Connection()
+                               self._connection.connect("connection-event", self._on_connection_change, constants.__app_magic__)
+                               self._connection.request_connection(conic.CONNECT_FLAG_NONE)
+                       else:
+                               _moduleLogger.warning("No connection support")
+               except Exception, e:
+                       with gtk_toolbox.gtk_lock():
+                               self._errorDisplay.push_exception()
+
+               # Setup costly backends
+               try:
+                       from backends import gv_backend
+                       from backends import file_backend
+                       import gv_views
+                       from backends import merge_backend
+
+                       with gtk_toolbox.gtk_lock():
+                               self._smsEntryWindow = gv_views.SmsEntryWindow(self._widgetTree, self._window, self._app)
+                       try:
+                               os.makedirs(constants._data_path_)
+                       except OSError, e:
+                               if e.errno != 17:
+                                       raise
+                       gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
+
+                       self._phoneBackends.update({
+                               self.GV_BACKEND: gv_backend.GVDialer(gvCookiePath),
+                       })
+                       with gtk_toolbox.gtk_lock():
+                               unifiedDialpad = gv_views.Dialpad(self._widgetTree, self._errorDisplay)
+                               self._dialpads.update({
+                                       self.GV_BACKEND: unifiedDialpad,
+                               })
+                               self._accountViews.update({
+                                       self.GV_BACKEND: gv_views.AccountInfo(
+                                               self._widgetTree, self._phoneBackends[self.GV_BACKEND], self._alarmHandler, self._errorDisplay
+                                       ),
+                               })
+                               self._accountViews[self.GV_BACKEND].save_everything = self._save_settings
+                               self._historyViews.update({
+                                       self.GV_BACKEND: gv_views.CallHistoryView(
+                                               self._widgetTree, self._phoneBackends[self.GV_BACKEND], self._errorDisplay
+                                       ),
+                               })
+                               self._messagesViews.update({
+                                       self.GV_BACKEND: gv_views.MessagesView(
+                                               self._widgetTree, self._phoneBackends[self.GV_BACKEND], self._errorDisplay
+                                       ),
+                               })
+                               self._contactsViews.update({
+                                       self.GV_BACKEND: gv_views.ContactsView(
+                                               self._widgetTree, self._phoneBackends[self.GV_BACKEND], self._errorDisplay
+                                       ),
+                               })
+
+                       fileBackend = file_backend.FilesystemAddressBookFactory(self._fsContactsPath)
+
+                       self._smsEntryWindow.send_sms = self._on_sms_clicked
+                       self._smsEntryWindow.dial = self._on_dial_clicked
+                       self._dialpads[self.GV_BACKEND].add_contact = self._add_contact
+                       self._dialpads[self.GV_BACKEND].dial = self._on_dial_clicked
+                       self._historyViews[self.GV_BACKEND].add_contact = self._add_contact
+                       self._messagesViews[self.GV_BACKEND].add_contact = self._add_contact
+                       self._contactsViews[self.GV_BACKEND].add_contact = self._add_contact
+
+                       addressBooks = [
+                               self._phoneBackends[self.GV_BACKEND],
+                               fileBackend,
+                       ]
+                       mergedBook = merge_backend.MergedAddressBook(addressBooks, merge_backend.MergedAddressBook.basic_firtname_sorter)
+                       self._contactsViews[self.GV_BACKEND].append(mergedBook)
+                       self._contactsViews[self.GV_BACKEND].extend(addressBooks)
+                       self._contactsViews[self.GV_BACKEND].open_addressbook(*self._contactsViews[self.GV_BACKEND].get_addressbooks().next()[0][0:2])
+
+                       callbackMapping = {
+                               "on_paste": self._on_paste,
+                               "on_refresh": self._on_menu_refresh,
+                               "on_clearcookies_clicked": self._on_clearcookies_clicked,
+                               "on_about_activate": self._on_about_activate,
+                       }
+                       if hildonize.GTK_MENU_USED:
+                               self._widgetTree.signal_autoconnect(callbackMapping)
+                       self._notebook.connect("switch-page", self._on_notebook_switch_page)
+                       self._widgetTree.get_widget("clearcookies").connect("clicked", self._on_clearcookies_clicked)
+
+                       with gtk_toolbox.gtk_lock():
+                               self._originalCurrentLabels = [
+                                       self._notebook.get_tab_label(self._notebook.get_nth_page(pageIndex)).get_text()
+                                       for pageIndex in xrange(self._notebook.get_n_pages())
+                               ]
+                               self._notebookTapHandler = gtk_toolbox.TapOrHold(self._notebook)
+                               self._notebookTapHandler.enable()
+                       self._notebookTapHandler.on_tap = self._reset_tab_refresh
+                       self._notebookTapHandler.on_hold = self._on_tab_refresh
+                       self._notebookTapHandler.on_holding = self._set_tab_refresh
+                       self._notebookTapHandler.on_cancel = self._reset_tab_refresh
+
+                       config = ConfigParser.SafeConfigParser()
+                       config.read(constants._user_settings_)
+                       with gtk_toolbox.gtk_lock():
+                               self.load_settings(config)
+               except Exception, e:
+                       with gtk_toolbox.gtk_lock():
+                               self._errorDisplay.push_exception()
+               finally:
+                       self._initDone = True
+                       self._spawn_attempt_login()
+
+       def _spawn_attempt_login(self, *args):
+               self._loginSink.send(args)
+
+       def _attempt_login(self, force = False):
+               """
+               @note This must be run outside of the UI lock
+               """
+               try:
+                       assert self._initDone, "Attempting login before app is fully loaded"
+
+                       serviceId = self.NULL_BACKEND
+                       loggedIn = False
+                       if not force and self._defaultBackendId != self.NULL_BACKEND:
+                               with gtk_toolbox.gtk_lock():
+                                       banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
+                               try:
+                                       self.refresh_session()
+                                       serviceId = self._defaultBackendId
+                                       loggedIn = True
+                               except Exception, e:
+                                       _moduleLogger.exception('Session refresh failed with the following message "%s"' % str(e))
+                               finally:
+                                       with gtk_toolbox.gtk_lock():
+                                               hildonize.show_busy_banner_end(banner)
+
+                       if not loggedIn:
+                               loggedIn, serviceId = self._login_by_user()
+
+                       with gtk_toolbox.gtk_lock():
+                               self._change_loggedin_status(serviceId)
+                               if loggedIn:
+                                       hildonize.show_information_banner(self._window, "Logged In")
+                               else:
+                                       hildonize.show_information_banner(self._window, "Login Failed")
+                               if not self._phoneBackends[self._defaultBackendId].get_callback_number():
+                                       # subtle reminder to the users to configure things
+                                       self._notebook.set_current_page(self.ACCOUNT_TAB)
+
+               except Exception, e:
+                       with gtk_toolbox.gtk_lock():
+                               self._errorDisplay.push_exception()
+
+       def refresh_session(self):
+               """
+               @note Thread agnostic
+               """
+               assert self._initDone, "Attempting login before app is fully loaded"
+
+               loggedIn = False
+               if not loggedIn:
+                       loggedIn = self._login_by_cookie()
+               if not loggedIn:
+                       loggedIn = self._login_by_settings()
+
+               if not loggedIn:
+                       raise RuntimeError("Login Failed")
+
+       def _login_by_cookie(self):
+               """
+               @note Thread agnostic
+               """
+               loggedIn = False
+
+               isQuickLoginPossible = self._phoneBackends[self._defaultBackendId].is_quick_login_possible()
+               if self._credentials != ("", "") and isQuickLoginPossible:
+                       if not loggedIn:
+                               loggedIn = self._phoneBackends[self._defaultBackendId].is_authed()
+
+               if loggedIn:
+                       _moduleLogger.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId])
+               else:
+                       # If the cookies are bad, scratch them completely
+                       self._phoneBackends[self._defaultBackendId].logout()
+
+               return loggedIn
+
+       def _login_by_settings(self):
+               """
+               @note Thread agnostic
+               """
+               if self._credentials == ("", ""):
+                       # Don't bother with the settings if they are blank
+                       return False
+
+               username, password = self._credentials
+               loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password)
+               if loggedIn:
+                       self._credentials = username, password
+                       _moduleLogger.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId])
+               return loggedIn
+
+       def _login_by_user(self):
+               """
+               @note This must be run outside of the UI lock
+               """
+               loggedIn, (username, password) = False, self._credentials
+               tmpServiceId = self.GV_BACKEND
+               while not loggedIn:
+                       with gtk_toolbox.gtk_lock():
+                               credentials = self._credentialsDialog.request_credentials(
+                                       defaultCredentials = self._credentials
+                               )
+                               banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
+                       try:
+                               username, password = credentials
+                               loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
+                       finally:
+                               with gtk_toolbox.gtk_lock():
+                                       hildonize.show_busy_banner_end(banner)
+
+               if loggedIn:
+                       serviceId = tmpServiceId
+                       self._credentials = username, password
+                       _moduleLogger.info("Logged into %r through user request" % self._phoneBackends[serviceId])
+               else:
+                       # Hint to the user that they are not logged in
+                       serviceId = self.NULL_BACKEND
+                       self._notebook.set_current_page(self.ACCOUNT_TAB)
+
+               return loggedIn, serviceId
+
+       def _add_contact(self, *args, **kwds):
+               self._smsEntryWindow.add_contact(*args, **kwds)
+
+       def _change_loggedin_status(self, newStatus):
+               oldStatus = self._selectedBackendId
+               if oldStatus == newStatus:
+                       return
+
+               _moduleLogger.debug("Changing from %s to %s" % (oldStatus, newStatus))
+               self._dialpads[oldStatus].disable()
+               self._accountViews[oldStatus].disable()
+               self._historyViews[oldStatus].disable()
+               self._messagesViews[oldStatus].disable()
+               self._contactsViews[oldStatus].disable()
+
+               self._dialpads[newStatus].enable()
+               self._accountViews[newStatus].enable()
+               self._historyViews[newStatus].enable()
+               self._messagesViews[newStatus].enable()
+               self._contactsViews[newStatus].enable()
+
+               self._selectedBackendId = newStatus
+
+               self._accountViews[self._selectedBackendId].update()
+               self._refresh_active_tab()
+               self._refresh_orientation()
+
+       def load_settings(self, config):
+               """
+               @note UI Thread
+               """
+               try:
+                       if not PROFILE_STARTUP:
+                               self._defaultBackendId = config.getint(constants.__pretty_app_name__, "active")
+                       else:
+                               self._defaultBackendId = self.NULL_BACKEND
+                       blobs = (
+                               config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
+                               for i in xrange(len(self._credentials))
+                       )
+                       creds = (
+                               base64.b64decode(blob)
+                               for blob in blobs
+                       )
+                       self._credentials = tuple(creds)
+
+                       if self._alarmHandler is not None:
+                               self._alarmHandler.load_settings(config, "alarm")
+
+                       isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
+                       if isFullscreen:
+                               self._window.fullscreen()
+
+                       isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
+                       if isPortrait ^ self.__isPortrait:
+                               if isPortrait:
+                                       orientation = gtk.ORIENTATION_VERTICAL
+                               else:
+                                       orientation = gtk.ORIENTATION_HORIZONTAL
+                               self.set_orientation(orientation)
+               except ConfigParser.NoOptionError, e:
+                       _moduleLogger.exception(
+                               "Settings file %s is missing section %s" % (
+                                       constants._user_settings_,
+                                       e.section,
+                               ),
+                       )
+               except ConfigParser.NoSectionError, e:
+                       _moduleLogger.exception(
+                               "Settings file %s is missing section %s" % (
+                                       constants._user_settings_,
+                                       e.section,
+                               ),
+                       )
+
+               for backendId, view in itertools.chain(
+                       self._dialpads.iteritems(),
+                       self._accountViews.iteritems(),
+                       self._messagesViews.iteritems(),
+                       self._historyViews.iteritems(),
+                       self._contactsViews.iteritems(),
+               ):
+                       sectionName = "%s - %s" % (backendId, view.name())
+                       try:
+                               view.load_settings(config, sectionName)
+                       except ConfigParser.NoOptionError, e:
+                               _moduleLogger.exception(
+                                       "Settings file %s is missing section %s" % (
+                                               constants._user_settings_,
+                                               e.section,
+                                       ),
+                               )
+                       except ConfigParser.NoSectionError, e:
+                               _moduleLogger.exception(
+                                       "Settings file %s is missing section %s" % (
+                                               constants._user_settings_,
+                                               e.section,
+                                       ),
+                               )
+
+       def save_settings(self, config):
+               """
+               @note Thread Agnostic
+               """
+               # Because we now only support GVoice, if there are user credentials,
+               # always assume its using the GVoice backend
+               if self._credentials[0] and self._credentials[1]:
+                       backend = self.GV_BACKEND
+               else:
+                       backend = self.NULL_BACKEND
+
+               config.add_section(constants.__pretty_app_name__)
+               config.set(constants.__pretty_app_name__, "active", str(backend))
+               config.set(constants.__pretty_app_name__, "portrait", str(self.__isPortrait))
+               config.set(constants.__pretty_app_name__, "fullscreen", str(self._isFullScreen))
+               for i, value in enumerate(self._credentials):
+                       blob = base64.b64encode(value)
+                       config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
+               config.add_section("alarm")
+               if self._alarmHandler is not None:
+                       self._alarmHandler.save_settings(config, "alarm")
+
+               for backendId, view in itertools.chain(
+                       self._dialpads.iteritems(),
+                       self._accountViews.iteritems(),
+                       self._messagesViews.iteritems(),
+                       self._historyViews.iteritems(),
+                       self._contactsViews.iteritems(),
+               ):
+                       sectionName = "%s - %s" % (backendId, view.name())
+                       config.add_section(sectionName)
+                       view.save_settings(config, sectionName)
+
+       def _save_settings(self):
+               """
+               @note Thread Agnostic
+               """
+               config = ConfigParser.SafeConfigParser()
+               self.save_settings(config)
+               with open(constants._user_settings_, "wb") as configFile:
+                       config.write(configFile)
+
+       def _refresh_active_tab(self):
+               pageIndex = self._notebook.get_current_page()
+               if pageIndex == self.CONTACTS_TAB:
+                       self._contactsViews[self._selectedBackendId].update(force=True)
+               elif pageIndex == self.RECENT_TAB:
+                       self._historyViews[self._selectedBackendId].update(force=True)
+               elif pageIndex == self.MESSAGES_TAB:
+                       self._messagesViews[self._selectedBackendId].update(force=True)
+
+               if pageIndex in (self.RECENT_TAB, self.MESSAGES_TAB):
+                       if self._ledHandler is not None:
+                               self._ledHandler.off()
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       hildonize.window_to_portrait(self._window)
+                       self._notebook.set_property("tab-pos", gtk.POS_BOTTOM)
+                       self.__isPortrait = True
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       hildonize.window_to_landscape(self._window)
+                       self._notebook.set_property("tab-pos", gtk.POS_LEFT)
+                       self.__isPortrait = False
+               else:
+                       raise NotImplementedError(orientation)
+
+       def get_orientation(self):
+               return gtk.ORIENTATION_VERTICAL if self.__isPortrait else gtk.ORIENTATION_HORIZONTAL
+
+       def _toggle_rotate(self):
+               if self.__isPortrait:
+                       self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+               else:
+                       self.set_orientation(gtk.ORIENTATION_VERTICAL)
+
+       def _refresh_orientation(self):
+               """
+               Mostly meant to be used when switching backends
+               """
+               if self.__isPortrait:
+                       self.set_orientation(gtk.ORIENTATION_VERTICAL)
+               else:
+                       self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+
+       @gtk_toolbox.log_exception(_moduleLogger)
+       def _on_close(self, *args, **kwds):
+               try:
+                       if self._initDone:
+                               self._save_settings()
+
+                       try:
+                               self._deviceState.close()
+                       except AttributeError:
+                               pass # Either None or close was removed (in Fremantle)
+                       try:
+                               self._osso.close()
+                       except AttributeError:
+                               pass # Either None or close was removed (in Fremantle)
+               finally:
+                       gtk.main_quit()
+
+       def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
+               """
+               For shutdown or save_unsaved_data, our only state is cookies and I think the cookie manager handles that for us.
+               For system_inactivity, we have no background tasks to pause
+
+               @note Hildon specific
+               """
+               try:
+                       if memory_low:
+                               for backendId in self.BACKENDS:
+                                       self._phoneBackends[backendId].clear_caches()
+                               self._contactsViews[self._selectedBackendId].clear_caches()
+                               gc.collect()
+
+                       if save_unsaved_data or shutdown:
+                               self._save_settings()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_connection_change(self, connection, event, magicIdentifier):
+               """
+               @note Hildon specific
+               """
+               try:
+                       import conic
+
+                       status = event.get_status()
+                       error = event.get_error()
+                       iap_id = event.get_iap_id()
+                       bearer = event.get_bearer_type()
+
+                       if status == conic.STATUS_CONNECTED:
+                               if self._initDone:
+                                       self._spawn_attempt_login()
+                       elif status == conic.STATUS_DISCONNECTED:
+                               if self._initDone:
+                                       self._defaultBackendId = self._selectedBackendId
+                                       self._change_loggedin_status(self.NULL_BACKEND)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_window_state_change(self, widget, event, *args):
+               """
+               @note Hildon specific
+               """
+               try:
+                       if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
+                               self._isFullScreen = True
+                       else:
+                               self._isFullScreen = False
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_key_press(self, widget, event, *args):
+               """
+               @note Hildon specific
+               """
+               RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
+               try:
+                       if (
+                               event.keyval == gtk.keysyms.F6 or
+                               event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               if self._isFullScreen:
+                                       self._window.unfullscreen()
+                               else:
+                                       self._window.fullscreen()
+                       elif event.keyval == gtk.keysyms.l and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               with open(constants._user_logpath_, "r") as f:
+                                       logLines = f.xreadlines()
+                                       log = "".join(logLines)
+                                       self._clipboard.set_text(str(log))
+                       elif (
+                               event.keyval in (gtk.keysyms.w, gtk.keysyms.q) and
+                               event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               self._window.destroy()
+                       elif event.keyval == gtk.keysyms.o and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               self._toggle_rotate()
+                               return True
+                       elif event.keyval == gtk.keysyms.r and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               self._refresh_active_tab()
+                       elif event.keyval == gtk.keysyms.i and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               self._import_contacts()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_clearcookies_clicked(self, *args):
+               try:
+                       self._phoneBackends[self._selectedBackendId].logout()
+                       self._accountViews[self._selectedBackendId].clear()
+                       self._historyViews[self._selectedBackendId].clear()
+                       self._messagesViews[self._selectedBackendId].clear()
+                       self._contactsViews[self._selectedBackendId].clear()
+                       self._change_loggedin_status(self.NULL_BACKEND)
+
+                       self._spawn_attempt_login(True)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_notebook_switch_page(self, notebook, page, pageIndex):
+               try:
+                       self._reset_tab_refresh()
+
+                       didRecentUpdate = False
+                       didMessagesUpdate = False
+
+                       if pageIndex == self.RECENT_TAB:
+                               didRecentUpdate = self._historyViews[self._selectedBackendId].update()
+                       elif pageIndex == self.MESSAGES_TAB:
+                               didMessagesUpdate = self._messagesViews[self._selectedBackendId].update()
+                       elif pageIndex == self.CONTACTS_TAB:
+                               self._contactsViews[self._selectedBackendId].update()
+                       elif pageIndex == self.ACCOUNT_TAB:
+                               self._accountViews[self._selectedBackendId].update()
+
+                       if didRecentUpdate or didMessagesUpdate:
+                               if self._ledHandler is not None:
+                                       self._ledHandler.off()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _set_tab_refresh(self, *args):
+               try:
+                       pageIndex = self._notebook.get_current_page()
+                       child = self._notebook.get_nth_page(pageIndex)
+                       self._notebook.get_tab_label(child).set_text("Refresh?")
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return False
+
+       def _reset_tab_refresh(self, *args):
+               try:
+                       pageIndex = self._notebook.get_current_page()
+                       child = self._notebook.get_nth_page(pageIndex)
+                       self._notebook.get_tab_label(child).set_text(self._originalCurrentLabels[pageIndex])
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return False
+
+       def _on_tab_refresh(self, *args):
+               try:
+                       self._refresh_active_tab()
+                       self._reset_tab_refresh()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return False
+
+       def _on_sms_clicked(self, numbers, message):
+               try:
+                       assert numbers, "No number specified"
+                       assert message, "Empty message"
+                       self.refresh_session()
+                       try:
+                               loggedIn = self._phoneBackends[self._selectedBackendId].is_authed()
+                       except Exception, e:
+                               loggedIn = False
+                               self._errorDisplay.push_exception()
+                               return
+
+                       if not loggedIn:
+                               self._errorDisplay.push_message(
+                                       "Backend link with GoogleVoice is not working, please try again"
+                               )
+                               return
+
+                       dialed = False
+                       try:
+                               self._phoneBackends[self._selectedBackendId].send_sms(numbers, message)
+                               hildonize.show_information_banner(self._window, "Sending to %s" % ", ".join(numbers))
+                               _moduleLogger.info("Sending SMS to %r" % numbers)
+                               dialed = True
+                       except Exception, e:
+                               self._errorDisplay.push_exception()
+
+                       if dialed:
+                               self._dialpads[self._selectedBackendId].clear()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_dial_clicked(self, number):
+               try:
+                       assert number, "No number to call"
+                       self.refresh_session()
+                       try:
+                               loggedIn = self._phoneBackends[self._selectedBackendId].is_authed()
+                       except Exception, e:
+                               loggedIn = False
+                               self._errorDisplay.push_exception()
+                               return
+
+                       if not loggedIn:
+                               self._errorDisplay.push_message(
+                                       "Backend link with GoogleVoice is not working, please try again"
+                               )
+                               return
+
+                       dialed = False
+                       try:
+                               assert self._phoneBackends[self._selectedBackendId].get_callback_number() != "", "No callback number specified"
+                               self._phoneBackends[self._selectedBackendId].call(number)
+                               hildonize.show_information_banner(self._window, "Calling %s" % number)
+                               _moduleLogger.info("Calling %s" % number)
+                               dialed = True
+                       except Exception, e:
+                               self._errorDisplay.push_exception()
+
+                       if dialed:
+                               self._dialpads[self._selectedBackendId].clear()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _import_contacts(self):
+               csvFilter = gtk.FileFilter()
+               csvFilter.set_name("Contacts")
+               csvFilter.add_pattern("*.csv")
+               importFileChooser = gtk.FileChooserDialog(
+                       title="Contacts",
+                       parent=self._window,
+               )
+               importFileChooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+               importFileChooser.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+               importFileChooser.set_property("filter", csvFilter)
+               userResponse = importFileChooser.run()
+               importFileChooser.hide()
+               if userResponse == gtk.RESPONSE_OK:
+                       filename = importFileChooser.get_filename()
+                       shutil.copy2(filename, self._fsContactsPath)
+
+       def _on_menu_refresh(self, *args):
+               try:
+                       self._refresh_active_tab()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_paste(self, *args):
+               try:
+                       contents = self._clipboard.wait_for_text()
+                       if contents is not None:
+                               self._dialpads[self._selectedBackendId].set_number(contents)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_about_activate(self, *args):
+               try:
+                       dlg = gtk.AboutDialog()
+                       dlg.set_name(constants.__pretty_app_name__)
+                       dlg.set_version("%s-%d" % (constants.__version__, constants.__build__))
+                       dlg.set_copyright("Copyright 2008 - LGPL")
+                       dlg.set_comments("Dialcentral is a touch screen enhanced interface to your GoogleVoice account.  This application is not affiliated with Google in any way")
+                       dlg.set_website("http://gc-dialer.garage.maemo.org/")
+                       dlg.set_authors(["<z2n@merctech.com>", "Eric Warnke <ericew@gmail.com>", "Ed Page <eopage@byu.net>"])
+                       dlg.run()
+                       dlg.destroy()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+def run_doctest():
+       import doctest
+
+       failureCount, testCount = doctest.testmod()
+       if not failureCount:
+               print "Tests Successful"
+               sys.exit(0)
+       else:
+               sys.exit(1)
+
+
+def run_dialpad():
+       gtk.gdk.threads_init()
+
+       handle = Dialcentral()
+       if not PROFILE_STARTUP:
+               gtk.main()
+
+
+class DummyOptions(object):
+
+       def __init__(self):
+               self.test = False
+
+
+if __name__ == "__main__":
+       logging.basicConfig(level=logging.DEBUG)
+       try:
+               if len(sys.argv) > 1:
+                       try:
+                               import optparse
+                       except ImportError:
+                               optparse = None
+
+                       if optparse is not None:
+                               parser = optparse.OptionParser()
+                               parser.add_option("-t", "--test", action="store_true", dest="test", help="Run tests")
+                               (commandOptions, commandArgs) = parser.parse_args()
+               else:
+                       commandOptions = DummyOptions()
+                       commandArgs = []
+
+               if commandOptions.test:
+                       run_doctest()
+               else:
+                       run_dialpad()
+       finally:
+               logging.shutdown()
diff --git a/src/dialcentral.glade b/src/dialcentral.glade
new file mode 100644 (file)
index 0000000..97ca390
--- /dev/null
@@ -0,0 +1,1406 @@
+<?xml version="1.0"?>
+<glade-interface>
+  <!-- interface-requires gtk+ 2.16 -->
+  <!-- interface-naming-policy toplevel-contextual -->
+  <widget class="GtkWindow" id="mainWindow">
+    <property name="title" translatable="yes">Dialer</property>
+    <property name="default_width">800</property>
+    <property name="default_height">480</property>
+    <child>
+      <widget class="GtkVBox" id="mainLayout">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkMenuBar" id="dialpad_menubar">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkMenuItem" id="login_menu_item">
+                <property name="visible">True</property>
+                <property name="label">_Login</property>
+                <property name="use_underline">True</property>
+                <signal name="activate" handler="on_clearcookies_clicked"/>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="paste_menu_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Paste</property>
+                <property name="use_underline">True</property>
+                <signal name="activate" handler="on_paste"/>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="refreshMenuItem">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Refresh</property>
+                <property name="use_underline">True</property>
+                <signal name="activate" handler="on_refresh"/>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="about">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_About</property>
+                <property name="use_underline">True</property>
+                <signal name="activate" handler="on_about_activate"/>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkEventBox" id="errorEventBox">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkHBox" id="errorBox">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkImage" id="errorImage">
+                    <property name="visible">True</property>
+                    <property name="stock">gtk-dialog-error</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="errorDescription">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Unknown Error</property>
+                    <property name="use_markup">True</property>
+                    <property name="ellipsize">end</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkImage" id="errorClose">
+                    <property name="visible">True</property>
+                    <property name="stock">gtk-close</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkNotebook" id="notebook">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="tab_pos">left</property>
+            <property name="show_border">False</property>
+            <property name="homogeneous">True</property>
+            <child>
+              <widget class="GtkVBox" id="keypad_vbox">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkHBox" id="hbox3">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkButton" id="plus">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="focus_on_click">False</property>
+                        <accelerator key="0" signal="clicked"/>
+                        <child>
+                          <widget class="GtkHBox" id="hbox5">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkImage" id="image3">
+                                <property name="visible">True</property>
+                                <property name="tooltip" translatable="yes">+</property>
+                                <property name="xalign">1</property>
+                                <property name="stock">gtk-add</property>
+                              </widget>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="numberdisplay">
+                        <property name="height_request">50</property>
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">&lt;span size="35000" weight="bold"&gt;&lt;/span&gt;</property>
+                        <property name="use_markup">True</property>
+                        <property name="justify">center</property>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="back">
+                        <property name="label" translatable="yes">gtk-go-back</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_stock">True</property>
+                        <property name="focus_on_click">False</property>
+                        <accelerator key="BackSpace" signal="clicked"/>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkTable" id="keypadview">
+                    <property name="visible">True</property>
+                    <property name="n_rows">4</property>
+                    <property name="n_columns">3</property>
+                    <property name="homogeneous">True</property>
+                    <child>
+                      <widget class="GtkButton" id="digit1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="1" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label12">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="33000" weight="bold"&gt;1&lt;/span&gt;
+&lt;span size="9000"&gt;  &lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                          </widget>
+                        </child>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="c" signal="clicked"/>
+                        <accelerator key="b" signal="clicked"/>
+                        <accelerator key="a" signal="clicked"/>
+                        <accelerator key="2" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label10">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;2&lt;/span&gt;
+&lt;span size="12000"&gt;ABC&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="f" signal="clicked"/>
+                        <accelerator key="e" signal="clicked"/>
+                        <accelerator key="d" signal="clicked"/>
+                        <accelerator key="3" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label11">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold" stretch="ultraexpanded"&gt;3&lt;/span&gt;
+&lt;span size="12000"&gt;DEF&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit4">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="i" signal="clicked"/>
+                        <accelerator key="h" signal="clicked"/>
+                        <accelerator key="g" signal="clicked"/>
+                        <accelerator key="4" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label13">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;4&lt;/span&gt;
+&lt;span size="12000"&gt;GHI&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="l" signal="clicked"/>
+                        <accelerator key="k" signal="clicked"/>
+                        <accelerator key="j" signal="clicked"/>
+                        <accelerator key="5" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label14">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;5&lt;/span&gt;
+&lt;span size="12000"&gt;JKL&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit6">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="o" signal="clicked"/>
+                        <accelerator key="n" signal="clicked"/>
+                        <accelerator key="m" signal="clicked"/>
+                        <accelerator key="6" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label15">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;6&lt;/span&gt;
+&lt;span size="12000"&gt;MNO&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit7">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="s" signal="clicked"/>
+                        <accelerator key="r" signal="clicked"/>
+                        <accelerator key="q" signal="clicked"/>
+                        <accelerator key="p" signal="clicked"/>
+                        <accelerator key="7" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label16">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;7&lt;/span&gt;
+&lt;span size="12000"&gt;PQRS&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit8">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="v" signal="clicked"/>
+                        <accelerator key="u" signal="clicked"/>
+                        <accelerator key="t" signal="clicked"/>
+                        <accelerator key="8" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label17">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;8&lt;/span&gt;
+&lt;span size="12000"&gt;TUV&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit9">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="z" signal="clicked"/>
+                        <accelerator key="y" signal="clicked"/>
+                        <accelerator key="x" signal="clicked"/>
+                        <accelerator key="w" signal="clicked"/>
+                        <accelerator key="9" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label18">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="30000" weight="bold"&gt;9&lt;/span&gt;
+&lt;span size="12000"&gt;WXYZ&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="digit0">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <property name="focus_on_click">False</property>
+                        <signal name="clicked" handler="on_digit_clicked"/>
+                        <accelerator key="0" signal="clicked"/>
+                        <child>
+                          <widget class="GtkLabel" id="label19">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">&lt;span size="33000" weight="bold"&gt;0&lt;/span&gt;</property>
+                            <property name="use_markup">True</property>
+                            <property name="justify">center</property>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="dialpadCall">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="receives_default">False</property>
+                        <accelerator key="Return" signal="clicked"/>
+                        <child>
+                          <widget class="GtkHBox" id="hbox1">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkImage" id="image1">
+                                <property name="visible">True</property>
+                                <property name="xalign">1</property>
+                                <property name="stock">gtk-yes</property>
+                              </widget>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label8">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="xpad">5</property>
+                                <property name="label" translatable="yes">&lt;span size="17000" weight="bold"&gt;Call&lt;/span&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="right_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="dialpadSMS">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <accelerator key="Return" signal="clicked"/>
+                        <child>
+                          <widget class="GtkHBox" id="hbox2">
+                            <property name="visible">True</property>
+                            <child>
+                              <widget class="GtkImage" id="image2">
+                                <property name="visible">True</property>
+                                <property name="xalign">1</property>
+                                <property name="stock">gtk-select-font</property>
+                              </widget>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label2">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="xpad">5</property>
+                                <property name="label" translatable="yes">&lt;span size="17000" weight="bold"&gt;SMS&lt;/span&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="keypad">
+                <property name="height_request">30</property>
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Keypad</property>
+              </widget>
+              <packing>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkVBox" id="vbox2">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <widget class="GtkButton" id="historyFilterSelector">
+                    <property name="label" translatable="yes">All</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="history_scrolledwindow">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <child>
+                      <widget class="GtkTreeView" id="historyview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="rules_hint">True</property>
+                        <property name="enable_grid_lines">horizontal</property>
+                        <property name="enable_tree_lines">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="history">
+                <property name="height_request">30</property>
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">History</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkVBox" id="vbox3">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <widget class="GtkHBox" id="hbox4">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkButton" id="messageTypeButton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="messageStatusButton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="message_scrolledwindow">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <child>
+                      <widget class="GtkViewport" id="viewport1">
+                        <property name="visible">True</property>
+                        <property name="resize_mode">queue</property>
+                        <child>
+                          <widget class="GtkVBox" id="vbox4">
+                            <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
+                            <child>
+                              <widget class="GtkTreeView" id="messages_view">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="rules_hint">True</property>
+                                <property name="enable_grid_lines">horizontal</property>
+                                <property name="enable_tree_lines">True</property>
+                              </widget>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </widget>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="messages">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Messages</property>
+              </widget>
+              <packing>
+                <property name="position">2</property>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkVBox" id="vbox5">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <widget class="GtkButton" id="addressbookSelectButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="contacts_scrolledwindow">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <child>
+                      <widget class="GtkTreeView" id="contactsview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="headers_visible">False</property>
+                        <property name="rules_hint">True</property>
+                        <property name="fixed_height_mode">True</property>
+                        <property name="enable_grid_lines">horizontal</property>
+                        <property name="enable_tree_lines">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="contacts">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Contacts</property>
+              </widget>
+              <packing>
+                <property name="position">3</property>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkTable" id="accountview">
+                <property name="visible">True</property>
+                <property name="border_width">11</property>
+                <property name="n_rows">7</property>
+                <property name="n_columns">2</property>
+                <child>
+                  <widget class="GtkLabel" id="gcnumber_display">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">No Number Available</property>
+                    <property name="use_markup">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="gcnumber_label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="ypad">10</property>
+                    <property name="label" translatable="yes">Account Number:</property>
+                  </widget>
+                  <packing>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="callback_number_label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="ypad">10</property>
+                    <property name="label" translatable="yes">Callback Number:</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkVBox" id="vbox1">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <widget class="GtkCheckButton" id="missedCheckbox">
+                        <property name="label" translatable="yes">Missed Calls</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkCheckButton" id="voicemailCheckbox">
+                        <property name="label" translatable="yes">Voicemail</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkCheckButton" id="smsCheckbox">
+                        <property name="label" translatable="yes">SMS</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="notifyCheckbox">
+                    <property name="label" translatable="yes">Notifications</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="yalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="clearcookies">
+                    <property name="label" translatable="yes">New Login</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="focus_on_click">False</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="minutesEntryButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="callbackSelectButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">4</property>
+                <property name="tab_expand">True</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="account">
+                <property name="height_request">30</property>
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Account</property>
+              </widget>
+              <packing>
+                <property name="position">4</property>
+                <property name="tab_fill">False</property>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+  <widget class="GtkDialog" id="loginDialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Login</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="skip_pager_hint">True</property>
+    <property name="deletable">False</property>
+    <property name="transient_for">mainWindow</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="loginLayout">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkComboBox" id="serviceCombo">
+            <property name="visible">True</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="n_rows">2</property>
+            <property name="n_columns">2</property>
+            <child>
+              <widget class="GtkLabel" id="username_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Username</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="password_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Password</property>
+              </widget>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkEntry" id="usernameentry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkEntry" id="passwordentry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="visibility">False</property>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <widget class="GtkButton" id="logins_close_button">
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="loginbutton">
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+  <widget class="GtkWindow" id="smsWindow">
+    <property name="title" translatable="yes">SMS Entry</property>
+    <child>
+      <widget class="GtkVBox" id="smsLayout">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <widget class="GtkEventBox" id="smsErrorEventBox">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkHBox" id="smsErrorBox">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkImage" id="smsErrorImage">
+                    <property name="visible">True</property>
+                    <property name="stock">gtk-dialog-error</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="smsErrorDescription">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Unknown Error</property>
+                    <property name="use_markup">True</property>
+                    <property name="ellipsize">end</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkImage" id="smsErrorClose">
+                    <property name="visible">True</property>
+                    <property name="stock">gtk-close</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <widget class="GtkScrolledWindow" id="smsMessages_scrolledwindow">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <child>
+                  <widget class="GtkViewport" id="smsMessagesViewPort">
+                    <property name="visible">True</property>
+                    <property name="resize_mode">queue</property>
+                    <child>
+                      <widget class="GtkVBox" id="smsMessagesLayout">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <widget class="GtkTreeView" id="smsMessages">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkHSeparator" id="hseparator1">
+                            <property name="visible">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkVBox" id="smsTargetList">
+                            <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">3</property>
+                            <child>
+                              <placeholder/>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkFrame" id="frame1">
+                            <property name="visible">True</property>
+                            <property name="border_width">5</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <widget class="GtkVBox" id="vbox2">
+                                <property name="visible">True</property>
+                                <property name="orientation">vertical</property>
+                                <child>
+                                  <widget class="GtkScrolledWindow" id="smsMessage_scrolledEntry">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="hscrollbar_policy">never</property>
+                                    <property name="vscrollbar_policy">automatic</property>
+                                    <child>
+                                      <widget class="GtkTextView" id="smsEntry">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="wrap_mode">word</property>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label3">
+                                <property name="label" translatable="yes">&lt;b&gt;frame1&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="type">label_item</property>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="position">3</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkFrame" id="frame2">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <widget class="GtkHBox" id="smsButtonLayout">
+                <property name="visible">True</property>
+                <property name="spacing">5</property>
+                <child>
+                  <widget class="GtkHBox" id="smsCountBox">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkLabel" id="smsLetterCount1">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Letters:</property>
+                        <property name="use_markup">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="smsLetterCount">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">0</property>
+                        <property name="use_markup">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.47999998927116394</property>
+                    <property name="yalign">0.49000000953674316</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="phoneTypeSelection">
+                    <property name="label" translatable="yes">No Phone Types Available</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label6">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.47999998927116394</property>
+                    <property name="yalign">0.49000000953674316</property>
+                  </widget>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="sendSmsButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <child>
+                      <widget class="GtkHBox" id="hbox1">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkImage" id="image1">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-select-font</property>
+                          </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label2">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">SMS</property>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="dialButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <child>
+                      <widget class="GtkHBox" id="hbox2">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkImage" id="image2">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-apply</property>
+                          </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label4">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Dial</property>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">5</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label1">
+                <property name="label" translatable="yes">&lt;b&gt;frame2&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </widget>
+              <packing>
+                <property name="type">label_item</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>
diff --git a/src/dialcentral.py b/src/dialcentral.py
new file mode 100755 (executable)
index 0000000..bfc0f26
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import os
+import sys
+import logging
+
+
+_moduleLogger = logging.getLogger("dialcentral")
+sys.path.insert(0,"/usr/lib/dialcentral/")
+
+
+import constants
+import dc_glade
+
+
+try:
+       os.makedirs(constants._data_path_)
+except OSError, e:
+       if e.errno != 17:
+               raise
+
+logging.basicConfig(level=logging.DEBUG, filename=constants._user_logpath_)
+_moduleLogger.info("Dialcentral %s-%s" % (constants.__version__, constants.__build__))
+_moduleLogger.info("OS: %s" % (os.uname()[0], ))
+_moduleLogger.info("Kernel: %s (%s) for %s" % os.uname()[2:])
+_moduleLogger.info("Hostname: %s" % os.uname()[1])
+
+try:
+       dc_glade.run_dialpad()
+finally:
+       logging.shutdown()
diff --git a/src/examples/log_notifier.py b/src/examples/log_notifier.py
new file mode 100644 (file)
index 0000000..2318549
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import sys
+import datetime
+import ConfigParser
+
+
+sys.path.insert(0,"/usr/lib/dialcentral/")
+
+
+import constants
+import alarm_notify
+
+
+def notify_on_change():
+       filename = "%s/notification.log" % constants._data_path_
+       with open(constants._notifier_logpath_, "a") as file:
+               file.write("Notification: %r\n" % (datetime.datetime.now(), ))
+
+               config = ConfigParser.SafeConfigParser()
+               config.read(constants._user_settings_)
+               backend = alarm_notify.create_backend(config)
+               notifyUser = alarm_notify.is_changed(config, backend)
+
+               if notifyUser:
+                       file.write("\tChange occurred\n")
+
+
+if __name__ == "__main__":
+       notify_on_change()
diff --git a/src/examples/sound_notifier.py b/src/examples/sound_notifier.py
new file mode 100644 (file)
index 0000000..c31e413
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import ConfigParser
+import logging
+
+
+sys.path.insert(0,"/usr/lib/dialcentral/")
+
+
+import constants
+import alarm_notify
+
+
+def notify_on_change():
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._user_settings_)
+       backend = alarm_notify.create_backend(config)
+       notifyUser = alarm_notify.is_changed(config, backend)
+
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._custom_notifier_settings_)
+       soundFile = config.get("Sound Notifier", "soundfile")
+       soundFile = "/usr/lib/gv-notifier/alert.mp3"
+
+       if notifyUser:
+               import subprocess
+               import led_handler
+               logging.info("Changed, playing %s" % soundFile)
+               led = led_handler.LedHandler()
+               led.on()
+               soundOn = subprocess.call("/usr/bin/dbus-send --dest=com.nokia.osso_media_server --print-reply /com/nokia/osso_media_server com.nokia.osso_media_server.music.play_media string:file://%s",shell=True)
+       else:
+               logging.info("No Change")
+
+
+if __name__ == "__main__":
+       logging.basicConfig(level=logging.WARNING, filename=constants._notifier_logpath_)
+       logging.info("Sound Notifier %s-%s" % (constants.__version__, constants.__build__))
+       logging.info("OS: %s" % (os.uname()[0], ))
+       logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])
+       logging.info("Hostname: %s" % os.uname()[1])
+       try:
+               notify_on_change()
+       except:
+               logging.exception("Error")
+               raise
index f687e6b..769e19b 100644 (file)
@@ -414,11 +414,11 @@ def safecall(f, errorDisplay=None, default=None, exception=Exception):
 
 class ErrorDisplay(object):
 
-       def __init__(self, widgetTree):
+       def __init__(self, errorBox, errorDescription, errorClose):
                super(ErrorDisplay, self).__init__()
-               self.__errorBox = widgetTree.get_widget("errorEventBox")
-               self.__errorDescription = widgetTree.get_widget("errorDescription")
-               self.__errorClose = widgetTree.get_widget("errorClose")
+               self.__errorBox = errorBox
+               self.__errorDescription = errorDescription
+               self.__errorClose = errorClose
                self.__parentBox = self.__errorBox.get_parent()
 
                self.__errorBox.connect("button_release_event", self._on_close)
@@ -751,18 +751,6 @@ class TapOrHold(object):
 
 
 if __name__ == "__main__":
-       if True:
-               win = gtk.Window()
-               win.set_title("Tap'N'Hold")
-               eventBox = gtk.EventBox()
-               win.add(eventBox)
-
-               context = ContextHandler(eventBox, coroutines.printer_sink())
-               context.enable()
-               win.connect("destroy", lambda w: gtk.main_quit())
-
-               win.show_all()
-
        if False:
                import datetime
                cal = PopupCalendar(None, datetime.datetime.now())
diff --git a/src/gv_views.py b/src/gv_views.py
new file mode 100644 (file)
index 0000000..be6b127
--- /dev/null
@@ -0,0 +1,1827 @@
+#!/usr/bin/env python
+
+"""
+DialCentral - Front end for Google's GoogleVoice service.
+Copyright (C) 2008  Mark Bergman bergman AT merctech 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
+
+@todo Collapse voicemails
+"""
+
+from __future__ import with_statement
+
+import re
+import ConfigParser
+import itertools
+import logging
+
+import gobject
+import pango
+import gtk
+
+import gtk_toolbox
+import hildonize
+from backends import gv_backend
+from backends import null_backend
+
+
+_moduleLogger = logging.getLogger("gv_views")
+
+
+def make_ugly(prettynumber):
+       """
+       function to take a phone number and strip out all non-numeric
+       characters
+
+       >>> make_ugly("+012-(345)-678-90")
+       '+01234567890'
+       """
+       return normalize_number(prettynumber)
+
+
+def normalize_number(prettynumber):
+       """
+       function to take a phone number and strip out all non-numeric
+       characters
+
+       >>> normalize_number("+012-(345)-678-90")
+       '+01234567890'
+       >>> normalize_number("1-(345)-678-9000")
+       '+13456789000'
+       >>> normalize_number("+1-(345)-678-9000")
+       '+13456789000'
+       """
+       uglynumber = re.sub('[^0-9+]', '', prettynumber)
+
+       if uglynumber.startswith("+"):
+               pass
+       elif uglynumber.startswith("1"):
+               uglynumber = "+"+uglynumber
+       elif 10 <= len(uglynumber):
+               assert uglynumber[0] not in ("+", "1")
+               uglynumber = "+1"+uglynumber
+       else:
+               pass
+
+       return uglynumber
+
+
+def _make_pretty_with_areacode(phonenumber):
+       prettynumber = "(%s)" % (phonenumber[0:3], )
+       if 3 < len(phonenumber):
+               prettynumber += " %s" % (phonenumber[3:6], )
+               if 6 < len(phonenumber):
+                       prettynumber += "-%s" % (phonenumber[6:], )
+       return prettynumber
+
+
+def _make_pretty_local(phonenumber):
+       prettynumber = "%s" % (phonenumber[0:3], )
+       if 3 < len(phonenumber):
+               prettynumber += "-%s" % (phonenumber[3:], )
+       return prettynumber
+
+
+def _make_pretty_international(phonenumber):
+       prettynumber = phonenumber
+       if phonenumber.startswith("1"):
+               prettynumber = "1 "
+               prettynumber += _make_pretty_with_areacode(phonenumber[1:])
+       return prettynumber
+
+
+def make_pretty(phonenumber):
+       """
+       Function to take a phone number and return the pretty version
+       pretty numbers:
+               if phonenumber begins with 0:
+                       ...-(...)-...-....
+               if phonenumber begins with 1: ( for gizmo callback numbers )
+                       1 (...)-...-....
+               if phonenumber is 13 digits:
+                       (...)-...-....
+               if phonenumber is 10 digits:
+                       ...-....
+       >>> make_pretty("12")
+       '12'
+       >>> make_pretty("1234567")
+       '123-4567'
+       >>> make_pretty("2345678901")
+       '+1 (234) 567-8901'
+       >>> make_pretty("12345678901")
+       '+1 (234) 567-8901'
+       >>> make_pretty("01234567890")
+       '+012 (345) 678-90'
+       >>> make_pretty("+01234567890")
+       '+012 (345) 678-90'
+       >>> make_pretty("+12")
+       '+1 (2)'
+       >>> make_pretty("+123")
+       '+1 (23)'
+       >>> make_pretty("+1234")
+       '+1 (234)'
+       """
+       if phonenumber is None or phonenumber is "":
+               return ""
+
+       phonenumber = normalize_number(phonenumber)
+
+       if phonenumber[0] == "+":
+               prettynumber = _make_pretty_international(phonenumber[1:])
+               if not prettynumber.startswith("+"):
+                       prettynumber = "+"+prettynumber
+       elif 8 < len(phonenumber) and phonenumber[0] in ("1", ):
+               prettynumber = _make_pretty_international(phonenumber)
+       elif 7 < len(phonenumber):
+               prettynumber = _make_pretty_with_areacode(phonenumber)
+       elif 3 < len(phonenumber):
+               prettynumber = _make_pretty_local(phonenumber)
+       else:
+               prettynumber = phonenumber
+       return prettynumber.strip()
+
+
+def abbrev_relative_date(date):
+       """
+       >>> abbrev_relative_date("42 hours ago")
+       '42 h'
+       >>> abbrev_relative_date("2 days ago")
+       '2 d'
+       >>> abbrev_relative_date("4 weeks ago")
+       '4 w'
+       """
+       parts = date.split(" ")
+       return "%s %s" % (parts[0], parts[1][0])
+
+
+def _collapse_message(messageLines, maxCharsPerLine, maxLines):
+       lines = 0
+
+       numLines = len(messageLines)
+       for line in messageLines[0:min(maxLines, numLines)]:
+               linesPerLine = max(1, int(len(line) / maxCharsPerLine))
+               allowedLines = maxLines - lines
+               acceptedLines = min(allowedLines, linesPerLine)
+               acceptedChars = acceptedLines * maxCharsPerLine
+
+               if acceptedChars < (len(line) + 3):
+                       suffix = "..."
+               else:
+                       acceptedChars = len(line) # eh, might as well complete the line
+                       suffix = ""
+               abbrevMessage = "%s%s" % (line[0:acceptedChars], suffix)
+               yield abbrevMessage
+
+               lines += acceptedLines
+               if maxLines <= lines:
+                       break
+
+
+def collapse_message(message, maxCharsPerLine, maxLines):
+       r"""
+       >>> collapse_message("Hello", 60, 2)
+       'Hello'
+       >>> collapse_message("Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789", 60, 2)
+       'Hello world how are you doing today? 01234567890123456789012...'
+       >>> collapse_message('''Hello world how are you doing today?
+       ... 01234567890123456789
+       ... 01234567890123456789
+       ... 01234567890123456789
+       ... 01234567890123456789''', 60, 2)
+       'Hello world how are you doing today?\n01234567890123456789'
+       >>> collapse_message('''
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+       ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789''', 60, 2)
+       '\nHello world how are you doing today? 01234567890123456789012...'
+       """
+       messageLines = message.split("\n")
+       return "\n".join(_collapse_message(messageLines, maxCharsPerLine, maxLines))
+
+
+def _get_contact_numbers(backend, contactId, number):
+       if contactId:
+               contactPhoneNumbers = list(backend.get_contact_details(contactId))
+               uglyContactNumbers = (
+                       make_ugly(contactNumber)
+                       for (numberDescription, contactNumber) in contactPhoneNumbers
+               )
+               defaultMatches = [
+                       (
+                               number == contactNumber or
+                               number[1:] == contactNumber and number.startswith("1") or
+                               number[2:] == contactNumber and number.startswith("+1") or
+                               number == contactNumber[1:] and contactNumber.startswith("1") or
+                               number == contactNumber[2:] and contactNumber.startswith("+1")
+                       )
+                       for contactNumber in uglyContactNumbers
+               ]
+               try:
+                       defaultIndex = defaultMatches.index(True)
+               except ValueError:
+                       contactPhoneNumbers.append(("Other", number))
+                       defaultIndex = len(contactPhoneNumbers)-1
+                       _moduleLogger.warn(
+                               "Could not find contact %r's number %s among %r" % (
+                                       contactId, number, contactPhoneNumbers
+                               )
+                       )
+       else:
+               contactPhoneNumbers = [("Phone", number)]
+               defaultIndex = -1
+
+       return contactPhoneNumbers, defaultIndex
+
+
+class SmsEntryWindow(object):
+
+       MAX_CHAR = 160
+
+       def __init__(self, widgetTree, parent, app):
+               self._clipboard = gtk.clipboard_get()
+               self._widgetTree = widgetTree
+               self._parent = parent
+               self._app = app
+               self._isFullScreen = False
+
+               self._window = self._widgetTree.get_widget("smsWindow")
+               self._window = hildonize.hildonize_window(self._app, self._window)
+               self._window.set_title("SMS")
+               self._window.connect("delete-event", self._on_delete)
+               self._window.connect("key-press-event", self._on_key_press)
+               self._window.connect("window-state-event", self._on_window_state_change)
+               self._widgetTree.get_widget("smsMessagesViewPort").get_parent().show()
+
+               errorBox = self._widgetTree.get_widget("smsErrorEventBox")
+               errorDescription = self._widgetTree.get_widget("smsErrorDescription")
+               errorClose = self._widgetTree.get_widget("smsErrorClose")
+               self._errorDisplay = gtk_toolbox.ErrorDisplay(errorBox, errorDescription, errorClose)
+
+               self._smsButton = self._widgetTree.get_widget("sendSmsButton")
+               self._smsButton.connect("clicked", self._on_send)
+               self._dialButton = self._widgetTree.get_widget("dialButton")
+               self._dialButton.connect("clicked", self._on_dial)
+
+               self._letterCountLabel = self._widgetTree.get_widget("smsLetterCount")
+
+               self._messagemodel = gtk.ListStore(gobject.TYPE_STRING)
+               self._messagesView = self._widgetTree.get_widget("smsMessages")
+
+               textrenderer = gtk.CellRendererText()
+               textrenderer.set_property("wrap-mode", pango.WRAP_WORD)
+               textrenderer.set_property("wrap-width", 450)
+               messageColumn = gtk.TreeViewColumn("")
+               messageColumn.pack_start(textrenderer, expand=True)
+               messageColumn.add_attribute(textrenderer, "markup", 0)
+               messageColumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+               self._messagesView.append_column(messageColumn)
+               self._messagesView.set_headers_visible(False)
+               self._messagesView.set_model(self._messagemodel)
+               self._messagesView.set_fixed_height_mode(False)
+
+               self._conversationView = self._messagesView.get_parent()
+               self._conversationViewPort = self._conversationView.get_parent()
+               self._scrollWindow = self._conversationViewPort.get_parent()
+
+               self._targetList = self._widgetTree.get_widget("smsTargetList")
+               self._phoneButton = self._widgetTree.get_widget("phoneTypeSelection")
+               self._phoneButton.connect("clicked", self._on_phone)
+               self._smsEntry = self._widgetTree.get_widget("smsEntry")
+               self._smsEntry.get_buffer().connect("changed", self._on_entry_changed)
+               self._smsEntrySize = None
+
+               self._contacts = []
+
+       def add_contact(self, name, contactDetails, messages = (), defaultIndex = -1):
+               contactNumbers = list(self._to_contact_numbers(contactDetails))
+               assert contactNumbers, "Contact must have at least one number"
+               contactIndex = defaultIndex if defaultIndex != -1 else 0
+               contact = contactNumbers, contactIndex, messages
+               self._contacts.append(contact)
+
+               nameLabel = gtk.Label(name)
+               selector = gtk.Button(contactNumbers[0][1])
+               if len(contactNumbers) == 1:
+                       selector.set_sensitive(False)
+               removeContact = gtk.Button(stock="gtk-delete")
+               row = gtk.HBox()
+               row.pack_start(nameLabel, True, True)
+               row.pack_start(selector, True, True)
+               row.pack_start(removeContact, False, False)
+               row.show_all()
+               self._targetList.pack_start(row)
+               selector.connect("clicked", self._on_choose_phone_n, row)
+               removeContact.connect("clicked", self._on_remove_phone_n, row)
+               self._update_button_state()
+               self._update_context()
+
+               parentSize = self._parent.get_size()
+               self._window.resize(parentSize[0], max(parentSize[1]-10, 100))
+               self._window.show()
+               self._window.present()
+
+               self._smsEntry.grab_focus()
+               self._scroll_to_bottom()
+
+       def clear(self):
+               del self._contacts[:]
+
+               for row in list(self._targetList.get_children()):
+                       self._targetList.remove(row)
+               self._smsEntry.get_buffer().set_text("")
+               self._update_letter_count()
+               self._update_context()
+
+       def fullscreen(self):
+               self._window.fullscreen()
+
+       def unfullscreen(self):
+               self._window.unfullscreen()
+
+       def _remove_contact(self, contactIndex):
+               del self._contacts[contactIndex]
+
+               row = list(self._targetList.get_children())[contactIndex]
+               self._targetList.remove(row)
+               self._update_button_state()
+               self._update_context()
+               self._scroll_to_bottom()
+
+       def _scroll_to_bottom(self):
+               dx = self._conversationView.get_allocation().height - self._conversationViewPort.get_allocation().height
+               dx = max(dx, 0)
+               adjustment = self._scrollWindow.get_vadjustment()
+               adjustment.value = dx
+
+       def _update_letter_count(self):
+               if self._smsEntrySize is None:
+                       self._smsEntrySize = self._smsEntry.size_request()
+               else:
+                       self._smsEntry.set_size_request(*self._smsEntrySize)
+               entryLength = self._smsEntry.get_buffer().get_char_count()
+
+               numTexts, numCharInText = divmod(entryLength, self.MAX_CHAR)
+               if numTexts:
+                       self._letterCountLabel.set_text("%s.%s" % (numTexts, numCharInText))
+               else:
+                       self._letterCountLabel.set_text("%s" % (numCharInText, ))
+
+               self._update_button_state()
+
+       def _update_context(self):
+               self._messagemodel.clear()
+               if len(self._contacts) == 0:
+                       self._messagesView.hide()
+                       self._targetList.hide()
+                       self._phoneButton.hide()
+                       self._phoneButton.set_label("Error: You shouldn't see this")
+               elif len(self._contacts) == 1:
+                       contactNumbers, index, messages = self._contacts[0]
+                       if messages:
+                               self._messagesView.show()
+                               for message in messages:
+                                       row = (message, )
+                                       self._messagemodel.append(row)
+                               messagesSelection = self._messagesView.get_selection()
+                               messagesSelection.select_path((len(messages)-1, ))
+                       else:
+                               self._messagesView.hide()
+                       self._targetList.hide()
+                       self._phoneButton.show()
+                       self._phoneButton.set_label(contactNumbers[index][1])
+                       if 1 < len(contactNumbers):
+                               self._phoneButton.set_sensitive(True)
+                       else:
+                               self._phoneButton.set_sensitive(False)
+               else:
+                       self._messagesView.hide()
+                       self._targetList.show()
+                       self._phoneButton.hide()
+                       self._phoneButton.set_label("Error: You shouldn't see this")
+
+       def _update_button_state(self):
+               if len(self._contacts) == 0:
+                       self._dialButton.set_sensitive(False)
+                       self._smsButton.set_sensitive(False)
+               elif len(self._contacts) == 1:
+                       entryLength = self._smsEntry.get_buffer().get_char_count()
+                       if entryLength == 0:
+                               self._dialButton.set_sensitive(True)
+                               self._smsButton.set_sensitive(False)
+                       else:
+                               self._dialButton.set_sensitive(False)
+                               self._smsButton.set_sensitive(True)
+               else:
+                       self._dialButton.set_sensitive(False)
+                       self._smsButton.set_sensitive(True)
+
+       def _to_contact_numbers(self, contactDetails):
+               for phoneType, phoneNumber in contactDetails:
+                       display = " - ".join((make_pretty(phoneNumber), phoneType))
+                       yield (phoneNumber, display)
+
+       def _pseudo_destroy(self):
+               self.clear()
+               self._window.hide()
+
+       def _request_number(self, contactIndex):
+               contactNumbers, index, messages = self._contacts[contactIndex]
+               assert 0 <= index, "%r" % index
+
+               index = hildonize.touch_selector(
+                       self._window,
+                       "Phone Numbers",
+                       (description for (number, description) in contactNumbers),
+                       index,
+               )
+               self._contacts[contactIndex] = contactNumbers, index, messages
+
+       def send_sms(self, numbers, message):
+               raise NotImplementedError()
+
+       def dial(self, number):
+               raise NotImplementedError()
+
+       def _on_phone(self, *args):
+               try:
+                       assert len(self._contacts) == 1, "One and only one contact is required"
+                       self._request_number(0)
+
+                       contactNumbers, numberIndex, messages = self._contacts[0]
+                       self._phoneButton.set_label(contactNumbers[numberIndex][1])
+                       row = list(self._targetList.get_children())[0]
+                       phoneButton = list(row.get_children())[1]
+                       phoneButton.set_label(contactNumbers[numberIndex][1])
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_choose_phone_n(self, button, row):
+               try:
+                       assert 1 < len(self._contacts), "More than one contact required"
+                       targetList = list(self._targetList.get_children())
+                       index = targetList.index(row)
+                       self._request_number(index)
+
+                       contactNumbers, numberIndex, messages = self._contacts[0]
+                       phoneButton = list(row.get_children())[1]
+                       phoneButton.set_label(contactNumbers[numberIndex][1])
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_remove_phone_n(self, button, row):
+               try:
+                       assert 1 < len(self._contacts), "More than one contact required"
+                       targetList = list(self._targetList.get_children())
+                       index = targetList.index(row)
+
+                       del self._contacts[index]
+                       self._targetList.remove(row)
+                       self._update_context()
+                       self._update_button_state()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_entry_changed(self, *args):
+               try:
+                       self._update_letter_count()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_send(self, *args):
+               try:
+                       assert 0 < len(self._contacts), "At least one contact required (%r)" % self._contacts
+                       phoneNumbers = [
+                               make_ugly(contact[0][contact[1]][0])
+                               for contact in self._contacts
+                       ]
+
+                       entryBuffer = self._smsEntry.get_buffer()
+                       enteredMessage = entryBuffer.get_text(entryBuffer.get_start_iter(), entryBuffer.get_end_iter())
+                       enteredMessage = enteredMessage.strip()
+                       assert enteredMessage, "No message provided"
+                       self.send_sms(phoneNumbers, enteredMessage)
+                       self._pseudo_destroy()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_dial(self, *args):
+               try:
+                       assert len(self._contacts) == 1, "One and only one contact allowed (%r)" % self._contacts
+                       contact = self._contacts[0]
+                       contactNumber = contact[0][contact[1]][0]
+                       phoneNumber = make_ugly(contactNumber)
+                       self.dial(phoneNumber)
+                       self._pseudo_destroy()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_delete(self, *args):
+               try:
+                       self._window.emit_stop_by_name("delete-event")
+                       if hildonize.IS_FREMANTLE_SUPPORTED:
+                               self._window.hide()
+                       else:
+                               self._pseudo_destroy()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return True
+
+       def _on_window_state_change(self, widget, event, *args):
+               try:
+                       if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
+                               self._isFullScreen = True
+                       else:
+                               self._isFullScreen = False
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_key_press(self, widget, event):
+               RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
+               try:
+                       if (
+                               event.keyval == gtk.keysyms.F6 or
+                               event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               if self._isFullScreen:
+                                       self._window.unfullscreen()
+                               else:
+                                       self._window.fullscreen()
+                       elif event.keyval == ord("c") and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               message = "\n".join(
+                                       messagePart[0]
+                                       for messagePart in self._messagemodel
+                               )
+                               self._clipboard.set_text(str(message))
+                       elif (
+                               event.keyval == gtk.keysyms.h and
+                               event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               self._window.hide()
+                       elif (
+                               event.keyval == gtk.keysyms.w and
+                               event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               self._pseudo_destroy()
+                       elif (
+                               event.keyval == gtk.keysyms.q and
+                               event.get_state() & gtk.gdk.CONTROL_MASK
+                       ):
+                               self._parent.destroy()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+class Dialpad(object):
+
+       def __init__(self, widgetTree, errorDisplay):
+               self._clipboard = gtk.clipboard_get()
+               self._errorDisplay = errorDisplay
+
+               self._numberdisplay = widgetTree.get_widget("numberdisplay")
+               self._callButton = widgetTree.get_widget("dialpadCall")
+               self._sendSMSButton = widgetTree.get_widget("dialpadSMS")
+               self._backButton = widgetTree.get_widget("back")
+               self._plusButton = widgetTree.get_widget("plus")
+               self._phonenumber = ""
+               self._prettynumber = ""
+
+               callbackMapping = {
+                       "on_digit_clicked": self._on_digit_clicked,
+               }
+               widgetTree.signal_autoconnect(callbackMapping)
+               self._sendSMSButton.connect("clicked", self._on_sms_clicked)
+               self._callButton.connect("clicked", self._on_call_clicked)
+               self._plusButton.connect("clicked", self._on_plus)
+
+               self._originalLabel = self._backButton.get_label()
+               self._backTapHandler = gtk_toolbox.TapOrHold(self._backButton)
+               self._backTapHandler.on_tap = self._on_backspace
+               self._backTapHandler.on_hold = self._on_clearall
+               self._backTapHandler.on_holding = self._set_clear_button
+               self._backTapHandler.on_cancel = self._reset_back_button
+
+               self._window = gtk_toolbox.find_parent_window(self._numberdisplay)
+               self._keyPressEventId = 0
+
+       def enable(self):
+               self._sendSMSButton.grab_focus()
+               self._backTapHandler.enable()
+               self._keyPressEventId = self._window.connect("key-press-event", self._on_key_press)
+
+       def disable(self):
+               self._window.disconnect(self._keyPressEventId)
+               self._keyPressEventId = 0
+               self._reset_back_button()
+               self._backTapHandler.disable()
+
+       def add_contact(self, *args, **kwds):
+               """
+               @note Actual function is patched in later
+               """
+               raise NotImplementedError("Horrible unknown error has occurred")
+
+       def dial(self, number):
+               """
+               @note Actual function is patched in later
+               """
+               raise NotImplementedError("Horrible unknown error has occurred")
+
+       def get_number(self):
+               return self._phonenumber
+
+       def set_number(self, number):
+               """
+               Set the number to dial
+               """
+               try:
+                       self._phonenumber = make_ugly(number)
+                       self._prettynumber = make_pretty(self._phonenumber)
+                       self._numberdisplay.set_label("<span size='30000' weight='bold'>%s</span>" % (self._prettynumber))
+                       if self._phonenumber:
+                               self._plusButton.set_sensitive(False)
+                       else:
+                               self._plusButton.set_sensitive(True)
+               except TypeError, e:
+                       self._errorDisplay.push_exception()
+
+       def clear(self):
+               self.set_number("")
+
+       @staticmethod
+       def name():
+               return "Dialpad"
+
+       def load_settings(self, config, section):
+               pass
+
+       def save_settings(self, config, section):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+       def _on_key_press(self, widget, event):
+               try:
+                       if event.keyval == ord("v") and event.get_state() & gtk.gdk.CONTROL_MASK:
+                               contents = self._clipboard.wait_for_text()
+                               if contents is not None:
+                                       self.set_number(contents)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_call_clicked(self, widget):
+               try:
+                       phoneNumber = self.get_number()
+                       self.dial(phoneNumber)
+                       self.set_number("")
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_sms_clicked(self, widget):
+               try:
+                       phoneNumber = self.get_number()
+                       self.add_contact(
+                               "(Dialpad)",
+                               [("Dialer", phoneNumber)], ()
+                       )
+                       self.set_number("")
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_digit_clicked(self, widget):
+               try:
+                       self.set_number(self._phonenumber + widget.get_name()[-1])
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_plus(self, *args):
+               try:
+                       self.set_number(self._phonenumber + "+")
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_backspace(self, taps):
+               try:
+                       self.set_number(self._phonenumber[:-taps])
+                       self._reset_back_button()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_clearall(self, taps):
+               try:
+                       self.clear()
+                       self._reset_back_button()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return False
+
+       def _set_clear_button(self):
+               try:
+                       self._backButton.set_label("gtk-clear")
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _reset_back_button(self):
+               try:
+                       self._backButton.set_label(self._originalLabel)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+class AccountInfo(object):
+
+       def __init__(self, widgetTree, backend, alarmHandler, errorDisplay):
+               self._errorDisplay = errorDisplay
+               self._backend = backend
+               self._isPopulated = False
+               self._alarmHandler = alarmHandler
+               self._notifyOnMissed = False
+               self._notifyOnVoicemail = False
+               self._notifyOnSms = False
+
+               self._callbackList = []
+               self._accountViewNumberDisplay = widgetTree.get_widget("gcnumber_display")
+               self._callbackSelectButton = widgetTree.get_widget("callbackSelectButton")
+               self._onCallbackSelectChangedId = 0
+
+               self._notifyCheckbox = widgetTree.get_widget("notifyCheckbox")
+               self._minutesEntryButton = widgetTree.get_widget("minutesEntryButton")
+               self._missedCheckbox = widgetTree.get_widget("missedCheckbox")
+               self._voicemailCheckbox = widgetTree.get_widget("voicemailCheckbox")
+               self._smsCheckbox = widgetTree.get_widget("smsCheckbox")
+               self._onNotifyToggled = 0
+               self._onMinutesChanged = 0
+               self._onMissedToggled = 0
+               self._onVoicemailToggled = 0
+               self._onSmsToggled = 0
+               self._applyAlarmTimeoutId = None
+
+               self._window = gtk_toolbox.find_parent_window(self._minutesEntryButton)
+               self._callbackNumber = ""
+
+       def enable(self):
+               assert self._backend.is_authed(), "Attempting to enable backend while not logged in"
+
+               self._accountViewNumberDisplay.set_use_markup(True)
+               self.set_account_number("")
+
+               del self._callbackList[:]
+               self._onCallbackSelectChangedId = self._callbackSelectButton.connect("clicked", self._on_callbackentry_clicked)
+               self._set_callback_label("")
+
+               if self._alarmHandler is not None:
+                       self._notifyCheckbox.set_active(self._alarmHandler.isEnabled)
+                       self._minutesEntryButton.set_label("%d minutes" % self._alarmHandler.recurrence)
+                       self._missedCheckbox.set_active(self._notifyOnMissed)
+                       self._voicemailCheckbox.set_active(self._notifyOnVoicemail)
+                       self._smsCheckbox.set_active(self._notifyOnSms)
+
+                       self._onNotifyToggled = self._notifyCheckbox.connect("toggled", self._on_notify_toggled)
+                       self._onMinutesChanged = self._minutesEntryButton.connect("clicked", self._on_minutes_clicked)
+                       self._onMissedToggled = self._missedCheckbox.connect("toggled", self._on_missed_toggled)
+                       self._onVoicemailToggled = self._voicemailCheckbox.connect("toggled", self._on_voicemail_toggled)
+                       self._onSmsToggled = self._smsCheckbox.connect("toggled", self._on_sms_toggled)
+               else:
+                       self._notifyCheckbox.set_sensitive(False)
+                       self._minutesEntryButton.set_sensitive(False)
+                       self._missedCheckbox.set_sensitive(False)
+                       self._voicemailCheckbox.set_sensitive(False)
+                       self._smsCheckbox.set_sensitive(False)
+
+               self.update(force=True)
+
+       def disable(self):
+               self._callbackSelectButton.disconnect(self._onCallbackSelectChangedId)
+               self._onCallbackSelectChangedId = 0
+               self._set_callback_label("")
+
+               if self._alarmHandler is not None:
+                       self._notifyCheckbox.disconnect(self._onNotifyToggled)
+                       self._minutesEntryButton.disconnect(self._onMinutesChanged)
+                       self._missedCheckbox.disconnect(self._onNotifyToggled)
+                       self._voicemailCheckbox.disconnect(self._onNotifyToggled)
+                       self._smsCheckbox.disconnect(self._onNotifyToggled)
+                       self._onNotifyToggled = 0
+                       self._onMinutesChanged = 0
+                       self._onMissedToggled = 0
+                       self._onVoicemailToggled = 0
+                       self._onSmsToggled = 0
+               else:
+                       self._notifyCheckbox.set_sensitive(True)
+                       self._minutesEntryButton.set_sensitive(True)
+                       self._missedCheckbox.set_sensitive(True)
+                       self._voicemailCheckbox.set_sensitive(True)
+                       self._smsCheckbox.set_sensitive(True)
+
+               self.clear()
+               del self._callbackList[:]
+
+       def set_account_number(self, number):
+               """
+               Displays current account number
+               """
+               self._accountViewNumberDisplay.set_label("<span size='23000' weight='bold'>%s</span>" % (number))
+
+       def update(self, force = False):
+               if not force and self._isPopulated:
+                       return False
+               self._populate_callback_combo()
+               self.set_account_number(self._backend.get_account_number())
+               return True
+
+       def clear(self):
+               self._set_callback_label("")
+               self.set_account_number("")
+               self._isPopulated = False
+
+       def save_everything(self):
+               raise NotImplementedError
+
+       @staticmethod
+       def name():
+               return "Account Info"
+
+       def load_settings(self, config, section):
+               self._callbackNumber = make_ugly(config.get(section, "callback"))
+               self._notifyOnMissed = config.getboolean(section, "notifyOnMissed")
+               self._notifyOnVoicemail = config.getboolean(section, "notifyOnVoicemail")
+               self._notifyOnSms = config.getboolean(section, "notifyOnSms")
+
+       def save_settings(self, config, section):
+               """
+               @note Thread Agnostic
+               """
+               config.set(section, "callback", self._callbackNumber)
+               config.set(section, "notifyOnMissed", repr(self._notifyOnMissed))
+               config.set(section, "notifyOnVoicemail", repr(self._notifyOnVoicemail))
+               config.set(section, "notifyOnSms", repr(self._notifyOnSms))
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+       def _populate_callback_combo(self):
+               self._isPopulated = True
+               del self._callbackList[:]
+               try:
+                       callbackNumbers = self._backend.get_callback_numbers()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+                       self._isPopulated = False
+                       return
+
+               if len(callbackNumbers) == 0:
+                       callbackNumbers = {"": "No callback numbers available"}
+
+               for number, description in callbackNumbers.iteritems():
+                       self._callbackList.append((make_pretty(number), description))
+
+               self._set_callback_number(self._callbackNumber)
+
+       def _set_callback_number(self, number):
+               try:
+                       if not self._backend.is_valid_syntax(number) and 0 < len(number):
+                               self._errorDisplay.push_message("%s is not a valid callback number" % number)
+                       elif number == self._backend.get_callback_number() and 0 < len(number):
+                               _moduleLogger.warning(
+                                       "Callback number already is %s" % (
+                                               self._backend.get_callback_number(),
+                                       ),
+                               )
+                               self._set_callback_label(number)
+                       else:
+                               if number.startswith("1747"): number = "+" + number
+                               self._backend.set_callback_number(number)
+                               assert make_ugly(number) == make_ugly(self._backend.get_callback_number()), "Callback number should be %s but instead is %s" % (
+                                       make_pretty(number), make_pretty(self._backend.get_callback_number())
+                               )
+                               self._callbackNumber = make_ugly(number)
+                               self._set_callback_label(number)
+                               _moduleLogger.info(
+                                       "Callback number set to %s" % (
+                                               self._backend.get_callback_number(),
+                                       ),
+                               )
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _set_callback_label(self, uglyNumber):
+               prettyNumber = make_pretty(uglyNumber)
+               if len(prettyNumber) == 0:
+                       prettyNumber = "No Callback Number"
+               self._callbackSelectButton.set_label(prettyNumber)
+
+       def _update_alarm_settings(self, recurrence):
+               try:
+                       isEnabled = self._notifyCheckbox.get_active()
+                       if isEnabled != self._alarmHandler.isEnabled or recurrence != self._alarmHandler.recurrence:
+                               self._alarmHandler.apply_settings(isEnabled, recurrence)
+               finally:
+                       self.save_everything()
+                       self._notifyCheckbox.set_active(self._alarmHandler.isEnabled)
+                       self._minutesEntryButton.set_label("%d Minutes" % self._alarmHandler.recurrence)
+
+       def _on_callbackentry_clicked(self, *args):
+               try:
+                       actualSelection = make_pretty(self._callbackNumber)
+
+                       userOptions = dict(
+                               (number, "%s (%s)" % (number, description))
+                               for (number, description) in self._callbackList
+                       )
+                       defaultSelection = userOptions.get(actualSelection, actualSelection)
+
+                       userSelection = hildonize.touch_selector_entry(
+                               self._window,
+                               "Callback Number",
+                               list(userOptions.itervalues()),
+                               defaultSelection,
+                       )
+                       reversedUserOptions = dict(
+                               itertools.izip(userOptions.itervalues(), userOptions.iterkeys())
+                       )
+                       selectedNumber = reversedUserOptions.get(userSelection, userSelection)
+
+                       number = make_ugly(selectedNumber)
+                       self._set_callback_number(number)
+               except RuntimeError, e:
+                       _moduleLogger.exception("%s" % str(e))
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_notify_toggled(self, *args):
+               try:
+                       if self._applyAlarmTimeoutId is not None:
+                               gobject.source_remove(self._applyAlarmTimeoutId)
+                               self._applyAlarmTimeoutId = None
+                       self._applyAlarmTimeoutId = gobject.timeout_add(500, self._on_apply_timeout)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_minutes_clicked(self, *args):
+               recurrenceChoices = [
+                       (1, "1 minute"),
+                       (2, "2 minutes"),
+                       (3, "3 minutes"),
+                       (5, "5 minutes"),
+                       (8, "8 minutes"),
+                       (10, "10 minutes"),
+                       (15, "15 minutes"),
+                       (30, "30 minutes"),
+                       (45, "45 minutes"),
+                       (60, "1 hour"),
+                       (3*60, "3 hours"),
+                       (6*60, "6 hours"),
+                       (12*60, "12 hours"),
+               ]
+               try:
+                       actualSelection = self._alarmHandler.recurrence
+
+                       closestSelectionIndex = 0
+                       for i, possible in enumerate(recurrenceChoices):
+                               if possible[0] <= actualSelection:
+                                       closestSelectionIndex = i
+                       recurrenceIndex = hildonize.touch_selector(
+                               self._window,
+                               "Minutes",
+                               (("%s" % m[1]) for m in recurrenceChoices),
+                               closestSelectionIndex,
+                       )
+                       recurrence = recurrenceChoices[recurrenceIndex][0]
+
+                       self._update_alarm_settings(recurrence)
+               except RuntimeError, e:
+                       _moduleLogger.exception("%s" % str(e))
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_apply_timeout(self, *args):
+               try:
+                       self._applyAlarmTimeoutId = None
+
+                       self._update_alarm_settings(self._alarmHandler.recurrence)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+               return False
+
+       def _on_missed_toggled(self, *args):
+               try:
+                       self._notifyOnMissed = self._missedCheckbox.get_active()
+                       self.save_everything()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_voicemail_toggled(self, *args):
+               try:
+                       self._notifyOnVoicemail = self._voicemailCheckbox.get_active()
+                       self.save_everything()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_sms_toggled(self, *args):
+               try:
+                       self._notifyOnSms = self._smsCheckbox.get_active()
+                       self.save_everything()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+class CallHistoryView(object):
+
+       NUMBER_IDX = 0
+       DATE_IDX = 1
+       ACTION_IDX = 2
+       FROM_IDX = 3
+       FROM_ID_IDX = 4
+
+       HISTORY_ITEM_TYPES = ["All", "Received", "Missed", "Placed"]
+
+       def __init__(self, widgetTree, backend, errorDisplay):
+               self._errorDisplay = errorDisplay
+               self._backend = backend
+
+               self._isPopulated = False
+               self._historymodel = gtk.ListStore(
+                       gobject.TYPE_STRING, # number
+                       gobject.TYPE_STRING, # date
+                       gobject.TYPE_STRING, # action
+                       gobject.TYPE_STRING, # from
+                       gobject.TYPE_STRING, # from id
+               )
+               self._historymodelfiltered = self._historymodel.filter_new()
+               self._historymodelfiltered.set_visible_func(self._is_history_visible)
+               self._historyview = widgetTree.get_widget("historyview")
+               self._historyviewselection = None
+               self._onRecentviewRowActivatedId = 0
+
+               textrenderer = gtk.CellRendererText()
+               textrenderer.set_property("yalign", 0)
+               self._dateColumn = gtk.TreeViewColumn("Date")
+               self._dateColumn.pack_start(textrenderer, expand=True)
+               self._dateColumn.add_attribute(textrenderer, "text", self.DATE_IDX)
+
+               textrenderer = gtk.CellRendererText()
+               textrenderer.set_property("yalign", 0)
+               self._actionColumn = gtk.TreeViewColumn("Action")
+               self._actionColumn.pack_start(textrenderer, expand=True)
+               self._actionColumn.add_attribute(textrenderer, "text", self.ACTION_IDX)
+
+               textrenderer = gtk.CellRendererText()
+               textrenderer.set_property("yalign", 0)
+               textrenderer.set_property("ellipsize", pango.ELLIPSIZE_END)
+               textrenderer.set_property("width-chars", len("1 (555) 555-1234"))
+               self._numberColumn = gtk.TreeViewColumn("Number")
+               self._numberColumn.pack_start(textrenderer, expand=True)
+               self._numberColumn.add_attribute(textrenderer, "text", self.NUMBER_IDX)
+
+               textrenderer = gtk.CellRendererText()
+               textrenderer.set_property("yalign", 0)
+               hildonize.set_cell_thumb_selectable(textrenderer)
+               self._nameColumn = gtk.TreeViewColumn("From")
+               self._nameColumn.pack_start(textrenderer, expand=True)
+               self._nameColumn.add_attribute(textrenderer, "text", self.FROM_IDX)
+               self._nameColumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+
+               self._window = gtk_toolbox.find_parent_window(self._historyview)
+
+               self._historyFilterSelector = widgetTree.get_widget("historyFilterSelector")
+               self._historyFilterSelector.connect("clicked", self._on_history_filter_clicked)
+               self._selectedFilter = "All"
+
+               self._updateSink = gtk_toolbox.threaded_stage(
+                       gtk_toolbox.comap(
+                               self._idly_populate_historyview,
+                               gtk_toolbox.null_sink(),
+                       )
+               )
+
+       def enable(self):
+               assert self._backend.is_authed(), "Attempting to enable backend while not logged in"
+               self._historyFilterSelector.set_label(self._selectedFilter)
+
+               self._historyview.set_model(self._historymodelfiltered)
+               self._historyview.set_fixed_height_mode(False)
+
+               self._historyview.append_column(self._dateColumn)
+               self._historyview.append_column(self._actionColumn)
+               self._historyview.append_column(self._numberColumn)
+               self._historyview.append_column(self._nameColumn)
+               self._historyviewselection = self._historyview.get_selection()
+               self._historyviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+               self._onRecentviewRowActivatedId = self._historyview.connect("row-activated", self._on_historyview_row_activated)
+
+       def disable(self):
+               self._historyview.disconnect(self._onRecentviewRowActivatedId)
+
+               self.clear()
+
+               self._historyview.remove_column(self._dateColumn)
+               self._historyview.remove_column(self._actionColumn)
+               self._historyview.remove_column(self._nameColumn)
+               self._historyview.remove_column(self._numberColumn)
+               self._historyview.set_model(None)
+
+       def add_contact(self, *args, **kwds):
+               """
+               @note Actual dial function is patched in later
+               """
+               raise NotImplementedError("Horrible unknown error has occurred")
+
+       def update(self, force = False):
+               if not force and self._isPopulated:
+                       return False
+               self._updateSink.send(())
+               return True
+
+       def clear(self):
+               self._isPopulated = False
+               self._historymodel.clear()
+
+       @staticmethod
+       def name():
+               return "Recent Calls"
+
+       def load_settings(self, config, sectionName):
+               try:
+                       self._selectedFilter = config.get(sectionName, "filter")
+                       if self._selectedFilter not in self.HISTORY_ITEM_TYPES:
+                               self._messageType = self.HISTORY_ITEM_TYPES[0]
+               except ConfigParser.NoOptionError:
+                       pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               config.set(sectionName, "filter", self._selectedFilter)
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+       def _is_history_visible(self, model, iter):
+               try:
+                       action = model.get_value(iter, self.ACTION_IDX)
+                       if action is None:
+                               return False # this seems weird but oh well
+
+                       if self._selectedFilter in [action, "All"]:
+                               return True
+                       else:
+                               return False
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _idly_populate_historyview(self):
+               with gtk_toolbox.gtk_lock():
+                       banner = hildonize.show_busy_banner_start(self._window, "Loading Call History")
+               try:
+                       self._historymodel.clear()
+                       self._isPopulated = True
+
+                       try:
+                               historyItems = self._backend.get_recent()
+                       except Exception, e:
+                               self._errorDisplay.push_exception_with_lock()
+                               self._isPopulated = False
+                               historyItems = []
+
+                       historyItems = (
+                               gv_backend.decorate_recent(data)
+                               for data in gv_backend.sort_messages(historyItems)
+                       )
+
+                       for contactId, personName, phoneNumber, date, action in historyItems:
+                               if not personName:
+                                       personName = "Unknown"
+                               date = abbrev_relative_date(date)
+                               prettyNumber = phoneNumber[2:] if phoneNumber.startswith("+1") else phoneNumber
+                               prettyNumber = make_pretty(prettyNumber)
+                               item = (prettyNumber, date, action.capitalize(), personName, contactId)
+                               with gtk_toolbox.gtk_lock():
+                                       self._historymodel.append(item)
+               except Exception, e:
+                       self._errorDisplay.push_exception_with_lock()
+               finally:
+                       with gtk_toolbox.gtk_lock():
+                               hildonize.show_busy_banner_end(banner)
+
+               return False
+
+       def _on_history_filter_clicked(self, *args, **kwds):
+               try:
+                       selectedComboIndex = self.HISTORY_ITEM_TYPES.index(self._selectedFilter)
+
+                       try:
+                               newSelectedComboIndex = hildonize.touch_selector(
+                                       self._window,
+                                       "History",
+                                       self.HISTORY_ITEM_TYPES,
+                                       selectedComboIndex,
+                               )
+                       except RuntimeError:
+                               return
+
+                       option = self.HISTORY_ITEM_TYPES[newSelectedComboIndex]
+                       self._selectedFilter = option
+                       self._historyFilterSelector.set_label(self._selectedFilter)
+                       self._historymodelfiltered.refilter()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _history_summary(self, expectedNumber):
+               for number, action, date, whoFrom, whoFromId in self._historymodel:
+                       if expectedNumber is not None and expectedNumber == number:
+                               yield "%s <i>(%s)</i> - %s %s" % (number, whoFrom, date, action)
+
+       def _on_historyview_row_activated(self, treeview, path, view_column):
+               try:
+                       childPath = self._historymodelfiltered.convert_path_to_child_path(path)
+                       itr = self._historymodel.get_iter(childPath)
+                       if not itr:
+                               return
+
+                       prettyNumber = self._historymodel.get_value(itr, self.NUMBER_IDX)
+                       number = make_ugly(prettyNumber)
+                       description = list(self._history_summary(prettyNumber))
+                       contactName = self._historymodel.get_value(itr, self.FROM_IDX)
+                       contactId = self._historymodel.get_value(itr, self.FROM_ID_IDX)
+                       contactPhoneNumbers, defaultIndex = _get_contact_numbers(self._backend, contactId, number)
+
+                       self.add_contact(
+                               contactName,
+                               contactPhoneNumbers,
+                               messages = description,
+                               defaultIndex = defaultIndex,
+                       )
+                       self._historyviewselection.unselect_all()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+class MessagesView(object):
+
+       NUMBER_IDX = 0
+       DATE_IDX = 1
+       HEADER_IDX = 2
+       MESSAGE_IDX = 3
+       MESSAGES_IDX = 4
+       FROM_ID_IDX = 5
+       MESSAGE_DATA_IDX = 6
+
+       NO_MESSAGES = "None"
+       VOICEMAIL_MESSAGES = "Voicemail"
+       TEXT_MESSAGES = "SMS"
+       ALL_TYPES = "All Messages"
+       MESSAGE_TYPES = [NO_MESSAGES, VOICEMAIL_MESSAGES, TEXT_MESSAGES, ALL_TYPES]
+
+       UNREAD_STATUS = "Unread"
+       UNARCHIVED_STATUS = "Inbox"
+       ALL_STATUS = "Any"
+       MESSAGE_STATUSES = [UNREAD_STATUS, UNARCHIVED_STATUS, ALL_STATUS]
+
+       def __init__(self, widgetTree, backend, errorDisplay):
+               self._errorDisplay = errorDisplay
+               self._backend = backend
+
+               self._isPopulated = False
+               self._messagemodel = gtk.ListStore(
+                       gobject.TYPE_STRING, # number
+                       gobject.TYPE_STRING, # date
+                       gobject.TYPE_STRING, # header
+                       gobject.TYPE_STRING, # message
+                       object, # messages
+                       gobject.TYPE_STRING, # from id
+                       object, # message data
+               )
+               self._messagemodelfiltered = self._messagemodel.filter_new()
+               self._messagemodelfiltered.set_visible_func(self._is_message_visible)
+               self._messageview = widgetTree.get_widget("messages_view")
+               self._messageviewselection = None
+               self._onMessageviewRowActivatedId = 0
+
+               self._messageRenderer = gtk.CellRendererText()
+               self._messageRenderer.set_property("wrap-mode", pango.WRAP_WORD)
+               self._messageRenderer.set_property("wrap-width", 500)
+               self._messageColumn = gtk.TreeViewColumn("Messages")
+               self._messageColumn.pack_start(self._messageRenderer, expand=True)
+               self._messageColumn.add_attribute(self._messageRenderer, "markup", self.MESSAGE_IDX)
+               self._messageColumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+
+               self._window = gtk_toolbox.find_parent_window(self._messageview)
+
+               self._messageTypeButton = widgetTree.get_widget("messageTypeButton")
+               self._onMessageTypeClickedId = 0
+               self._messageType = self.ALL_TYPES
+               self._messageStatusButton = widgetTree.get_widget("messageStatusButton")
+               self._onMessageStatusClickedId = 0
+               self._messageStatus = self.ALL_STATUS
+
+               self._updateSink = gtk_toolbox.threaded_stage(
+                       gtk_toolbox.comap(
+                               self._idly_populate_messageview,
+                               gtk_toolbox.null_sink(),
+                       )
+               )
+
+       def enable(self):
+               assert self._backend.is_authed(), "Attempting to enable backend while not logged in"
+               self._messageview.set_model(self._messagemodelfiltered)
+               self._messageview.set_headers_visible(False)
+               self._messageview.set_fixed_height_mode(False)
+
+               self._messageview.append_column(self._messageColumn)
+               self._messageviewselection = self._messageview.get_selection()
+               self._messageviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+               self._messageTypeButton.set_label(self._messageType)
+               self._messageStatusButton.set_label(self._messageStatus)
+
+               self._onMessageviewRowActivatedId = self._messageview.connect(
+                       "row-activated", self._on_messageview_row_activated
+               )
+               self._onMessageTypeClickedId = self._messageTypeButton.connect(
+                       "clicked", self._on_message_type_clicked
+               )
+               self._onMessageStatusClickedId = self._messageStatusButton.connect(
+                       "clicked", self._on_message_status_clicked
+               )
+
+       def disable(self):
+               self._messageview.disconnect(self._onMessageviewRowActivatedId)
+               self._messageTypeButton.disconnect(self._onMessageTypeClickedId)
+               self._messageStatusButton.disconnect(self._onMessageStatusClickedId)
+
+               self.clear()
+
+               self._messageview.remove_column(self._messageColumn)
+               self._messageview.set_model(None)
+
+       def add_contact(self, *args, **kwds):
+               """
+               @note Actual dial function is patched in later
+               """
+               raise NotImplementedError("Horrible unknown error has occurred")
+
+       def update(self, force = False):
+               if not force and self._isPopulated:
+                       return False
+               self._updateSink.send(())
+               return True
+
+       def clear(self):
+               self._isPopulated = False
+               self._messagemodel.clear()
+
+       @staticmethod
+       def name():
+               return "Messages"
+
+       def load_settings(self, config, sectionName):
+               try:
+                       self._messageType = config.get(sectionName, "type")
+                       if self._messageType not in self.MESSAGE_TYPES:
+                               self._messageType = self.ALL_TYPES
+                       self._messageStatus = config.get(sectionName, "status")
+                       if self._messageStatus not in self.MESSAGE_STATUSES:
+                               self._messageStatus = self.ALL_STATUS
+               except ConfigParser.NoOptionError:
+                       pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               config.set(sectionName, "status", self._messageStatus)
+               config.set(sectionName, "type", self._messageType)
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+       def _is_message_visible(self, model, iter):
+               try:
+                       message = model.get_value(iter, self.MESSAGE_DATA_IDX)
+                       if message is None:
+                               return False # this seems weird but oh well
+                       return self._filter_messages(message, self._messageType, self._messageStatus)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       @classmethod
+       def _filter_messages(cls, message, type, status):
+               if type == cls.ALL_TYPES:
+                       isType = True
+               else:
+                       messageType = message["type"]
+                       isType = messageType == type
+
+               if status == cls.ALL_STATUS:
+                       isStatus = True
+               else:
+                       isUnarchived = not message["isArchived"]
+                       isUnread = not message["isRead"]
+                       if status == cls.UNREAD_STATUS:
+                               isStatus = isUnarchived and isUnread
+                       elif status == cls.UNARCHIVED_STATUS:
+                               isStatus = isUnarchived
+                       else:
+                               assert "Status %s is bad for %r" % (status, message)
+
+               return isType and isStatus
+
+       _MIN_MESSAGES_SHOWN = 4
+
+       def _idly_populate_messageview(self):
+               with gtk_toolbox.gtk_lock():
+                       banner = hildonize.show_busy_banner_start(self._window, "Loading Messages")
+               try:
+                       self._messagemodel.clear()
+                       self._isPopulated = True
+
+                       if self._messageType == self.NO_MESSAGES:
+                               messageItems = []
+                       else:
+                               try:
+                                       messageItems = self._backend.get_messages()
+                               except Exception, e:
+                                       self._errorDisplay.push_exception_with_lock()
+                                       self._isPopulated = False
+                                       messageItems = []
+
+                       messageItems = (
+                               (gv_backend.decorate_message(message), message)
+                               for message in gv_backend.sort_messages(messageItems)
+                       )
+
+                       for (contactId, header, number, relativeDate, messages), messageData in messageItems:
+                               prettyNumber = number[2:] if number.startswith("+1") else number
+                               prettyNumber = make_pretty(prettyNumber)
+
+                               firstMessage = "<b>%s - %s</b> <i>(%s)</i>" % (header, prettyNumber, relativeDate)
+                               expandedMessages = [firstMessage]
+                               expandedMessages.extend(messages)
+                               if (self._MIN_MESSAGES_SHOWN + 1) < len(messages):
+                                       firstMessage = "<b>%s - %s</b> <i>(%s)</i>" % (header, prettyNumber, relativeDate)
+                                       secondMessage = "<i>%d Messages Hidden...</i>" % (len(messages) - self._MIN_MESSAGES_SHOWN, )
+                                       collapsedMessages = [firstMessage, secondMessage]
+                                       collapsedMessages.extend(messages[-(self._MIN_MESSAGES_SHOWN+0):])
+                               else:
+                                       collapsedMessages = expandedMessages
+                               #collapsedMessages = _collapse_message(collapsedMessages, 60, self._MIN_MESSAGES_SHOWN)
+
+                               number = make_ugly(number)
+
+                               row = number, relativeDate, header, "\n".join(collapsedMessages), expandedMessages, contactId, messageData
+                               with gtk_toolbox.gtk_lock():
+                                       self._messagemodel.append(row)
+               except Exception, e:
+                       self._errorDisplay.push_exception_with_lock()
+               finally:
+                       with gtk_toolbox.gtk_lock():
+                               hildonize.show_busy_banner_end(banner)
+                               self._messagemodelfiltered.refilter()
+
+               return False
+
+       def _on_messageview_row_activated(self, treeview, path, view_column):
+               try:
+                       childPath = self._messagemodelfiltered.convert_path_to_child_path(path)
+                       itr = self._messagemodel.get_iter(childPath)
+                       if not itr:
+                               return
+
+                       number = make_ugly(self._messagemodel.get_value(itr, self.NUMBER_IDX))
+                       description = self._messagemodel.get_value(itr, self.MESSAGES_IDX)
+
+                       contactId = self._messagemodel.get_value(itr, self.FROM_ID_IDX)
+                       header = self._messagemodel.get_value(itr, self.HEADER_IDX)
+                       contactPhoneNumbers, defaultIndex = _get_contact_numbers(self._backend, contactId, number)
+
+                       self.add_contact(
+                               header,
+                               contactPhoneNumbers,
+                               messages = description,
+                               defaultIndex = defaultIndex,
+                       )
+                       self._messageviewselection.unselect_all()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_message_type_clicked(self, *args, **kwds):
+               try:
+                       selectedIndex = self.MESSAGE_TYPES.index(self._messageType)
+
+                       try:
+                               newSelectedIndex = hildonize.touch_selector(
+                                       self._window,
+                                       "Message Type",
+                                       self.MESSAGE_TYPES,
+                                       selectedIndex,
+                               )
+                       except RuntimeError:
+                               return
+
+                       if selectedIndex != newSelectedIndex:
+                               self._messageType = self.MESSAGE_TYPES[newSelectedIndex]
+                               self._messageTypeButton.set_label(self._messageType)
+                               self._messagemodelfiltered.refilter()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_message_status_clicked(self, *args, **kwds):
+               try:
+                       selectedIndex = self.MESSAGE_STATUSES.index(self._messageStatus)
+
+                       try:
+                               newSelectedIndex = hildonize.touch_selector(
+                                       self._window,
+                                       "Message Status",
+                                       self.MESSAGE_STATUSES,
+                                       selectedIndex,
+                               )
+                       except RuntimeError:
+                               return
+
+                       if selectedIndex != newSelectedIndex:
+                               self._messageStatus = self.MESSAGE_STATUSES[newSelectedIndex]
+                               self._messageStatusButton.set_label(self._messageStatus)
+                               self._messagemodelfiltered.refilter()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+
+class ContactsView(object):
+
+       CONTACT_TYPE_IDX = 0
+       CONTACT_NAME_IDX = 1
+       CONTACT_ID_IDX = 2
+
+       def __init__(self, widgetTree, backend, errorDisplay):
+               self._errorDisplay = errorDisplay
+               self._backend = backend
+
+               self._addressBook = None
+               self._selectedComboIndex = 0
+               self._addressBookFactories = [null_backend.NullAddressBook()]
+
+               self._booksList = []
+               self._bookSelectionButton = widgetTree.get_widget("addressbookSelectButton")
+
+               self._isPopulated = False
+               self._contactsmodel = gtk.ListStore(
+                       gobject.TYPE_STRING, # Contact Type
+                       gobject.TYPE_STRING, # Contact Name
+                       gobject.TYPE_STRING, # Contact ID
+               )
+               self._contactsviewselection = None
+               self._contactsview = widgetTree.get_widget("contactsview")
+
+               self._contactColumn = gtk.TreeViewColumn("Contact")
+               displayContactSource = False
+               if displayContactSource:
+                       textrenderer = gtk.CellRendererText()
+                       self._contactColumn.pack_start(textrenderer, expand=False)
+                       self._contactColumn.add_attribute(textrenderer, 'text', self.CONTACT_TYPE_IDX)
+               textrenderer = gtk.CellRendererText()
+               hildonize.set_cell_thumb_selectable(textrenderer)
+               self._contactColumn.pack_start(textrenderer, expand=True)
+               self._contactColumn.add_attribute(textrenderer, 'text', self.CONTACT_NAME_IDX)
+               self._contactColumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+               self._contactColumn.set_sort_column_id(1)
+               self._contactColumn.set_visible(True)
+
+               self._onContactsviewRowActivatedId = 0
+               self._onAddressbookButtonChangedId = 0
+               self._window = gtk_toolbox.find_parent_window(self._contactsview)
+
+               self._updateSink = gtk_toolbox.threaded_stage(
+                       gtk_toolbox.comap(
+                               self._idly_populate_contactsview,
+                               gtk_toolbox.null_sink(),
+                       )
+               )
+
+       def enable(self):
+               assert self._backend.is_authed(), "Attempting to enable backend while not logged in"
+
+               self._contactsview.set_model(self._contactsmodel)
+               self._contactsview.set_fixed_height_mode(False)
+               self._contactsview.append_column(self._contactColumn)
+               self._contactsviewselection = self._contactsview.get_selection()
+               self._contactsviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+               del self._booksList[:]
+               for (factoryId, bookId), (factoryName, bookName) in self.get_addressbooks():
+                       if factoryName and bookName:
+                               entryName = "%s: %s" % (factoryName, bookName)
+                       elif factoryName:
+                               entryName = factoryName
+                       elif bookName:
+                               entryName = bookName
+                       else:
+                               entryName = "Bad name (%d)" % factoryId
+                       row = (str(factoryId), bookId, entryName)
+                       self._booksList.append(row)
+
+               self._onContactsviewRowActivatedId = self._contactsview.connect("row-activated", self._on_contactsview_row_activated)
+               self._onAddressbookButtonChangedId = self._bookSelectionButton.connect("clicked", self._on_addressbook_button_changed)
+
+               if len(self._booksList) <= self._selectedComboIndex:
+                       self._selectedComboIndex = 0
+               self._bookSelectionButton.set_label(self._booksList[self._selectedComboIndex][2])
+
+               selectedFactoryId = self._booksList[self._selectedComboIndex][0]
+               selectedBookId = self._booksList[self._selectedComboIndex][1]
+               self.open_addressbook(selectedFactoryId, selectedBookId)
+
+       def disable(self):
+               self._contactsview.disconnect(self._onContactsviewRowActivatedId)
+               self._bookSelectionButton.disconnect(self._onAddressbookButtonChangedId)
+
+               self.clear()
+
+               self._bookSelectionButton.set_label("")
+               self._contactsview.set_model(None)
+               self._contactsview.remove_column(self._contactColumn)
+
+       def add_contact(self, *args, **kwds):
+               """
+               @note Actual dial function is patched in later
+               """
+               raise NotImplementedError("Horrible unknown error has occurred")
+
+       def get_addressbooks(self):
+               """
+               @returns Iterable of ((Factory Id, Book Id), (Factory Name, Book Name))
+               """
+               for i, factory in enumerate(self._addressBookFactories):
+                       for bookFactory, bookId, bookName in factory.get_addressbooks():
+                               yield (str(i), bookId), (factory.factory_name(), bookName)
+
+       def open_addressbook(self, bookFactoryId, bookId):
+               bookFactoryIndex = int(bookFactoryId)
+               addressBook = self._addressBookFactories[bookFactoryIndex].open_addressbook(bookId)
+               self._addressBook = addressBook
+
+       def update(self, force = False):
+               if not force and self._isPopulated:
+                       return False
+               self._updateSink.send(())
+               return True
+
+       def clear(self):
+               self._isPopulated = False
+               self._contactsmodel.clear()
+               for factory in self._addressBookFactories:
+                       factory.clear_caches()
+               self._addressBook.clear_caches()
+
+       def append(self, book):
+               self._addressBookFactories.append(book)
+
+       def extend(self, books):
+               self._addressBookFactories.extend(books)
+
+       @staticmethod
+       def name():
+               return "Contacts"
+
+       def load_settings(self, config, sectionName):
+               try:
+                       self._selectedComboIndex = config.getint(sectionName, "selectedAddressbook")
+               except ConfigParser.NoOptionError:
+                       self._selectedComboIndex = 0
+
+       def save_settings(self, config, sectionName):
+               config.set(sectionName, "selectedAddressbook", str(self._selectedComboIndex))
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+       def _idly_populate_contactsview(self):
+               with gtk_toolbox.gtk_lock():
+                       banner = hildonize.show_busy_banner_start(self._window, "Loading Contacts")
+               try:
+                       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 Exception, e:
+                                       contacts = []
+                                       self._isPopulated = False
+                                       self._errorDisplay.push_exception_with_lock()
+                               for contactId, contactName in contacts:
+                                       contactType = addressBook.contact_source_short_name(contactId)
+                                       row = contactType, contactName, contactId
+                                       self._contactsmodel.append(row)
+
+                               with gtk_toolbox.gtk_lock():
+                                       self._contactsview.set_model(self._contactsmodel)
+
+                       self._isPopulated = True
+               except Exception, e:
+                       self._errorDisplay.push_exception_with_lock()
+               finally:
+                       with gtk_toolbox.gtk_lock():
+                               hildonize.show_busy_banner_end(banner)
+               return False
+
+       def _on_addressbook_button_changed(self, *args, **kwds):
+               try:
+                       try:
+                               newSelectedComboIndex = hildonize.touch_selector(
+                                       self._window,
+                                       "Addressbook",
+                                       (("%s" % m[2]) for m in self._booksList),
+                                       self._selectedComboIndex,
+                               )
+                       except RuntimeError:
+                               return
+
+                       selectedFactoryId = self._booksList[newSelectedComboIndex][0]
+                       selectedBookId = self._booksList[newSelectedComboIndex][1]
+
+                       oldAddressbook = self._addressBook
+                       self.open_addressbook(selectedFactoryId, selectedBookId)
+                       forceUpdate = True if oldAddressbook is not self._addressBook else False
+                       self.update(force=forceUpdate)
+
+                       self._selectedComboIndex = newSelectedComboIndex
+                       self._bookSelectionButton.set_label(self._booksList[self._selectedComboIndex][2])
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
+       def _on_contactsview_row_activated(self, treeview, path, view_column):
+               try:
+                       itr = self._contactsmodel.get_iter(path)
+                       if not itr:
+                               return
+
+                       contactId = self._contactsmodel.get_value(itr, self.CONTACT_ID_IDX)
+                       contactName = self._contactsmodel.get_value(itr, self.CONTACT_NAME_IDX)
+                       try:
+                               contactDetails = self._addressBook.get_contact_details(contactId)
+                       except Exception, e:
+                               contactDetails = []
+                               self._errorDisplay.push_exception()
+                       contactPhoneNumbers = [phoneNumber for phoneNumber in contactDetails]
+
+                       if len(contactPhoneNumbers) == 0:
+                               return
+
+                       self.add_contact(
+                               contactName,
+                               contactPhoneNumbers,
+                               messages = (contactName, ),
+                       )
+                       self._contactsviewselection.unselect_all()
+               except Exception, e:
+                       self._errorDisplay.push_exception()
diff --git a/src/led_handler.py b/src/led_handler.py
new file mode 100755 (executable)
index 0000000..211036e
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import dbus
+
+
+class LedHandler(object):
+
+       def __init__(self):
+               self._bus = dbus.SystemBus()
+               self._rawMceRequest = self._bus.get_object("com.nokia.mce", "/com/nokia/mce/request")
+               self._mceRequest = dbus.Interface(self._rawMceRequest, dbus_interface="com.nokia.mce.request")
+
+               self._ledPattern = "PatternCommunicationChat"
+
+       def on(self):
+               self._mceRequest.req_led_pattern_activate(self._ledPattern)
+
+       def off(self):
+               self._mceRequest.req_led_pattern_deactivate(self._ledPattern)
+
+
+if __name__ == "__main__":
+       leds = LedHandler()
+       leds.off()
diff --git a/src/maeqt.py b/src/maeqt.py
deleted file mode 100644 (file)
index d61c669..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-from PyQt4 import QtCore
-
-
-def _null_set_stackable(window, isStackable):
-       pass
-
-
-def _maemo_set_stackable(window, isStackable):
-       window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable)
-
-
-try:
-       QtCore.Qt.WA_Maemo5StackedWindow
-       set_stackable = _maemo_set_stackable
-except AttributeError:
-       set_stackable = _null_set_stackable
-
-
-def _null_set_autorient(window, isStackable):
-       pass
-
-
-def _maemo_set_autorient(window, isStackable):
-       window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable)
-
-
-try:
-       QtCore.Qt.WA_Maemo5AutoOrientation
-       set_autorient = _maemo_set_autorient
-except AttributeError:
-       set_autorient = _null_set_autorient
-
-
-def _null_set_landscape(window, isStackable):
-       pass
-
-
-def _maemo_set_landscape(window, isStackable):
-       window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable)
-
-
-try:
-       QtCore.Qt.WA_Maemo5LandscapeOrientation
-       set_landscape = _maemo_set_landscape
-except AttributeError:
-       set_landscape = _null_set_landscape
-
-
-def _null_set_portrait(window, isStackable):
-       pass
-
-
-def _maemo_set_portrait(window, isStackable):
-       window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable)
-
-
-try:
-       QtCore.Qt.WA_Maemo5PortraitOrientation
-       set_portrait = _maemo_set_portrait
-except AttributeError:
-       set_portrait = _null_set_portrait
-
-
-def _null_show_progress_indicator(window, isStackable):
-       pass
-
-
-def _maemo_show_progress_indicator(window, isStackable):
-       window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow, isStackable)
-
-
-try:
-       QtCore.Qt.WA_Maemo5ShowProgressIndicator
-       show_progress_indicator = _maemo_show_progress_indicator
-except AttributeError:
-       show_progress_indicator = _null_show_progress_indicator
-
-
-def _null_mark_numbers_preferred(widget):
-       pass
-
-
-def _newqt_mark_numbers_preferred(widget):
-       widget.setInputMethodHints(QtCore.Qt.ImhPreferNumbers)
-
-
-try:
-       QtCore.Qt.ImhPreferNumbers
-       mark_numbers_preferred = _newqt_mark_numbers_preferred
-except AttributeError:
-       mark_numbers_preferred = _null_mark_numbers_preferred
diff --git a/src/null_views.py b/src/null_views.py
new file mode 100644 (file)
index 0000000..2299b28
--- /dev/null
@@ -0,0 +1,251 @@
+#!/usr/bin/python2.5
+
+"""
+DialCentral - Front end for Google's Grand Central service.
+Copyright (C) 2008  Mark Bergman bergman AT merctech 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
+"""
+
+import gobject
+import gtk
+
+
+class Dialpad(object):
+
+       def __init__(self, widgetTree):
+               self._buttons = [
+                       widgetTree.get_widget(buttonName)
+                       for buttonName in ("dialpadCall", "dialpadSMS")
+               ]
+               self._numberdisplay = widgetTree.get_widget("numberdisplay")
+
+       def enable(self):
+               for button in self._buttons:
+                       button.set_sensitive(False)
+
+       def disable(self):
+               for button in self._buttons:
+                       button.set_sensitive(True)
+
+       @staticmethod
+       def name():
+               return "Dialpad"
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+
+class AccountInfo(object):
+
+       def __init__(self, widgetTree):
+               self._callbackList = gtk.ListStore(gobject.TYPE_STRING)
+               self._accountViewNumberDisplay = widgetTree.get_widget("gcnumber_display")
+               self._callbackSelectButton = widgetTree.get_widget("callbackSelectButton")
+               self._clearCookiesButton = widgetTree.get_widget("clearcookies")
+
+               self._notifyCheckbox = widgetTree.get_widget("notifyCheckbox")
+               self._minutesEntryButton = widgetTree.get_widget("minutesEntryButton")
+               self._missedCheckbox = widgetTree.get_widget("missedCheckbox")
+               self._voicemailCheckbox = widgetTree.get_widget("voicemailCheckbox")
+               self._smsCheckbox = widgetTree.get_widget("smsCheckbox")
+
+       def enable(self):
+               self._callbackSelectButton.set_sensitive(False)
+               self._clearCookiesButton.set_sensitive(False)
+
+               self._notifyCheckbox.set_sensitive(False)
+               self._minutesEntryButton.set_sensitive(False)
+               self._missedCheckbox.set_sensitive(False)
+               self._voicemailCheckbox.set_sensitive(False)
+               self._smsCheckbox.set_sensitive(False)
+
+               self._accountViewNumberDisplay.set_label("")
+
+       def disable(self):
+               self._callbackSelectButton.set_sensitive(True)
+               self._clearCookiesButton.set_sensitive(True)
+
+               self._notifyCheckbox.set_sensitive(True)
+               self._minutesEntryButton.set_sensitive(True)
+               self._missedCheckbox.set_sensitive(True)
+               self._voicemailCheckbox.set_sensitive(True)
+               self._smsCheckbox.set_sensitive(True)
+
+       @staticmethod
+       def update(force = False):
+               return False
+
+       @staticmethod
+       def clear():
+               pass
+
+       @staticmethod
+       def name():
+               return "Account Info"
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+
+class CallHistoryView(object):
+
+       def __init__(self, widgetTree):
+               self._historyFilterSelector = widgetTree.get_widget("historyFilterSelector")
+
+       def enable(self):
+               self._historyFilterSelector.set_sensitive(False)
+
+       def disable(self):
+               self._historyFilterSelector.set_sensitive(True)
+
+       def update(self, force = False):
+               return False
+
+       @staticmethod
+       def clear():
+               pass
+
+       @staticmethod
+       def name():
+               return "Recent Calls"
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+
+class MessagesView(object):
+
+       def __init__(self, widgetTree):
+               self._messageTypeButton = widgetTree.get_widget("messageTypeButton")
+               self._messageStatusButton = widgetTree.get_widget("messageStatusButton")
+
+       def enable(self):
+               self._messageTypeButton.set_sensitive(False)
+               self._messageStatusButton.set_sensitive(False)
+
+       def disable(self):
+               self._messageTypeButton.set_sensitive(True)
+               self._messageStatusButton.set_sensitive(True)
+
+       def update(self, force = False):
+               return False
+
+       @staticmethod
+       def clear():
+               pass
+
+       @staticmethod
+       def name():
+               return "Messages"
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
+
+
+class ContactsView(object):
+
+       def __init__(self, widgetTree):
+               self._bookSelectionButton = widgetTree.get_widget("addressbookSelectButton")
+
+       def enable(self):
+               self._bookSelectionButton.set_sensitive(False)
+
+       def disable(self):
+               self._bookSelectionButton.set_sensitive(True)
+
+       def update(self, force = False):
+               return False
+
+       @staticmethod
+       def clear():
+               pass
+
+       @staticmethod
+       def name():
+               return "Contacts"
+
+       def load_settings(self, config, sectionName):
+               pass
+
+       def save_settings(self, config, sectionName):
+               """
+               @note Thread Agnostic
+               """
+               pass
+
+       def set_orientation(self, orientation):
+               if orientation == gtk.ORIENTATION_VERTICAL:
+                       pass
+               elif orientation == gtk.ORIENTATION_HORIZONTAL:
+                       pass
+               else:
+                       raise NotImplementedError(orientation)
index d12305a..eb99ebc 100755 (executable)
@@ -12,17 +12,25 @@ import constants
 
 
 __appname__ = constants.__app_name__
-__description__ = """REPLACEME
-REPLACEME
+__description__ = """Touch screen enhanced interface to the GoogleVoice phone service"
+Features:
 .
-Homepage: REPLACEME
+* Dialpad for quick call
+.
+* Checking voicemails, texts, call history
+.
+* Sending texts
+.
+* Notification support for texts, voicemail, and/or missed calls
+.
+Homepage: http://gc-dialer.garage.maemo.org/
 """
 __author__ = "Ed Page"
 __email__ = "eopage@byu.net"
 __version__ = constants.__version__
 __build__ = constants.__build__
 __changelog__ = """
-REPLACEME
+* Fixed a minor packaging issue
 """.strip()
 
 
@@ -30,9 +38,12 @@ __postinstall__ = """#!/bin/sh -e
 
 gtk-update-icon-cache -f /usr/share/icons/hicolor
 rm -f ~/.%(name)s/%(name)s.log
+rm -f ~/.%(name)s/notifier.log
 """ % {"name": constants.__app_name__}
 
 __preremove__ = """#!/bin/sh -e
+
+python /usr/lib/dialcentral/alarm_handler.py -d || true
 """
 
 
@@ -66,7 +77,7 @@ def build_package(distribution):
        p = py2deb.Py2deb(__appname__)
        p.prettyName = constants.__pretty_app_name__
        p.description = __description__
-       p.bugTracker = "REPLACEME"
+       p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Dialcentral"
        p.author = __author__
        p.mail = __email__
        p.license = "lgpl"
@@ -85,9 +96,9 @@ def build_package(distribution):
        p.recommends = ", ".join([
        ])
        p.section = {
-               "debian": "REPLACEME",
-               "diablo": "user/REPLACEME",
-               "fremantle": "user/REPLACEME",
+               "debian": "comm",
+               "diablo": "user/network",
+               "fremantle": "user/network",
        }[distribution]
        p.arch = "all"
        p.urgency = "low"
@@ -97,23 +108,23 @@ def build_package(distribution):
        p.postinstall = __postinstall__
        p.preremove = __preremove__
        p.icon = {
-               "debian": "REPLACEME",
-               "diablo": "REPLACEME",
-               "fremantle": "REPLACEME", # Fremantle natively uses 48x48
+               "debian": "26x26-dialcentral.png",
+               "diablo": "26x26-dialcentral.png",
+               "fremantle": "64x64-dialcentral.png", # Fremantle natively uses 48x48
        }[distribution]
-       p["/opt/%s/bin" % constants.__appname__] = [ "%s.py" % constants.__appname__ ]
+       p["/opt/%s/bin" % __appname__] = [ "%s.py" % __appname__ ]
        for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
-               fullPath = "/opt/%s/lib" % constants.__appname__
+               fullPath = "/opt/%s/lib" % __appname__
                if relPath:
                        fullPath += os.sep+relPath
                p[fullPath] = list(
                        "|".join((oldName, newName))
                        for (oldName, newName) in files
                )
-       p["/usr/share/applications/hildon"] = ["%s.desktop" % constants.__appname__]
-       p["/usr/share/icons/hicolor/26x26/hildon"] = ["%s.png" % constants.__appname__]
-       p["/usr/share/icons/hicolor/64x64/hildon"] = ["%s.png" % constants.__appname__]
-       p["/usr/share/icons/hicolor/scalable/hildon"] = ["%s.png" % constants.__appname__]
+       p["/usr/share/applications/hildon"] = ["dialcentral.desktop"]
+       p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-dialcentral.png|dialcentral.png"]
+       p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-dialcentral.png|dialcentral.png"]
+       p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-dialcentral.png|dialcentral.png"]
 
        if distribution == "debian":
                print p
diff --git a/support/dialcentral.desktop b/support/dialcentral.desktop
new file mode 100644 (file)
index 0000000..c5ec2f3
--- /dev/null
@@ -0,0 +1,7 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Name=DialCentral
+Exec=/usr/bin/run-standalone.sh /opt/dialcentral/bin/dialcentral.py
+Icon=dialcentral
diff --git a/support/icons/hicolor/26x26/hildon/dialcentral.png b/support/icons/hicolor/26x26/hildon/dialcentral.png
new file mode 100644 (file)
index 0000000..df50c66
Binary files /dev/null and b/support/icons/hicolor/26x26/hildon/dialcentral.png differ
diff --git a/support/icons/hicolor/64x64/hildon/dialcentral.png b/support/icons/hicolor/64x64/hildon/dialcentral.png
new file mode 100644 (file)
index 0000000..8d98390
Binary files /dev/null and b/support/icons/hicolor/64x64/hildon/dialcentral.png differ
diff --git a/support/icons/hicolor/scalable/hildon/dialcentral.png b/support/icons/hicolor/scalable/hildon/dialcentral.png
new file mode 100644 (file)
index 0000000..a875350
Binary files /dev/null and b/support/icons/hicolor/scalable/hildon/dialcentral.png differ
diff --git a/tests/basic_data/basic.csv b/tests/basic_data/basic.csv
new file mode 100644 (file)
index 0000000..6ffd844
--- /dev/null
@@ -0,0 +1,2 @@
+familyname,phone,addr1,addr2,addr3,addr4,name1,name2,name3,name4\r
+"Last, First","555-123-4567","1234 Foo St","Austin, Texas 78727","","","First <name@domain.com>"\r
diff --git a/tests/basic_data/empty.csv b/tests/basic_data/empty.csv
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/basic_data/google.csv b/tests/basic_data/google.csv
new file mode 100644 (file)
index 0000000..3fa4d3e
--- /dev/null
@@ -0,0 +1,7 @@
+Name,E-mail,Notes,Section 1 - Description,Section 1 - Email,Section 1 - IM,Section 1 - Phone,Section 1 - Mobile,Section 1 - Pager,Section 1 - Fax,Section 1 - Company,Section 1 - Title,Section 1 - Other,Section 1 - Address,Section 2 - Description,Section 2 - Email,Section 2 - IM,Section 2 - Phone,Section 2 - Mobile,Section 2 - Pager,Section 2 - Fax,Section 2 - Company,Section 2 - Title,Section 2 - Other,Section 2 - Address,Section 3 - Description,Section 3 - Email,Section 3 - IM,Section 3 - Phone,Section 3 - Mobile,Section 3 - Pager,Section 3 - Fax,Section 3 - Company,Section 3 - Title,Section 3 - Other,Section 3 - Address\r
+First Last,name@domain.com,"Categories: Others\r
+\r
+\r
+Categories: Others",Other,name2@domain.com,,,,,,,,,,Personal,name3@domain.com; name4@domain.com; name5@domain.com; name6@domain.com,,17471234567,5551234567,,,,,,\r
+First1 Last,,"Categories: Friends\r
+",Personal,,,,5557654321,,,,,,\r
diff --git a/tests/basic_data/grandcentral.csv b/tests/basic_data/grandcentral.csv
new file mode 100644 (file)
index 0000000..4808cf2
--- /dev/null
@@ -0,0 +1,3 @@
+Name,E-mail Address,Categories,Company,Job Title,Home Address,Home Phone,Mobile Phone,Business Phone,GrandCentral,Suffix,Title,Initials,Web Page,Notes\r
+First Last,,Family,,,1234567 Foo St Austn Tx 78727,5559983254,5554023626,5559988899,,,,,,\r
+First1 Last,,Others,,,,5556835460,,,,,,,,\r
diff --git a/tests/basic_data/settings.ini b/tests/basic_data/settings.ini
new file mode 100644 (file)
index 0000000..d9a6c81
--- /dev/null
@@ -0,0 +1,37 @@
+[1 - Contacts]
+
+[2 - Account Info]
+callback = 
+
+[1 - Recent Calls]
+
+[2 - Messages]
+
+[0 - Messages]
+
+[1 - Messages]
+
+[2 - Dialpad]
+
+[2 - Contacts]
+
+[0 - Recent Calls]
+
+[DialCentral]
+active = 0
+bin_blob_0 = 
+bin_blob_1 = 
+
+[1 - Account Info]
+callback = 
+
+[1 - Dialpad]
+
+[0 - Dialpad]
+
+[0 - Account Info]
+
+[0 - Contacts]
+
+[2 - Recent Calls]
+
diff --git a/tests/dummy_hildon/__init__.py b/tests/dummy_hildon/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/dummy_hildon/hildon.py b/tests/dummy_hildon/hildon.py
new file mode 100644 (file)
index 0000000..331e979
--- /dev/null
@@ -0,0 +1,35 @@
+import gobject
+import gtk
+
+class FileChooserDialog(gtk.FileChooserDialog):
+       """
+       @bug The buttons currently don't do anything
+       """
+
+       def __init__(self, *args, **kwds):
+               super(FileChooserDialog, self).__init__(*args, **kwds)
+               self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+               self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+
+class Program(object):
+
+       def add_window(self, window):
+               pass
+
+
+class Window(gtk.Window, object):
+
+       def __init__(self):
+               super(Window, self).__init__(gtk.WINDOW_TOPLEVEL)
+               self.set_default_size(700, 500)
+
+       def set_menu(self, menu):
+               self._hildonMenu = menu
+
+
+gobject.type_register(Window)
+
+
+def hildon_helper_set_thumb_scrollbar(widget, value):
+       pass
diff --git a/tests/gv_samples/__init__.py b/tests/gv_samples/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/gv_samples/generate_gv_samples.py b/tests/gv_samples/generate_gv_samples.py
new file mode 100755 (executable)
index 0000000..5f1b399
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import logging
+
+import sys
+sys.path.append("/usr/lib/dialcentral")
+sys.path.append("../../src")
+
+from backends import gv_backend
+
+
+def main():
+       username = sys.argv[1]
+       password = sys.argv[2]
+       gv_backend.grab_debug_info(username, password)
+
+
+if __name__ == "__main__":
+       logging.basicConfig(level=logging.DEBUG)
+       main()
diff --git a/tests/test_file_backend.py b/tests/test_file_backend.py
new file mode 100644 (file)
index 0000000..eea4856
--- /dev/null
@@ -0,0 +1,155 @@
+from __future__ import with_statement
+
+import os
+import warnings
+
+import test_utils
+
+import sys
+sys.path.append("../src")
+
+from backends import file_backend
+
+
+def test_factory():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data")
+               factory = file_backend.FilesystemAddressBookFactory(csvPath)
+               assert factory.factory_name() == "File"
+               abooks = list(factory.get_addressbooks())
+               abooks.sort()
+               assert len(abooks) == 4
+               abookNames = [abook[2] for abook in abooks]
+               assert abookNames == ["basic", "empty", "google", "grandcentral"], "%s" % abookNames
+
+               for abook_factory, abookId, abookName in abooks:
+                       abook = abook_factory.open_addressbook(abookId)
+                       assert isinstance(abook, file_backend.CsvAddressBook)
+       finally:
+               warnings.resetwarnings()
+
+
+def test_nonexistent_csv():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "nonexistent.csv")
+               abook = file_backend.CsvAddressBook(csvPath)
+
+               assert abook.factory_name() == "csv"
+
+               contacts = list(abook.get_contacts())
+               assert len(contacts) == 0
+       finally:
+               warnings.resetwarnings()
+
+
+def test_empty_csv():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "empty.csv")
+               abook = file_backend.CsvAddressBook(csvPath)
+
+               assert abook.factory_name() == "csv"
+
+               contacts = list(abook.get_contacts())
+               assert len(contacts) == 0
+       finally:
+               warnings.resetwarnings()
+
+
+def test_basic_csv():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "basic.csv")
+               abook = file_backend.CsvAddressBook(csvPath)
+
+               assert abook.factory_name() == "csv"
+
+               contacts = list(abook.get_contacts())
+               contacts.sort()
+               assert len(contacts) == 1
+
+               contactId, contactName = contacts[0]
+               assert contactName == "Last, First"
+               assert abook.contact_source_short_name(contactId) == "csv"
+
+               details = list(abook.get_contact_details(contactId))
+               assert len(details) == 1
+               details.sort()
+               assert details == [("phone", "555-123-4567")], "%s" % details
+       finally:
+               warnings.resetwarnings()
+
+
+def test_google_csv():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "google.csv")
+               abook = file_backend.CsvAddressBook(csvPath)
+
+               assert abook.factory_name() == "csv"
+
+               contacts = list(abook.get_contacts())
+               contacts.sort()
+               assert len(contacts) == 2
+
+               contactId, contactName = contacts[0]
+               assert contactName == "First Last"
+               assert abook.contact_source_short_name(contactId) == "csv"
+
+               details = list(abook.get_contact_details(contactId))
+               assert len(details) == 2
+               details.sort()
+               assert details == [
+                       ("Section 2 - Mobile", "5551234567"),
+                       ("Section 2 - Phone", "17471234567"),
+               ], "%s" % details
+
+               contactId, contactName = contacts[1]
+               assert contactName == "First1 Last"
+               assert abook.contact_source_short_name(contactId) == "csv"
+
+               details = list(abook.get_contact_details(contactId))
+               assert len(details) == 1
+               details.sort()
+               assert details == [("Section 1 - Mobile", "5557654321")], "%s" % details
+       finally:
+               warnings.resetwarnings()
+
+
+def test_grandcentral_csv():
+       warnings.simplefilter("always")
+       try:
+               csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "grandcentral.csv")
+               abook = file_backend.CsvAddressBook(csvPath)
+
+               assert abook.factory_name() == "csv"
+
+               contacts = list(abook.get_contacts())
+               contacts.sort()
+               assert len(contacts) == 2
+
+               contactId, contactName = contacts[0]
+               assert contactName == "First Last"
+               assert abook.contact_source_short_name(contactId) == "csv"
+
+               details = list(abook.get_contact_details(contactId))
+               assert len(details) == 3
+               details.sort()
+               assert details == [
+                       ("Business Phone", "5559988899"),
+                       ("Home Phone", "5559983254"),
+                       ("Mobile Phone", "5554023626"),
+               ], "%s" % details
+
+               contactId, contactName = contacts[1]
+               assert contactName == "First1 Last"
+               assert abook.contact_source_short_name(contactId) == "csv"
+
+               details = list(abook.get_contact_details(contactId))
+               assert len(details) == 1
+               details.sort()
+               assert details == [("Home Phone", "5556835460")], "%s" % details
+       finally:
+               warnings.resetwarnings()
diff --git a/tests/test_gv_backend.py b/tests/test_gv_backend.py
new file mode 100644 (file)
index 0000000..ad38fde
--- /dev/null
@@ -0,0 +1,54 @@
+from __future__ import with_statement
+
+import os
+import warnings
+import cookielib
+
+import test_utils
+
+import sys
+sys.path.append("../src")
+
+from backends import gv_backend
+
+
+def generate_mock(cookiesSucceed, username, password):
+
+       class MockModule(object):
+
+               class MozillaEmulator(object):
+
+                       def __init__(self, trycount = 1):
+                               self.cookies = cookielib.LWPCookieJar()
+                               self.trycount = trycount
+
+                       def download(self, url,
+                                       postdata = None, extraheaders = None, forbid_redirect = False,
+                                       trycount = None, only_head = False,
+                               ):
+                               return ""
+
+       return MockModule
+
+
+def test_not_logged_in():
+       correctUsername, correctPassword = "", ""
+       MockBrowserModule = generate_mock(False, correctUsername, correctPassword)
+       gv_backend.browser_emu, RealBrowser = MockBrowserModule, gv_backend.browser_emu
+       try:
+               backend = gv_backend.GVDialer()
+               assert not backend.is_authed()
+               assert not backend.login("bad_name", "bad_password")
+               backend.logout()
+               with test_utils.expected(RuntimeError):
+                       backend.dial("5551234567")
+               with test_utils.expected(RuntimeError):
+                       backend.send_sms("5551234567", "Hello World")
+               assert backend.get_account_number() == "", "%s" % backend.get_account_number()
+               assert backend.get_callback_number() == ""
+               with test_utils.expected(Exception):
+                       recent = list(backend.get_recent())
+               with test_utils.expected(Exception):
+                       messages = list(backend.get_messages())
+       finally:
+               gv_backend.browser_emu = RealBrowser
diff --git a/tests/test_startup.py b/tests/test_startup.py
new file mode 100644 (file)
index 0000000..5058fc0
--- /dev/null
@@ -0,0 +1,108 @@
+from __future__ import with_statement
+
+import os
+import time
+import warnings
+
+import test_utils
+
+import sys
+sys.path.append("../src")
+
+import dc_glade
+
+
+def startup(factory):
+       handle = factory()
+       with test_utils.expected(AssertionError("Attempting login before app is fully loaded")):
+               handle.refresh_session()
+
+       for i in xrange(10):
+               if handle._initDone:
+                       print "Completed init on iteration %d" % i
+                       break
+               time.sleep(1)
+       assert handle._initDone
+
+       with test_utils.expected(RuntimeError("Login Failed")):
+               handle.refresh_session()
+
+       handle._save_settings()
+
+       del handle
+
+
+def atest_startup_with_no_data_dir_with_dummy_hildon():
+       warnings.simplefilter("always")
+       hildonPath = os.path.join(os.path.dirname(__file__), "dummy_hildon")
+       sys.path.insert(0, hildonPath)
+       import hildon
+       dc_glade.hildon = hildon
+       try:
+               dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
+               dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+               try:
+                       startup(dc_glade.Dialcentral)
+               finally:
+                       try:
+                               os.remove(dc_glade.Dialcentral._user_settings)
+                       except:
+                               pass
+                       try:
+                               os.removedirs(dc_glade.Dialcentral._data_path)
+                       except:
+                               pass
+       finally:
+               dc_glade.hildon = None
+               sys.path.remove(hildonPath)
+               warnings.resetwarnings()
+
+
+def atest_startup_with_no_data_dir():
+       warnings.simplefilter("always")
+       dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
+       dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+       try:
+               startup(dc_glade.Dialcentral)
+       finally:
+               try:
+                       os.remove(dc_glade.Dialcentral._user_settings)
+               except:
+                       pass
+               try:
+                       os.removedirs(dc_glade.Dialcentral._data_path)
+               except:
+                       pass
+               warnings.resetwarnings()
+
+
+def atest_startup_with_empty_data_dir():
+       warnings.simplefilter("always")
+       dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "empty_data")
+       dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+       try:
+               startup(dc_glade.Dialcentral)
+       finally:
+               try:
+                       os.remove(dc_glade.Dialcentral._user_settings)
+               except:
+                       pass
+               try:
+                       os.removedirs(dc_glade.Dialcentral._data_path)
+               except:
+                       pass
+               warnings.resetwarnings()
+
+
+def atest_startup_with_basic_data_dir():
+       warnings.simplefilter("always")
+       try:
+               dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
+               dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+
+               startup(dc_glade.Dialcentral)
+       finally:
+               warnings.resetwarnings()
diff --git a/www/dialcentral.deb b/www/dialcentral.deb
new file mode 100644 (file)
index 0000000..c37e2cd
Binary files /dev/null and b/www/dialcentral.deb differ
index a2b137b..af76fb4 100644 (file)
@@ -1,24 +1,25 @@
 <html>
        <head>
-               <title></title>
+               <title>DialCentral - An Interface for GoogleVoice</title>
        </head>
        <body>
                <h1>
+                       DialCentral
                </h1>
-               <h2></h2>
+               <h2>An Interface for GoogleVoice</h2>
                <h3><a href="index.html">[About]</a> <a href="screenshots.html">[Screenshots]</a> <a href="download.html">[Download]</a>
                <h3>Download</h3>
 
                <h4>Packages</h4>
-               <p>Maemo 5 and Later: Go to the application installer, enable Extras, and download</p>
+               <p>Maemo 5 and Later: Go to the application installer, enable Extras, and download Dialcentral (Note: technically its still in extras-testing because people haven't been reviewing it)</p>
 
-               <p>Maemo 4.1 and Earlier: Add the <a href="http://wiki.maemo.org/Extras">Extras Repository</a> and check the App Manager</p>
+               <p>Maemo 4.1 and Earlier: Add the <a href="http://wiki.maemo.org/Extras">Extras Repository</a> and check the App Manager for DialCentral</p>
 
-               <p>Linux: <a href="">.deb files</a></p>
+               <p>Linux: <a href="dialcentral.deb">.deb files</a></p>
 
                <h3>Development</h3>
                <h4>Source</h4>
-               <p>For the most up to date version check out <a href="">git</a>.
+               <p>For the most up to date version check out <a href="https://garage.maemo.org/scm/?group_id=657">git</a>.
                </p>
                <p>Requires</p>
                <ul>
 
                <h4>Bugs</h4>
 
-               <p>Discuss your issue on <a href="">Maemo.Org Talk</a></p>
+               <p>Discuss your issue on <a href="http://talk.maemo.org/showthread.php?p=293533">Maemo.Org Talk</a></p>
 
-               <p>File a <a href="">bug report</a></p>
-               <p>View  <a href="">existing bug reports</a></p>
+               <p>Check out a list of helpful <a href="http://talk.maemo.org/showpost.php?p=293533&postcount=1">troubleshooting tips</a></p>
+
+               <p>File a <a href="https://bugs.maemo.org/enter_bug.cgi?product=Dialcentral">bug report</a> against Extras-&gt;Dialcentral</p>
+               <p>View  <a href="https://bugs.maemo.org/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&product=Dialcentral&content=">existing bug reports</a></p>
        </body>
 </html>
diff --git a/www/images/Dialcentral - Accounts - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Accounts - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..5e606c5
Binary files /dev/null and b/www/images/Dialcentral - Accounts - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Accounts Callback - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Accounts Callback - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..472ce8b
Binary files /dev/null and b/www/images/Dialcentral - Accounts Callback - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Contacts - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Contacts - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..597f03a
Binary files /dev/null and b/www/images/Dialcentral - Contacts - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Contacts Phone Select - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Contacts Phone Select - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..23cb32d
Binary files /dev/null and b/www/images/Dialcentral - Contacts Phone Select - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Contacts Response - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Contacts Response - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..8f0f3af
Binary files /dev/null and b/www/images/Dialcentral - Contacts Response - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..cf5876f
Binary files /dev/null and b/www/images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Messages - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Messages - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..8bf1d59
Binary files /dev/null and b/www/images/Dialcentral - Messages - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Messages Response Down - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Messages Response Down - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..5204b2a
Binary files /dev/null and b/www/images/Dialcentral - Messages Response Down - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Messages Response Start - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Messages Response Start - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..6494993
Binary files /dev/null and b/www/images/Dialcentral - Messages Response Start - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Messages Response Up - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Messages Response Up - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..ccd3ffe
Binary files /dev/null and b/www/images/Dialcentral - Messages Response Up - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Recent - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Recent - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..b355983
Binary files /dev/null and b/www/images/Dialcentral - Recent - 1.0.7-12 Fremantle.png differ
diff --git a/www/images/Dialcentral - Recent Response - 1.0.7-12 Fremantle.png b/www/images/Dialcentral - Recent Response - 1.0.7-12 Fremantle.png
new file mode 100644 (file)
index 0000000..f36c470
Binary files /dev/null and b/www/images/Dialcentral - Recent Response - 1.0.7-12 Fremantle.png differ
index b794594..e104e24 100644 (file)
@@ -1,30 +1,53 @@
 <html>
        <head>
-               <title></title>
+               <title>DialCentral - An Interface for GoogleVoice</title>
        </head>
        <body>
                <h1>
+                       DialCentral
                </h1>
-               <h2></h2>
+               <h2>An Interface for GoogleVoice</h2>
 
                <h3><a href="">[About]</a> <a href="screenshots.html">[Screenshots]</a> <a href="download.html">[Download]</a>
 
                <h3>About</h3>
                <p>
+               DialCentral (formerly called GC Dialer) is meant as an interface to Google's GoogleVoice service that integrates with your Maemo device or Linux computer.
                </p>
 
 
-               <p>This has been tested on Maemo 5, Maemo 4.1, and Ubuntu 9.04.  Go check out some <a href="">reviews</a>  or join the <a href="">conversation</a></p>
+               <p>DialCentral has been tested on Maemo 5, Maemo 4.1, Ubuntu 9.04, and Mer 0.16-testing5.  Go check out some <a href="http://maemo.org/downloads/product/OS2008/dialcentral/">reviews</a> (just don't use that old download link) or join the <a href="http://talk.maemo.org/showthread.php?p=293533">conversation</a></p>
 
-               <p>This is Free Software and available under the <a href="http://www.gnu.org/licenses/lgpl-2.1.html">LGPLv2.1</a>.
+               <p>DialCentral is Free Software and available under the <a href="http://www.gnu.org/licenses/lgpl-2.1.html">LGPLv2.1</a>.
 
                <h4>Features</h4>
 
-               <p>(See <a href="">Maemo.Org Talk</a>)</p>
+               <p>DialCentral v1.0.8-5 (See <a href="http://talk.maemo.org/showthread.php?p=293533">Maemo.Org Talk</a>)</p>
 
                <ul>
-                       <li></li>
+                       <li>Dialpad interface to click-to-call</li>
+                       <li>Ability to send SMS messages through GoogleVoice</li>
+                       <li>Recent calls list for easily calling people back</li>
+                       <li>History of voicemail transcripts and SMS conversations</li>
+                       <li>Contacts list, pulling from GoogleVoice and CSV Files (like GrandCentral and GoogleContact exports)</li>
+                       <li>Recent Call history, voicemail, and SMS notification (Maemo 4.1 only)</li>
+                       <li>Shortcuts:
+                       <ul>
+                               <li>Hold down any tab to force it to refresh</li>
+                               <li>Dialpad: hold down the back button to change it to clear</li>
+                               <li>Ctrl+c from SMS Dialog to copy message history</li>
+                               <li>Ctrl+v on dialpad to paste a number</li>
+                               <li>Ctrl+l to copy the debug log</li>
+                               <li>Ctrl+enter to toggle fullscreen</li>
+                               </ul>
+                       </li>
                </ul>
 
+               <h4>Sample Screenshot:</h4>
+               <div>
+                       <p>Dialcentral 1.0.7 on Startup (Maemo): </p>
+                       <p><img src="./images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Dialpad on Maemo 5"/></p>
+               </div>
+
        </body>
 </html>
index a7bdf98..2b8fe09 100644 (file)
@@ -1,14 +1,65 @@
 <html>
        <head>
-               <title></title>
+               <title>DialCentral - An Interface for GoogleVoice</title>
        </head>
        <body>
                <h1>
+                       DialCentral
                </h1>
-               <h2></h2>
+               <h2>An Interface for GoogleVoice</h2>
                <h3><a href="index.html">[About]</a> <a href="screenshots.html">[Screenshots]</a> <a href="download.html">[Download]</a>
 
                <h3>Screen shots</h3>
 
+               <div>
+                       <p>Dialcentral 1.0.7 on Startup (Maemo): </p>
+                       <p><img src="./images/Dialcentral - Dialpad - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Dialpad on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's list of recent call activity (Maemo): </p>
+                       <p><img src="./images/Dialcentral - Recent - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's List of Recent Call Activity on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's responding to recent call activity (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Recent Response - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Responding to a piece of Recent Activity on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's list of recent messages (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Messages - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's List of Recent Messages on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's responding to a recent message (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Messages Response Start - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Responding to a recent message on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's responding to a recent message and scrolling down for some status or changing the number we are responding to (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Messages Response Down - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Responding to a recent message on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's responding to a recent message and scrolling up to see more history (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Messages Response Up - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Responding to a recent message on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's list of contacts (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Contacts - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's List of Contacts on Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's choice for which number for a contact(Maemo):</p>
+                       <p><img src="./images/Dialcentral - Contacts Phone Select - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Choosing which number to use for a contact Maemo 5"/></p>
+               </div>
+
+               <div>
+                       <p>Dialcentral 1.0.7's calling a contact (Maemo):</p>
+                       <p><img src="./images/Dialcentral - Contacts Response - 1.0.7-12 Fremantle.png" alt="Screenshot of DialCentral v1.0.7's Calling a contact Maemo 5"/></p>
+               </div>
+
        </body>
 </html>