PROJECT_NAME=gc_dialer
-SOURCE_PATH=gc_dialer
+SOURCE_PATH=src
SOURCE=$(SOURCE_PATH)/gc_dialer.py $(SOURCE_PATH)/gcbackend.py $(SOURCE_PATH)/browser_emu.py
OBJ=$(SOURCE:.py=.pyc)
LINT_STATS_PATH=~/.pylint.d
#Construct the program by cat-ing all the python files together
echo "#!/usr/bin/python2.5" > $(BUILD_BIN)
#echo "from __future__ import with_statement" >> $(PACKAGE_PATH)/usr/local/bin/gc_dialer.py
- cat gc_dialer/gc_dialer.py gc_dialer/gcbackend.py gc_dialer/browser_emu.py | grep -e '^import ' | sort -u >> $(BUILD_BIN)
- cat gc_dialer/browser_emu.py gc_dialer/gcbackend.py gc_dialer/gc_dialer.py | grep -v 'browser_emu' | grep -v 'gcbackend' | grep -v "#!" >> $(BUILD_BIN)
+ cat $(SOURCE_PATH)/gc_dialer.py $(SOURCE_PATH)/gcbackend.py $(SOURCE_PATH)/browser_emu.py | grep -e '^import ' | sort -u >> $(BUILD_BIN)
+ cat $(SOURCE_PATH)/browser_emu.py $(SOURCE_PATH)/gcbackend.py $(SOURCE_PATH)/gc_dialer.py | grep -v 'browser_emu' | grep -v 'gcbackend' | grep -v "#!" >> $(BUILD_BIN)
chmod 755 $(BUILD_BIN)
$(TAG_FILE): $(SOURCE)
+++ /dev/null
-"""
-@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
- - caching
- - configurable user agent string
- - GET and POST
- - multipart POST (send files)
- - receive content into file
- - progress indicator
-
-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:
-
- - For testing, use a MozillaCacher instance - this will cache all pages and make testing quicker
- - 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
-
-TODO:
-
-- should have a method to save/load cookies
-"""
-
-import os
-import urllib
-import urllib2
-import cookielib
-import warnings
-
-
-class MozillaEmulator(object):
-
- def __init__(self, cacher=None, trycount=0):
- """Create a new MozillaEmulator object.
-
- @param cacher: A dictionary like object, that can cache search results on a storage device.
- You can use a simple dictionary here, but it is not recommended.
- You can also put None here to disable caching completely.
- @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."""
- if cacher is None:
- cacher = {}
- self.cacher = cacher
- self.cookies = cookielib.LWPCookieJar()
- self.debug = False
- self.trycount = trycount
-
- def build_opener(self, url, postdata=None, extraheaders=None, forbid_redirect=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 forbid_redirect:
- redirector = HTTPNoRedirector()
- else:
- redirector = urllib2.HTTPRedirectHandler()
-
- 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; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4')]
- if not postdata is None:
- req.add_data(postdata)
- return (req, u)
-
- def download(self, url, postdata=None, extraheaders=None, forbid_redirect=False,
- trycount=None, fd=None, onprogress=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 forbid_redirect: 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 fd: You can pass a file descriptor here. In this case,
- the data will be written into the file. Please note that
- when you save the raw data into a file then it won't be cached.
- @param onprogress: A function that has two parameters:
- the size of the resource and the downloaded size. This will be
- called for each 1KB chunk. (If the HTTP header does not contain
- the content-length field, then the size parameter will be zero!)
- @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, unless fd was specified. When fd
- was given, the return value is undefined.
- """
- warnings.warn("Performing download of %s" % url, UserWarning, 2)
-
- 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, forbid_redirect)
- openerdirector = u.open(req)
- if self.debug:
- print req.get_method(), url
- print openerdirector.code, openerdirector.msg
- print openerdirector.headers
- self.cookies.extract_cookies(openerdirector, req)
- if only_head:
- return openerdirector
- return openerdirector.read()
- except urllib2.URLError:
- cnt += 1
- if (trycount > -1) and (trycount < cnt):
- raise
- # Retry :-)
- if self.debug:
- print "MozillaEmulator: urllib2.URLError, retryting ", cnt
-
-
-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
- raise e
+++ /dev/null
-[Desktop Entry]
-Encoding=UTF-8
-Version=1.0
-Type=Application
-Name=Grandcentral Dialer
-Exec=/usr/local/bin/gc_dialer.py
-Icon=gc_dialer
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Thu Jul 17 19:50:07 2008 -->
-<glade-interface>
- <widget class="GtkWindow" id="Dialpad">
- <property name="width_request">400</property>
- <property name="height_request">350</property>
- <property name="title" translatable="yes">Dialer</property>
- <child>
- <widget class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <child>
- <widget class="GtkMenuBar" id="menubar1">
- <property name="visible">True</property>
- <child>
- <widget class="GtkMenuItem" id="file_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_File</property>
- <property name="use_underline">True</property>
- <child>
- <widget class="GtkMenu" id="menu1">
- <property name="visible">True</property>
- <child>
- <widget class="GtkImageMenuItem" id="login_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_New Login</property>
- <property name="use_underline">True</property>
- <signal name="activate" handler="on_clearcookies_clicked"/>
- <child internal-child="image">
- <widget class="GtkImage" id="menu-item-image11">
- <property name="stock">gtk-new</property>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
- <property name="visible">True</property>
- </widget>
- </child>
- <child>
- <widget class="GtkImageMenuItem" id="quit_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">gtk-quit</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- <signal name="activate" handler="on_dialpad_quit"/>
- </widget>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GtkMenuItem" id="edit_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_Edit</property>
- <property name="use_underline">True</property>
- <child>
- <widget class="GtkMenu" id="menu2">
- <property name="visible">True</property>
- <child>
- <widget class="GtkImageMenuItem" id="paste_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">gtk-paste</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- <signal name="activate" handler="on_paste"/>
- </widget>
- </child>
- <child>
- <widget class="GtkImageMenuItem" id="delete_menu_item">
- <property name="visible">True</property>
- <property name="label" translatable="yes">gtk-delete</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- <signal name="activate" handler="on_clear_number"/>
- </widget>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkNotebook" id="notebook">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="tab_pos">GTK_POS_BOTTOM</property>
- <property name="show_border">False</property>
- <property name="homogeneous">True</property>
- <signal name="switch_page" handler="on_notebook_switch_page"/>
- <child>
- <widget class="GtkVBox" id="vbox2">
- <property name="visible">True</property>
- <child>
- <widget class="GtkLabel" id="numberdisplay">
- <property name="height_request">50</property>
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="35000" weight="bold">(518) 555-1212</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_CENTER</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="1" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label12">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="33000" weight="bold">1</span>
-<span size="9000"> </span></property>
- <property name="use_markup">True</property>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GtkButton" id="digit2">
- <property name="visible">True</property>
- <property name="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="2" modifiers="" signal="clicked"/>
- <accelerator key="a" modifiers="" signal="clicked"/>
- <accelerator key="b" modifiers="" signal="clicked"/>
- <accelerator key="c" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label10">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">2</span>
-<span size="12000">ABC</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="3" modifiers="" signal="clicked"/>
- <accelerator key="d" modifiers="" signal="clicked"/>
- <accelerator key="e" modifiers="" signal="clicked"/>
- <accelerator key="f" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label11">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold" stretch="ultraexpanded">3</span>
-<span size="12000">DEF</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="4" modifiers="" signal="clicked"/>
- <accelerator key="g" modifiers="" signal="clicked"/>
- <accelerator key="h" modifiers="" signal="clicked"/>
- <accelerator key="i" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label13">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">4</span>
-<span size="12000">GHI</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="5" modifiers="" signal="clicked"/>
- <accelerator key="j" modifiers="" signal="clicked"/>
- <accelerator key="k" modifiers="" signal="clicked"/>
- <accelerator key="l" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label14">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">5</span>
-<span size="12000">JKL</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="6" modifiers="" signal="clicked"/>
- <accelerator key="m" modifiers="" signal="clicked"/>
- <accelerator key="n" modifiers="" signal="clicked"/>
- <accelerator key="o" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label15">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">6</span>
-<span size="12000">MNO</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="7" modifiers="" signal="clicked"/>
- <accelerator key="p" modifiers="" signal="clicked"/>
- <accelerator key="q" modifiers="" signal="clicked"/>
- <accelerator key="r" modifiers="" signal="clicked"/>
- <accelerator key="s" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label16">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">7</span>
-<span size="12000">PQRS</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="8" modifiers="" signal="clicked"/>
- <accelerator key="t" modifiers="" signal="clicked"/>
- <accelerator key="u" modifiers="" signal="clicked"/>
- <accelerator key="v" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label17">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">8</span>
-<span size="12000">TUV</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="9" modifiers="" signal="clicked"/>
- <accelerator key="w" modifiers="" signal="clicked"/>
- <accelerator key="x" modifiers="" signal="clicked"/>
- <accelerator key="y" modifiers="" signal="clicked"/>
- <accelerator key="z" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label18">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="30000" weight="bold">9</span>
-<span size="12000">WXYZ</span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="back">
- <property name="visible">True</property>
- <property name="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_back_clicked"/>
- <accelerator key="BackSpace" modifiers="" 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-no</property>
- </widget>
- </child>
- <child>
- <widget class="GtkLabel" id="label9">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="xpad">5</property>
- <property name="label" translatable="yes"><span size="17000" weight="Bold">Back</span></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>
- <child>
- <widget class="GtkButton" id="digit0">
- <property name="visible">True</property>
- <property name="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_digit_clicked"/>
- <accelerator key="0" modifiers="" signal="clicked"/>
- <child>
- <widget class="GtkLabel" id="label19">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="33000" weight="bold">0</span>
-<span size="9000"></span></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_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="dial">
- <property name="visible">True</property>
- <property name="has_default">True</property>
- <property name="focus_on_click">False</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_dial_clicked"/>
- <accelerator key="Return" modifiers="" 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>
- </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"><span size="17000" weight="bold">Dial</span></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>
- </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="type">tab</property>
- <property name="tab_expand">True</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkScrolledWindow" id="scrolledwindow2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_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="enable_search">False</property>
- <property name="fixed_height_mode">True</property>
- <property name="enable_grid_lines">GTK_TREE_VIEW_GRID_LINES_HORIZONTAL</property>
- <property name="enable_tree_lines">True</property>
- <signal name="row_activated" handler="on_contactsview_row_activated"/>
- </widget>
- </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="contacts">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Contacts</property>
- </widget>
- <packing>
- <property name="type">tab</property>
- <property name="position">1</property>
- <property name="tab_expand">True</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
- <child>
- <widget class="GtkTreeView" id="recentview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="headers_visible">False</property>
- <property name="enable_search">False</property>
- <property name="fixed_height_mode">True</property>
- <property name="enable_grid_lines">GTK_TREE_VIEW_GRID_LINES_HORIZONTAL</property>
- <property name="enable_tree_lines">True</property>
- <signal name="row_activated" handler="on_recentview_row_activated"/>
- </widget>
- </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="recent">
- <property name="height_request">30</property>
- <property name="visible">True</property>
- <property name="label" translatable="yes">Recent</property>
- </widget>
- <packing>
- <property name="type">tab</property>
- <property name="position">1</property>
- <property name="tab_expand">True</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkTable" id="accountview">
- <property name="visible">True</property>
- <property name="border_width">11</property>
- <property name="n_rows">3</property>
- <property name="n_columns">2</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <widget class="GtkComboBoxEntry" id="callbackcombo">
- <property name="visible">True</property>
- <child internal-child="entry">
- <widget class="GtkEntry" id="comboboxentry-entry2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <signal name="changed" handler="on_callbackentry_changed"/>
- </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>
- <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">1</property>
- <property name="xpad">5</property>
- <property name="label" translatable="yes">Callback Number:</property>
- </widget>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="clearcookies">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">Clear Account Information
-must reauthenticate</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_clearcookies_clicked"/>
- </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>
- <widget class="GtkLabel" id="gcnumberlabel">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="15000" weight="bold">(518) 555-1212</span></property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="xpad">5</property>
- <property name="label" translatable="yes">GrandCentral
-Number:</property>
- <property name="justify">GTK_JUSTIFY_RIGHT</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="position">2</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="type">tab</property>
- <property name="position">2</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkVBox" id="vbox3">
- <property name="visible">True</property>
- <child>
- <widget class="GtkLabel" id="about_title">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><span size="20000" weight="bold">GrandCentral Dialer</span>
-Copyright 2008</property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_CENTER</property>
- </widget>
- </child>
- <child>
- <widget class="GtkLabel" id="about_description">
- <property name="visible">True</property>
- <property name="label" translatable="yes">GUI front-end to initiate outbound call from Grandcentral.com, typically with Grancentral configured to connect the outbound call to a VOIP number accessible via Gizmo on the Internet Tablet.</property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="about_authors">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Authors: Mark Bergman <bergman@merctech.com>, Eric Warnke <ericew@gmail.com></property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="position">3</property>
- <property name="tab_expand">True</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="about">
- <property name="height_request">30</property>
- <property name="visible">True</property>
- <property name="label" translatable="yes">About</property>
- </widget>
- <packing>
- <property name="type">tab</property>
- <property name="position">3</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- <widget class="GtkDialog" id="login_dialog">
- <property name="border_width">5</property>
- <property name="title" translatable="yes">Grandcentral Login</property>
- <property name="resizable">False</property>
- <property name="modal">True</property>
- <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">GDK_WINDOW_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">Dialpad</property>
- <property name="has_separator">False</property>
- <child internal-child="vbox">
- <widget class="GtkVBox" id="dialog-vbox1">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <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="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>
- <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="GtkLabel" id="label6">
- <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="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Username</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <widget class="GtkHButtonBox" id="dialog-action_area1">
- <property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
- <child>
- <widget class="GtkButton" id="loginbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">Login</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_loginbutton_clicked"/>
- </widget>
- </child>
- <child>
- <widget class="GtkButton" id="closebutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">Close</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_loginclose_clicked"/>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">GTK_PACK_END</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- <widget class="GtkDialog" id="phonetype_dialog">
- <property name="border_width">5</property>
- <property name="title" translatable="yes">Select Phone Type</property>
- <property name="resizable">False</property>
- <property name="modal">True</property>
- <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">GDK_WINDOW_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">Dialpad</property>
- <property name="has_separator">False</property>
- <child internal-child="vbox">
- <widget class="GtkVBox" id="dialog-vbox3">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <widget class="GtkTreeView" id="phonetypes">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="headers_clickable">True</property>
- <signal name="row_activated" handler="on_phonetype_select"/>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <widget class="GtkHButtonBox" id="dialog-action_area3">
- <property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
- <child>
- <widget class="GtkButton" id="select_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Select</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_phonetype_select"/>
- </widget>
- </child>
- <child>
- <widget class="GtkButton" id="cancel_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">Cancel</property>
- <property name="response_id">0</property>
- <signal name="clicked" handler="on_phonetype_cancel"/>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">GTK_PACK_END</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
-</glade-interface>
+++ /dev/null
-#!/usr/bin/python2.5
-
-
-"""
-Grandcentral Dialer
-Python front-end to a wget script to use grandcentral.com to place outbound VOIP calls.
-(C) 2008 Mark Bergman
-bergman@merctech.com
-"""
-
-
-import sys
-import gc
-import os
-import threading
-import time
-import re
-import warnings
-
-import gobject
-import gtk
-import gtk.glade
-
-try:
- import hildon
-except ImportError:
- hildon = None
-
-try:
- import osso
- try:
- import abook
- import evolution.ebook as evobook
- except ImportError:
- abook = None
- evobook = None
-except ImportError:
- osso = None
-
-try:
- import conic
-except ImportError:
- conic = None
-
-try:
- import doctest
- import optparse
-except ImportError:
- doctest = None
- optparse = None
-
-from gcbackend import GCDialer
-
-import socket
-
-
-socket.setdefaulttimeout(5)
-
-
-def make_ugly(prettynumber):
- """
- function to take a phone number and strip out all non-numeric
- characters
-
- >>> make_ugly("+012-(345)-678-90")
- '01234567890'
- """
- uglynumber = re.sub('\D', '', prettynumber)
- return uglynumber
-
-
-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")
- '(234)-567-8901'
- >>> make_pretty("12345678901")
- '1 (234)-567-8901'
- >>> make_pretty("01234567890")
- '+012-(345)-678-90'
- """
- if phonenumber is None:
- return ""
-
- if len(phonenumber) < 3:
- return phonenumber
-
- if phonenumber[0] == "0":
- prettynumber = ""
- prettynumber += "+%s" % phonenumber[0:3]
- if 3 < len(phonenumber):
- prettynumber += "-(%s)" % phonenumber[3:6]
- if 6 < len(phonenumber):
- prettynumber += "-%s" % phonenumber[6:9]
- if 9 < len(phonenumber):
- prettynumber += "-%s" % phonenumber[9:]
- return prettynumber
- elif len(phonenumber) <= 7:
- prettynumber = "%s-%s" % (phonenumber[0:3], phonenumber[3:])
- elif len(phonenumber) > 8 and phonenumber[0] == "1":
- prettynumber = "1 (%s)-%s-%s" % (phonenumber[1:4], phonenumber[4:7], phonenumber[7:])
- elif len(phonenumber) > 7:
- prettynumber = "(%s)-%s-%s" % (phonenumber[0:3], phonenumber[3:6], phonenumber[6:])
- return prettynumber
-
-
-class PhoneTypeSelector(object):
-
- def __init__(self, widgetTree, gcBackend):
- self._gcBackend = gcBackend
- self._widgetTree = widgetTree
- self._dialog = self._widgetTree.get_widget("phonetype_dialog")
-
- self._selectButton = self._widgetTree.get_widget("select_button")
- self._selectButton.connect("clicked", self._on_phonetype_select)
-
- self._cancelButton = self._widgetTree.get_widget("cancel_button")
- self._cancelButton.connect("clicked", self._on_phonetype_cancel)
-
- self._typemodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
- self._typeviewselection = None
-
- typeview = self._widgetTree.get_widget("phonetypes")
- typeview.connect("row-activated", self._on_phonetype_select)
- typeview.set_model(self._typemodel)
- textrenderer = gtk.CellRendererText()
-
- # Add the column to the treeview
- column = gtk.TreeViewColumn("Phone Numbers", textrenderer, text=1)
- column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
-
- typeview.append_column(column)
-
- self._typeviewselection = typeview.get_selection()
- self._typeviewselection.set_mode(gtk.SELECTION_SINGLE)
-
- def run(self, contactDetails):
- self._typemodel.clear()
-
- for phoneType, phoneNumber in contactDetails:
- self._typemodel.append((phoneNumber, "%s - %s" % (make_pretty(phoneNumber), phoneType)))
-
- userResponse = self._dialog.run()
-
- if userResponse == gtk.RESPONSE_OK:
- model, itr = self._typeviewselection.get_selected()
- if itr:
- phoneNumber = self._typemodel.get_value(itr, 0)
- else:
- phoneNumber = ""
-
- self._typeviewselection.unselect_all()
- self._dialog.hide()
- return phoneNumber
-
- def _on_phonetype_select(self, *args):
- self._dialog.response(gtk.RESPONSE_OK)
-
- def _on_phonetype_cancel(self, *args):
- self._dialog.response(gtk.RESPONSE_CANCEL)
-
-
-class Dialpad(object):
-
- __app_name__ = "gc_dialer"
- __version__ = "0.7.0"
- __app_magic__ = 0xdeadbeef
-
- _glade_files = [
- './gc_dialer.glade',
- '../lib/gc_dialer.glade',
- '/usr/local/lib/gc_dialer.glade',
- ]
-
- def __init__(self):
- self._phonenumber = ""
- self._prettynumber = ""
- self._areacode = "518"
-
- self._clipboard = gtk.clipboard_get()
-
- self._deviceIsOnline = True
- self._callbackNeedsSetup = True
-
- self._recenttime = 0.0
- self._recentmodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
- self._recentviewselection = None
-
- self._contactstime = 0.0
- self._contactsmodel = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
- self._contactsviewselection = None
-
- for path in Dialpad._glade_files:
- if os.path.isfile(path):
- self._widgetTree = gtk.glade.XML(path)
- break
- else:
- self.display_error_message("Cannot find gc_dialer.glade")
- gtk.main_quit()
- return
-
- aboutHeader = self._widgetTree.get_widget("about_title")
- aboutHeader.set_label("%s\nVersion %s" % (aboutHeader.get_label(), Dialpad.__version__))
-
- #Get the buffer associated with the number display
- self._numberdisplay = self._widgetTree.get_widget("numberdisplay")
- self.set_number("")
- self._notebook = self._widgetTree.get_widget("notebook")
-
- self._window = self._widgetTree.get_widget("Dialpad")
-
- global hildon
- self._app = None
- self._isFullScreen = False
- if hildon is not None and isinstance(self._window, gtk.Window):
- warnings.warn("Hildon installed but glade file not updated to work with hildon", UserWarning, 2)
- hildon = None
- elif hildon is not None:
- self._app = hildon.Program()
- self._window.set_title("Keypad")
- self._app.add_window(self._window)
- self._widgetTree.get_widget("callbackcombo").get_child().set_property('hildon-input-mode', (1 << 4))
- self._widgetTree.get_widget("usernameentry").set_property('hildon-input-mode', 7)
- self._widgetTree.get_widget("passwordentry").set_property('hildon-input-mode', 7|(1 << 29))
-
- gtkMenu = self._widgetTree.get_widget("menubar1")
- menu = gtk.Menu()
- for child in gtkMenu.get_children():
- child.reparent(menu)
- self._window.set_menu(menu)
- gtkMenu.destroy()
-
- self._window.connect("key-press-event", self._on_key_press)
- self._window.connect("window-state-event", self._on_window_state_change)
- else:
- warnings.warn("No Hildon", UserWarning, 2)
-
- self._osso = None
- self._ebook = None
- if osso is not None:
- self._osso = osso.Context(Dialpad.__app_name__, Dialpad.__version__, False)
- device = osso.DeviceState(self._osso)
- device.set_device_state_callback(self._on_device_state_change, 0)
- if abook is not None and evobook is not None:
- abook.init_with_name(Dialpad.__app_name__, self._osso)
- self._ebook = evobook.open_addressbook("default")
- else:
- warnings.warn("No abook and No evolution address book support", UserWarning, 2)
- else:
- warnings.warn("No OSSO", UserWarning, 2)
-
- self._connection = None
- if conic is not None:
- self._connection = conic.Connection()
- self._connection.connect("connection-event", self._on_connection_change, Dialpad.__app_magic__)
- self._connection.request_connection(conic.CONNECT_FLAG_NONE)
- else:
- warnings.warn("No Internet Connectivity API ", UserWarning, 2)
-
- callbackMapping = {
- # Process signals from buttons
- "on_loginbutton_clicked": self._on_loginbutton_clicked,
- "on_loginclose_clicked": self._on_loginclose_clicked,
-
- "on_dialpad_quit": (lambda data: gtk.main_quit()),
- "on_paste": self._on_paste,
- "on_clear_number": self._on_clear_number,
-
- "on_clearcookies_clicked": self._on_clearcookies_clicked,
- "on_notebook_switch_page": self._on_notebook_switch_page,
- "on_recentview_row_activated": self._on_recentview_row_activated,
- "on_contactsview_row_activated" : self._on_contactsview_row_activated,
-
- "on_digit_clicked": self._on_digit_clicked,
- "on_back_clicked": self._on_backspace,
- "on_dial_clicked": self._on_dial_clicked,
- }
- self._widgetTree.signal_autoconnect(callbackMapping)
- self._widgetTree.get_widget("callbackcombo").get_child().connect("changed", self._on_callbackentry_changed)
-
- if self._window:
- self._window.connect("destroy", gtk.main_quit)
- self._window.show_all()
-
- self._gcBackend = GCDialer()
-
- self._phoneTypeSelector = PhoneTypeSelector(self._widgetTree, self._gcBackend)
-
- self.attempt_login(2)
- gobject.idle_add(self._init_grandcentral)
- gobject.idle_add(self._init_recent_view)
- gobject.idle_add(self._init_contacts_view)
-
- def _init_grandcentral(self):
- """ Deferred initalization of the grandcentral info """
-
- if self._gcBackend.is_authed():
- if self._gcBackend.get_callback_number() is None:
- self._gcBackend.set_sane_callback()
- self.set_account_number()
-
- return False
-
- def _init_recent_view(self):
- """ Deferred initalization of the recent view treeview """
-
- recentview = self._widgetTree.get_widget("recentview")
- recentview.set_model(self._recentmodel)
- textrenderer = gtk.CellRendererText()
-
- # Add the column to the treeview
- column = gtk.TreeViewColumn("Calls", textrenderer, text=1)
- column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
-
- recentview.append_column(column)
-
- self._recentviewselection = recentview.get_selection()
- self._recentviewselection.set_mode(gtk.SELECTION_SINGLE)
-
- return False
-
- def _init_contacts_view(self):
- """ deferred initalization of the contacts view treeview """
-
- contactsview = self._widgetTree.get_widget("contactsview")
- contactsview.set_model(self._contactsmodel)
-
- # Add the column to the treeview
- column = gtk.TreeViewColumn("Contact")
-
- iconrenderer = gtk.CellRendererPixbuf()
- column.pack_start(iconrenderer, expand=False)
- column.add_attribute(iconrenderer, 'pixbuf', 0)
-
- textrenderer = gtk.CellRendererText()
- column.pack_start(textrenderer, expand=True)
- column.add_attribute(textrenderer, 'text', 1)
-
- textrenderer = gtk.CellRendererText()
- column.pack_start(textrenderer, expand=True)
- column.add_attribute(textrenderer, 'text', 4)
-
- column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
- column.set_sort_column_id(1)
- column.set_visible(True)
- contactsview.append_column(column)
-
- #textrenderer = gtk.CellRendererText()
- #column = gtk.TreeViewColumn("Location", textrenderer, text=2)
- #column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
- #column.set_sort_column_id(2)
- #column.set_visible(True)
- #contactsview.append_column(column)
-
- #textrenderer = gtk.CellRendererText()
- #column = gtk.TreeViewColumn("Phone", textrenderer, text=3)
- #column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
- #column.set_sort_column_id(3)
- #column.set_visible(True)
- #contactsview.append_column(column)
-
- self._contactsviewselection = contactsview.get_selection()
- self._contactsviewselection.set_mode(gtk.SELECTION_SINGLE)
-
- return False
-
- def _setup_callback_combo(self):
- combobox = self._widgetTree.get_widget("callbackcombo")
- self.callbacklist = gtk.ListStore(gobject.TYPE_STRING)
- combobox.set_model(self.callbacklist)
- combobox.set_text_column(0)
- for number, description in self._gcBackend.get_callback_numbers().iteritems():
- self.callbacklist.append([make_pretty(number)])
-
- combobox.get_child().set_text(make_pretty(self._gcBackend.get_callback_number()))
- self._callbackNeedsSetup = False
-
- def populate_recentview(self):
- self._recentmodel.clear()
-
- for personsName, phoneNumber, date, action in self._gcBackend.get_recent():
- item = (phoneNumber, "%s on %s from/to %s - %s" % (action.capitalize(), date, personsName, phoneNumber))
- self._recentmodel.append(item)
-
- self._recenttime = time.time()
- return False
-
- def populate_contactsview(self):
- self._contactsmodel.clear()
-
- # completely disable updating the treeview while we populate the data
- contactsview = self._widgetTree.get_widget("contactsview")
- contactsview.freeze_child_notify()
- contactsview.set_model(None)
-
- # get gc icon
- gc_icon = gtk.gdk.pixbuf_new_from_file_at_size('gc_contact.png', 16, 16)
- for contactId, contactName in self._gcBackend.get_contacts():
- self._contactsmodel.append((gc_icon,) + (contactName, "", contactId) + ("",))
-
- # restart the treeview data rendering
- contactsview.set_model(self._contactsmodel)
- contactsview.thaw_child_notify()
-
- self._contactstime = time.time()
- return False
-
- def attempt_login(self, numOfAttempts = 1):
- assert 0 < numOfAttempts, "That was pointless having 0 or less login attempts"
- dialog = self._widgetTree.get_widget("login_dialog")
-
- if self._gcBackend.is_authed():
- return True
-
- for i in range(numOfAttempts):
- dialog.run()
-
- username = self._widgetTree.get_widget("usernameentry").get_text()
- password = self._widgetTree.get_widget("passwordentry").get_text()
- self._widgetTree.get_widget("passwordentry").set_text("")
-
- loggedIn = self._gcBackend.login(username, password)
- dialog.hide()
- if loggedIn:
- return True
-
- return False
-
- def display_error_message(self, msg):
- error_dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
-
- def close(dialog, response, editor):
- editor.about_dialog = None
- dialog.destroy()
- error_dialog.connect("response", close, self)
- error_dialog.run()
-
- def set_number(self, number):
- self._phonenumber = make_ugly(number)
- self._prettynumber = make_pretty(self._phonenumber)
- self._numberdisplay.set_label("<span size='30000' weight='bold'>%s</span>" % ( self._prettynumber ) )
-
- def set_account_number(self):
- accountnumber = self._gcBackend.get_account_number()
- self._widgetTree.get_widget("gcnumberlabel").set_label("<span size='23000' weight='bold'>%s</span>" % (accountnumber))
-
- 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
- """
- if memory_low:
- self._gcBackend.clear_caches()
- re.purge()
- gc.collect()
-
- def _on_connection_change(self, connection, event, magicIdentifier):
- """
- @note Hildon specific
- """
- status = event.get_status()
- error = event.get_error()
- iap_id = event.get_iap_id()
- bearer = event.get_bearer_type()
-
- if status == conic.STATUS_CONNECTED:
- self._window.set_sensitive(True)
- self._deviceIsOnline = True
- elif status == conic.STATUS_DISCONNECTED:
- self._window.set_sensitive(False)
- self._deviceIsOnline = False
-
- def _on_window_state_change(self, widget, event, *args):
- """
- @note Hildon specific
- """
- if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
- self._isFullScreen = True
- else:
- self._isFullScreen = False
-
- def _on_key_press(self, widget, event, *args):
- """
- @note Hildon specific
- """
- if event.keyval == gtk.keysyms.F6:
- if self._isFullScreen:
- self._window.unfullscreen()
- else:
- self._window.fullscreen()
-
- def _on_loginbutton_clicked(self, *args):
- self._widgetTree.get_widget("login_dialog").response(gtk.RESPONSE_OK)
-
- def _on_loginclose_clicked(self, *args):
- gtk.main_quit()
- sys.exit(0)
-
- def _on_clearcookies_clicked(self, *args):
- self._gcBackend.reset()
- self._callbackNeedsSetup = True
- self._recenttime = 0.0
- self._contactstime = 0.0
- self._recentmodel.clear()
- self._widgetTree.get_widget("callbackcombo").get_child().set_text("")
-
- # re-run the inital grandcentral setup
- self.attempt_login(2)
- gobject.idle_add(self._init_grandcentral)
-
- def _on_callbackentry_changed(self, *args):
- """
- @todo Potential blocking on web access, maybe we should defer this or put up a dialog?
- """
- text = make_ugly(self._widgetTree.get_widget("callbackcombo").get_child().get_text())
- if not self._gcBackend.is_valid_syntax(text):
- warnings.warn("%s is not a valid callback number" % text, UserWarning, 2)
- elif text != self._gcBackend.get_callback_number():
- self._gcBackend.set_callback_number(text)
- else:
- warnings.warn("Callback number already is %s" % self._gcBackend.get_callback_number(), UserWarning, 2)
-
- def _on_recentview_row_activated(self, treeview, path, view_column):
- model, itr = self._recentviewselection.get_selected()
- if not itr:
- return
-
- self.set_number(self._recentmodel.get_value(itr, 0))
- self._notebook.set_current_page(0)
- self._recentviewselection.unselect_all()
-
- def _on_contactsview_row_activated(self, treeview, path, view_column):
- model, itr = self._contactsviewselection.get_selected()
- if not itr:
- return
-
- contactId = self._contactsmodel.get_value(itr, 3)
- contactDetails = self._gcBackend.get_contact_details(contactId)
- contactDetails = [phoneNumber for phoneNumber in contactDetails]
-
- if len(contactDetails) == 0:
- phoneNumber = ""
- elif len(contactDetails) == 1:
- phoneNumber = contactDetails[0][1]
- else:
- phoneNumber = self._phoneTypeSelector.run(contactDetails)
-
- if 0 < len(phoneNumber):
- self.set_number(phoneNumber)
- self._notebook.set_current_page(0)
-
- self._contactsviewselection.unselect_all()
-
- def _on_notebook_switch_page(self, notebook, page, page_num):
- if page_num == 1 and 300 < (time.time() - self._contactstime):
- gobject.idle_add(self.populate_contactsview)
- elif page_num == 2 and 300 < (time.time() - self._recenttime):
- gobject.idle_add(self.populate_recentview)
- elif page_num == 3 and self._callbackNeedsSetup:
- gobject.idle_add(self._setup_callback_combo)
-
- if hildon:
- self._window.set_title(self._notebook.get_tab_label(self._notebook.get_nth_page(page_num)).get_text())
-
- def _on_dial_clicked(self, widget):
- """
- @todo Potential blocking on web access, maybe we should defer parts of this or put up a dialog?
- """
- loggedIn = self.attempt_login(2)
- if not loggedIn or not self._gcBackend.is_authed() or self._gcBackend.get_callback_number() == "":
- self.display_error_message("Backend link with grandcentral is not working, please try again")
- warnings.warn("Backend Status: Logged in? %s, Authenticated? %s, Callback=%s" % (loggedIn, self._gcBackend.is_authed(), self._gcBackend.get_callback_number()), UserWarning, 2)
- return
-
- try:
- callSuccess = self._gcBackend.dial(self._phonenumber)
- except ValueError, e:
- self._gcBackend._msg = e.message
- callSuccess = False
-
- if not callSuccess:
- self.display_error_message(self._gcBackend._msg)
- else:
- self.set_number("")
-
- self._recentmodel.clear()
- self._recenttime = 0.0
-
- def _on_paste(self, *args):
- contents = self._clipboard.wait_for_text()
- phoneNumber = re.sub('\D', '', contents)
- self.set_number(phoneNumber)
-
- def _on_clear_number(self, *args):
- self.set_number("")
-
- def _on_digit_clicked(self, widget):
- self.set_number(self._phonenumber + widget.get_name()[5])
-
- def _on_backspace(self, widget):
- self.set_number(self._phonenumber[:-1])
-
-
-def run_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()
- title = 'Dialpad'
- handle = Dialpad()
- gtk.main()
-
-
-class DummyOptions(object):
-
- def __init__(self):
- self.test = False
-
-
-if __name__ == "__main__":
- if hildon is not None:
- gtk.set_application_name("Dialer")
-
- 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()
+++ /dev/null
-#!/usr/bin/python
-
-"""
-Grandcentral Dialer backend code
-Eric Warnke <ericew@gmail.com>
-Copyright 2008 GPLv2
-"""
-
-
-import os
-import re
-import urllib
-import urllib2
-import time
-import warnings
-
-from browser_emu import MozillaEmulator
-
-
-class GCDialer(object):
- """
- This class encapsulates all of the knowledge necessary to interace with the grandcentral servers
- the functions include login, setting up a callback number, and initalting a callback
- """
-
- _gcDialingStrRe = re.compile("This may take a few seconds", re.M) # string from Grandcentral.com on successful dial
- _accessTokenRe = re.compile(r"""<input type="hidden" name="a_t" [^>]*value="(.*)"/>""")
- _isLoginPageRe = re.compile(r"""<form method="post" action="https://www.grandcentral.com/mobile/account/login">""")
- _callbackRe = re.compile(r"""name="default_number" value="(\d+)" />\s+(.*)\s$""", re.M)
- _accountNumRe = re.compile(r"""<img src="/images/mobile/inbox_logo.gif" alt="GrandCentral" />\s*(.{14})\s* """, re.M)
- _inboxRe = re.compile(r"""<td>.*?(voicemail|received|missed|call return).*?</td>\s+<td>\s+<font size="2">\s+(.*?)\s+ \| \s+<a href="/mobile/contacts/.*?">(.*?)\s?</a>\s+<br/>\s+(.*?)\s?<a href=""", re.S)
- _contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
- _contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
- _contactDetailGroupRe = re.compile(r"""Group:\s*(\w*)""", re.S)
- _contactDetailPhoneRe = re.compile(r"""(\w+):[0-9\-\(\) \t]*?<a href="/mobile/calls/click_to_call\?destno=(\d+).*?">call</a>""", re.S)
-
- _validateRe = re.compile("^[0-9]{10,}$")
-
- _forwardselectURL = "http://www.grandcentral.com/mobile/settings/forwarding_select"
- _loginURL = "https://www.grandcentral.com/mobile/account/login"
- _setforwardURL = "http://www.grandcentral.com/mobile/settings/set_forwarding?from=settings"
- _clicktocallURL = "http://www.grandcentral.com/mobile/calls/click_to_call?a_t=%s&destno=%s"
- _inboxallURL = "http://www.grandcentral.com/mobile/messages/inbox?types=all"
- _contactsURL = "http://www.grandcentral.com/mobile/contacts"
- _contactDetailURL = "http://www.grandcentral.com/mobile/contacts/detail"
-
- def __init__(self, cookieFile = None):
- # Important items in this function are the setup of the browser emulation and cookie file
- self._msg = ""
-
- self._browser = MozillaEmulator(None, 0)
- if cookieFile is None:
- cookieFile = os.path.join(os.path.expanduser("~"), ".gc_dialer_cookies.txt")
- self._browser.cookies.filename = cookieFile
- if os.path.isfile(cookieFile):
- self._browser.cookies.load()
-
- self._accessToken = None
- self._accountNum = None
- self._callbackNumbers = {}
- self._lastAuthed = 0.0
-
- def is_authed(self, force = False):
- """
- Attempts to detect a current session and pull the auth token ( a_t ) from the page.
- @note Once logged in try not to reauth more than once a minute.
- @returns If authenticated
- """
-
- if time.time() - self._lastAuthed < 60 and not force:
- return True
-
- try:
- forwardSelectionPage = self._browser.download(GCDialer._forwardselectURL)
- except urllib2.URLError, e:
- warnings.warn("%s is not accesible" % GCDialer._forwardselectURL, UserWarning, 2)
- return False
-
- self._browser.cookies.save()
- if GCDialer._isLoginPageRe.search(forwardSelectionPage) is None:
- self._grab_token(forwardSelectionPage)
- self._lastAuthed = time.time()
- return True
-
- return False
-
- def login(self, username, password):
- """
- Attempt to login to grandcentral
- @returns Whether login was successful or not
- """
- if self.is_authed():
- return True
-
- loginPostData = urllib.urlencode( {'username' : username , 'password' : password } )
-
- try:
- loginSuccessOrFailurePage = self._browser.download(GCDialer._loginURL, loginPostData)
- except urllib2.URLError, e:
- warnings.warn("%s is not accesible" % GCDialer._loginURL, UserWarning, 2)
- return False
-
- return self.is_authed()
-
- def dial(self, number):
- """
- This is the main function responsible for initating the callback
- """
- self._msg = ""
-
- # If the number is not valid throw exception
- if not self.is_valid_syntax(number):
- raise ValueError('number is not valid')
-
- # No point if we don't have the magic cookie
- if not self.is_authed():
- self._msg = "Not authenticated"
- return False
-
- # Strip leading 1 from 11 digit dialing
- if len(number) == 11 and number[0] == 1:
- number = number[1:]
-
- try:
- callSuccessPage = self._browser.download(
- GCDialer._clicktocallURL % (self._accessToken, number),
- None,
- {'Referer' : 'http://www.grandcentral.com/mobile/messages'}
- )
- except urllib2.URLError, e:
- warnings.warn("%s is not accesible" % GCDialer._clicktocallURL, UserWarning, 2)
- return False
-
- if GCDialer._gcDialingStrRe.search(callSuccessPage) is not None:
- return True
- else:
- self._msg = "Grand Central returned an error"
- return False
-
- self._msg = "Unknown Error"
- return False
-
- def clear_caches(self):
- pass
-
- def reset(self):
- self._lastAuthed = 0.0
- self._browser.cookies.clear()
- self._browser.cookies.save()
-
- 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 grand central phone number
- """
- return self._accountNum
-
- def set_sane_callback(self):
- """
- 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 = self.get_callback_numbers()
-
- for number, description in numbers.iteritems():
- if not re.compile(r"""1747""").match(number) is None:
- self.set_callback_number(number)
- return
-
- for number, description in numbers.iteritems():
- if not re.compile(r"""gizmo""", re.I).search(description) is None:
- self.set_callback_number(number)
- return
-
- for number, description in numbers.iteritems():
- if not re.compile(r"""computer""", re.I).search(description) is None:
- self.set_callback_number(number)
- return
-
- for number, description in numbers.iteritems():
- self.set_callback_number(number)
- return
-
- def get_callback_numbers(self):
- """
- @returns a dictionary mapping call back numbers to descriptions
- @note These results are cached for 30 minutes.
- """
- if time.time() - self._lastAuthed < 1800 or self.is_authed():
- return self._callbackNumbers
-
- return {}
-
- def set_callback_number(self, callbacknumber):
- """
- Set the number that grandcental calls
- @param callbacknumber should be a proper 10 digit number
- """
- callbackPostData = urllib.urlencode({'a_t' : self._accessToken, 'default_number' : callbacknumber })
- try:
- callbackSetPage = self._browser.download(GCDialer._setforwardURL, callbackPostData)
- except urllib2.URLError, e:
- warnings.warn("%s is not accesible" % GCDialer._setforwardURL, UserWarning, 2)
- return False
-
- self._browser.cookies.save()
- return True
-
- def get_callback_number(self):
- """
- @returns Current callback number or None
- """
- for c in self._browser.cookies:
- if c.name == "pda_forwarding_number":
- return c.value
- return None
-
- def get_recent(self):
- """
- @returns Iterable of (personsName, phoneNumber, date, action)
- """
- try:
- recentCallsPage = self._browser.download(GCDialer._inboxallURL)
- except urllib2.URLError, e:
- warnings.warn("%s is not accesible" % GCDialer._inboxallURL, UserWarning, 2)
- return
-
- for match in self._inboxRe.finditer(recentCallsPage):
- phoneNumber = match.group(4)
- action = match.group(1)
- date = match.group(2)
- personsName = match.group(3)
- yield personsName, phoneNumber, date, action
-
- def get_contacts(self):
- contactsPagesUrls = [GCDialer._contactsURL]
- for contactsPageUrl in contactsPagesUrls:
- print contactsPageUrl
- contactsPage = self._browser.download(contactsPageUrl)
- for contact_match in self._contactsRe.finditer(contactsPage):
- contactId = contact_match.group(1)
- contactName = contact_match.group(2)
- yield contactId, contactName
- next_match = self._contactsNextRe.match(contactsPage)
- if next_match is not None:
- newContactsPageUrl = self._contactsURL + next_match.group(1)
- contactsPagesUrls.append(newContactsPageUrl)
-
- def get_contact_details(self, contactId):
- detailPage = self._browser.download(GCDialer._contactDetailURL + '/' + contactId)
- for detail_match in self._contactDetailPhoneRe.finditer(detailPage):
- phoneType = detail_match.group(1)
- phoneNumber = detail_match.group(2)
- yield (phoneType, phoneNumber)
-
- def _grab_token(self, data):
- "Pull the magic cookie from the datastream"
- atGroup = GCDialer._accessTokenRe.search(data)
- self._accessToken = atGroup.group(1)
-
- anGroup = GCDialer._accountNumRe.search(data)
- self._accountNum = anGroup.group(1)
-
- self._callbackNumbers = {}
- for match in GCDialer._callbackRe.finditer(data):
- self._callbackNumbers[match.group(1)] = match.group(2)
--- /dev/null
+"""
+@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
+ - caching
+ - configurable user agent string
+ - GET and POST
+ - multipart POST (send files)
+ - receive content into file
+ - progress indicator
+
+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:
+
+ - For testing, use a MozillaCacher instance - this will cache all pages and make testing quicker
+ - 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
+
+TODO:
+
+- should have a method to save/load cookies
+"""
+
+import os
+import urllib
+import urllib2
+import cookielib
+import warnings
+
+
+class MozillaEmulator(object):
+
+ def __init__(self, cacher=None, trycount=0):
+ """Create a new MozillaEmulator object.
+
+ @param cacher: A dictionary like object, that can cache search results on a storage device.
+ You can use a simple dictionary here, but it is not recommended.
+ You can also put None here to disable caching completely.
+ @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."""
+ if cacher is None:
+ cacher = {}
+ self.cacher = cacher
+ self.cookies = cookielib.LWPCookieJar()
+ self.debug = False
+ self.trycount = trycount
+
+ def build_opener(self, url, postdata=None, extraheaders=None, forbid_redirect=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 forbid_redirect:
+ redirector = HTTPNoRedirector()
+ else:
+ redirector = urllib2.HTTPRedirectHandler()
+
+ 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; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4')]
+ if not postdata is None:
+ req.add_data(postdata)
+ return (req, u)
+
+ def download(self, url, postdata=None, extraheaders=None, forbid_redirect=False,
+ trycount=None, fd=None, onprogress=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 forbid_redirect: 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 fd: You can pass a file descriptor here. In this case,
+ the data will be written into the file. Please note that
+ when you save the raw data into a file then it won't be cached.
+ @param onprogress: A function that has two parameters:
+ the size of the resource and the downloaded size. This will be
+ called for each 1KB chunk. (If the HTTP header does not contain
+ the content-length field, then the size parameter will be zero!)
+ @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, unless fd was specified. When fd
+ was given, the return value is undefined.
+ """
+ warnings.warn("Performing download of %s" % url, UserWarning, 2)
+
+ 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, forbid_redirect)
+ openerdirector = u.open(req)
+ if self.debug:
+ print req.get_method(), url
+ print openerdirector.code, openerdirector.msg
+ print openerdirector.headers
+ self.cookies.extract_cookies(openerdirector, req)
+ if only_head:
+ return openerdirector
+ return openerdirector.read()
+ except urllib2.URLError:
+ cnt += 1
+ if (trycount > -1) and (trycount < cnt):
+ raise
+ # Retry :-)
+ if self.debug:
+ print "MozillaEmulator: urllib2.URLError, retryting ", cnt
+
+
+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
+ raise e
--- /dev/null
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Name=Grandcentral Dialer
+Exec=/usr/local/bin/gc_dialer.py
+Icon=gc_dialer
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.5 on Thu Jul 17 19:50:07 2008 -->
+<glade-interface>
+ <widget class="GtkWindow" id="Dialpad">
+ <property name="width_request">400</property>
+ <property name="height_request">350</property>
+ <property name="title" translatable="yes">Dialer</property>
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkMenuBar" id="menubar1">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkMenuItem" id="file_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_File</property>
+ <property name="use_underline">True</property>
+ <child>
+ <widget class="GtkMenu" id="menu1">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkImageMenuItem" id="login_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_New Login</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_clearcookies_clicked"/>
+ <child internal-child="image">
+ <widget class="GtkImage" id="menu-item-image11">
+ <property name="stock">gtk-new</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkImageMenuItem" id="quit_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">gtk-quit</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_dialpad_quit"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkMenuItem" id="edit_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit</property>
+ <property name="use_underline">True</property>
+ <child>
+ <widget class="GtkMenu" id="menu2">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkImageMenuItem" id="paste_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">gtk-paste</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_paste"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkImageMenuItem" id="delete_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">gtk-delete</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_clear_number"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkNotebook" id="notebook">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tab_pos">GTK_POS_BOTTOM</property>
+ <property name="show_border">False</property>
+ <property name="homogeneous">True</property>
+ <signal name="switch_page" handler="on_notebook_switch_page"/>
+ <child>
+ <widget class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkLabel" id="numberdisplay">
+ <property name="height_request">50</property>
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="35000" weight="bold">(518) 555-1212</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_CENTER</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="1" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label12">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="33000" weight="bold">1</span>
+<span size="9000"> </span></property>
+ <property name="use_markup">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="digit2">
+ <property name="visible">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="2" modifiers="" signal="clicked"/>
+ <accelerator key="a" modifiers="" signal="clicked"/>
+ <accelerator key="b" modifiers="" signal="clicked"/>
+ <accelerator key="c" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label10">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">2</span>
+<span size="12000">ABC</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="3" modifiers="" signal="clicked"/>
+ <accelerator key="d" modifiers="" signal="clicked"/>
+ <accelerator key="e" modifiers="" signal="clicked"/>
+ <accelerator key="f" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label11">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold" stretch="ultraexpanded">3</span>
+<span size="12000">DEF</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="4" modifiers="" signal="clicked"/>
+ <accelerator key="g" modifiers="" signal="clicked"/>
+ <accelerator key="h" modifiers="" signal="clicked"/>
+ <accelerator key="i" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label13">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">4</span>
+<span size="12000">GHI</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="5" modifiers="" signal="clicked"/>
+ <accelerator key="j" modifiers="" signal="clicked"/>
+ <accelerator key="k" modifiers="" signal="clicked"/>
+ <accelerator key="l" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label14">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">5</span>
+<span size="12000">JKL</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="6" modifiers="" signal="clicked"/>
+ <accelerator key="m" modifiers="" signal="clicked"/>
+ <accelerator key="n" modifiers="" signal="clicked"/>
+ <accelerator key="o" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label15">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">6</span>
+<span size="12000">MNO</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="7" modifiers="" signal="clicked"/>
+ <accelerator key="p" modifiers="" signal="clicked"/>
+ <accelerator key="q" modifiers="" signal="clicked"/>
+ <accelerator key="r" modifiers="" signal="clicked"/>
+ <accelerator key="s" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label16">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">7</span>
+<span size="12000">PQRS</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="8" modifiers="" signal="clicked"/>
+ <accelerator key="t" modifiers="" signal="clicked"/>
+ <accelerator key="u" modifiers="" signal="clicked"/>
+ <accelerator key="v" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label17">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">8</span>
+<span size="12000">TUV</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="9" modifiers="" signal="clicked"/>
+ <accelerator key="w" modifiers="" signal="clicked"/>
+ <accelerator key="x" modifiers="" signal="clicked"/>
+ <accelerator key="y" modifiers="" signal="clicked"/>
+ <accelerator key="z" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label18">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="30000" weight="bold">9</span>
+<span size="12000">WXYZ</span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="back">
+ <property name="visible">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_back_clicked"/>
+ <accelerator key="BackSpace" modifiers="" 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-no</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label9">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes"><span size="17000" weight="Bold">Back</span></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>
+ <child>
+ <widget class="GtkButton" id="digit0">
+ <property name="visible">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_digit_clicked"/>
+ <accelerator key="0" modifiers="" signal="clicked"/>
+ <child>
+ <widget class="GtkLabel" id="label19">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="33000" weight="bold">0</span>
+<span size="9000"></span></property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_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="dial">
+ <property name="visible">True</property>
+ <property name="has_default">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_dial_clicked"/>
+ <accelerator key="Return" modifiers="" 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>
+ </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"><span size="17000" weight="bold">Dial</span></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>
+ </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="type">tab</property>
+ <property name="tab_expand">True</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_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="enable_search">False</property>
+ <property name="fixed_height_mode">True</property>
+ <property name="enable_grid_lines">GTK_TREE_VIEW_GRID_LINES_HORIZONTAL</property>
+ <property name="enable_tree_lines">True</property>
+ <signal name="row_activated" handler="on_contactsview_row_activated"/>
+ </widget>
+ </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="contacts">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Contacts</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ <property name="position">1</property>
+ <property name="tab_expand">True</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+ <child>
+ <widget class="GtkTreeView" id="recentview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ <property name="enable_search">False</property>
+ <property name="fixed_height_mode">True</property>
+ <property name="enable_grid_lines">GTK_TREE_VIEW_GRID_LINES_HORIZONTAL</property>
+ <property name="enable_tree_lines">True</property>
+ <signal name="row_activated" handler="on_recentview_row_activated"/>
+ </widget>
+ </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="recent">
+ <property name="height_request">30</property>
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Recent</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ <property name="position">1</property>
+ <property name="tab_expand">True</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkTable" id="accountview">
+ <property name="visible">True</property>
+ <property name="border_width">11</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <widget class="GtkComboBoxEntry" id="callbackcombo">
+ <property name="visible">True</property>
+ <child internal-child="entry">
+ <widget class="GtkEntry" id="comboboxentry-entry2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <signal name="changed" handler="on_callbackentry_changed"/>
+ </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>
+ <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">1</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">Callback Number:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton" id="clearcookies">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">Clear Account Information
+must reauthenticate</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_clearcookies_clicked"/>
+ </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>
+ <widget class="GtkLabel" id="gcnumberlabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="15000" weight="bold">(518) 555-1212</span></property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">GrandCentral
+Number:</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">2</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="type">tab</property>
+ <property name="position">2</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkLabel" id="about_title">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span size="20000" weight="bold">GrandCentral Dialer</span>
+Copyright 2008</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_CENTER</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="about_description">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">GUI front-end to initiate outbound call from Grandcentral.com, typically with Grancentral configured to connect the outbound call to a VOIP number accessible via Gizmo on the Internet Tablet.</property>
+ <property name="wrap">True</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="about_authors">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Authors: Mark Bergman <bergman@merctech.com>, Eric Warnke <ericew@gmail.com></property>
+ <property name="wrap">True</property>
+ </widget>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">3</property>
+ <property name="tab_expand">True</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="about">
+ <property name="height_request">30</property>
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">About</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ <property name="position">3</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <widget class="GtkDialog" id="login_dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Grandcentral Login</property>
+ <property name="resizable">False</property>
+ <property name="modal">True</property>
+ <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">GDK_WINDOW_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">Dialpad</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <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="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>
+ <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="GtkLabel" id="label6">
+ <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="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Username</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <child>
+ <widget class="GtkButton" id="loginbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">Login</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_loginbutton_clicked"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="closebutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">Close</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_loginclose_clicked"/>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <widget class="GtkDialog" id="phonetype_dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Select Phone Type</property>
+ <property name="resizable">False</property>
+ <property name="modal">True</property>
+ <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">GDK_WINDOW_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">Dialpad</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialog-vbox3">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <widget class="GtkTreeView" id="phonetypes">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_clickable">True</property>
+ <signal name="row_activated" handler="on_phonetype_select"/>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialog-action_area3">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <child>
+ <widget class="GtkButton" id="select_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Select</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_phonetype_select"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="cancel_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="response_id">0</property>
+ <signal name="clicked" handler="on_phonetype_cancel"/>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+</glade-interface>
--- /dev/null
+#!/usr/bin/python2.5
+
+
+"""
+Grandcentral Dialer
+Python front-end to a wget script to use grandcentral.com to place outbound VOIP calls.
+(C) 2008 Mark Bergman
+bergman@merctech.com
+"""
+
+
+import sys
+import gc
+import os
+import threading
+import time
+import re
+import warnings
+
+import gobject
+import gtk
+import gtk.glade
+
+try:
+ import hildon
+except ImportError:
+ hildon = None
+
+try:
+ import osso
+ try:
+ import abook
+ import evolution.ebook as evobook
+ except ImportError:
+ abook = None
+ evobook = None
+except ImportError:
+ osso = None
+
+try:
+ import conic
+except ImportError:
+ conic = None
+
+try:
+ import doctest
+ import optparse
+except ImportError:
+ doctest = None
+ optparse = None
+
+from gcbackend import GCDialer
+
+import socket
+
+
+socket.setdefaulttimeout(5)
+
+
+def make_ugly(prettynumber):
+ """
+ function to take a phone number and strip out all non-numeric
+ characters
+
+ >>> make_ugly("+012-(345)-678-90")
+ '01234567890'
+ """
+ uglynumber = re.sub('\D', '', prettynumber)
+ return uglynumber
+
+
+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")
+ '(234)-567-8901'
+ >>> make_pretty("12345678901")
+ '1 (234)-567-8901'
+ >>> make_pretty("01234567890")
+ '+012-(345)-678-90'
+ """
+ if phonenumber is None:
+ return ""
+
+ if len(phonenumber) < 3:
+ return phonenumber
+
+ if phonenumber[0] == "0":
+ prettynumber = ""
+ prettynumber += "+%s" % phonenumber[0:3]
+ if 3 < len(phonenumber):
+ prettynumber += "-(%s)" % phonenumber[3:6]
+ if 6 < len(phonenumber):
+ prettynumber += "-%s" % phonenumber[6:9]
+ if 9 < len(phonenumber):
+ prettynumber += "-%s" % phonenumber[9:]
+ return prettynumber
+ elif len(phonenumber) <= 7:
+ prettynumber = "%s-%s" % (phonenumber[0:3], phonenumber[3:])
+ elif len(phonenumber) > 8 and phonenumber[0] == "1":
+ prettynumber = "1 (%s)-%s-%s" % (phonenumber[1:4], phonenumber[4:7], phonenumber[7:])
+ elif len(phonenumber) > 7:
+ prettynumber = "(%s)-%s-%s" % (phonenumber[0:3], phonenumber[3:6], phonenumber[6:])
+ return prettynumber
+
+
+class PhoneTypeSelector(object):
+
+ def __init__(self, widgetTree, gcBackend):
+ self._gcBackend = gcBackend
+ self._widgetTree = widgetTree
+ self._dialog = self._widgetTree.get_widget("phonetype_dialog")
+
+ self._selectButton = self._widgetTree.get_widget("select_button")
+ self._selectButton.connect("clicked", self._on_phonetype_select)
+
+ self._cancelButton = self._widgetTree.get_widget("cancel_button")
+ self._cancelButton.connect("clicked", self._on_phonetype_cancel)
+
+ self._typemodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
+ self._typeviewselection = None
+
+ typeview = self._widgetTree.get_widget("phonetypes")
+ typeview.connect("row-activated", self._on_phonetype_select)
+ typeview.set_model(self._typemodel)
+ textrenderer = gtk.CellRendererText()
+
+ # Add the column to the treeview
+ column = gtk.TreeViewColumn("Phone Numbers", textrenderer, text=1)
+ column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+
+ typeview.append_column(column)
+
+ self._typeviewselection = typeview.get_selection()
+ self._typeviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+ def run(self, contactDetails):
+ self._typemodel.clear()
+
+ for phoneType, phoneNumber in contactDetails:
+ self._typemodel.append((phoneNumber, "%s - %s" % (make_pretty(phoneNumber), phoneType)))
+
+ userResponse = self._dialog.run()
+
+ if userResponse == gtk.RESPONSE_OK:
+ model, itr = self._typeviewselection.get_selected()
+ if itr:
+ phoneNumber = self._typemodel.get_value(itr, 0)
+ else:
+ phoneNumber = ""
+
+ self._typeviewselection.unselect_all()
+ self._dialog.hide()
+ return phoneNumber
+
+ def _on_phonetype_select(self, *args):
+ self._dialog.response(gtk.RESPONSE_OK)
+
+ def _on_phonetype_cancel(self, *args):
+ self._dialog.response(gtk.RESPONSE_CANCEL)
+
+
+class Dialpad(object):
+
+ __app_name__ = "gc_dialer"
+ __version__ = "0.7.0"
+ __app_magic__ = 0xdeadbeef
+
+ _glade_files = [
+ './gc_dialer.glade',
+ '../lib/gc_dialer.glade',
+ '/usr/local/lib/gc_dialer.glade',
+ ]
+
+ def __init__(self):
+ self._phonenumber = ""
+ self._prettynumber = ""
+ self._areacode = "518"
+
+ self._clipboard = gtk.clipboard_get()
+
+ self._deviceIsOnline = True
+ self._callbackNeedsSetup = True
+
+ self._recenttime = 0.0
+ self._recentmodel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
+ self._recentviewselection = None
+
+ self._contactstime = 0.0
+ self._contactsmodel = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
+ self._contactsviewselection = None
+
+ for path in Dialpad._glade_files:
+ if os.path.isfile(path):
+ self._widgetTree = gtk.glade.XML(path)
+ break
+ else:
+ self.display_error_message("Cannot find gc_dialer.glade")
+ gtk.main_quit()
+ return
+
+ aboutHeader = self._widgetTree.get_widget("about_title")
+ aboutHeader.set_label("%s\nVersion %s" % (aboutHeader.get_label(), Dialpad.__version__))
+
+ #Get the buffer associated with the number display
+ self._numberdisplay = self._widgetTree.get_widget("numberdisplay")
+ self.set_number("")
+ self._notebook = self._widgetTree.get_widget("notebook")
+
+ self._window = self._widgetTree.get_widget("Dialpad")
+
+ global hildon
+ self._app = None
+ self._isFullScreen = False
+ if hildon is not None and isinstance(self._window, gtk.Window):
+ warnings.warn("Hildon installed but glade file not updated to work with hildon", UserWarning, 2)
+ hildon = None
+ elif hildon is not None:
+ self._app = hildon.Program()
+ self._window.set_title("Keypad")
+ self._app.add_window(self._window)
+ self._widgetTree.get_widget("callbackcombo").get_child().set_property('hildon-input-mode', (1 << 4))
+ self._widgetTree.get_widget("usernameentry").set_property('hildon-input-mode', 7)
+ self._widgetTree.get_widget("passwordentry").set_property('hildon-input-mode', 7|(1 << 29))
+
+ gtkMenu = self._widgetTree.get_widget("menubar1")
+ menu = gtk.Menu()
+ for child in gtkMenu.get_children():
+ child.reparent(menu)
+ self._window.set_menu(menu)
+ gtkMenu.destroy()
+
+ self._window.connect("key-press-event", self._on_key_press)
+ self._window.connect("window-state-event", self._on_window_state_change)
+ else:
+ warnings.warn("No Hildon", UserWarning, 2)
+
+ self._osso = None
+ self._ebook = None
+ if osso is not None:
+ self._osso = osso.Context(Dialpad.__app_name__, Dialpad.__version__, False)
+ device = osso.DeviceState(self._osso)
+ device.set_device_state_callback(self._on_device_state_change, 0)
+ if abook is not None and evobook is not None:
+ abook.init_with_name(Dialpad.__app_name__, self._osso)
+ self._ebook = evobook.open_addressbook("default")
+ else:
+ warnings.warn("No abook and No evolution address book support", UserWarning, 2)
+ else:
+ warnings.warn("No OSSO", UserWarning, 2)
+
+ self._connection = None
+ if conic is not None:
+ self._connection = conic.Connection()
+ self._connection.connect("connection-event", self._on_connection_change, Dialpad.__app_magic__)
+ self._connection.request_connection(conic.CONNECT_FLAG_NONE)
+ else:
+ warnings.warn("No Internet Connectivity API ", UserWarning, 2)
+
+ callbackMapping = {
+ # Process signals from buttons
+ "on_loginbutton_clicked": self._on_loginbutton_clicked,
+ "on_loginclose_clicked": self._on_loginclose_clicked,
+
+ "on_dialpad_quit": (lambda data: gtk.main_quit()),
+ "on_paste": self._on_paste,
+ "on_clear_number": self._on_clear_number,
+
+ "on_clearcookies_clicked": self._on_clearcookies_clicked,
+ "on_notebook_switch_page": self._on_notebook_switch_page,
+ "on_recentview_row_activated": self._on_recentview_row_activated,
+ "on_contactsview_row_activated" : self._on_contactsview_row_activated,
+
+ "on_digit_clicked": self._on_digit_clicked,
+ "on_back_clicked": self._on_backspace,
+ "on_dial_clicked": self._on_dial_clicked,
+ }
+ self._widgetTree.signal_autoconnect(callbackMapping)
+ self._widgetTree.get_widget("callbackcombo").get_child().connect("changed", self._on_callbackentry_changed)
+
+ if self._window:
+ self._window.connect("destroy", gtk.main_quit)
+ self._window.show_all()
+
+ self._gcBackend = GCDialer()
+
+ self._phoneTypeSelector = PhoneTypeSelector(self._widgetTree, self._gcBackend)
+
+ self.attempt_login(2)
+ gobject.idle_add(self._init_grandcentral)
+ gobject.idle_add(self._init_recent_view)
+ gobject.idle_add(self._init_contacts_view)
+
+ def _init_grandcentral(self):
+ """ Deferred initalization of the grandcentral info """
+
+ if self._gcBackend.is_authed():
+ if self._gcBackend.get_callback_number() is None:
+ self._gcBackend.set_sane_callback()
+ self.set_account_number()
+
+ return False
+
+ def _init_recent_view(self):
+ """ Deferred initalization of the recent view treeview """
+
+ recentview = self._widgetTree.get_widget("recentview")
+ recentview.set_model(self._recentmodel)
+ textrenderer = gtk.CellRendererText()
+
+ # Add the column to the treeview
+ column = gtk.TreeViewColumn("Calls", textrenderer, text=1)
+ column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+
+ recentview.append_column(column)
+
+ self._recentviewselection = recentview.get_selection()
+ self._recentviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+ return False
+
+ def _init_contacts_view(self):
+ """ deferred initalization of the contacts view treeview """
+
+ contactsview = self._widgetTree.get_widget("contactsview")
+ contactsview.set_model(self._contactsmodel)
+
+ # Add the column to the treeview
+ column = gtk.TreeViewColumn("Contact")
+
+ iconrenderer = gtk.CellRendererPixbuf()
+ column.pack_start(iconrenderer, expand=False)
+ column.add_attribute(iconrenderer, 'pixbuf', 0)
+
+ textrenderer = gtk.CellRendererText()
+ column.pack_start(textrenderer, expand=True)
+ column.add_attribute(textrenderer, 'text', 1)
+
+ textrenderer = gtk.CellRendererText()
+ column.pack_start(textrenderer, expand=True)
+ column.add_attribute(textrenderer, 'text', 4)
+
+ column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+ column.set_sort_column_id(1)
+ column.set_visible(True)
+ contactsview.append_column(column)
+
+ #textrenderer = gtk.CellRendererText()
+ #column = gtk.TreeViewColumn("Location", textrenderer, text=2)
+ #column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+ #column.set_sort_column_id(2)
+ #column.set_visible(True)
+ #contactsview.append_column(column)
+
+ #textrenderer = gtk.CellRendererText()
+ #column = gtk.TreeViewColumn("Phone", textrenderer, text=3)
+ #column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+ #column.set_sort_column_id(3)
+ #column.set_visible(True)
+ #contactsview.append_column(column)
+
+ self._contactsviewselection = contactsview.get_selection()
+ self._contactsviewselection.set_mode(gtk.SELECTION_SINGLE)
+
+ return False
+
+ def _setup_callback_combo(self):
+ combobox = self._widgetTree.get_widget("callbackcombo")
+ self.callbacklist = gtk.ListStore(gobject.TYPE_STRING)
+ combobox.set_model(self.callbacklist)
+ combobox.set_text_column(0)
+ for number, description in self._gcBackend.get_callback_numbers().iteritems():
+ self.callbacklist.append([make_pretty(number)])
+
+ combobox.get_child().set_text(make_pretty(self._gcBackend.get_callback_number()))
+ self._callbackNeedsSetup = False
+
+ def populate_recentview(self):
+ self._recentmodel.clear()
+
+ for personsName, phoneNumber, date, action in self._gcBackend.get_recent():
+ item = (phoneNumber, "%s on %s from/to %s - %s" % (action.capitalize(), date, personsName, phoneNumber))
+ self._recentmodel.append(item)
+
+ self._recenttime = time.time()
+ return False
+
+ def populate_contactsview(self):
+ self._contactsmodel.clear()
+
+ # completely disable updating the treeview while we populate the data
+ contactsview = self._widgetTree.get_widget("contactsview")
+ contactsview.freeze_child_notify()
+ contactsview.set_model(None)
+
+ # get gc icon
+ gc_icon = gtk.gdk.pixbuf_new_from_file_at_size('gc_contact.png', 16, 16)
+ for contactId, contactName in self._gcBackend.get_contacts():
+ self._contactsmodel.append((gc_icon,) + (contactName, "", contactId) + ("",))
+
+ # restart the treeview data rendering
+ contactsview.set_model(self._contactsmodel)
+ contactsview.thaw_child_notify()
+
+ self._contactstime = time.time()
+ return False
+
+ def attempt_login(self, numOfAttempts = 1):
+ assert 0 < numOfAttempts, "That was pointless having 0 or less login attempts"
+ dialog = self._widgetTree.get_widget("login_dialog")
+
+ if self._gcBackend.is_authed():
+ return True
+
+ for i in range(numOfAttempts):
+ dialog.run()
+
+ username = self._widgetTree.get_widget("usernameentry").get_text()
+ password = self._widgetTree.get_widget("passwordentry").get_text()
+ self._widgetTree.get_widget("passwordentry").set_text("")
+
+ loggedIn = self._gcBackend.login(username, password)
+ dialog.hide()
+ if loggedIn:
+ return True
+
+ return False
+
+ def display_error_message(self, msg):
+ error_dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
+
+ def close(dialog, response, editor):
+ editor.about_dialog = None
+ dialog.destroy()
+ error_dialog.connect("response", close, self)
+ error_dialog.run()
+
+ def set_number(self, number):
+ self._phonenumber = make_ugly(number)
+ self._prettynumber = make_pretty(self._phonenumber)
+ self._numberdisplay.set_label("<span size='30000' weight='bold'>%s</span>" % ( self._prettynumber ) )
+
+ def set_account_number(self):
+ accountnumber = self._gcBackend.get_account_number()
+ self._widgetTree.get_widget("gcnumberlabel").set_label("<span size='23000' weight='bold'>%s</span>" % (accountnumber))
+
+ 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
+ """
+ if memory_low:
+ self._gcBackend.clear_caches()
+ re.purge()
+ gc.collect()
+
+ def _on_connection_change(self, connection, event, magicIdentifier):
+ """
+ @note Hildon specific
+ """
+ status = event.get_status()
+ error = event.get_error()
+ iap_id = event.get_iap_id()
+ bearer = event.get_bearer_type()
+
+ if status == conic.STATUS_CONNECTED:
+ self._window.set_sensitive(True)
+ self._deviceIsOnline = True
+ elif status == conic.STATUS_DISCONNECTED:
+ self._window.set_sensitive(False)
+ self._deviceIsOnline = False
+
+ def _on_window_state_change(self, widget, event, *args):
+ """
+ @note Hildon specific
+ """
+ if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
+ self._isFullScreen = True
+ else:
+ self._isFullScreen = False
+
+ def _on_key_press(self, widget, event, *args):
+ """
+ @note Hildon specific
+ """
+ if event.keyval == gtk.keysyms.F6:
+ if self._isFullScreen:
+ self._window.unfullscreen()
+ else:
+ self._window.fullscreen()
+
+ def _on_loginbutton_clicked(self, *args):
+ self._widgetTree.get_widget("login_dialog").response(gtk.RESPONSE_OK)
+
+ def _on_loginclose_clicked(self, *args):
+ gtk.main_quit()
+ sys.exit(0)
+
+ def _on_clearcookies_clicked(self, *args):
+ self._gcBackend.reset()
+ self._callbackNeedsSetup = True
+ self._recenttime = 0.0
+ self._contactstime = 0.0
+ self._recentmodel.clear()
+ self._widgetTree.get_widget("callbackcombo").get_child().set_text("")
+
+ # re-run the inital grandcentral setup
+ self.attempt_login(2)
+ gobject.idle_add(self._init_grandcentral)
+
+ def _on_callbackentry_changed(self, *args):
+ """
+ @todo Potential blocking on web access, maybe we should defer this or put up a dialog?
+ """
+ text = make_ugly(self._widgetTree.get_widget("callbackcombo").get_child().get_text())
+ if not self._gcBackend.is_valid_syntax(text):
+ warnings.warn("%s is not a valid callback number" % text, UserWarning, 2)
+ elif text != self._gcBackend.get_callback_number():
+ self._gcBackend.set_callback_number(text)
+ else:
+ warnings.warn("Callback number already is %s" % self._gcBackend.get_callback_number(), UserWarning, 2)
+
+ def _on_recentview_row_activated(self, treeview, path, view_column):
+ model, itr = self._recentviewselection.get_selected()
+ if not itr:
+ return
+
+ self.set_number(self._recentmodel.get_value(itr, 0))
+ self._notebook.set_current_page(0)
+ self._recentviewselection.unselect_all()
+
+ def _on_contactsview_row_activated(self, treeview, path, view_column):
+ model, itr = self._contactsviewselection.get_selected()
+ if not itr:
+ return
+
+ contactId = self._contactsmodel.get_value(itr, 3)
+ contactDetails = self._gcBackend.get_contact_details(contactId)
+ contactDetails = [phoneNumber for phoneNumber in contactDetails]
+
+ if len(contactDetails) == 0:
+ phoneNumber = ""
+ elif len(contactDetails) == 1:
+ phoneNumber = contactDetails[0][1]
+ else:
+ phoneNumber = self._phoneTypeSelector.run(contactDetails)
+
+ if 0 < len(phoneNumber):
+ self.set_number(phoneNumber)
+ self._notebook.set_current_page(0)
+
+ self._contactsviewselection.unselect_all()
+
+ def _on_notebook_switch_page(self, notebook, page, page_num):
+ if page_num == 1 and 300 < (time.time() - self._contactstime):
+ gobject.idle_add(self.populate_contactsview)
+ elif page_num == 2 and 300 < (time.time() - self._recenttime):
+ gobject.idle_add(self.populate_recentview)
+ elif page_num == 3 and self._callbackNeedsSetup:
+ gobject.idle_add(self._setup_callback_combo)
+
+ if hildon:
+ self._window.set_title(self._notebook.get_tab_label(self._notebook.get_nth_page(page_num)).get_text())
+
+ def _on_dial_clicked(self, widget):
+ """
+ @todo Potential blocking on web access, maybe we should defer parts of this or put up a dialog?
+ """
+ loggedIn = self.attempt_login(2)
+ if not loggedIn or not self._gcBackend.is_authed() or self._gcBackend.get_callback_number() == "":
+ self.display_error_message("Backend link with grandcentral is not working, please try again")
+ warnings.warn("Backend Status: Logged in? %s, Authenticated? %s, Callback=%s" % (loggedIn, self._gcBackend.is_authed(), self._gcBackend.get_callback_number()), UserWarning, 2)
+ return
+
+ try:
+ callSuccess = self._gcBackend.dial(self._phonenumber)
+ except ValueError, e:
+ self._gcBackend._msg = e.message
+ callSuccess = False
+
+ if not callSuccess:
+ self.display_error_message(self._gcBackend._msg)
+ else:
+ self.set_number("")
+
+ self._recentmodel.clear()
+ self._recenttime = 0.0
+
+ def _on_paste(self, *args):
+ contents = self._clipboard.wait_for_text()
+ phoneNumber = re.sub('\D', '', contents)
+ self.set_number(phoneNumber)
+
+ def _on_clear_number(self, *args):
+ self.set_number("")
+
+ def _on_digit_clicked(self, widget):
+ self.set_number(self._phonenumber + widget.get_name()[5])
+
+ def _on_backspace(self, widget):
+ self.set_number(self._phonenumber[:-1])
+
+
+def run_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()
+ title = 'Dialpad'
+ handle = Dialpad()
+ gtk.main()
+
+
+class DummyOptions(object):
+
+ def __init__(self):
+ self.test = False
+
+
+if __name__ == "__main__":
+ if hildon is not None:
+ gtk.set_application_name("Dialer")
+
+ 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()
--- /dev/null
+#!/usr/bin/python
+
+"""
+Grandcentral Dialer backend code
+Eric Warnke <ericew@gmail.com>
+Copyright 2008 GPLv2
+"""
+
+
+import os
+import re
+import urllib
+import urllib2
+import time
+import warnings
+
+from browser_emu import MozillaEmulator
+
+
+class GCDialer(object):
+ """
+ This class encapsulates all of the knowledge necessary to interace with the grandcentral servers
+ the functions include login, setting up a callback number, and initalting a callback
+ """
+
+ _gcDialingStrRe = re.compile("This may take a few seconds", re.M) # string from Grandcentral.com on successful dial
+ _accessTokenRe = re.compile(r"""<input type="hidden" name="a_t" [^>]*value="(.*)"/>""")
+ _isLoginPageRe = re.compile(r"""<form method="post" action="https://www.grandcentral.com/mobile/account/login">""")
+ _callbackRe = re.compile(r"""name="default_number" value="(\d+)" />\s+(.*)\s$""", re.M)
+ _accountNumRe = re.compile(r"""<img src="/images/mobile/inbox_logo.gif" alt="GrandCentral" />\s*(.{14})\s* """, re.M)
+ _inboxRe = re.compile(r"""<td>.*?(voicemail|received|missed|call return).*?</td>\s+<td>\s+<font size="2">\s+(.*?)\s+ \| \s+<a href="/mobile/contacts/.*?">(.*?)\s?</a>\s+<br/>\s+(.*?)\s?<a href=""", re.S)
+ _contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
+ _contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
+ _contactDetailGroupRe = re.compile(r"""Group:\s*(\w*)""", re.S)
+ _contactDetailPhoneRe = re.compile(r"""(\w+):[0-9\-\(\) \t]*?<a href="/mobile/calls/click_to_call\?destno=(\d+).*?">call</a>""", re.S)
+
+ _validateRe = re.compile("^[0-9]{10,}$")
+
+ _forwardselectURL = "http://www.grandcentral.com/mobile/settings/forwarding_select"
+ _loginURL = "https://www.grandcentral.com/mobile/account/login"
+ _setforwardURL = "http://www.grandcentral.com/mobile/settings/set_forwarding?from=settings"
+ _clicktocallURL = "http://www.grandcentral.com/mobile/calls/click_to_call?a_t=%s&destno=%s"
+ _inboxallURL = "http://www.grandcentral.com/mobile/messages/inbox?types=all"
+ _contactsURL = "http://www.grandcentral.com/mobile/contacts"
+ _contactDetailURL = "http://www.grandcentral.com/mobile/contacts/detail"
+
+ def __init__(self, cookieFile = None):
+ # Important items in this function are the setup of the browser emulation and cookie file
+ self._msg = ""
+
+ self._browser = MozillaEmulator(None, 0)
+ if cookieFile is None:
+ cookieFile = os.path.join(os.path.expanduser("~"), ".gc_dialer_cookies.txt")
+ self._browser.cookies.filename = cookieFile
+ if os.path.isfile(cookieFile):
+ self._browser.cookies.load()
+
+ self._accessToken = None
+ self._accountNum = None
+ self._callbackNumbers = {}
+ self._lastAuthed = 0.0
+
+ def is_authed(self, force = False):
+ """
+ Attempts to detect a current session and pull the auth token ( a_t ) from the page.
+ @note Once logged in try not to reauth more than once a minute.
+ @returns If authenticated
+ """
+
+ if time.time() - self._lastAuthed < 60 and not force:
+ return True
+
+ try:
+ forwardSelectionPage = self._browser.download(GCDialer._forwardselectURL)
+ except urllib2.URLError, e:
+ warnings.warn("%s is not accesible" % GCDialer._forwardselectURL, UserWarning, 2)
+ return False
+
+ self._browser.cookies.save()
+ if GCDialer._isLoginPageRe.search(forwardSelectionPage) is None:
+ self._grab_token(forwardSelectionPage)
+ self._lastAuthed = time.time()
+ return True
+
+ return False
+
+ def login(self, username, password):
+ """
+ Attempt to login to grandcentral
+ @returns Whether login was successful or not
+ """
+ if self.is_authed():
+ return True
+
+ loginPostData = urllib.urlencode( {'username' : username , 'password' : password } )
+
+ try:
+ loginSuccessOrFailurePage = self._browser.download(GCDialer._loginURL, loginPostData)
+ except urllib2.URLError, e:
+ warnings.warn("%s is not accesible" % GCDialer._loginURL, UserWarning, 2)
+ return False
+
+ return self.is_authed()
+
+ def dial(self, number):
+ """
+ This is the main function responsible for initating the callback
+ """
+ self._msg = ""
+
+ # If the number is not valid throw exception
+ if not self.is_valid_syntax(number):
+ raise ValueError('number is not valid')
+
+ # No point if we don't have the magic cookie
+ if not self.is_authed():
+ self._msg = "Not authenticated"
+ return False
+
+ # Strip leading 1 from 11 digit dialing
+ if len(number) == 11 and number[0] == 1:
+ number = number[1:]
+
+ try:
+ callSuccessPage = self._browser.download(
+ GCDialer._clicktocallURL % (self._accessToken, number),
+ None,
+ {'Referer' : 'http://www.grandcentral.com/mobile/messages'}
+ )
+ except urllib2.URLError, e:
+ warnings.warn("%s is not accesible" % GCDialer._clicktocallURL, UserWarning, 2)
+ return False
+
+ if GCDialer._gcDialingStrRe.search(callSuccessPage) is not None:
+ return True
+ else:
+ self._msg = "Grand Central returned an error"
+ return False
+
+ self._msg = "Unknown Error"
+ return False
+
+ def clear_caches(self):
+ pass
+
+ def reset(self):
+ self._lastAuthed = 0.0
+ self._browser.cookies.clear()
+ self._browser.cookies.save()
+
+ 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 grand central phone number
+ """
+ return self._accountNum
+
+ def set_sane_callback(self):
+ """
+ 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 = self.get_callback_numbers()
+
+ for number, description in numbers.iteritems():
+ if not re.compile(r"""1747""").match(number) is None:
+ self.set_callback_number(number)
+ return
+
+ for number, description in numbers.iteritems():
+ if not re.compile(r"""gizmo""", re.I).search(description) is None:
+ self.set_callback_number(number)
+ return
+
+ for number, description in numbers.iteritems():
+ if not re.compile(r"""computer""", re.I).search(description) is None:
+ self.set_callback_number(number)
+ return
+
+ for number, description in numbers.iteritems():
+ self.set_callback_number(number)
+ return
+
+ def get_callback_numbers(self):
+ """
+ @returns a dictionary mapping call back numbers to descriptions
+ @note These results are cached for 30 minutes.
+ """
+ if time.time() - self._lastAuthed < 1800 or self.is_authed():
+ return self._callbackNumbers
+
+ return {}
+
+ def set_callback_number(self, callbacknumber):
+ """
+ Set the number that grandcental calls
+ @param callbacknumber should be a proper 10 digit number
+ """
+ callbackPostData = urllib.urlencode({'a_t' : self._accessToken, 'default_number' : callbacknumber })
+ try:
+ callbackSetPage = self._browser.download(GCDialer._setforwardURL, callbackPostData)
+ except urllib2.URLError, e:
+ warnings.warn("%s is not accesible" % GCDialer._setforwardURL, UserWarning, 2)
+ return False
+
+ self._browser.cookies.save()
+ return True
+
+ def get_callback_number(self):
+ """
+ @returns Current callback number or None
+ """
+ for c in self._browser.cookies:
+ if c.name == "pda_forwarding_number":
+ return c.value
+ return None
+
+ def get_recent(self):
+ """
+ @returns Iterable of (personsName, phoneNumber, date, action)
+ """
+ try:
+ recentCallsPage = self._browser.download(GCDialer._inboxallURL)
+ except urllib2.URLError, e:
+ warnings.warn("%s is not accesible" % GCDialer._inboxallURL, UserWarning, 2)
+ return
+
+ for match in self._inboxRe.finditer(recentCallsPage):
+ phoneNumber = match.group(4)
+ action = match.group(1)
+ date = match.group(2)
+ personsName = match.group(3)
+ yield personsName, phoneNumber, date, action
+
+ def get_contacts(self):
+ contactsPagesUrls = [GCDialer._contactsURL]
+ for contactsPageUrl in contactsPagesUrls:
+ print contactsPageUrl
+ contactsPage = self._browser.download(contactsPageUrl)
+ for contact_match in self._contactsRe.finditer(contactsPage):
+ contactId = contact_match.group(1)
+ contactName = contact_match.group(2)
+ yield contactId, contactName
+ next_match = self._contactsNextRe.match(contactsPage)
+ if next_match is not None:
+ newContactsPageUrl = self._contactsURL + next_match.group(1)
+ contactsPagesUrls.append(newContactsPageUrl)
+
+ def get_contact_details(self, contactId):
+ detailPage = self._browser.download(GCDialer._contactDetailURL + '/' + contactId)
+ for detail_match in self._contactDetailPhoneRe.finditer(detailPage):
+ phoneType = detail_match.group(1)
+ phoneNumber = detail_match.group(2)
+ yield (phoneType, phoneNumber)
+
+ def _grab_token(self, data):
+ "Pull the magic cookie from the datastream"
+ atGroup = GCDialer._accessTokenRe.search(data)
+ self._accessToken = atGroup.group(1)
+
+ anGroup = GCDialer._accountNumRe.search(data)
+ self._accountNum = anGroup.group(1)
+
+ self._callbackNumbers = {}
+ for match in GCDialer._callbackRe.finditer(data):
+ self._callbackNumbers[match.group(1)] = match.group(2)