4 from __future__ import with_statement
11 import logging.handlers
13 import util.qt_compat as qt_compat
14 QtCore = qt_compat.QtCore
15 QtGui = qt_compat.import_module("QtGui")
19 from util import qtpie
20 from util import qwrappers
21 from util import qui_utils
22 from util import linux as linux_utils
23 from util import misc as misc_utils
28 _moduleLogger = logging.getLogger(__name__)
31 class Dialcentral(qwrappers.ApplicationWrapper):
34 os.path.join(os.path.dirname(__file__), "data"),
37 def __init__(self, app):
39 self._aboutDialog = None
40 self.notifyOnMissed = False
41 self.notifyOnVoicemail = False
42 self.notifyOnSms = False
44 self._streamHandler = None
45 self._ledHandler = None
46 self._alarmHandler = alarm_handler.AlarmHandler()
48 qwrappers.ApplicationWrapper.__init__(self, app, constants)
50 def load_settings(self):
52 settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
53 config = ConfigParser.SafeConfigParser()
54 config.read(settingsPath)
56 _moduleLogger.info("No settings")
59 _moduleLogger.info("Settings were corrupt")
61 except ConfigParser.MissingSectionHeaderError:
62 _moduleLogger.info("Settings were corrupt")
65 _moduleLogger.exception("Unknown loading error")
67 self._mainWindow.load_settings(config)
69 def save_settings(self):
70 _moduleLogger.info("Saving settings")
71 config = ConfigParser.SafeConfigParser()
73 self._mainWindow.save_settings(config)
75 settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
76 with open(settingsPath, "wb") as configFile:
77 config.write(configFile)
79 def get_icon(self, name):
80 if self._dataPath is None:
81 for path in self._DATA_PATHS:
82 if os.path.exists(os.path.join(path, name)):
85 if self._dataPath is not None:
86 icon = QtGui.QIcon(os.path.join(self._dataPath, name))
91 def get_resource(self, name):
92 if self._dataPath is None:
93 for path in self._DATA_PATHS:
94 if os.path.exists(os.path.join(path, name)):
97 if self._dataPath is not None:
98 return os.path.join(self._dataPath, name)
102 def _close_windows(self):
103 qwrappers.ApplicationWrapper._close_windows(self)
104 if self._aboutDialog is not None:
105 self._aboutDialog.close()
108 def fsContactsPath(self):
109 return linux_utils.get_resource_path("data", constants.__app_name__, "contacts")
112 def streamHandler(self):
113 if self._streamHandler is None:
114 import stream_handler
115 self._streamHandler = stream_handler.StreamHandler()
116 return self._streamHandler
119 def alarmHandler(self):
120 return self._alarmHandler
123 def ledHandler(self):
124 if self._ledHandler is None:
126 self._ledHandler = led_handler.LedHandler()
127 return self._ledHandler
129 def _new_main_window(self):
130 return MainWindow(None, self)
133 @qt_compat.Slot(bool)
134 @misc_utils.log_exception(_moduleLogger)
135 def _on_about(self, checked = True):
136 with qui_utils.notify_error(self._errorLog):
137 if self._aboutDialog is None:
139 self._aboutDialog = dialogs.AboutDialog(self)
140 response = self._aboutDialog.run(self._mainWindow.window)
143 class DelayedWidget(object):
145 def __init__(self, app, settingsNames):
146 self._layout = QtGui.QVBoxLayout()
147 self._layout.setContentsMargins(0, 0, 0, 0)
148 self._widget = QtGui.QWidget()
149 self._widget.setContentsMargins(0, 0, 0, 0)
150 self._widget.setLayout(self._layout)
151 self._settings = dict((name, "") for name in settingsNames)
154 self._isEnabled = True
161 return self._child is not None
163 def set_child(self, child):
164 if self._child is not None:
165 self._layout.removeWidget(self._child.toplevel)
167 if self._child is not None:
168 self._layout.addWidget(self._child.toplevel)
170 self._child.set_settings(self._settings)
175 self._child.disable()
182 self._isEnabled = True
183 if self._child is not None:
187 self._isEnabled = False
188 if self._child is not None:
189 self._child.disable()
192 if self._child is not None:
195 def refresh(self, force=True):
196 if self._child is not None:
197 self._child.refresh(force)
199 def get_settings(self):
200 if self._child is not None:
201 return self._child.get_settings()
203 return self._settings
205 def set_settings(self, settings):
206 if self._child is not None:
207 self._child.set_settings(settings)
209 self._settings = settings
212 def _tab_factory(tab, app, session, errorLog):
214 return gv_views.__dict__[tab](app, session, errorLog)
217 class MainWindow(qwrappers.WindowWrapper):
231 assert len(_TAB_TITLES) == MAX_TABS
239 assert len(_TAB_ICONS) == MAX_TABS
242 functools.partial(_tab_factory, "Dialpad"),
243 functools.partial(_tab_factory, "History"),
244 functools.partial(_tab_factory, "Messages"),
245 functools.partial(_tab_factory, "Contacts"),
247 assert len(_TAB_CLASS) == MAX_TABS
249 # Hack to allow delay importing/loading of tabs
250 _TAB_SETTINGS_NAMES = [
254 ("selectedAddressbook", ),
256 assert len(_TAB_SETTINGS_NAMES) == MAX_TABS
258 def __init__(self, parent, app):
259 qwrappers.WindowWrapper.__init__(self, parent, app)
260 self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
261 self._window.resized.connect(self._on_window_resized)
262 self._errorLog = self._app.errorLog
264 cachePath = linux_utils.get_resource_path("cache", constants.__app_name__)
265 self._session = session.Session(self._errorLog, cachePath)
266 self._session.error.connect(self._on_session_error)
267 self._session.loggedIn.connect(self._on_login)
268 self._session.loggedOut.connect(self._on_logout)
269 self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
270 self._session.newMessages.connect(self._on_new_message_alert)
271 self._app.alarmHandler.applicationNotifySignal.connect(self._on_app_alert)
272 self._voicemailRefreshDelay = QtCore.QTimer()
273 self._voicemailRefreshDelay.setInterval(30 * 1000)
274 self._voicemailRefreshDelay.timeout.connect(self._on_call_missed)
275 self._voicemailRefreshDelay.setSingleShot(True)
276 self._callHandler = None
277 self._updateVoicemailOnMissedCall = False
279 self._defaultCredentials = "", ""
280 self._curentCredentials = "", ""
283 self._credentialsDialog = None
284 self._smsEntryDialog = None
285 self._accountDialog = None
287 self._tabsContents = [
288 DelayedWidget(self._app, self._TAB_SETTINGS_NAMES[i])
289 for i in xrange(self.MAX_TABS)
291 for tab in self._tabsContents:
294 self._tabWidget = QtGui.QTabWidget()
295 if qui_utils.screen_orientation() == QtCore.Qt.Vertical:
296 self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
298 self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
299 defaultTabIconSize = self._tabWidget.iconSize()
300 defaultTabIconWidth, defaultTabIconHeight = defaultTabIconSize.width(), defaultTabIconSize.height()
301 for tabIndex, (tabTitle, tabIcon) in enumerate(
302 zip(self._TAB_TITLES, self._TAB_ICONS)
304 icon = self._app.get_icon(tabIcon)
305 if constants.IS_MAEMO and icon is not None:
309 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, tabTitle)
311 iconSize = icon.availableSizes()[0]
312 defaultTabIconWidth = max(defaultTabIconWidth, iconSize.width())
313 defaultTabIconHeight = max(defaultTabIconHeight, iconSize.height())
314 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, tabTitle)
315 defaultTabIconWidth = max(defaultTabIconWidth, 32)
316 defaultTabIconHeight = max(defaultTabIconHeight, 32)
317 self._tabWidget.setIconSize(QtCore.QSize(defaultTabIconWidth, defaultTabIconHeight))
318 self._tabWidget.currentChanged[int].connect(self._on_tab_changed)
319 self._tabWidget.setContentsMargins(0, 0, 0, 0)
321 self._layout.addWidget(self._tabWidget)
323 self._loginAction = QtGui.QAction(None)
324 self._loginAction.setText("Login")
325 self._loginAction.triggered.connect(self._on_login_requested)
327 self._importAction = QtGui.QAction(None)
328 self._importAction.setText("Import")
329 self._importAction.triggered.connect(self._on_import)
331 self._accountAction = QtGui.QAction(None)
332 self._accountAction.setText("Account")
333 self._accountAction.triggered.connect(self._on_account)
335 self._refreshConnectionAction = QtGui.QAction(None)
336 self._refreshConnectionAction.setText("Refresh Connection")
337 self._refreshConnectionAction.setShortcut(QtGui.QKeySequence("CTRL+a"))
338 self._refreshConnectionAction.triggered.connect(self._on_refresh_connection)
340 self._refreshTabAction = QtGui.QAction(None)
341 self._refreshTabAction.setText("Refresh Tab")
342 self._refreshTabAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
343 self._refreshTabAction.triggered.connect(self._on_refresh)
345 fileMenu = self._window.menuBar().addMenu("&File")
346 fileMenu.addAction(self._loginAction)
347 fileMenu.addAction(self._refreshTabAction)
348 fileMenu.addAction(self._refreshConnectionAction)
350 toolsMenu = self._window.menuBar().addMenu("&Tools")
351 toolsMenu.addAction(self._accountAction)
352 toolsMenu.addAction(self._importAction)
353 toolsMenu.addAction(self._app.aboutAction)
355 self._initialize_tab(self._tabWidget.currentIndex())
356 self.set_fullscreen(self._app.fullscreenAction.isChecked())
357 self.update_orientation(self._app.orientation)
359 def _init_call_handler(self):
360 if self._callHandler is not None:
363 self._callHandler = call_handler.MissedCallWatcher()
364 self._callHandler.callMissed.connect(self._voicemailRefreshDelay.start)
366 def set_default_credentials(self, username, password):
367 self._defaultCredentials = username, password
369 def get_default_credentials(self):
370 return self._defaultCredentials
372 def walk_children(self):
373 if self._smsEntryDialog is not None:
374 return (self._smsEntryDialog, )
379 qwrappers.WindowWrapper.start(self)
380 assert self._session.state == self._session.LOGGEDOUT_STATE, "Initialization messed up"
381 if self._defaultCredentials != ("", ""):
382 username, password = self._defaultCredentials[0], self._defaultCredentials[1]
383 self._curentCredentials = username, password
384 self._session.login(username, password)
386 self._prompt_for_login()
390 self._credentialsDialog,
395 for child in self.walk_children():
396 child.window.destroyed.disconnect(self._on_child_close)
397 child.window.closed.disconnect(self._on_child_close)
402 qwrappers.WindowWrapper.destroy(self)
403 if self._session.state != self._session.LOGGEDOUT_STATE:
404 self._session.logout()
406 def get_current_tab(self):
407 return self._currentTab
409 def set_current_tab(self, tabIndex):
410 self._tabWidget.setCurrentIndex(tabIndex)
412 def load_settings(self, config):
415 orientation = self._app.orientation
419 config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
420 for i in xrange(len(self.get_default_credentials()))
422 isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
423 tabIndex = config.getint(constants.__pretty_app_name__, "tab")
424 orientation = config.get(constants.__pretty_app_name__, "orientation")
425 except ConfigParser.NoOptionError, e:
427 "Settings file is missing option %s" % (
431 except ConfigParser.NoSectionError, e:
433 "Settings file is missing section %s" % (
438 _moduleLogger.exception("Unknown loading error")
441 self._app.alarmHandler.load_settings(config, "alarm")
442 self._app.notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
443 self._app.notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
444 self._app.notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
445 self._updateVoicemailOnMissedCall = config.getboolean("2 - Account Info", "updateVoicemailOnMissedCall")
446 except ConfigParser.NoOptionError, e:
448 "Settings file is missing option %s" % (
452 except ConfigParser.NoSectionError, e:
454 "Settings file is missing section %s" % (
459 _moduleLogger.exception("Unknown loading error")
462 base64.b64decode(blob)
465 self.set_default_credentials(*creds)
466 self._app.fullscreenAction.setChecked(isFullscreen)
467 self._app.set_orientation(orientation)
468 self.set_current_tab(tabIndex)
470 backendId = 2 # For backwards compatibility
471 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
472 sectionName = "%s - %s" % (backendId, tabTitle)
473 settings = self._tabsContents[tabIndex].get_settings()
474 for settingName in settings.iterkeys():
476 settingValue = config.get(sectionName, settingName)
477 except ConfigParser.NoOptionError, e:
479 "Settings file is missing section %s" % (
484 except ConfigParser.NoSectionError, e:
486 "Settings file is missing section %s" % (
492 _moduleLogger.exception("Unknown loading error")
494 settings[settingName] = settingValue
495 self._tabsContents[tabIndex].set_settings(settings)
497 def save_settings(self, config):
498 config.add_section(constants.__pretty_app_name__)
499 config.set(constants.__pretty_app_name__, "tab", str(self.get_current_tab()))
500 config.set(constants.__pretty_app_name__, "fullscreen", str(self._app.fullscreenAction.isChecked()))
501 config.set(constants.__pretty_app_name__, "orientation", str(self._app.orientation))
502 for i, value in enumerate(self.get_default_credentials()):
503 blob = base64.b64encode(value)
504 config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
506 config.add_section("alarm")
507 self._app.alarmHandler.save_settings(config, "alarm")
508 config.add_section("2 - Account Info")
509 config.set("2 - Account Info", "notifyOnMissed", repr(self._app.notifyOnMissed))
510 config.set("2 - Account Info", "notifyOnVoicemail", repr(self._app.notifyOnVoicemail))
511 config.set("2 - Account Info", "notifyOnSms", repr(self._app.notifyOnSms))
512 config.set("2 - Account Info", "updateVoicemailOnMissedCall", repr(self._updateVoicemailOnMissedCall))
514 backendId = 2 # For backwards compatibility
515 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
516 sectionName = "%s - %s" % (backendId, tabTitle)
517 config.add_section(sectionName)
518 tabSettings = self._tabsContents[tabIndex].get_settings()
519 for settingName, settingValue in tabSettings.iteritems():
520 config.set(sectionName, settingName, settingValue)
522 def update_orientation(self, orientation):
523 qwrappers.WindowWrapper.update_orientation(self, orientation)
524 windowOrientation = self.idealWindowOrientation
525 if windowOrientation == QtCore.Qt.Horizontal:
526 self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
528 self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
530 def _initialize_tab(self, index):
531 assert index < self.MAX_TABS, "Invalid tab"
532 if not self._tabsContents[index].has_child():
533 tab = self._TAB_CLASS[index](self._app, self._session, self._errorLog)
534 self._tabsContents[index].set_child(tab)
535 self._tabsContents[index].refresh(force=False)
537 def _prompt_for_login(self):
538 if self._credentialsDialog is None:
540 self._credentialsDialog = dialogs.CredentialsDialog(self._app)
541 credentials = self._credentialsDialog.run(
542 self._defaultCredentials[0], self._defaultCredentials[1], self.window
544 if credentials is None:
546 username, password = credentials
547 self._curentCredentials = username, password
548 self._session.login(username, password)
550 def _show_account_dialog(self):
551 if self._accountDialog is None:
553 self._accountDialog = dialogs.AccountDialog(self._window, self._app, self._app.errorLog)
554 self._accountDialog.setIfNotificationsSupported(self._app.alarmHandler.backgroundNotificationsSupported)
555 self._accountDialog.settingsApproved.connect(self._on_settings_approved)
557 if self._callHandler is not None and not self._callHandler.isSupported:
558 self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_NOT_SUPPORTED
559 elif self._updateVoicemailOnMissedCall:
560 self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_ENABLED
562 self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_DISABLED
563 self._accountDialog.notifications = self._app.alarmHandler.alarmType
564 self._accountDialog.notificationTime = self._app.alarmHandler.recurrence
565 self._accountDialog.notifyOnMissed = self._app.notifyOnMissed
566 self._accountDialog.notifyOnVoicemail = self._app.notifyOnVoicemail
567 self._accountDialog.notifyOnSms = self._app.notifyOnSms
568 self._accountDialog.set_callbacks(
569 self._session.get_callback_numbers(), self._session.get_callback_number()
571 accountNumberToDisplay = self._session.get_account_number()
572 if not accountNumberToDisplay:
573 accountNumberToDisplay = "Not Available (%s)" % self._session.state
574 self._accountDialog.set_account_number(accountNumberToDisplay)
575 self._accountDialog.orientation = self._app.orientation
577 self._accountDialog.run()
580 @misc_utils.log_exception(_moduleLogger)
581 def _on_settings_approved(self):
582 if self._accountDialog.doClear:
583 self._session.logout_and_clear()
584 self._defaultCredentials = "", ""
585 self._curentCredentials = "", ""
586 for tab in self._tabsContents:
589 callbackNumber = self._accountDialog.selectedCallback
590 self._session.set_callback_number(callbackNumber)
592 if self._accountDialog.updateVMOnMissedCall == self._accountDialog.VOICEMAIL_CHECK_NOT_SUPPORTED:
594 elif self._accountDialog.updateVMOnMissedCall == self._accountDialog.VOICEMAIL_CHECK_ENABLED:
595 self._updateVoicemailOnMissedCall = True
596 self._init_call_handler()
597 self._callHandler.start()
599 self._updateVoicemailOnMissedCall = False
600 if self._callHandler is not None:
601 self._callHandler.stop()
603 self._accountDialog.notifyOnMissed or
604 self._accountDialog.notifyOnVoicemail or
605 self._accountDialog.notifyOnSms
607 notifications = self._accountDialog.notifications
609 notifications = self._accountDialog.ALARM_NONE
610 self._app.alarmHandler.apply_settings(notifications, self._accountDialog.notificationTime)
612 self._app.notifyOnMissed = self._accountDialog.notifyOnMissed
613 self._app.notifyOnVoicemail = self._accountDialog.notifyOnVoicemail
614 self._app.notifyOnSms = self._accountDialog.notifyOnSms
615 self._app.set_orientation(self._accountDialog.orientation)
616 self._app.save_settings()
619 @misc_utils.log_exception(_moduleLogger)
620 def _on_window_resized(self):
621 with qui_utils.notify_error(self._app.errorLog):
622 windowOrientation = self.idealWindowOrientation
623 if windowOrientation == QtCore.Qt.Horizontal:
624 self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
626 self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
629 @misc_utils.log_exception(_moduleLogger)
630 def _on_new_message_alert(self):
631 with qui_utils.notify_error(self._errorLog):
632 if self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_APPLICATION:
633 if self._currentTab == self.MESSAGES_TAB or not self._app.ledHandler.isReal:
634 self._errorLog.push_message("New messages")
636 self._app.ledHandler.on()
639 @misc_utils.log_exception(_moduleLogger)
640 def _on_call_missed(self):
641 with qui_utils.notify_error(self._errorLog):
642 self._session.update_messages(self._session.MESSAGE_VOICEMAILS, force=True)
645 @misc_utils.log_exception(_moduleLogger)
646 def _on_session_error(self, message):
647 with qui_utils.notify_error(self._errorLog):
648 self._errorLog.push_error(message)
651 @misc_utils.log_exception(_moduleLogger)
653 with qui_utils.notify_error(self._errorLog):
654 changedAccounts = self._defaultCredentials != self._curentCredentials
655 noCallback = not self._session.get_callback_number()
656 if changedAccounts or noCallback:
657 self._show_account_dialog()
659 self._defaultCredentials = self._curentCredentials
661 for tab in self._tabsContents:
663 self._initialize_tab(self._currentTab)
664 if self._updateVoicemailOnMissedCall:
665 self._init_call_handler()
666 self._callHandler.start()
669 @misc_utils.log_exception(_moduleLogger)
670 def _on_logout(self):
671 with qui_utils.notify_error(self._errorLog):
672 for tab in self._tabsContents:
674 if self._callHandler is not None:
675 self._callHandler.stop()
678 @misc_utils.log_exception(_moduleLogger)
679 def _on_app_alert(self):
680 with qui_utils.notify_error(self._errorLog):
681 if self._session.state == self._session.LOGGEDIN_STATE:
683 (True, True): self._session.MESSAGE_ALL,
684 (True, False): self._session.MESSAGE_TEXTS,
685 (False, True): self._session.MESSAGE_VOICEMAILS,
686 }[(self._app.notifyOnSms, self._app.notifyOnVoicemail)]
687 self._session.update_messages(messageType, force=True)
690 @misc_utils.log_exception(_moduleLogger)
691 def _on_recipients_changed(self):
692 with qui_utils.notify_error(self._errorLog):
693 if self._session.draft.get_num_contacts() == 0:
696 if self._smsEntryDialog is None:
698 self._smsEntryDialog = dialogs.SMSEntryWindow(self.window, self._app, self._session, self._errorLog)
699 self._smsEntryDialog.window.destroyed.connect(self._on_child_close)
700 self._smsEntryDialog.window.closed.connect(self._on_child_close)
701 self._smsEntryDialog.window.show()
703 @misc_utils.log_exception(_moduleLogger)
704 def _on_child_close(self, obj = None):
705 self._smsEntryDialog = None
708 @qt_compat.Slot(bool)
709 @misc_utils.log_exception(_moduleLogger)
710 def _on_login_requested(self, checked = True):
711 with qui_utils.notify_error(self._errorLog):
712 self._prompt_for_login()
715 @misc_utils.log_exception(_moduleLogger)
716 def _on_tab_changed(self, index):
717 with qui_utils.notify_error(self._errorLog):
718 self._currentTab = index
719 self._initialize_tab(index)
720 if self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_APPLICATION:
721 self._app.ledHandler.off()
724 @qt_compat.Slot(bool)
725 @misc_utils.log_exception(_moduleLogger)
726 def _on_refresh(self, checked = True):
727 with qui_utils.notify_error(self._errorLog):
728 self._tabsContents[self._currentTab].refresh(force=True)
731 @qt_compat.Slot(bool)
732 @misc_utils.log_exception(_moduleLogger)
733 def _on_refresh_connection(self, checked = True):
734 with qui_utils.notify_error(self._errorLog):
735 self._session.refresh_connection()
738 @qt_compat.Slot(bool)
739 @misc_utils.log_exception(_moduleLogger)
740 def _on_import(self, checked = True):
741 with qui_utils.notify_error(self._errorLog):
742 csvName = QtGui.QFileDialog.getOpenFileName(self._window, caption="Import", filter="CSV Files (*.csv)")
743 csvName = unicode(csvName)
747 shutil.copy2(csvName, self._app.fsContactsPath)
748 if self._tabsContents[self.CONTACTS_TAB].has_child:
749 self._tabsContents[self.CONTACTS_TAB].child.update_addressbooks()
752 @qt_compat.Slot(bool)
753 @misc_utils.log_exception(_moduleLogger)
754 def _on_account(self, checked = True):
755 with qui_utils.notify_error(self._errorLog):
756 assert self._session.state == self._session.LOGGEDIN_STATE, "Must be logged in for settings"
757 self._show_account_dialog()
762 os.makedirs(linux_utils.get_resource_path("config", constants.__app_name__))
767 os.makedirs(linux_utils.get_resource_path("cache", constants.__app_name__))
772 os.makedirs(linux_utils.get_resource_path("data", constants.__app_name__))
777 logPath = linux_utils.get_resource_path("cache", constants.__app_name__, "%s.log" % constants.__app_name__)
778 logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
779 logging.basicConfig(level=logging.DEBUG, format=logFormat)
780 rotating = logging.handlers.RotatingFileHandler(logPath, maxBytes=512*1024, backupCount=1)
781 rotating.setFormatter(logging.Formatter(logFormat))
782 root = logging.getLogger()
783 root.addHandler(rotating)
784 _moduleLogger.info("%s %s-%s" % (constants.__app_name__, constants.__version__, constants.__build__))
785 _moduleLogger.info("OS: %s" % (os.uname()[0], ))
786 _moduleLogger.info("Kernel: %s (%s) for %s" % os.uname()[2:])
787 _moduleLogger.info("Hostname: %s" % os.uname()[1])
791 gobject.threads_init()
793 _moduleLogger.info("GObject support not available")
797 from dbus.mainloop.qt import DBusQtMainLoop
798 DBusQtMainLoop(set_as_default=True)
799 _moduleLogger.info("Using Qt mainloop")
802 from dbus.mainloop.glib import DBusGMainLoop
803 DBusGMainLoop(set_as_default=True)
804 _moduleLogger.info("Using GObject mainloop")
806 _moduleLogger.info("Mainloop not available")
808 _moduleLogger.info("DBus support not available")
810 app = QtGui.QApplication([])
811 handle = Dialcentral(app)
816 if __name__ == "__main__":