152d0f57857ace386d2047f69ffa3f2f7dd50167
[gc-dialer] / src / dialcentral_qt.py
1 #!/usr/bin/env python
2 # -*- coding: UTF8 -*-
3
4 from __future__ import with_statement
5
6 import os
7 import base64
8 import ConfigParser
9 import functools
10 import logging
11
12 from PyQt4 import QtGui
13 from PyQt4 import QtCore
14 import dbus
15 import dbus.mainloop.glib
16
17 import constants
18 import call_handler
19 from util import qtpie
20 from util import qwrappers
21 from util import qui_utils
22 from util import misc as misc_utils
23
24 import session
25
26
27 _moduleLogger = logging.getLogger(__name__)
28
29
30 class LedWrapper(object):
31
32         def __init__(self):
33                 self._ledHandler = None
34                 self._init = False
35
36         def off(self):
37                 self._lazy_init()
38                 if self._ledHandler is not None:
39                         self._ledHandler.off()
40
41         def _lazy_init(self):
42                 if self._init:
43                         return
44                 self._init = True
45                 try:
46                         import led_handler
47                         self._ledHandler = led_handler.LedHandler()
48                 except Exception, e:
49                         _moduleLogger.exception('Unable to initialize LED Handling: "%s"' % str(e))
50                         self._ledHandler = None
51
52
53 class Dialcentral(qwrappers.ApplicationWrapper):
54
55         _DATA_PATHS = [
56                 os.path.join(os.path.dirname(__file__), "../share"),
57                 os.path.join(os.path.dirname(__file__), "../data"),
58         ]
59
60         def __init__(self, app):
61                 self._dataPath = None
62                 self._aboutDialog = None
63                 self._ledHandler = LedWrapper()
64                 self.notifyOnMissed = False
65                 self.notifyOnVoicemail = False
66                 self.notifyOnSms = False
67
68                 try:
69                         import alarm_handler
70                         if alarm_handler.AlarmHandler is not alarm_handler._NoneAlarmHandler:
71                                 self._alarmHandler = alarm_handler.AlarmHandler()
72                         else:
73                                 self._alarmHandler = None
74                 except (ImportError, OSError):
75                         self._alarmHandler = None
76                 except Exception:
77                         _moduleLogger.exception("Notification failure")
78                         self._alarmHandler = None
79                 if self._alarmHandler is None:
80                         _moduleLogger.info("No notification support")
81
82                 qwrappers.ApplicationWrapper.__init__(self, app, constants)
83
84         def load_settings(self):
85                 try:
86                         config = ConfigParser.SafeConfigParser()
87                         config.read(constants._user_settings_)
88                 except IOError, e:
89                         _moduleLogger.info("No settings")
90                         return
91                 except ValueError:
92                         _moduleLogger.info("Settings were corrupt")
93                         return
94                 except ConfigParser.MissingSectionHeaderError:
95                         _moduleLogger.info("Settings were corrupt")
96                         return
97                 except Exception:
98                         _moduleLogger.exception("Unknown loading error")
99
100                 blobs = "", ""
101                 isFullscreen = False
102                 isPortrait = qui_utils.screen_orientation() == QtCore.Qt.Vertical
103                 tabIndex = 0
104                 try:
105                         blobs = [
106                                 config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
107                                 for i in xrange(len(self._mainWindow.get_default_credentials()))
108                         ]
109                         isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
110                         tabIndex = config.getint(constants.__pretty_app_name__, "tab")
111                         isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
112                 except ConfigParser.NoOptionError, e:
113                         _moduleLogger.info(
114                                 "Settings file %s is missing option %s" % (
115                                         constants._user_settings_,
116                                         e.option,
117                                 ),
118                         )
119                 except ConfigParser.NoSectionError, e:
120                         _moduleLogger.info(
121                                 "Settings file %s is missing section %s" % (
122                                         constants._user_settings_,
123                                         e.section,
124                                 ),
125                         )
126                 except Exception:
127                         _moduleLogger.exception("Unknown loading error")
128
129                 if self._alarmHandler is not None:
130                         try:
131                                 self._alarmHandler.load_settings(config, "alarm")
132                                 self.notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
133                                 self.notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
134                                 self.notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
135                         except ConfigParser.NoOptionError, e:
136                                 _moduleLogger.info(
137                                         "Settings file %s is missing option %s" % (
138                                                 constants._user_settings_,
139                                                 e.option,
140                                         ),
141                                 )
142                         except ConfigParser.NoSectionError, e:
143                                 _moduleLogger.info(
144                                         "Settings file %s is missing section %s" % (
145                                                 constants._user_settings_,
146                                                 e.section,
147                                         ),
148                                 )
149                         except Exception:
150                                 _moduleLogger.exception("Unknown loading error")
151
152                 creds = (
153                         base64.b64decode(blob)
154                         for blob in blobs
155                 )
156                 self._mainWindow.set_default_credentials(*creds)
157                 self._fullscreenAction.setChecked(isFullscreen)
158                 self._orientationAction.setChecked(isPortrait)
159                 self._mainWindow.set_current_tab(tabIndex)
160                 self._mainWindow.load_settings(config)
161
162         def save_settings(self):
163                 _moduleLogger.info("Saving settings")
164                 config = ConfigParser.SafeConfigParser()
165
166                 config.add_section(constants.__pretty_app_name__)
167                 config.set(constants.__pretty_app_name__, "tab", str(self._mainWindow.get_current_tab()))
168                 config.set(constants.__pretty_app_name__, "fullscreen", str(self._fullscreenAction.isChecked()))
169                 config.set(constants.__pretty_app_name__, "portrait", str(self._orientationAction.isChecked()))
170                 for i, value in enumerate(self._mainWindow.get_default_credentials()):
171                         blob = base64.b64encode(value)
172                         config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
173
174                 if self._alarmHandler is not None:
175                         config.add_section("alarm")
176                         self._alarmHandler.save_settings(config, "alarm")
177                 config.add_section("2 - Account Info")
178                 config.set("2 - Account Info", "notifyOnMissed", repr(self.notifyOnMissed))
179                 config.set("2 - Account Info", "notifyOnVoicemail", repr(self.notifyOnVoicemail))
180                 config.set("2 - Account Info", "notifyOnSms", repr(self.notifyOnSms))
181
182                 self._mainWindow.save_settings(config)
183
184                 with open(constants._user_settings_, "wb") as configFile:
185                         config.write(configFile)
186
187         def get_icon(self, name):
188                 if self._dataPath is None:
189                         for path in self._DATA_PATHS:
190                                 if os.path.exists(os.path.join(path, name)):
191                                         self._dataPath = path
192                                         break
193                 if self._dataPath is not None:
194                         icon = QtGui.QIcon(os.path.join(self._dataPath, name))
195                         return icon
196                 else:
197                         return None
198
199         def get_resource(self, name):
200                 if self._dataPath is None:
201                         for path in self._DATA_PATHS:
202                                 if os.path.exists(os.path.join(path, name)):
203                                         self._dataPath = path
204                                         break
205                 if self._dataPath is not None:
206                         return os.path.join(self._dataPath, name)
207                 else:
208                         return None
209
210         def _close_windows(self):
211                 qwrappers.ApplicationWrapper._close_windows(self)
212                 if self._aboutDialog  is not None:
213                         self._aboutDialog.close()
214
215         @property
216         def fsContactsPath(self):
217                 return os.path.join(constants._data_path_, "contacts")
218
219         @property
220         def alarmHandler(self):
221                 return self._alarmHandler
222
223         @property
224         def ledHandler(self):
225                 return self._ledHandler
226
227         def _new_main_window(self):
228                 return MainWindow(None, self)
229
230         @QtCore.pyqtSlot()
231         @QtCore.pyqtSlot(bool)
232         @misc_utils.log_exception(_moduleLogger)
233         def _on_about(self, checked = True):
234                 with qui_utils.notify_error(self._errorLog):
235                         if self._aboutDialog is None:
236                                 import dialogs
237                                 self._aboutDialog = dialogs.AboutDialog(self)
238                         response = self._aboutDialog.run(self._mainWindow.window)
239
240
241 class DelayedWidget(object):
242
243         def __init__(self, app, settingsNames):
244                 self._layout = QtGui.QVBoxLayout()
245                 self._layout.setContentsMargins(0, 0, 0, 0)
246                 self._widget = QtGui.QWidget()
247                 self._widget.setContentsMargins(0, 0, 0, 0)
248                 self._widget.setLayout(self._layout)
249                 self._settings = dict((name, "") for name in settingsNames)
250
251                 self._child = None
252                 self._isEnabled = True
253
254         @property
255         def toplevel(self):
256                 return self._widget
257
258         def has_child(self):
259                 return self._child is not None
260
261         def set_child(self, child):
262                 if self._child is not None:
263                         self._layout.removeWidget(self._child.toplevel)
264                 self._child = child
265                 if self._child is not None:
266                         self._layout.addWidget(self._child.toplevel)
267
268                 self._child.set_settings(self._settings)
269
270                 if self._isEnabled:
271                         self._child.enable()
272                 else:
273                         self._child.disable()
274
275         @property
276         def child(self):
277                 return self._child
278
279         def enable(self):
280                 self._isEnabled = True
281                 if self._child is not None:
282                         self._child.enable()
283
284         def disable(self):
285                 self._isEnabled = False
286                 if self._child is not None:
287                         self._child.disable()
288
289         def clear(self):
290                 if self._child is not None:
291                         self._child.clear()
292
293         def refresh(self, force=True):
294                 if self._child is not None:
295                         self._child.refresh(force)
296
297         def get_settings(self):
298                 if self._child is not None:
299                         return self._child.get_settings()
300                 else:
301                         return self._settings
302
303         def set_settings(self, settings):
304                 if self._child is not None:
305                         self._child.set_settings(settings)
306                 else:
307                         self._settings = settings
308
309
310 def _tab_factory(tab, app, session, errorLog):
311         import gv_views
312         return gv_views.__dict__[tab](app, session, errorLog)
313
314
315 class MainWindow(qwrappers.WindowWrapper):
316
317         KEYPAD_TAB = 0
318         RECENT_TAB = 1
319         MESSAGES_TAB = 2
320         CONTACTS_TAB = 3
321         MAX_TABS = 4
322
323         _TAB_TITLES = [
324                 "Dialpad",
325                 "History",
326                 "Messages",
327                 "Contacts",
328         ]
329         assert len(_TAB_TITLES) == MAX_TABS
330
331         _TAB_ICONS = [
332                 "dialpad.png",
333                 "history.png",
334                 "messages.png",
335                 "contacts.png",
336         ]
337         assert len(_TAB_ICONS) == MAX_TABS
338
339         _TAB_CLASS = [
340                 functools.partial(_tab_factory, "Dialpad"),
341                 functools.partial(_tab_factory, "History"),
342                 functools.partial(_tab_factory, "Messages"),
343                 functools.partial(_tab_factory, "Contacts"),
344         ]
345         assert len(_TAB_CLASS) == MAX_TABS
346
347         # Hack to allow delay importing/loading of tabs
348         _TAB_SETTINGS_NAMES = [
349                 (),
350                 ("filter", ),
351                 ("status", "type"),
352                 ("selectedAddressbook", ),
353         ]
354         assert len(_TAB_SETTINGS_NAMES) == MAX_TABS
355
356         def __init__(self, parent, app):
357                 qwrappers.WindowWrapper.__init__(self, parent, app)
358                 self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
359                 self._errorLog = self._app.errorLog
360
361                 self._session = session.Session(self._errorLog, constants._data_path_)
362                 self._session.error.connect(self._on_session_error)
363                 self._session.loggedIn.connect(self._on_login)
364                 self._session.loggedOut.connect(self._on_logout)
365                 self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
366                 self._voicemailRefreshDelay = QtCore.QTimer()
367                 self._voicemailRefreshDelay.setInterval(30 * 1000)
368                 self._voicemailRefreshDelay.timeout.connect(self._on_call_missed)
369                 self._voicemailRefreshDelay.setSingleShot(True)
370                 self._callHandler = call_handler.MissedCallWatcher()
371                 self._callHandler.callMissed.connect(self._voicemailRefreshDelay.start)
372                 self._session.newMessages.connect(self._on_new_message_alert)
373                 self._defaultCredentials = "", ""
374                 self._curentCredentials = "", ""
375                 self._currentTab = 0
376
377                 self._credentialsDialog = None
378                 self._smsEntryDialog = None
379                 self._accountDialog = None
380
381                 self._tabsContents = [
382                         DelayedWidget(self._app, self._TAB_SETTINGS_NAMES[i])
383                         for i in xrange(self.MAX_TABS)
384                 ]
385                 for tab in self._tabsContents:
386                         tab.disable()
387
388                 self._tabWidget = QtGui.QTabWidget()
389                 if qui_utils.screen_orientation() == QtCore.Qt.Vertical:
390                         self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
391                 else:
392                         self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
393                 defaultTabIconSize = self._tabWidget.iconSize()
394                 defaultTabIconWidth, defaultTabIconHeight = defaultTabIconSize.width(), defaultTabIconSize.height()
395                 for tabIndex, (tabTitle, tabIcon) in enumerate(
396                         zip(self._TAB_TITLES, self._TAB_ICONS)
397                 ):
398                         icon = self._app.get_icon(tabIcon)
399                         if constants.IS_MAEMO and icon is not None:
400                                 tabTitle = ""
401
402                         if icon is None:
403                                 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, tabTitle)
404                         else:
405                                 iconSize = icon.availableSizes()[0]
406                                 defaultTabIconWidth = max(defaultTabIconWidth, iconSize.width())
407                                 defaultTabIconHeight = max(defaultTabIconHeight, iconSize.height())
408                                 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, tabTitle)
409                 defaultTabIconWidth = max(defaultTabIconWidth, 32)
410                 defaultTabIconHeight = max(defaultTabIconHeight, 32)
411                 self._tabWidget.setIconSize(QtCore.QSize(defaultTabIconWidth, defaultTabIconHeight))
412                 self._tabWidget.currentChanged.connect(self._on_tab_changed)
413                 self._tabWidget.setContentsMargins(0, 0, 0, 0)
414
415                 self._layout.addWidget(self._tabWidget)
416
417                 self._loginTabAction = QtGui.QAction(None)
418                 self._loginTabAction.setText("Login")
419                 self._loginTabAction.triggered.connect(self._on_login_requested)
420
421                 self._importTabAction = QtGui.QAction(None)
422                 self._importTabAction.setText("Import")
423                 self._importTabAction.triggered.connect(self._on_import)
424
425                 self._accountTabAction = QtGui.QAction(None)
426                 self._accountTabAction.setText("Account")
427                 self._accountTabAction.triggered.connect(self._on_account)
428
429                 self._refreshTabAction = QtGui.QAction(None)
430                 self._refreshTabAction.setText("Refresh")
431                 self._refreshTabAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
432                 self._refreshTabAction.triggered.connect(self._on_refresh)
433
434                 fileMenu = self._window.menuBar().addMenu("&File")
435                 fileMenu.addAction(self._loginTabAction)
436                 fileMenu.addAction(self._refreshTabAction)
437
438                 toolsMenu = self._window.menuBar().addMenu("&Tools")
439                 toolsMenu.addAction(self._accountTabAction)
440                 toolsMenu.addAction(self._importTabAction)
441                 toolsMenu.addAction(self._app.aboutAction)
442
443                 self._initialize_tab(self._tabWidget.currentIndex())
444                 self.set_fullscreen(self._app.fullscreenAction.isChecked())
445                 self.set_orientation(self._app.orientationAction.isChecked())
446
447         def set_default_credentials(self, username, password):
448                 self._defaultCredentials = username, password
449
450         def get_default_credentials(self):
451                 return self._defaultCredentials
452
453         def walk_children(self):
454                 if self._smsEntryDialog is not None:
455                         return (self._smsEntryDialog, )
456                 else:
457                         return ()
458
459         def start(self):
460                 qwrappers.WindowWrapper.start(self)
461                 assert self._session.state == self._session.LOGGEDOUT_STATE, "Initialization messed up"
462                 if self._defaultCredentials != ("", ""):
463                         username, password = self._defaultCredentials[0], self._defaultCredentials[1]
464                         self._curentCredentials = username, password
465                         self._session.login(username, password)
466                 else:
467                         self._prompt_for_login()
468
469         def close(self):
470                 for diag in (
471                         self._credentialsDialog,
472                         self._accountDialog,
473                 ):
474                         if diag is not None:
475                                 diag.close()
476                 for child in self.walk_children():
477                         child.window.destroyed.disconnect(self._on_child_close)
478                         child.window.closed.disconnect(self._on_child_close)
479                         child.close()
480                 self._window.close()
481
482         def destroy(self):
483                 qwrappers.WindowWrapper.destroy(self)
484                 if self._session.state != self._session.LOGGEDOUT_STATE:
485                         self._session.logout()
486
487         def get_current_tab(self):
488                 return self._currentTab
489
490         def set_current_tab(self, tabIndex):
491                 self._tabWidget.setCurrentIndex(tabIndex)
492
493         def load_settings(self, config):
494                 backendId = 2 # For backwards compatibility
495                 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
496                         sectionName = "%s - %s" % (backendId, tabTitle)
497                         settings = self._tabsContents[tabIndex].get_settings()
498                         for settingName in settings.iterkeys():
499                                 try:
500                                         settingValue = config.get(sectionName, settingName)
501                                 except ConfigParser.NoOptionError, e:
502                                         _moduleLogger.info(
503                                                 "Settings file %s is missing section %s" % (
504                                                         constants._user_settings_,
505                                                         e.section,
506                                                 ),
507                                         )
508                                         return
509                                 except ConfigParser.NoSectionError, e:
510                                         _moduleLogger.info(
511                                                 "Settings file %s is missing section %s" % (
512                                                         constants._user_settings_,
513                                                         e.section,
514                                                 ),
515                                         )
516                                         return
517                                 except Exception:
518                                         _moduleLogger.exception("Unknown loading error")
519                                         return
520                                 settings[settingName] = settingValue
521                         self._tabsContents[tabIndex].set_settings(settings)
522
523         def save_settings(self, config):
524                 backendId = 2 # For backwards compatibility
525                 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
526                         sectionName = "%s - %s" % (backendId, tabTitle)
527                         config.add_section(sectionName)
528                         tabSettings = self._tabsContents[tabIndex].get_settings()
529                         for settingName, settingValue in tabSettings.iteritems():
530                                 config.set(sectionName, settingName, settingValue)
531
532         def set_orientation(self, isPortrait):
533                 qwrappers.WindowWrapper.set_orientation(self, isPortrait)
534                 if isPortrait:
535                         self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
536                 else:
537                         self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
538
539         def _initialize_tab(self, index):
540                 assert index < self.MAX_TABS, "Invalid tab"
541                 if not self._tabsContents[index].has_child():
542                         tab = self._TAB_CLASS[index](self._app, self._session, self._errorLog)
543                         self._tabsContents[index].set_child(tab)
544                 self._tabsContents[index].refresh(force=False)
545
546         def _prompt_for_login(self):
547                 if self._credentialsDialog is None:
548                         import dialogs
549                         self._credentialsDialog = dialogs.CredentialsDialog(self._app)
550                 credentials = self._credentialsDialog.run(
551                         self._defaultCredentials[0], self._defaultCredentials[1], self.window
552                 )
553                 if credentials is None:
554                         return
555                 username, password = credentials
556                 self._curentCredentials = username, password
557                 self._session.login(username, password)
558
559         def _show_account_dialog(self):
560                 if self._accountDialog is None:
561                         import dialogs
562                         self._accountDialog = dialogs.AccountDialog(self._app)
563                         if self._app.alarmHandler is None:
564                                 self._accountDialog.setIfNotificationsSupported(False)
565                 if self._app.alarmHandler is not None:
566                         self._accountDialog.notifications = self._app.alarmHandler.isEnabled
567                         self._accountDialog.notificationTime = self._app.alarmHandler.recurrence
568                         self._accountDialog.notifyOnMissed = self._app.notifyOnMissed
569                         self._accountDialog.notifyOnVoicemail = self._app.notifyOnVoicemail
570                         self._accountDialog.notifyOnSms = self._app.notifyOnSms
571                 self._accountDialog.set_callbacks(
572                         self._session.get_callback_numbers(), self._session.get_callback_number()
573                 )
574                 accountNumberToDisplay = self._session.get_account_number()
575                 if not accountNumberToDisplay:
576                         accountNumberToDisplay = "Not Available (%s)" % self._session.state
577                 self._accountDialog.set_account_number(accountNumberToDisplay)
578                 response = self._accountDialog.run(self.window)
579                 if response == QtGui.QDialog.Accepted:
580                         if self._accountDialog.doClear:
581                                 self._session.logout_and_clear()
582                                 self._defaultCredentials = "", ""
583                                 self._curentCredentials = "", ""
584                                 for tab in self._tabsContents:
585                                         tab.disable()
586                         else:
587                                 callbackNumber = self._accountDialog.selectedCallback
588                                 self._session.set_callback_number(callbackNumber)
589                         if self._app.alarmHandler is not None:
590                                 self._app.alarmHandler.apply_settings(self._accountDialog.notifications, self._accountDialog.notificationTime)
591                                 self._app.notifyOnMissed = self._accountDialog.notifyOnMissed
592                                 self._app.notifyOnVoicemail = self._accountDialog.notifyOnVoicemail
593                                 self._app.notifyOnSms = self._accountDialog.notifyOnSms
594                                 self._app.save_settings()
595                 elif response == QtGui.QDialog.Rejected:
596                         _moduleLogger.info("Cancelled")
597                 else:
598                         _moduleLogger.info("Unknown response")
599
600         @QtCore.pyqtSlot()
601         @misc_utils.log_exception(_moduleLogger)
602         def _on_call_missed(self):
603                 with qui_utils.notify_error(self._errorLog):
604                         self._session.update_messages(True)
605
606         @QtCore.pyqtSlot()
607         @misc_utils.log_exception(_moduleLogger)
608         def _on_new_message_alert(self):
609                 with qui_utils.notify_error(self._errorLog):
610                         self._errorLog.push_message("New messages available")
611
612         @QtCore.pyqtSlot(str)
613         @misc_utils.log_exception(_moduleLogger)
614         def _on_session_error(self, message):
615                 with qui_utils.notify_error(self._errorLog):
616                         self._errorLog.push_error(message)
617
618         @QtCore.pyqtSlot()
619         @misc_utils.log_exception(_moduleLogger)
620         def _on_login(self):
621                 with qui_utils.notify_error(self._errorLog):
622                         changedAccounts = self._defaultCredentials != self._curentCredentials
623                         noCallback = not self._session.get_callback_number()
624                         if changedAccounts or noCallback:
625                                 self._show_account_dialog()
626
627                         self._defaultCredentials = self._curentCredentials
628
629                         for tab in self._tabsContents:
630                                 tab.enable()
631                         self._initialize_tab(self._currentTab)
632                         self._callHandler.start()
633
634         @QtCore.pyqtSlot()
635         @misc_utils.log_exception(_moduleLogger)
636         def _on_logout(self):
637                 with qui_utils.notify_error(self._errorLog):
638                         for tab in self._tabsContents:
639                                 tab.disable()
640                         self._callHandler.stop()
641
642         @QtCore.pyqtSlot()
643         @misc_utils.log_exception(_moduleLogger)
644         def _on_recipients_changed(self):
645                 with qui_utils.notify_error(self._errorLog):
646                         if self._session.draft.get_num_contacts() == 0:
647                                 return
648
649                         if self._smsEntryDialog is None:
650                                 import dialogs
651                                 self._smsEntryDialog = dialogs.SMSEntryWindow(self.window, self._app, self._session, self._errorLog)
652                                 self._smsEntryDialog.window.destroyed.connect(self._on_child_close)
653                                 self._smsEntryDialog.window.closed.connect(self._on_child_close)
654                                 self._smsEntryDialog.window.show()
655
656         @misc_utils.log_exception(_moduleLogger)
657         def _on_child_close(self, obj = None):
658                 self._smsEntryDialog = None
659
660         @QtCore.pyqtSlot()
661         @QtCore.pyqtSlot(bool)
662         @misc_utils.log_exception(_moduleLogger)
663         def _on_login_requested(self, checked = True):
664                 with qui_utils.notify_error(self._errorLog):
665                         self._prompt_for_login()
666
667         @QtCore.pyqtSlot(int)
668         @misc_utils.log_exception(_moduleLogger)
669         def _on_tab_changed(self, index):
670                 with qui_utils.notify_error(self._errorLog):
671                         self._currentTab = index
672                         self._initialize_tab(index)
673
674         @QtCore.pyqtSlot()
675         @QtCore.pyqtSlot(bool)
676         @misc_utils.log_exception(_moduleLogger)
677         def _on_refresh(self, checked = True):
678                 with qui_utils.notify_error(self._errorLog):
679                         self._tabsContents[self._currentTab].refresh(force=True)
680
681         @QtCore.pyqtSlot()
682         @QtCore.pyqtSlot(bool)
683         @misc_utils.log_exception(_moduleLogger)
684         def _on_import(self, checked = True):
685                 with qui_utils.notify_error(self._errorLog):
686                         csvName = QtGui.QFileDialog.getOpenFileName(self._window, caption="Import", filter="CSV Files (*.csv)")
687                         csvName = unicode(csvName)
688                         if not csvName:
689                                 return
690                         import shutil
691                         shutil.copy2(csvName, self._app.fsContactsPath)
692                         if self._tabsContents[self.CONTACTS_TAB].has_child:
693                                 self._tabsContents[self.CONTACTS_TAB].child.update_addressbooks()
694
695         @QtCore.pyqtSlot()
696         @QtCore.pyqtSlot(bool)
697         @misc_utils.log_exception(_moduleLogger)
698         def _on_account(self, checked = True):
699                 with qui_utils.notify_error(self._errorLog):
700                         assert self._session.state == self._session.LOGGEDIN_STATE, "Must be logged in for settings"
701                         self._show_account_dialog()
702
703
704 def run():
705         app = QtGui.QApplication([])
706         l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
707         handle = Dialcentral(app)
708         qtpie.init_pies()
709         return app.exec_()
710
711
712 if __name__ == "__main__":
713         import sys
714
715         logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
716         logging.basicConfig(level=logging.DEBUG, format=logFormat)
717         try:
718                 os.makedirs(constants._data_path_)
719         except OSError, e:
720                 if e.errno != 17:
721                         raise
722
723         val = run()
724         sys.exit(val)