From 4d66a0929ce766445781f96ce8941497d7e1ef95 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Tue, 6 Jan 2015 22:40:49 +0100 Subject: [PATCH] Add "Copy description page URL" button in search tab Closes #2371. --- src/searchengine/search.ui | 10 ++++++++++ src/searchengine/searchengine.cpp | 24 ++++++++++++++++++++++++ src/searchengine/searchengine.h | 1 + 3 files changed, 35 insertions(+) diff --git a/src/searchengine/search.ui b/src/searchengine/search.ui index 71664f67f..ae35d4927 100644 --- a/src/searchengine/search.ui +++ b/src/searchengine/search.ui @@ -118,6 +118,16 @@ + + + + false + + + Copy description page URL + + + diff --git a/src/searchengine/searchengine.cpp b/src/searchengine/searchengine.cpp index 0a18dd5db..f96c7eea8 100644 --- a/src/searchengine/searchengine.cpp +++ b/src/searchengine/searchengine.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include @@ -74,6 +75,7 @@ SearchEngine::SearchEngine(MainWindow* parent) download_button->setIcon(GuiIconProvider::instance()->getIcon("download")); goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl")); enginesButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network")); + copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy")); tabWidget->setTabsClosable(true); connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); // Boolean initialization @@ -159,10 +161,12 @@ void SearchEngine::tab_changed(int t) if (currentSearchTab->getCurrentSearchListModel()->rowCount()) { download_button->setEnabled(true); goToDescBtn->setEnabled(true); + copyURLBtn->setEnabled(true); } else { download_button->setEnabled(false); goToDescBtn->setEnabled(false); + copyURLBtn->setEnabled(false); } search_status->setText(currentSearchTab->status); } @@ -529,6 +533,7 @@ void SearchEngine::appendSearchResult(const QString &line) // Enable clear & download buttons download_button->setEnabled(true); goToDescBtn->setEnabled(true); + copyURLBtn->setEnabled(true); } void SearchEngine::closeTab(int index) @@ -554,6 +559,7 @@ void SearchEngine::closeTab(int index) download_button->setEnabled(false); goToDescBtn->setEnabled(false); search_status->setText(tr("Stopped")); + copyURLBtn->setEnabled(false); } } @@ -586,3 +592,21 @@ void SearchEngine::on_goToDescBtn_clicked() } } } + +void SearchEngine::on_copyURLBtn_clicked() +{ + QStringList urls; + QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); + foreach (const QModelIndex &index, selectedIndexes) { + if (index.column() == SearchSortModel::NAME) { + QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); + const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); + if (!descUrl.isEmpty()) + urls << descUrl.toUtf8(); + } + } + if (!urls.empty()) { + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(urls.join("\n")); + } +} diff --git a/src/searchengine/searchengine.h b/src/searchengine/searchengine.h index 68d229688..bc2d26626 100644 --- a/src/searchengine/searchengine.h +++ b/src/searchengine/searchengine.h @@ -109,6 +109,7 @@ protected slots: private slots: void on_goToDescBtn_clicked(); + void on_copyURLBtn_clicked(); private: // Search related