Adding error display to the editor
[gc-dialer] / src / dialogs.py
index 193408d..15dcc8a 100644 (file)
@@ -154,18 +154,27 @@ class SMSEntryWindow(object):
 
        MAX_CHAR = 160
 
+       # @bug on n900 no scrolling for history qtextedit
+
        def __init__(self, parent, app, session, errorLog):
                self._session = session
                self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
                self._session.draft.called.connect(self._on_op_finished)
                self._session.draft.sentMessage.connect(self._on_op_finished)
                self._session.draft.cancelled.connect(self._on_op_finished)
+               self._session.draft.error.connect(self._on_op_error)
                self._errorLog = errorLog
 
+               self._errorDisplay = qui_utils.ErrorDisplay(self._errorLog)
+
                self._targetLayout = QtGui.QVBoxLayout()
                self._targetList = QtGui.QWidget()
                self._targetList.setLayout(self._targetLayout)
                self._history = QtGui.QTextEdit()
+               self._history.setReadOnly(True)
+               self._history.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom)
+               self._history.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
+               self._history.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
                self._smsEntry = QtGui.QTextEdit()
                self._smsEntry.textChanged.connect(self._on_letter_count_changed)
 
@@ -173,15 +182,18 @@ class SMSEntryWindow(object):
                self._entryLayout.addWidget(self._targetList)
                self._entryLayout.addWidget(self._history)
                self._entryLayout.addWidget(self._smsEntry)
+               self._entryLayout.setContentsMargins(0, 0, 0, 0)
                self._entryWidget = QtGui.QWidget()
                self._entryWidget.setLayout(self._entryLayout)
+               self._entryWidget.setContentsMargins(0, 0, 0, 0)
                self._scrollEntry = QtGui.QScrollArea()
                self._scrollEntry.setWidget(self._entryWidget)
+               self._scrollEntry.setWidgetResizable(True)
                self._scrollEntry.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom)
                self._scrollEntry.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
                self._scrollEntry.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
 
-               self._characterCountLabel = QtGui.QLabel("Letters: %s" % 0)
+               self._characterCountLabel = QtGui.QLabel("0 (0)")
                self._singleNumberSelector = QtGui.QComboBox()
                self._smsButton = QtGui.QPushButton("SMS")
                self._smsButton.clicked.connect(self._on_sms_clicked)
@@ -195,6 +207,7 @@ class SMSEntryWindow(object):
                self._buttonLayout.addWidget(self._dialButton)
 
                self._layout = QtGui.QVBoxLayout()
+               self._layout.addWidget(self._errorDisplay.toplevel)
                self._layout.addWidget(self._scrollEntry)
                self._layout.addLayout(self._buttonLayout)
 
@@ -266,6 +279,7 @@ class SMSEntryWindow(object):
                        self._scroll_to_bottom()
                        self._window.setWindowTitle(title)
                        self._window.show()
+                       self._smsEntry.setFocus(QtCore.Qt.OtherFocusReason)
                else:
                        self._targetList.setVisible(True)
                        while self._targetLayout.count():
@@ -302,6 +316,7 @@ class SMSEntryWindow(object):
                        self._scroll_to_bottom()
                        self._window.setWindowTitle("Contacts")
                        self._window.show()
+                       self._smsEntry.setFocus(QtCore.Qt.OtherFocusReason)
 
        def _populate_number_selector(self, selector, cid, numbers):
                while 0 < selector.count():
@@ -370,6 +385,11 @@ class SMSEntryWindow(object):
 
        @QtCore.pyqtSlot()
        @misc_utils.log_exception(_moduleLogger)
+       def _on_op_error(self, message):
+               self._errorLog.push_message(message)
+
+       @QtCore.pyqtSlot()
+       @misc_utils.log_exception(_moduleLogger)
        def _on_letter_count_changed(self):
                self._update_letter_count()
                self._update_button_state()