From 84d12083744a7cbe23de09d5110b9d426c58ef19 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 5 Feb 2009 09:03:08 +0100 Subject: [PATCH] Add more fancy dialog for channel join --- src/uisupport/networkmodelcontroller.cpp | 86 ++++++++++++++++++++++-- src/uisupport/networkmodelcontroller.h | 49 +++++++++++--- 2 files changed, 119 insertions(+), 16 deletions(-) diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index 3d56b1a1..626d495f 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -18,8 +18,14 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include +#include +#include +#include #include #include +#include #include "networkmodelcontroller.h" @@ -45,11 +51,11 @@ NetworkModelController::~NetworkModelController() { } -void NetworkModelController::registerAction(ActionType type, const QString &text, bool checkable) { - registerAction(type, QPixmap(), text, checkable); +Action * NetworkModelController::registerAction(ActionType type, const QString &text, bool checkable) { + return registerAction(type, QPixmap(), text, checkable); } -void NetworkModelController::registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable) { +Action * NetworkModelController::registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable) { Action *act; if(icon.isNull()) act = new Action(text, this); @@ -61,6 +67,7 @@ void NetworkModelController::registerAction(ActionType type, const QPixmap &icon _actionCollection->addAction(QString::number(type, 16), act); _actionByType[type] = act; + return act; } /******** Helper Functions ***********************************************************************/ @@ -189,8 +196,20 @@ void NetworkModelController::actionTriggered(QAction *action) { } void NetworkModelController::handleNetworkAction(ActionType type, QAction *) { + if(type == NetworkConnectAll || type == NetworkDisconnectAll) { + foreach(NetworkId id, Client::networkIds()) { + const Network *net = Client::network(id); + if(type == NetworkConnectAll && net->connectionState() == Network::Disconnected) + net->requestConnect(); + if(type == NetworkDisconnectAll && net->connectionState() != Network::Disconnected) + net->requestDisconnect(); + } + return; + } + if(!indexList().count()) return; + const Network *network = Client::network(indexList().at(0).data(NetworkModel::NetworkIdRole).value()); Q_CHECK_PTR(network); if(!network) @@ -305,10 +324,11 @@ void NetworkModelController::handleGeneralAction(ActionType type, QAction *actio case JoinChannel: { QString channelName = contextItem(); if(channelName.isEmpty()) { - bool ok; - channelName = QInputDialog::getText(0, tr("Join Channel"), tr("Input channel name:"), QLineEdit::Normal, QString(), &ok); - if(!ok) - return; + JoinDlg dlg(networkId); + if(dlg.exec() == QDialog::Accepted) { + channelName = dlg.channelName(); + networkId = dlg.networkId(); + } } if(!channelName.isEmpty()) { Client::instance()->userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(channelName)); @@ -387,3 +407,55 @@ void NetworkModelController::handleNickAction(ActionType type, QAction *) { } } } + +/*************************************************************************************************************** + * JoinDlg + ***************************************************************************************************************/ + +NetworkModelController::JoinDlg::JoinDlg(NetworkId defaultId, QWidget *parent) : QDialog(parent) { + setWindowIcon(SmallIcon("irc-join-channel")); + setWindowTitle(tr("Join Channel")); + + QGridLayout *layout = new QGridLayout(this); + layout->addWidget(new QLabel(tr("Network:")), 0, 0); + layout->addWidget(networks = new QComboBox, 0, 1); + layout->addWidget(new QLabel(tr("Channel:")), 1, 0); + layout->addWidget(channel = new QLineEdit, 1, 1); + layout->addWidget(buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel), 2, 0, 1, 2); + setLayout(layout); + + channel->setFocus(); + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + networks->setInsertPolicy(QComboBox::InsertAlphabetically); + + connect(buttonBox, SIGNAL(accepted()), SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); + connect(channel, SIGNAL(textChanged(QString)), SLOT(on_channel_textChanged(QString))); + + + QString defaultName; + foreach(NetworkId id, Client::networkIds()) { + const Network *net = Client::network(id); + if(net->isConnected()) { + networks->addItem(net->networkName(), QVariant::fromValue(id)); + if(id == defaultId) + defaultName = net->networkName(); + } + } + + if(!defaultName.isEmpty()) + networks->setCurrentIndex(networks->findText(defaultName)); + +} + +NetworkId NetworkModelController::JoinDlg::networkId() const { + return networks->itemData(networks->currentIndex()).value(); +} + +QString NetworkModelController::JoinDlg::channelName() const { + return channel->text(); +} + +void NetworkModelController::JoinDlg::on_channel_textChanged(const QString &text) { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); +} diff --git a/src/uisupport/networkmodelcontroller.h b/src/uisupport/networkmodelcontroller.h index 459d3873..4333a0c4 100644 --- a/src/uisupport/networkmodelcontroller.h +++ b/src/uisupport/networkmodelcontroller.h @@ -21,10 +21,16 @@ #ifndef NETWORKMODELCONTROLLER_H_ #define NETWORKMODELCONTROLLER_H_ +#include + #include "action.h" #include "actioncollection.h" #include "messagefilter.h" +class QComboBox; +class QDialogButtonBox; +class QLineEdit; + class NetworkModelController : public QObject { Q_OBJECT @@ -38,6 +44,8 @@ public: NetworkMask = 0x0f, NetworkConnect = 0x01, NetworkDisconnect = 0x02, + NetworkConnectAll = 0x03, + NetworkDisconnectAll = 0x04, // Buffer actions BufferMask = 0xf0, @@ -110,8 +118,8 @@ protected: void setContextItem(const QString &); void setSlot(QObject *receiver, const char *method); - void registerAction(ActionType type, const QString &text, bool checkable = false); - void registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable = false); + Action * registerAction(ActionType type, const QString &text, bool checkable = false); + Action * registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable = false); bool checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags(ActiveState | InactiveState)); QString nickName(const QModelIndex &index) const; @@ -126,14 +134,17 @@ signals: void showChannelList(NetworkId); void showIgnoreList(NetworkId); -private: - void handleNetworkAction(ActionType, QAction *); - void handleBufferAction(ActionType, QAction *); - void handleHideAction(ActionType, QAction *); - void handleNickAction(ActionType, QAction *); - void handleGeneralAction(ActionType, QAction *); - void handleExternalAction(ActionType, QAction *); +protected: + virtual void handleNetworkAction(ActionType, QAction *); + virtual void handleBufferAction(ActionType, QAction *); + virtual void handleHideAction(ActionType, QAction *); + virtual void handleNickAction(ActionType, QAction *); + virtual void handleGeneralAction(ActionType, QAction *); + virtual void handleExternalAction(ActionType, QAction *); + class JoinDlg; + +private: NetworkModel *_model; ActionCollection *_actionCollection; @@ -146,6 +157,26 @@ private: const char *_method; }; +//! Input dialog for joining a channel +class NetworkModelController::JoinDlg : public QDialog { + Q_OBJECT + +public: + JoinDlg(NetworkId id, QWidget *parent = 0); + + QString channelName() const; + NetworkId networkId() const; + +private slots: + void on_channel_textChanged(const QString &); + +private: + QComboBox *networks; + QLineEdit *channel; + QDialogButtonBox *buttonBox; +}; + + // inlines ActionCollection *NetworkModelController::actionCollection() const { return _actionCollection; } Action *NetworkModelController::action(ActionType type) const { return _actionByType.value(type, 0); } -- 2.20.1