summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-02-16 09:05:37 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-02-17 08:05:08 (GMT)
commit5a334fd9b676564a8915baad312d92bd86358eec (patch)
treeaaecbbccd9cddcb843c126b8c022f1d1e667efde /Swift/QtUI
parent231c2cb6d00061e70860626467107f4c63f359a0 (diff)
downloadswift-5a334fd9b676564a8915baad312d92bd86358eec.zip
swift-5a334fd9b676564a8915baad312d92bd86358eec.tar.bz2
Preliminary Chat State Notifications support.
Only covers Active and Composing (Which is very possibly all we care about).
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatTabs.cpp8
-rw-r--r--Swift/QtUI/QtChatWindow.cpp33
-rw-r--r--Swift/QtUI/QtChatWindow.h6
-rw-r--r--Swift/QtUI/QtTabbable.h3
4 files changed, 45 insertions, 5 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 6e5c55d..53fa5ce 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -104,7 +104,13 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
return;
}
tabs_->setTabText(index, widget->windowTitle());
- tabs_->tabBar()->setTabTextColor(index, tabbable->isWidgetAlerting() ? QColor(255,0,0) : QColor(-1,-1,-1)); //invalid resets to default
+ QColor tabTextColor;
+ switch (tabbable->getWidgetAlertState()) {
+ case QtTabbable::WaitingActivity : tabTextColor = QColor(255, 0, 0); break;
+ case QtTabbable::ImpendingActivity : tabTextColor = QColor(0, 255, 0); break;
+ default : tabTextColor = QColor(-1,-1,-1);//invalid resets to default
+ }
+ tabs_->tabBar()->setTabTextColor(index, tabTextColor);
if (widget == tabs_->currentWidget()) {
setWindowTitle(widget->windowTitle());
}
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index e982b21..6765e8a 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -56,7 +56,11 @@ QtChatWindow::QtChatWindow(const QString &contact, QtTreeWidgetFactory *treeWidg
input_->setAcceptRichText(false);
layout->addWidget(input_);
+ inputClearing_ = false;
+ contactIsTyping_ = false;
+
connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged()));
setFocusProxy(input_);
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(qAppFocusChanged(QWidget*, QWidget*)));
@@ -134,8 +138,20 @@ void QtChatWindow::setUnreadMessageCount(int count) {
updateTitleWithUnreadCount();
}
-bool QtChatWindow::isWidgetAlerting() {
- return unreadCount_ > 0;
+void QtChatWindow::setContactChatState(ChatState::ChatStateType state) {
+ contactIsTyping_ = (state == ChatState::Composing);
+ printf("Hay, composing %d, %d!\n", state, contactIsTyping_);
+ emit titleUpdated();
+}
+
+QtTabbable::AlertType QtChatWindow::getWidgetAlertState() {
+ if (contactIsTyping_) {
+ return ImpendingActivity;
+ }
+ if (unreadCount_ > 0) {
+ return WaitingActivity;
+ }
+ return NoActivity;
}
void QtChatWindow::setName(const String& name) {
@@ -205,7 +221,20 @@ void QtChatWindow::addSystemMessage(const String& message) {
void QtChatWindow::returnPressed() {
onSendMessageRequest(Q2PSTRING(input_->toPlainText()));
messageLog_->scrollToBottom();
+ inputClearing_ = true;
input_->clear();
+ inputClearing_ = false;
+}
+
+void QtChatWindow::handleInputChanged() {
+ if (inputClearing_) {
+ return;
+ }
+ if (input_->toPlainText().isEmpty()) {
+ onUserCancelsTyping();
+ } else {
+ onUserTyping();
+ }
}
void QtChatWindow::show() {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index e147fb8..bde91e1 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -35,7 +35,8 @@ namespace Swift {
SecurityLabel getSelectedSecurityLabel();
void setName(const String& name);
void setInputEnabled(bool enabled);
- virtual bool isWidgetAlerting();
+ QtTabbable::AlertType getWidgetAlertState();
+ void setContactChatState(ChatState::ChatStateType state);
protected slots:
void qAppFocusChanged(QWidget* old, QWidget* now);
@@ -45,11 +46,13 @@ namespace Swift {
void showEvent(QShowEvent* event);
private slots:
void returnPressed();
+ void handleInputChanged();
private:
void updateTitleWithUnreadCount();
int unreadCount_;
+ bool contactIsTyping_;
QString contact_;
QtChatView *messageLog_;
QtTextEdit* input_;
@@ -59,6 +62,7 @@ namespace Swift {
bool previousMessageWasSelf_;
bool previousMessageWasSystem_;
QString previousSenderName_;
+ bool inputClearing_;
};
}
diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h
index be528ce..cce45db 100644
--- a/Swift/QtUI/QtTabbable.h
+++ b/Swift/QtUI/QtTabbable.h
@@ -7,9 +7,10 @@ namespace Swift {
class QtTabbable : public QWidget {
Q_OBJECT
public:
+ enum AlertType {NoActivity, WaitingActivity, ImpendingActivity};
~QtTabbable();
bool isWidgetSelected();
- virtual bool isWidgetAlerting() {return false;};
+ virtual AlertType getWidgetAlertState() {return NoActivity;};
protected:
QtTabbable() : QWidget() {};