From 8e93326fd70af3c0accc599770796619ef3cee6e Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Thu, 21 Jun 2018 20:44:50 -0500 Subject: [PATCH] client: Convert /list #chan to UI advanced search Pass "/list" parameters to ChannelListDlg when opening, allowing for "/list #channel", to search in a similar fashion to current stable release. Add documentation to the showChannelList()/related functions. Prompt when "/list" is called without a valid network selected. This fixes running "/list" before any networks are selected resulting in a channel list dialog that wouldn't do anything. --- src/client/client.h | 24 +++++++++++++++++++++--- src/client/clientuserinputhandler.cpp | 4 ++-- src/qtui/channellistdlg.cpp | 9 +++++++++ src/qtui/channellistdlg.h | 10 ++++++++++ src/qtui/mainwin.cpp | 24 +++++++++++++++++++++--- src/qtui/mainwin.h | 9 ++++++++- src/uisupport/networkmodelcontroller.cpp | 2 +- src/uisupport/networkmodelcontroller.h | 10 +++++++++- 8 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index 7850b0fc..29ee3428 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -167,15 +167,33 @@ public: emit showIgnoreList(ignoreRule); } - void displayChannelList(NetworkId networkId) { - emit showChannelList(networkId); + /** + * Request to show the channel list dialog for the network, optionally searching by channel name + * + * @see Client::showChannelList() + * + * @param networkId Network ID for associated network + * @param channelFilters Partial channel name to search for, or empty to show all + */ + void displayChannelList(NetworkId networkId, const QString &channelFilters = {}) + { + emit showChannelList(networkId, channelFilters); } signals: void requestNetworkStates(); void showConfigWizard(const QVariantMap &coredata); - void showChannelList(NetworkId networkId); + + /** + * Request to show the channel list dialog for the network, optionally searching by channel name + * + * @see MainWin::showChannelList() + * + * @param networkId Network ID for associated network + * @param channelFilters Partial channel name to search for, or empty to show all + */ + void showChannelList(NetworkId networkId, const QString &channelFilters = {}); void showIgnoreList(QString ignoreRule); void connected(); diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp index 95a9988e..1be26927 100644 --- a/src/client/clientuserinputhandler.cpp +++ b/src/client/clientuserinputhandler.cpp @@ -142,8 +142,8 @@ void ClientUserInputHandler::handleIgnore(const BufferInfo &bufferInfo, const QS void ClientUserInputHandler::handleList(const BufferInfo &bufferInfo, const QString &text) { - Q_UNUSED(text) - Client::instance()->displayChannelList(bufferInfo.networkId()); + // Pass along any potential search parameters + Client::instance()->displayChannelList(bufferInfo.networkId(), text); } diff --git a/src/qtui/channellistdlg.cpp b/src/qtui/channellistdlg.cpp index 76b81bb0..f8b70284 100644 --- a/src/qtui/channellistdlg.cpp +++ b/src/qtui/channellistdlg.cpp @@ -84,6 +84,15 @@ void ChannelListDlg::setNetwork(NetworkId netId) } +void ChannelListDlg::setChannelFilters(const QString &channelFilters) +{ + // Enable advanced mode if searching + setAdvancedMode(!channelFilters.isEmpty()); + // Set channel search text after setting advanced mode so it's not cleared + ui.channelNameLineEdit->setText(channelFilters.trimmed()); +} + + void ChannelListDlg::requestSearch() { _listFinished = false; diff --git a/src/qtui/channellistdlg.h b/src/qtui/channellistdlg.h index e8a01ff3..b8187782 100644 --- a/src/qtui/channellistdlg.h +++ b/src/qtui/channellistdlg.h @@ -40,6 +40,16 @@ public: void setNetwork(NetworkId netId); + /** + * Set the channel search string, enabling advanced mode if needed + * + * Sets the channel name search text to the specified string, enabling advanced mode. If search + * string is empty, advanced mode will be automatically hidden. + * + * @param channelFilters Partial channel name to search for, or empty to not filter by name + */ + void setChannelFilters(const QString &channelFilters); + protected slots: void requestSearch(); void receiveChannelList(const NetworkId &netId, const QStringList &channelFilters, const QList &channelList); diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 99aaff3e..fd258838 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -206,8 +206,12 @@ void MainWin::init() connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId))); connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), SLOT(messagesInserted(const QModelIndex &, int, int))); - connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId))); - connect(Client::instance(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId))); + connect(GraphicalUi::contextMenuActionProvider(), + SIGNAL(showChannelList(NetworkId, const QString &)), + SLOT(showChannelList(NetworkId, const QString &))); + connect(Client::instance(), + SIGNAL(showChannelList(NetworkId, const QString &)), + SLOT(showChannelList(NetworkId, const QString &))); connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showNetworkConfig(NetworkId)), SLOT(showNetworkConfig(NetworkId))); connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString))); connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString))); @@ -1469,7 +1473,7 @@ void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantL } -void MainWin::showChannelList(NetworkId netId) +void MainWin::showChannelList(NetworkId netId, const QString &channelFilters) { ChannelListDlg *channelListDlg = new ChannelListDlg(); @@ -1477,10 +1481,24 @@ void MainWin::showChannelList(NetworkId netId) QAction *action = qobject_cast(sender()); if (action) netId = action->data().value(); + if (!netId.isValid()) { + // We still haven't found a valid network, probably no network selected, e.g. "/list" + // on the client homescreen when no networks are connected. + QMessageBox box(QMessageBox::Information, tr("No network selected"), + QString("%1").arg(tr("No network selected")), + QMessageBox::Ok, this); + box.setInformativeText(tr("Select a network before trying to view the channel list.")); + box.exec(); + return; + } } + channelListDlg->setAttribute(Qt::WA_DeleteOnClose); channelListDlg->setNetwork(netId); + if (!channelFilters.isEmpty()) { + channelListDlg->setChannelFilters(channelFilters); + } channelListDlg->show(); } diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index e5b6ba21..deb25002 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -121,7 +121,14 @@ private slots: void currentBufferChanged(BufferId); void messagesInserted(const QModelIndex &parent, int start, int end); void showAboutDlg(); - void showChannelList(NetworkId netId = NetworkId()); + + /** + * Show the channel list dialog for the network, optionally searching by channel name + * + * @param networkId Network ID for associated network + * @param channelFilters Partial channel name to search for, or empty to show all + */ + void showChannelList(NetworkId netId = {}, const QString &channelFilters = {}); void showNetworkConfig(NetworkId netId = NetworkId()); void showCoreConnectionDlg(); void showCoreConfigWizard(const QVariantList &, const QVariantList &); diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index 6a96ba6d..bb6482c0 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -413,7 +413,7 @@ void NetworkModelController::handleGeneralAction(ActionType type, QAction *actio } case ShowChannelList: if (networkId.isValid()) - emit showChannelList(networkId); + emit showChannelList(networkId, {}); break; case ShowNetworkConfig: if (networkId.isValid()) diff --git a/src/uisupport/networkmodelcontroller.h b/src/uisupport/networkmodelcontroller.h index 73ceabbc..5ffe1272 100644 --- a/src/uisupport/networkmodelcontroller.h +++ b/src/uisupport/networkmodelcontroller.h @@ -154,7 +154,15 @@ protected slots: virtual void actionTriggered(QAction *); signals: - void showChannelList(NetworkId); + /** + * Request to show the channel list dialog for the network, optionally searching by channel name + * + * @see MainWin::showChannelList() + * + * @param networkId Network ID for associated network + * @param channelFilters Partial channel name to search for, or empty to show all + */ + void showChannelList(NetworkId, const QString &); void showNetworkConfig(NetworkId); void showIgnoreList(QString); -- 2.20.1