diff --git a/src/GUI.cpp b/src/GUI.cpp index b6133c16c..8e0b25e1b 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -345,10 +345,18 @@ void GUI::on_actionBugReport_triggered() const { } void GUI::tab_changed(int new_tab) { - if(new_tab == TAB_TRANSFER) { + Q_UNUSED(new_tab); + // We cannot rely on the index new_tab + // because the tab order is undetermined now + if(tabs->currentWidget() == vSplitter) { qDebug("Changed tab to transfer list, refreshing the list"); transferList->refreshList(); properties->loadDynamicData(); + return; + } + if(tabs->currentWidget() == searchEngine) { + qDebug("Changed tab to search engine, giving focus to search input"); + searchEngine->giveFocusToSearchInput(); } } @@ -401,15 +409,17 @@ void GUI::createKeyboardShortcuts() { // Keyboard shortcuts slots void GUI::displayTransferTab() const { - tabs->setCurrentIndex(TAB_TRANSFER); + tabs->setCurrentWidget(transferList); } void GUI::displaySearchTab() const { - tabs->setCurrentIndex(TAB_SEARCH); + if(searchEngine) + tabs->setCurrentWidget(searchEngine); } void GUI::displayRSSTab() const { - tabs->setCurrentIndex(TAB_RSS); + if(rssWidget) + tabs->setCurrentWidget(rssWidget); } // End of keyboard shortcuts slots @@ -509,10 +519,12 @@ void GUI::on_actionExit_triggered() { close(); } -int GUI::getCurrentTabIndex() const { +QWidget* GUI::getCurrentTabWidget() const { if(isMinimized() || !isVisible()) - return -1; - return tabs->currentIndex(); + return 0; + if(tabs->currentIndex() == 0) + return transferList; + return tabs->currentWidget(); } void GUI::setTabText(int index, QString text) const { @@ -551,7 +563,7 @@ void GUI::on_actionAbout_triggered() { void GUI::showEvent(QShowEvent *e) { qDebug("** Show Event **"); - if(getCurrentTabIndex() == TAB_TRANSFER) { + if(getCurrentTabWidget() == transferList) { qDebug("-> Refreshing transfer list"); transferList->refreshList(); properties->loadDynamicData(); diff --git a/src/GUI.h b/src/GUI.h index b36ac8c91..ee7878720 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -37,8 +37,6 @@ #include "ui_mainwindow.h" #include "qtorrenthandle.h" -enum TabIndex{TAB_TRANSFER, TAB_SEARCH, TAB_RSS}; - class Bittorrent; class QTimer; class downloadFromURL; @@ -68,7 +66,7 @@ public: GUI(QWidget *parent=0, QStringList torrentCmdLine=QStringList()); ~GUI(); // Methods - int getCurrentTabIndex() const; + QWidget* getCurrentTabWidget() const; TransferListWidget* getTransferList() const { return transferList; } QMenu* getTrayIconMenu(); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index c6ead4538..1f86d7db3 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -2089,7 +2089,6 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { QString hash; #if LIBTORRENT_VERSION_MINOR > 14 hash = misc::toQString(p->info_hash); - #else // Unfortunately libtorrent v0.14 does not provide the hash, // only the torrent handle that is often invalid when it arrives diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index e275ab02f..8f456b81a 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -327,7 +327,7 @@ void PropertiesWidget::reloadPreferences() { void PropertiesWidget::loadDynamicData() { // Refresh only if the torrent handle is valid and if visible - if(!h.is_valid() || main_window->getCurrentTabIndex() != TAB_TRANSFER || state != VISIBLE) return; + if(!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return; try { // Transfer infos if(stackedProperties->currentIndex() == MAIN_TAB) { diff --git a/src/searchengine.cpp b/src/searchengine.cpp index 0864071b2..118124d4e 100644 --- a/src/searchengine.cpp +++ b/src/searchengine.cpp @@ -277,6 +277,10 @@ void SearchEngine::searchTextEdited(QString) { search_button->setText(tr("Search")); } +void SearchEngine::giveFocusToSearchInput() { + search_pattern->setFocus(); +} + // Function called when we click on search button void SearchEngine::on_search_button_clicked(){ #ifdef Q_WS_WIN @@ -549,7 +553,7 @@ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){ } QIniSettings settings("qBittorrent", "qBittorrent"); bool useNotificationBalloons = settings.value("Preferences/General/NotificationBaloons", true).toBool(); - if(useNotificationBalloons && parent->getCurrentTabIndex() != TAB_SEARCH) { + if(useNotificationBalloons && parent->getCurrentTabWidget() != this) { parent->showNotificationBaloon(tr("Search Engine"), tr("Search has finished")); } if(exitcode){ diff --git a/src/searchengine.h b/src/searchengine.h index 902b15e7d..b304687b0 100644 --- a/src/searchengine.h +++ b/src/searchengine.h @@ -104,6 +104,7 @@ public: public slots: void on_download_button_clicked(); void downloadTorrent(QString engine_url, QString torrent_url); + void giveFocusToSearchInput(); protected slots: // Search slots diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 0f3d92956..18445539d 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -486,7 +486,7 @@ void TransferListWidget::refreshList(bool force) { // Stop updating the display setUpdatesEnabled(false); // Refresh only if displayed - if(!force && main_window->getCurrentTabIndex() != TAB_TRANSFER) return; + if(!force && main_window->getCurrentTabWidget() != this) return; unsigned int nb_downloading = 0, nb_seeding=0, nb_active=0, nb_inactive = 0, nb_paused = 0; if(BTSession->getSession()->get_torrents().size() != (uint)listModel->rowCount()) { // Oups, we have torrents that are not displayed, fix this @@ -695,7 +695,7 @@ void TransferListWidget::pauseAllTorrents() { } void TransferListWidget::deleteSelectedTorrents() { - if(main_window->getCurrentTabIndex() != TAB_TRANSFER) return; + if(main_window->getCurrentTabWidget() != this) return; const QStringList& hashes = getSelectedTorrentsHashes(); if(!hashes.empty()) { bool delete_local_files = false;