X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnetworkmodelcontroller.cpp;h=58db5617ae594edd0e82cb6e64dcbd83cdbe665c;hp=3d56b1a1cdce8354eddb82ec773952e01c234470;hb=342b6d8a5869e438362914f3848e639ac6c70bbc;hpb=57058eabefe58082635c0ff83bbd4714baa5b6a9 diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index 3d56b1a1..58db5617 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 ***********************************************************************/ @@ -108,7 +115,7 @@ QString NetworkModelController::nickName(const QModelIndex &index) const { BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value(); if(!bufferInfo.isValid()) return QString(); - if(!bufferInfo.type() == BufferInfo::QueryBuffer) + if(bufferInfo.type() != BufferInfo::QueryBuffer) return QString(); return bufferInfo.bufferName(); // FIXME this might break with merged queries maybe @@ -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) @@ -213,11 +232,14 @@ void NetworkModelController::handleBufferAction(ActionType type, QAction *) { removeBuffers(indexList()); } else { + QList bufferList; // create temp list because model indexes might change foreach(QModelIndex index, indexList()) { BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value(); - if(!bufferInfo.isValid()) - continue; + if(bufferInfo.isValid()) + bufferList << bufferInfo; + } + foreach(BufferInfo bufferInfo, bufferList) { switch(type) { case BufferJoin: Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName())); @@ -254,6 +276,8 @@ void NetworkModelController::handleHideAction(ActionType type, QAction *action) filter |= Message::Mode; if(NetworkModelController::action(HideDayChange)->isChecked()) filter |= Message::DayChange; + if(NetworkModelController::action(HideTopic)->isChecked()) + filter |= Message::Topic; switch(type) { case HideJoin: @@ -262,6 +286,7 @@ void NetworkModelController::handleHideAction(ActionType type, QAction *action) case HideNick: case HideMode: case HideDayChange: + case HideTopic: if(_messageFilter) BufferSettings(_messageFilter->idString()).setMessageFilter(filter); else { @@ -298,17 +323,16 @@ void NetworkModelController::handleGeneralAction(ActionType type, QAction *actio if(!indexList().count()) return; NetworkId networkId = indexList().at(0).data(NetworkModel::NetworkIdRole).value(); - if(!networkId.isValid()) - return; switch(type) { 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(indexList().first()); + 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)); @@ -316,10 +340,12 @@ void NetworkModelController::handleGeneralAction(ActionType type, QAction *actio break; } case ShowChannelList: - emit showChannelList(networkId); + if(networkId.isValid()) + emit showChannelList(networkId); break; case ShowIgnoreList: - emit showIgnoreList(networkId); + if(networkId.isValid()) + emit showIgnoreList(networkId); break; default: break; @@ -387,3 +413,57 @@ void NetworkModelController::handleNickAction(ActionType type, QAction *) { } } } + +/*************************************************************************************************************** + * JoinDlg + ***************************************************************************************************************/ + +NetworkModelController::JoinDlg::JoinDlg(const QModelIndex &index, 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))); + + foreach(NetworkId id, Client::networkIds()) { + const Network *net = Client::network(id); + if(net->isConnected()) { + networks->addItem(net->networkName(), QVariant::fromValue(id)); + } + } + + if(index.isValid()) { + NetworkId networkId = index.data(NetworkModel::NetworkIdRole).value(); + if(networkId.isValid()) { + networks->setCurrentIndex(networks->findText(Client::network(networkId)->networkName())); + if(index.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer + && !index.data(NetworkModel::ItemActiveRole).toBool()) + channel->setText(index.data(Qt::DisplayRole).toString()); + } + } +} + +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()); +}