Import of contacts is implemented, just no refreshing of contact
authorEd Page <eopage@byu.net>
Sun, 14 Feb 2010 05:03:55 +0000 (23:03 -0600)
committerEd Page <eopage@byu.net>
Sun, 14 Feb 2010 05:03:55 +0000 (23:03 -0600)
src/dc_glade.py
src/dialcentral.glade

index 708d8e0..2e0adca 100755 (executable)
@@ -29,6 +29,7 @@ import threading
 import base64
 import ConfigParser
 import itertools
+import shutils
 import logging
 
 import gtk
@@ -97,6 +98,7 @@ class Dialcentral(object):
                self._alarmHandler = None
                self._ledHandler = None
                self._originalCurrentLabels = []
+               self._fsContactsPath = os.path.join(constants._data_path_, "contacts")
 
                for path in self._glade_files:
                        if os.path.isfile(path):
@@ -158,6 +160,10 @@ class Dialcentral(object):
                        button.connect("clicked", self._on_clearcookies_clicked)
                        menu.append(button)
 
+                       button= gtk.Button("Import Contacts")
+                       button.connect("clicked", self._on_contact_import)
+                       menu.append(button)
+
                        button= gtk.Button("Refresh")
                        button.connect("clicked", self._on_menu_refresh)
                        menu.append(button)
@@ -313,8 +319,7 @@ class Dialcentral(object):
                                        ),
                                })
 
-                       fsContactsPath = os.path.join(constants._data_path_, "contacts")
-                       fileBackend = file_backend.FilesystemAddressBookFactory(fsContactsPath)
+                       fileBackend = file_backend.FilesystemAddressBookFactory(self._fsContactsPath)
 
                        self._dialpads[self.GV_BACKEND].number_selected = self._select_action
                        self._historyViews[self.GV_BACKEND].number_selected = self._select_action
@@ -335,6 +340,7 @@ class Dialcentral(object):
                                "on_refresh": self._on_menu_refresh,
                                "on_clearcookies_clicked": self._on_clearcookies_clicked,
                                "on_about_activate": self._on_about_activate,
+                               "on_import": self._on_contact_import,
                        }
                        if hildonize.GTK_MENU_USED:
                                self._widgetTree.signal_autoconnect(callbackMapping)
@@ -879,6 +885,27 @@ class Dialcentral(object):
                except Exception, e:
                        self._errorDisplay.push_exception()
 
+       def _on_contact_import(self, *args):
+               try:
+                       csvFilter = gtk.FileFilter()
+                       csvFilter.set_name("Contacts")
+                       csvFilter.add_pattern("*.csv")
+                       importFileChooser = gtk.FileChooserDialog(
+                               title="Contacts",
+                               parent=self._window,
+                       )
+                       importFileChooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+                       importFileChooser.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+                       importFileChooser.set_property("filter", csvFilter)
+                       userResponse = importFileChooser.run()
+                       importFileChooser.hide()
+                       if userResponse == gtk.RESPONSE_OK:
+                               filename = importFileChooser.get_filename()
+                               shutils.copy2(filename, self._fsContactsPath)
+               except Exception, e:
+                       self._errorDisplay.push_exception()
+
        def _on_menu_refresh(self, *args):
                try:
                        self._refresh_active_tab()
index 4bee031..be6883a 100644 (file)
               </widget>
             </child>
             <child>
+              <widget class="GtkMenuItem" id="import_menu_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Import</property>
+                <property name="use_underline">True</property>
+                <signal name="activate" handler="on_import"/>
+              </widget>
+            </child>
+            <child>
               <widget class="GtkMenuItem" id="paste_menu_item">
                 <property name="visible">True</property>
                 <property name="label" translatable="yes">Paste</property>