Switching to make rotation more configurable4
[gc-dialer] / src / dialogs.py
index 3800916..0e1a92e 100644 (file)
@@ -7,8 +7,9 @@ import functools
 import copy
 import logging
 
-from PyQt4 import QtGui
-from PyQt4 import QtCore
+import util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
+QtGui = qt_compat.import_module("QtGui")
 
 import constants
 from util import qwrappers
@@ -80,8 +81,8 @@ class CredentialsDialog(object):
                except RuntimeError:
                        _moduleLogger.exception("Oh well")
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
                with qui_utils.notify_error(self._app.errorLog):
@@ -141,8 +142,8 @@ class AboutDialog(object):
                except RuntimeError:
                        _moduleLogger.exception("Oh well")
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
                with qui_utils.notify_error(self._app.errorLog):
@@ -214,18 +215,26 @@ class AccountDialog(object):
                self._credLayout.addWidget(self._voicemailNotificationButton, 4, 1)
                self._credLayout.addWidget(QtGui.QLabel(""), 5, 0)
                self._credLayout.addWidget(self._smsNotificationButton, 5, 1)
-               self._credLayout.addWidget(QtGui.QLabel(""), 6, 0)
+               self._credLayout.addWidget(QtGui.QLabel("Other"), 6, 0)
                self._credLayout.addWidget(self._voicemailOnMissedButton, 6, 1)
 
                self._credLayout.addWidget(QtGui.QLabel(""), 7, 0)
                self._credLayout.addWidget(self._clearButton, 7, 1)
+               self._credWidget = QtGui.QWidget()
+               self._credWidget.setLayout(self._credLayout)
+               self._credWidget.setContentsMargins(0, 0, 0, 0)
+               self._scrollSettings = QtGui.QScrollArea()
+               self._scrollSettings.setWidget(self._credWidget)
+               self._scrollSettings.setWidgetResizable(True)
+               self._scrollSettings.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
+               self._scrollSettings.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
 
                self._loginButton = QtGui.QPushButton("&Apply")
                self._buttonLayout = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel)
                self._buttonLayout.addButton(self._loginButton, QtGui.QDialogButtonBox.AcceptRole)
 
                self._layout = QtGui.QVBoxLayout()
-               self._layout.addLayout(self._credLayout)
+               self._layout.addWidget(self._scrollSettings)
                self._layout.addWidget(self._buttonLayout)
 
                self._dialog = QtGui.QDialog()
@@ -335,7 +344,7 @@ class AccountDialog(object):
        @property
        def selectedCallback(self):
                index = self._callbackSelector.currentIndex()
-               data = str(self._callbackSelector.itemData(index).toPyObject())
+               data = str(self._callbackSelector.itemData(index))
                return data
 
        def set_callbacks(self, choices, default):
@@ -394,22 +403,22 @@ class AccountDialog(object):
                        self._voicemailNotificationButton.setChecked(False)
                        self._smsNotificationButton.setChecked(False)
 
-       @QtCore.pyqtSlot(int)
+       @qt_compat.Slot(int)
        @misc_utils.log_exception(_moduleLogger)
        def _on_notification_change(self, index):
                with qui_utils.notify_error(self._app.errorLog):
                        self._update_notification_state()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_clear(self, checked = False):
                with qui_utils.notify_error(self._app.errorLog):
                        self._doClear = True
                        self._dialog.accept()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
                with qui_utils.notify_error(self._app.errorLog):
@@ -473,7 +482,7 @@ class ContactList(object):
                        )
                        callback.__name__ = "thanks partials for not having names and pyqt for requiring them"
                        numberSelector.activated.connect(
-                               QtCore.pyqtSlot(int)(callback)
+                               qt_compat.Slot(int)(callback)
                        )
 
                        if self._closeIcon is self._SENTINEL_ICON:
@@ -759,13 +768,13 @@ class VoicemailPlayer(object):
                        self._session.download_voicemail(messageId)
                        self._hide()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_recipients_changed(self):
                with qui_utils.notify_error(self._app.errorLog):
                        self._update_state()
 
-       @QtCore.pyqtSlot(str, str)
+       @qt_compat.Slot(str, str)
        @misc_utils.log_exception(_moduleLogger)
        def _on_voicemail_downloaded(self, messageId, filepath):
                with qui_utils.notify_error(self._app.errorLog):
@@ -849,6 +858,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                self._window.setWindowTitle("Contact")
                self._window.closed.connect(self._on_close_window)
                self._window.hidden.connect(self._on_close_window)
+               self._window.resized.connect(self._on_window_resized)
 
                self._scrollTimer = QtCore.QTimer()
                self._scrollTimer.setInterval(100)
@@ -859,7 +869,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                self._update_letter_count()
                self._update_target_fields()
                self.set_fullscreen(self._app.fullscreenAction.isChecked())
-               self.set_orientation(self._app.orientationAction.isChecked())
+               self.update_orientation(self._app.orientation)
 
        def close(self):
                if self._window is None:
@@ -898,12 +908,12 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                except RuntimeError:
                        _moduleLogger.exception("Oh well")
 
-       def set_orientation(self, isPortrait):
-               qwrappers.WindowWrapper.set_orientation(self, isPortrait)
+       def update_orientation(self, orientation):
+               qwrappers.WindowWrapper.update_orientation(self, orientation)
                self._scroll_to_bottom()
 
        def _update_letter_count(self):
-               count = self._smsEntry.toPlainText().size()
+               count = len(self._smsEntry.toPlainText())
                numTexts, numCharInText = divmod(count, self.MAX_CHAR)
                numTexts += 1
                numCharsLeftInText = self.MAX_CHAR - numCharInText
@@ -915,7 +925,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        self._dialButton.setEnabled(False)
                        self._smsButton.setEnabled(False)
                elif self._session.draft.get_num_contacts() == 1:
-                       count = self._smsEntry.toPlainText().size()
+                       count = len(self._smsEntry.toPlainText())
                        if count == 0:
                                self._dialButton.setEnabled(True)
                                self._smsButton.setEnabled(False)
@@ -924,7 +934,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                                self._smsButton.setEnabled(True)
                else:
                        self._dialButton.setEnabled(False)
-                       count = self._smsEntry.toPlainText().size()
+                       count = len(self._smsEntry.toPlainText())
                        if count == 0:
                                self._smsButton.setEnabled(False)
                        else:
@@ -1023,7 +1033,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        self._session.draft.message = message
                        self._session.draft.call()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_cancel_clicked(self, message):
                with qui_utils.notify_error(self._app.errorLog):
@@ -1042,7 +1052,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        number = numbers[index][0]
                        self._session.draft.set_selected_number(cid, number)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_refresh_history(self):
                with qui_utils.notify_error(self._app.errorLog):
@@ -1053,14 +1063,14 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        (cid, ) = self._session.draft.get_contacts()
                        self._update_history(cid)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_recipients_changed(self):
                with qui_utils.notify_error(self._app.errorLog):
                        self._update_target_fields()
                        self._update_button_state()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_op_started(self):
                with qui_utils.notify_error(self._app.errorLog):
@@ -1069,13 +1079,13 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        self._dialButton.setVisible(False)
                        self.show()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_calling_started(self):
                with qui_utils.notify_error(self._app.errorLog):
                        self._cancelButton.setVisible(True)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_op_finished(self):
                with qui_utils.notify_error(self._app.errorLog):
@@ -1087,7 +1097,7 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        self.close()
                        self.destroy()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_op_error(self, message):
                with qui_utils.notify_error(self._app.errorLog):
@@ -1098,15 +1108,21 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
 
                        self._errorLog.push_error(message)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_letter_count_changed(self):
                with qui_utils.notify_error(self._app.errorLog):
                        self._update_letter_count()
                        self._update_button_state()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_window_resized(self):
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._scroll_to_bottom()
+
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
                with qui_utils.notify_error(self._app.errorLog):