summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-05-02 18:38:42 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-08-21 18:08:37 (GMT)
commit8d6a78665b79a382dc1871852ed7bd150263db79 (patch)
tree1fb975506939049a509cb5ea36350a9236b0b7b3 /Swift/QtUI
parent7c44520ffa37faa83731edd85dfe8196ba625d52 (diff)
downloadswift-8d6a78665b79a382dc1871852ed7bd150263db79.zip
swift-8d6a78665b79a382dc1871852ed7bd150263db79.tar.bz2
Warn when sending corrections without support.
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp48
-rw-r--r--Swift/QtUI/QtChatWindow.h9
2 files changed, 56 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 32c3067..c7a6fa8 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -30,6 +30,7 @@
#include <QTextEdit>
#include <QTime>
#include <QUrl>
+#include <QPushButton>
namespace Swift {
QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false), previousMessageWasPresence_(false), eventStream_(eventStream) {
@@ -38,6 +39,7 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
completer_ = NULL;
theme_ = theme;
isCorrection_ = false;
+ correctionEnabled_ = Maybe;
updateTitleWithUnreadCount();
QtSettingsProvider settings;
@@ -45,10 +47,24 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(2);
+ alertWidget_ = new QWidget(this);
+ QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget_);
+ layout->addWidget(alertWidget_);
+ alertLabel_ = new QLabel(this);
+ alertLayout->addWidget(alertLabel_);
+ alertButton_ = new QPushButton(this);
+ connect (alertButton_, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked()));
+ alertLayout->addWidget(alertButton_);
+ QPalette palette = alertWidget_->palette();
+ palette.setColor(QPalette::Window, QColor(Qt::yellow));
+ palette.setColor(QPalette::WindowText, QColor(Qt::black));
+ alertWidget_->setPalette(palette);
+ alertLabel_->setPalette(palette);
+ alertWidget_->hide();
+
logRosterSplitter_ = new QSplitter(this);
logRosterSplitter_->setAutoFillBackground(true);
layout->addWidget(logRosterSplitter_);
-
messageLog_ = new QtChatView(theme, this);
logRosterSplitter_->addWidget(messageLog_);
@@ -104,10 +120,30 @@ QtChatWindow::~QtChatWindow() {
}
+
void QtChatWindow::handleFontResized(int fontSizeSteps) {
messageLog_->resizeFont(fontSizeSteps);
}
+void QtChatWindow::handleAlertButtonClicked() {
+ onAlertButtonClicked();
+}
+
+void QtChatWindow::setAlert(const std::string& alertText, const std::string& buttonText) {
+ alertLabel_->setText(alertText.c_str());
+ if (buttonText.empty()) {
+ alertButton_->hide();
+ } else {
+ alertButton_->setText(buttonText.c_str());
+ alertButton_->show();
+ }
+ alertWidget_->show();
+}
+
+void QtChatWindow::cancelAlert() {
+ alertWidget_->hide();
+}
+
void QtChatWindow::setTabComplete(TabComplete* completer) {
completer_ = completer;
}
@@ -146,6 +182,11 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
}
void QtChatWindow::beginCorrection() {
+ if (correctionEnabled_ == ChatWindow::Maybe) {
+ setAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
+ } else if (correctionEnabled_ == ChatWindow::No) {
+ setAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
+ }
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
cursor.beginEditBlock();
@@ -156,6 +197,7 @@ void QtChatWindow::beginCorrection() {
}
void QtChatWindow::cancelCorrection() {
+ cancelAlert();
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
cursor.removeSelectedText();
@@ -237,6 +279,10 @@ void QtChatWindow::setSecurityLabelsEnabled(bool enabled) {
}
}
+void QtChatWindow::setCorrectionEnabled(Tristate enabled) {
+ correctionEnabled_ = enabled;
+}
+
SecurityLabelsCatalog::Item QtChatWindow::getSelectedSecurityLabel() {
assert(labelsWidget_->isEnabled());
return availableLabels_[labelsWidget_->currentIndex()];
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 78d8f91..bc2d821 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -19,6 +19,7 @@ class QLineEdit;
class QComboBox;
class QLabel;
class QSplitter;
+class QPushButton;
namespace Swift {
class QtChatView;
@@ -63,6 +64,9 @@ namespace Swift {
public slots:
void handleChangeSplitterState(QByteArray state);
void handleFontResized(int fontSizeSteps);
+ void setAlert(const std::string& alertText, const std::string& buttonText = "");
+ void cancelAlert();
+ void setCorrectionEnabled(Tristate enabled);
signals:
void geometryChanged();
@@ -83,6 +87,7 @@ namespace Swift {
void handleInputChanged();
void handleKeyPressEvent(QKeyEvent* event);
void handleSplitterMoved(int pos, int index);
+ void handleAlertButtonClicked();
private:
void updateTitleWithUnreadCount();
@@ -102,6 +107,9 @@ namespace Swift {
QComboBox* labelsWidget_;
QtTreeWidget* treeWidget_;
QLabel* correctingLabel_;
+ QLabel* alertLabel_;
+ QWidget* alertWidget_;
+ QPushButton* alertButton_;
TabComplete* completer_;
std::vector<SecurityLabelsCatalog::Item> availableLabels_;
bool isCorrection_;
@@ -114,5 +122,6 @@ namespace Swift {
bool inputEnabled_;
IDGenerator id_;
QSplitter *logRosterSplitter_;
+ Tristate correctionEnabled_;
};
}