modernize: Pass arguments by value and move in constructors
[quassel.git] / src / qtui / channellistdlg.cpp
index 76b81bb..204590e 100644 (file)
@@ -33,7 +33,7 @@ ChannelListDlg::ChannelListDlg(QWidget *parent)
     _listFinished(true),
     _ircListModel(this),
     _sortFilter(this),
-    _simpleModeSpacer(0),
+    _simpleModeSpacer(nullptr),
     _advancedMode(false)
 {
     _sortFilter.setSourceModel(&_ircListModel);
@@ -49,6 +49,8 @@ ChannelListDlg::ChannelListDlg(QWidget *parent)
     ui.channelListView->setTabKeyNavigation(false);
     ui.channelListView->setModel(&_sortFilter);
     ui.channelListView->setSortingEnabled(true);
+    // Sort A-Z by default
+    ui.channelListView->sortByColumn(0, Qt::AscendingOrder);
     ui.channelListView->verticalHeader()->hide();
     ui.channelListView->horizontalHeader()->setStretchLastSection(true);
 
@@ -70,6 +72,9 @@ ChannelListDlg::ChannelListDlg(QWidget *parent)
     enableQuery(true);
     showFilterLine(false);
     showErrors(false);
+
+    // Set initial input focus
+    updateInputFocus();
 }
 
 
@@ -84,8 +89,22 @@ 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()
 {
+    if (!_netId.isValid()) {
+        // No valid network set yet
+        return;
+    }
+
     _listFinished = false;
     enableQuery(false);
     showErrors(false);
@@ -104,6 +123,8 @@ void ChannelListDlg::receiveChannelList(const NetworkId &netId, const QStringLis
     showFilterLine(!channelList.isEmpty());
     _ircListModel.setChannelList(channelList);
     enableQuery(_listFinished);
+    // Reset input focus since UI changed
+    updateInputFocus();
 }
 
 
@@ -130,7 +151,7 @@ void ChannelListDlg::setAdvancedMode(bool advanced)
         if (_simpleModeSpacer) {
             ui.searchLayout->removeItem(_simpleModeSpacer);
             delete _simpleModeSpacer;
-            _simpleModeSpacer = 0;
+            _simpleModeSpacer = nullptr;
         }
         ui.advancedModeLabel->setPixmap(icon::get("edit-clear-locationbar-rtl").pixmap(16));
     }
@@ -148,6 +169,18 @@ void ChannelListDlg::setAdvancedMode(bool advanced)
 }
 
 
+void ChannelListDlg::updateInputFocus()
+{
+    // Update keyboard focus to match what options are available.  Prioritize the channel name
+    // editor as one likely won't need to filter when already limiting the list.
+    if (ui.channelNameLineEdit->isVisible()) {
+        ui.channelNameLineEdit->setFocus();
+    } else if (ui.filterLineEdit->isVisible()) {
+        ui.filterLineEdit->setFocus();
+    }
+}
+
+
 void ChannelListDlg::showErrors(bool show)
 {
     if (!show) {