From 6bb73fb2d367a95cc1df2addf7dd5477b643c2e8 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 16 Aug 2009 16:14:56 +0100 Subject: Adding in a button to the roster for 'Add Contact' 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 onStartChatRequest; + boost::signal onAddContactRequest; boost::signal onJoinMUCRequest; boost::signal onChangeStatusRequest; boost::signal 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("%1").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 + +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 @@ + + + QtAddContactDialog + + + + 0 + 0 + 232 + 110 + + + + Add contact + + + + + + + + User's ID + + + + + + + + + + + + + + Name + + + + + + + + + + + + + + + Qt::RichText + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + + 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 #include #include +#include namespace Swift { @@ -29,6 +31,13 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() { treeWidget_ = dynamic_cast(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 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("" + escapedName + ""); 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("" + reducedName + + "..."); - 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") -- cgit v0.10.2-6-g49f6