diff options
author | Kevin Smith <git@kismith.co.uk> | 2009-08-16 15:14:56 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2009-08-16 15:14:56 (GMT) |
commit | 6bb73fb2d367a95cc1df2addf7dd5477b643c2e8 (patch) | |
tree | f6c42a9de8ff3800c9ffe1e44b92bff1e6eda7e6 | |
parent | 6d64d22bdc18a8b4d3ef1ae7087f657de6c9abd9 (diff) | |
download | swift-6bb73fb2d367a95cc1df2addf7dd5477b643c2e8.zip swift-6bb73fb2d367a95cc1df2addf7dd5477b643c2e8.tar.bz2 |
Adding in a button to the roster for 'Add Contact'
-rw-r--r-- | Swift/Controllers/MainWindow.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtAddContactDialog.cpp | 32 | ||||
-rw-r--r-- | Swift/QtUI/QtAddContactDialog.h | 26 | ||||
-rw-r--r-- | Swift/QtUI/QtAddContactDialog.ui | 72 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 20 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 4 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 2 |
8 files changed, 161 insertions, 2 deletions
diff --git a/Swift/Controllers/MainWindow.h b/Swift/Controllers/MainWindow.h index 945439e..1098230 100644 --- a/Swift/Controllers/MainWindow.h +++ b/Swift/Controllers/MainWindow.h @@ -20,6 +20,7 @@ namespace Swift { virtual void setMyStatusText(const String& status) = 0; boost::signal<void (const JID&)> onStartChatRequest; + boost::signal<void (const JID&, const String&)> onAddContactRequest; boost::signal<void (const JID&, const String&)> onJoinMUCRequest; boost::signal<void (StatusShow::Type, const String&)> onChangeStatusRequest; boost::signal<void (bool)> onShowOfflineToggled; diff --git a/Swift/QtUI/QtAddContactDialog.cpp b/Swift/QtUI/QtAddContactDialog.cpp new file mode 100644 index 0000000..09059c1 --- /dev/null +++ b/Swift/QtUI/QtAddContactDialog.cpp @@ -0,0 +1,32 @@ +#include "QtAddContactDialog.h" +#include "QtSwiftUtil.h" + +namespace Swift { + +QtAddContactDialog::QtAddContactDialog(QWidget* parent) : QDialog(parent) { + setupUi(this); + errorLabel_->hide(); + setAttribute(Qt::WA_DeleteOnClose, true); + connect(buttons_, SIGNAL(accepted()), SLOT(accept())); + connect(buttons_, SIGNAL(rejected()), SLOT(reject())); +} + +void QtAddContactDialog::accept() { + if (contactJID_->displayText().isEmpty()) { + showError("You must specify a contact to add."); + return; + } + if (name_->displayText().isEmpty()) { + showError("You must specify a name for the contact."); + return; + } + errorLabel_->hide(); + emit onAddCommand(JID(Q2PSTRING(contactJID_->displayText())), name_->displayText()); + QDialog::accept(); +} + +void QtAddContactDialog::showError(const QString& error) { + errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error)); + errorLabel_->show(); +} +} diff --git a/Swift/QtUI/QtAddContactDialog.h b/Swift/QtUI/QtAddContactDialog.h new file mode 100644 index 0000000..b231200 --- /dev/null +++ b/Swift/QtUI/QtAddContactDialog.h @@ -0,0 +1,26 @@ +#ifndef SWIFT_QtAddContactDialog_H +#define SWIFT_QtAddContactDialog_H + +#include "ui_QtAddContactDialog.h" +#include "Swiften/JID/JID.h" + +#include <QDialog> + +namespace Swift { + +class QtAddContactDialog : public QDialog, private Ui::QtAddContactDialog { + Q_OBJECT + + public: + QtAddContactDialog(QWidget* parent); + signals: + void onAddCommand(const JID& contact, const QString& name); + public slots: + void accept(); + private: + void showError(const QString& error); +}; + +} + +#endif diff --git a/Swift/QtUI/QtAddContactDialog.ui b/Swift/QtUI/QtAddContactDialog.ui new file mode 100644 index 0000000..8832626 --- /dev/null +++ b/Swift/QtUI/QtAddContactDialog.ui @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>QtAddContactDialog</class> + <widget class="QDialog" name="QtAddContactDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>232</width> + <height>110</height> + </rect> + </property> + <property name="windowTitle"> + <string>Add contact</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>User's ID</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="contactJID_"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Name</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="name_"/> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="errorLabel_"> + <property name="text"> + <string/> + </property> + <property name="textFormat"> + <enum>Qt::RichText</enum> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttons_"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + <property name="centerButtons"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index cf4bfd2..b02a86e 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -1,5 +1,6 @@ #include "QtMainWindow.h" +#include "QtAddContactDialog.h" #include "QtJoinMUCDialog.h" #include "QtSwiftUtil.h" #include "Roster/QtTreeWidgetFactory.h" @@ -13,6 +14,7 @@ #include <QPushButton> #include <QMenuBar> #include <QToolBar> +#include <QAction> namespace Swift { @@ -29,6 +31,13 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() { treeWidget_ = dynamic_cast<QtTreeWidget*>(treeWidgetFactory->createTreeWidget()); mainLayout->addWidget(treeWidget_); + bottomBar_ = new QToolBar(this); + mainLayout->addWidget(bottomBar_); + + addAction_ = new QAction("Add Contact", this); + bottomBar_->addAction(addAction_); + connect(addAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddActionTriggered(bool))); + this->setLayout(mainLayout); QMenu* viewMenu = new QMenu(tr("View"), this); @@ -46,6 +55,17 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() { chatMenu->addAction(joinMUCAction); } +void QtMainWindow::handleAddActionTriggered(bool checked) { + Q_UNUSED(checked); + QtAddContactDialog* addContact = new QtAddContactDialog(this); + connect(addContact, SIGNAL(onAddCommand(const JID&, const QString&)), SLOT(handleAddContactDialogComplete(const JID&, const QString&))); + addContact->show(); +} + +void QtMainWindow::handleAddContactDialogComplete(const JID& contact, const QString& name) { + onAddContactRequest(contact, Q2PSTRING(name)); +} + TreeWidget* QtMainWindow::getTreeWidget() { return treeWidget_; } diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index 44133af..a62c0a5 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -11,6 +11,8 @@ class QComboBox; class QLineEdit; class QPushButton; +class QToolBar; +class QAction; namespace Swift { class QtTreeWidget; @@ -32,6 +34,8 @@ namespace Swift { void handleShowOfflineToggled(bool); void handleJoinMUCAction(); void handleJoinMUCDialogComplete(const JID& muc, const QString& nick); + void handleAddContactDialogComplete(const JID& contact, const QString& name); + void handleAddActionTriggered(bool checked); private: std::vector<QMenu*> menus_; //QtStatusWidget* statusWidget_; @@ -40,6 +44,8 @@ namespace Swift { QPushButton* mucButton_; QtTreeWidget* treeWidget_; QtRosterHeader* meView_; + QToolBar* bottomBar_; + QAction* addAction_; }; } diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index 9b5410b..425b22d 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -101,13 +101,13 @@ void QtRosterHeader::resizeNameLabel() { nameLabel_->setText("<b>" + escapedName + "</b>"); int reductionCount = 0; while (nameLabel_->sizeHint().width() + statusWidget_->width() + 30 > width()) { - qDebug() << nameLabel_->sizeHint().width() << " " << statusWidget_->width() << " " << width(); + //qDebug() << nameLabel_->sizeHint().width() << " " << statusWidget_->width() << " " << width(); reductionCount++; QString reducedName = name_; reducedName.remove(name_.length() - reductionCount, reductionCount); reducedName.replace("<","<"); nameLabel_->setText("<b>" + reducedName + + "...</b>"); - qDebug() << "Shrunk " << escapedName << " down to " << reducedName; + // qDebug() << "Shrunk " << escapedName << " down to " << reducedName; } nameLabel_->setToolTip(name_); } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index cd810a4..191b39e 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -45,6 +45,7 @@ myenv.Command("DefaultTheme.qrc", "../resources/themes/Default", Action(generate sources = [ "main.cpp", + "QtAddContactDialog.cpp", "QtChatWindow.cpp", "QtChatWindowFactory.cpp", "QtJoinMUCDialog.cpp", @@ -82,6 +83,7 @@ else : swiftProgram = myenv.Program("swift", sources) myenv.Uic4("QtJoinMUCDialog.ui") +myenv.Uic4("QtAddContactDialog.ui") myenv.Qrc("DefaultTheme.qrc") myenv.Qrc("Swift.qrc") |