Fixing sms dialog
[gc-dialer] / src / dialcentral_qt.py
index cadafe0..da2a7a9 100755 (executable)
@@ -23,6 +23,30 @@ import session
 _moduleLogger = logging.getLogger(__name__)
 
 
+class LedWrapper(object):
+
+       def __init__(self):
+               self._ledHandler = None
+               self._init = False
+
+       def off(self):
+               self._lazy_init()
+               if self._ledHandler is not None:
+                       self._ledHandler.off()
+
+       def _lazy_init(self):
+               if self._init:
+                       return
+               self._init = True
+               try:
+                       import led_handler
+                       self._ledHandler = led_handler.LedHandler()
+               except Exception, e:
+                       _moduleLogger.exception('Unable to initialize LED Handling: "%s"' % str(e))
+                       self._ledHandler = None
+
+
+
 class Dialcentral(object):
 
        _DATA_PATHS = [
@@ -37,6 +61,7 @@ class Dialcentral(object):
                self._hiddenUnits = {}
                self._clipboard = QtGui.QApplication.clipboard()
                self._dataPath = None
+               self._ledHandler = LedWrapper()
                self.notifyOnMissed = False
                self.notifyOnVoicemail = False
                self.notifyOnSms = False
@@ -49,6 +74,12 @@ class Dialcentral(object):
                self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
                self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen)
 
+               self._orientationAction = QtGui.QAction(None)
+               self._orientationAction.setText("Orientation")
+               self._orientationAction.setCheckable(True)
+               self._orientationAction.setShortcut(QtGui.QKeySequence("CTRL+o"))
+               self._orientationAction.toggled.connect(self._on_toggle_orientation)
+
                self._logAction = QtGui.QAction(None)
                self._logAction.setText("Log")
                self._logAction.setShortcut(QtGui.QKeySequence("CTRL+l"))
@@ -104,6 +135,7 @@ class Dialcentral(object):
 
                blobs = "", ""
                isFullscreen = False
+               isPortrait = qui_utils.screen_orientation() == QtCore.Qt.Vertical
                tabIndex = 0
                try:
                        blobs = [
@@ -112,6 +144,7 @@ class Dialcentral(object):
                        ]
                        isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
                        tabIndex = config.getint(constants.__pretty_app_name__, "tab")
+                       isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
                except ConfigParser.NoOptionError, e:
                        _moduleLogger.info(
                                "Settings file %s is missing option %s" % (
@@ -158,6 +191,7 @@ class Dialcentral(object):
                )
                self._mainWindow.set_default_credentials(*creds)
                self._fullscreenAction.setChecked(isFullscreen)
+               self._orientationAction.setChecked(isPortrait)
                self._mainWindow.set_current_tab(tabIndex)
                self._mainWindow.load_settings(config)
 
@@ -168,6 +202,7 @@ class Dialcentral(object):
                config.add_section(constants.__pretty_app_name__)
                config.set(constants.__pretty_app_name__, "tab", str(self._mainWindow.get_current_tab()))
                config.set(constants.__pretty_app_name__, "fullscreen", str(self._fullscreenAction.isChecked()))
+               config.set(constants.__pretty_app_name__, "portrait", str(self._orientationAction.isChecked()))
                for i, value in enumerate(self._mainWindow.get_default_credentials()):
                        blob = base64.b64encode(value)
                        config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
@@ -206,6 +241,10 @@ class Dialcentral(object):
                return self._fullscreenAction
 
        @property
+       def orientationAction(self):
+               return self._orientationAction
+
+       @property
        def logAction(self):
                return self._logAction
 
@@ -217,6 +256,10 @@ class Dialcentral(object):
        def alarmHandler(self):
                return self._alarmHandler
 
+       @property
+       def ledHandler(self):
+               return self._ledHandler
+
        def _walk_children(self):
                if self._mainWindow is not None:
                        return (self._mainWindow, )
@@ -255,6 +298,13 @@ class Dialcentral(object):
        @QtCore.pyqtSlot()
        @QtCore.pyqtSlot(bool)
        @misc_utils.log_exception(_moduleLogger)
+       def _on_toggle_orientation(self, checked = False):
+               for window in self._walk_children():
+                       window.set_orientation(checked)
+
+       @QtCore.pyqtSlot()
+       @QtCore.pyqtSlot(bool)
+       @misc_utils.log_exception(_moduleLogger)
        def _on_log(self, checked = False):
                with open(constants._user_logpath_, "r") as f:
                        logLines = f.xreadlines()
@@ -444,7 +494,6 @@ class MainWindow(object):
 
                self._window = QtGui.QMainWindow(parent)
                self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
-               qui_utils.set_autorient(self._window, True)
                qui_utils.set_stackable(self._window, True)
                self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
                self._window.setCentralWidget(centralWidget)
@@ -488,6 +537,7 @@ class MainWindow(object):
                        self._window.addAction(self._closeWindowAction)
                        self._window.addAction(self._app.quitAction)
                        self._window.addAction(self._app.fullscreenAction)
+                       self._window.addAction(self._app.orientationAction)
                else:
                        fileMenu = self._window.menuBar().addMenu("&File")
                        fileMenu.addAction(self._loginTabAction)
@@ -503,10 +553,13 @@ class MainWindow(object):
                        toolsMenu.addAction(self._importTabAction)
                        toolsMenu.addAction(self._aboutAction)
 
+                       self._window.addAction(self._app.orientationAction)
+
                self._window.addAction(self._app.logAction)
 
                self._initialize_tab(self._tabWidget.currentIndex())
                self.set_fullscreen(self._app.fullscreenAction.isChecked())
+               self.set_orientation(self._app.orientationAction.isChecked())
 
        @property
        def window(self):
@@ -611,6 +664,16 @@ class MainWindow(object):
                for child in self.walk_children():
                        child.set_fullscreen(isFullscreen)
 
+       def set_orientation(self, isPortrait):
+               if isPortrait:
+                       self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
+                       qui_utils.set_window_orientation(self.window, QtCore.Qt.Vertical)
+               else:
+                       self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
+                       qui_utils.set_window_orientation(self.window, QtCore.Qt.Horizontal)
+               for child in self.walk_children():
+                       child.set_orientation(isPortrait)
+
        def _initialize_tab(self, index):
                assert index < self.MAX_TABS, "Invalid tab"
                if not self._tabsContents[index].has_child():