2008-06-25 23:29:29 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
2008-06-25 23:29:29 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
2016-05-26 18:07:19 +03:00
|
|
|
#include <QApplication>
|
2008-06-25 23:29:29 +04:00
|
|
|
#include <QDir>
|
2016-06-22 18:25:53 +03:00
|
|
|
#include <QMenu>
|
2015-09-23 23:20:22 +03:00
|
|
|
#include <QMetaEnum>
|
2008-06-25 23:29:29 +04:00
|
|
|
#include <QTreeView>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QHeaderView>
|
2009-08-27 16:37:39 +04:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-09-24 10:33:02 +03:00
|
|
|
#include <QLabel>
|
2016-05-26 18:07:19 +03:00
|
|
|
#include <QPalette>
|
2015-09-24 10:33:02 +03:00
|
|
|
#include <QVBoxLayout>
|
2015-11-18 19:13:25 +03:00
|
|
|
#include <QTableView>
|
2008-06-25 23:29:29 +04:00
|
|
|
|
2015-09-25 11:10:05 +03:00
|
|
|
#include "base/utils/misc.h"
|
|
|
|
#include "base/preferences.h"
|
2015-09-23 23:20:22 +03:00
|
|
|
#include "base/settingsstorage.h"
|
|
|
|
#include "guiiconprovider.h"
|
2015-09-24 10:33:02 +03:00
|
|
|
#include "searchsortmodel.h"
|
|
|
|
#include "searchlistdelegate.h"
|
|
|
|
#include "searchwidget.h"
|
|
|
|
#include "searchtab.h"
|
2016-02-27 23:37:41 +03:00
|
|
|
#include "ui_searchtab.h"
|
2008-06-25 23:29:29 +04:00
|
|
|
|
2015-09-23 23:20:22 +03:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
#define SETTINGS_KEY(name) "Search/" name
|
|
|
|
|
|
|
|
const QString KEY_FILTER_MODE_SETTING_NAME = SETTINGS_KEY("FilteringMode");
|
|
|
|
}
|
|
|
|
|
2015-09-24 10:33:02 +03:00
|
|
|
SearchTab::SearchTab(SearchWidget *parent)
|
|
|
|
: QWidget(parent)
|
2016-02-27 23:37:41 +03:00
|
|
|
, m_ui(new Ui::SearchTab())
|
2015-09-24 10:33:02 +03:00
|
|
|
, m_parent(parent)
|
2008-06-25 23:29:29 +04:00
|
|
|
{
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->setupUi(this);
|
2015-09-23 23:20:22 +03:00
|
|
|
|
2015-11-18 19:13:25 +03:00
|
|
|
// This hack fixes reordering of first column with Qt5.
|
|
|
|
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
|
|
|
QTableView unused;
|
2016-02-27 23:37:41 +03:00
|
|
|
unused.setVerticalHeader(m_ui->resultsBrowser->header());
|
|
|
|
m_ui->resultsBrowser->header()->setParent(m_ui->resultsBrowser);
|
2015-11-18 19:13:25 +03:00
|
|
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
2017-01-19 15:10:09 +03:00
|
|
|
|
2016-06-22 16:34:53 +03:00
|
|
|
loadSettings();
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2016-06-22 16:34:53 +03:00
|
|
|
header()->setStretchLastSection(false);
|
2015-09-24 10:33:02 +03:00
|
|
|
|
2015-04-11 14:26:25 +03:00
|
|
|
// Set Search results list model
|
2015-09-24 10:33:02 +03:00
|
|
|
m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this);
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
2015-09-23 23:20:22 +03:00
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
2015-09-24 10:33:02 +03:00
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
|
2016-06-16 21:44:33 +03:00
|
|
|
// Set columns text alignment
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
|
|
|
m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2015-09-24 10:33:02 +03:00
|
|
|
m_proxyModel = new SearchSortModel(this);
|
|
|
|
m_proxyModel->setDynamicSortFilter(true);
|
|
|
|
m_proxyModel->setSourceModel(m_searchListModel);
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsBrowser->setModel(m_proxyModel);
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2015-09-24 10:33:02 +03:00
|
|
|
m_searchDelegate = new SearchListDelegate(this);
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsBrowser->setItemDelegate(m_searchDelegate);
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
|
|
|
|
m_ui->resultsBrowser->hideColumn(SearchSortModel::DESC_LINK);
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsBrowser->setRootIsDecorated(false);
|
|
|
|
m_ui->resultsBrowser->setAllColumnsShowFocus(true);
|
|
|
|
m_ui->resultsBrowser->setSortingEnabled(true);
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2016-06-22 18:25:53 +03:00
|
|
|
//Ensure that at least one column is visible at all times
|
|
|
|
bool atLeastOne = false;
|
|
|
|
for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) {
|
|
|
|
if (!m_ui->resultsBrowser->isColumnHidden(i)) {
|
|
|
|
atLeastOne = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!atLeastOne)
|
|
|
|
m_ui->resultsBrowser->setColumnHidden(SearchSortModel::NAME, false);
|
|
|
|
//To also mitigate the above issue, we have to resize each column when
|
|
|
|
//its size is 0, because explicitly 'showing' the column isn't enough
|
|
|
|
//in the above scenario.
|
|
|
|
for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++)
|
|
|
|
if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i))
|
|
|
|
m_ui->resultsBrowser->resizeColumnToContents(i);
|
|
|
|
|
2015-04-11 14:26:25 +03:00
|
|
|
// Connect signals to slots (search part)
|
2016-04-11 15:00:50 +03:00
|
|
|
connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&)));
|
2015-04-11 14:26:25 +03:00
|
|
|
|
2016-06-22 18:25:53 +03:00
|
|
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &)));
|
2016-06-22 16:34:53 +03:00
|
|
|
connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings()));
|
|
|
|
connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings()));
|
2016-08-30 13:23:22 +03:00
|
|
|
connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings()));
|
2015-09-23 23:20:22 +03:00
|
|
|
|
|
|
|
fillFilterComboBoxes();
|
|
|
|
|
|
|
|
updateFilter();
|
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
connect(m_ui->filterMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->minSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->minSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->maxSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->maxSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->minSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->minSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->maxSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->maxSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->minSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
|
|
|
connect(m_ui->maxSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchTab::~SearchTab()
|
|
|
|
{
|
2016-06-22 16:34:53 +03:00
|
|
|
saveSettings();
|
2016-02-27 23:37:41 +03:00
|
|
|
delete m_ui;
|
2009-08-27 16:37:39 +04:00
|
|
|
}
|
|
|
|
|
2016-04-11 15:00:50 +03:00
|
|
|
void SearchTab::downloadItem(const QModelIndex &index)
|
2015-09-24 10:33:02 +03:00
|
|
|
{
|
|
|
|
QString torrentUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString();
|
2016-04-06 12:32:44 +03:00
|
|
|
QString siteUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::ENGINE_URL)).toString();
|
2016-05-26 18:07:19 +03:00
|
|
|
setRowColor(index.row(), QApplication::palette().color(QPalette::LinkVisited));
|
2016-04-06 12:32:44 +03:00
|
|
|
m_parent->downloadTorrent(siteUrl, torrentUrl);
|
2008-06-25 23:29:29 +04:00
|
|
|
}
|
|
|
|
|
2015-09-24 10:33:02 +03:00
|
|
|
QHeaderView* SearchTab::header() const
|
|
|
|
{
|
2016-02-27 23:37:41 +03:00
|
|
|
return m_ui->resultsBrowser->header();
|
2009-03-10 00:24:40 +03:00
|
|
|
}
|
|
|
|
|
2015-09-24 10:33:02 +03:00
|
|
|
QTreeView* SearchTab::getCurrentTreeView() const
|
2008-06-25 23:29:29 +04:00
|
|
|
{
|
2016-02-27 23:37:41 +03:00
|
|
|
return m_ui->resultsBrowser;
|
2008-06-25 23:29:29 +04:00
|
|
|
}
|
|
|
|
|
2015-09-23 23:20:22 +03:00
|
|
|
SearchSortModel* SearchTab::getCurrentSearchListProxy() const
|
2009-10-25 02:49:10 +04:00
|
|
|
{
|
2015-09-24 10:33:02 +03:00
|
|
|
return m_proxyModel;
|
2009-10-25 02:49:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItemModel* SearchTab::getCurrentSearchListModel() const
|
2008-06-25 23:29:29 +04:00
|
|
|
{
|
2015-09-24 10:33:02 +03:00
|
|
|
return m_searchListModel;
|
2008-06-25 23:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the color of a row in data model
|
2016-05-26 18:07:19 +03:00
|
|
|
void SearchTab::setRowColor(int row, const QColor &color)
|
2015-09-24 10:33:02 +03:00
|
|
|
{
|
|
|
|
m_proxyModel->setDynamicSortFilter(false);
|
2015-09-23 23:20:22 +03:00
|
|
|
for (int i = 0; i < m_proxyModel->columnCount(); ++i)
|
2016-05-26 18:07:19 +03:00
|
|
|
m_proxyModel->setData(m_proxyModel->index(row, i), color, Qt::ForegroundRole);
|
2015-09-24 10:33:02 +03:00
|
|
|
|
|
|
|
m_proxyModel->setDynamicSortFilter(true);
|
2008-06-25 23:29:29 +04:00
|
|
|
}
|
|
|
|
|
2015-09-23 23:20:22 +03:00
|
|
|
SearchTab::Status SearchTab::status() const
|
2015-09-24 10:33:02 +03:00
|
|
|
{
|
|
|
|
return m_status;
|
|
|
|
}
|
2008-06-25 23:29:29 +04:00
|
|
|
|
2015-09-23 23:20:22 +03:00
|
|
|
void SearchTab::setStatus(Status value)
|
2015-09-24 10:33:02 +03:00
|
|
|
{
|
|
|
|
m_status = value;
|
2015-09-23 23:20:22 +03:00
|
|
|
setStatusTip(statusText(value));
|
|
|
|
const int thisTabIndex = m_parent->searchTabs()->indexOf(this);
|
|
|
|
m_parent->searchTabs()->setTabToolTip(thisTabIndex, statusTip());
|
|
|
|
m_parent->searchTabs()->setTabIcon(thisTabIndex, GuiIconProvider::instance()->getIcon(statusIconName(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchTab::updateResultsCount()
|
|
|
|
{
|
|
|
|
const int totalResults = getCurrentSearchListModel() ? getCurrentSearchListModel()->rowCount(QModelIndex()) : 0;
|
|
|
|
const int filteredResults = getCurrentSearchListProxy() ? getCurrentSearchListProxy()->rowCount(QModelIndex()) : totalResults;
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->resultsLbl->setText(tr("Results (showing <i>%1</i> out of <i>%2</i>):", "i.e: Search results")
|
|
|
|
.arg(filteredResults).arg(totalResults));
|
2015-09-23 23:20:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchTab::updateFilter()
|
|
|
|
{
|
|
|
|
using Utils::Misc::SizeUnit;
|
|
|
|
SearchSortModel* filterModel = getCurrentSearchListProxy();
|
|
|
|
filterModel->enableNameFilter(filteringMode() == OnlyNames);
|
|
|
|
// we update size and seeds filter parameters in the model even if they are disabled
|
2016-02-27 23:37:41 +03:00
|
|
|
filterModel->setSeedsFilter(m_ui->minSeeds->value(), m_ui->maxSeeds->value());
|
2015-09-23 23:20:22 +03:00
|
|
|
filterModel->setSizeFilter(
|
2016-02-27 23:37:41 +03:00
|
|
|
sizeInBytes(m_ui->minSize->value(), static_cast<SizeUnit>(m_ui->minSizeUnit->currentIndex())),
|
|
|
|
sizeInBytes(m_ui->maxSize->value(), static_cast<SizeUnit>(m_ui->maxSizeUnit->currentIndex())));
|
2015-09-23 23:20:22 +03:00
|
|
|
|
|
|
|
SettingsStorage::instance()->storeValue(KEY_FILTER_MODE_SETTING_NAME,
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()));
|
|
|
|
|
2015-09-23 23:20:22 +03:00
|
|
|
filterModel->invalidate();
|
|
|
|
updateResultsCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchTab::fillFilterComboBoxes()
|
|
|
|
{
|
|
|
|
using Utils::Misc::SizeUnit;
|
|
|
|
QStringList unitStrings;
|
|
|
|
unitStrings.append(unitString(SizeUnit::Byte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::KibiByte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::MebiByte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::GibiByte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::TebiByte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::PebiByte));
|
|
|
|
unitStrings.append(unitString(SizeUnit::ExbiByte));
|
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->minSizeUnit->clear();
|
|
|
|
m_ui->maxSizeUnit->clear();
|
|
|
|
m_ui->minSizeUnit->addItems(unitStrings);
|
|
|
|
m_ui->maxSizeUnit->addItems(unitStrings);
|
2015-09-23 23:20:22 +03:00
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->minSize->setValue(0);
|
|
|
|
m_ui->minSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::MebiByte));
|
2015-09-23 23:20:22 +03:00
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->maxSize->setValue(-1);
|
2016-05-30 23:51:09 +03:00
|
|
|
m_ui->maxSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::GibiByte));
|
2015-09-23 23:20:22 +03:00
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->filterMode->clear();
|
2015-09-23 23:20:22 +03:00
|
|
|
|
|
|
|
QMetaEnum nameFilteringModeEnum =
|
|
|
|
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
|
|
|
|
|
2016-02-27 23:37:41 +03:00
|
|
|
m_ui->filterMode->addItem(tr("Torrent names only"), nameFilteringModeEnum.valueToKey(OnlyNames));
|
|
|
|
m_ui->filterMode->addItem(tr("Everywhere"), nameFilteringModeEnum.valueToKey(Everywhere));
|
2015-09-23 23:20:22 +03:00
|
|
|
|
|
|
|
QVariant selectedMode = SettingsStorage::instance()->loadValue(
|
|
|
|
KEY_FILTER_MODE_SETTING_NAME, nameFilteringModeEnum.valueToKey(OnlyNames));
|
2016-02-27 23:37:41 +03:00
|
|
|
int index = m_ui->filterMode->findData(selectedMode);
|
|
|
|
m_ui->filterMode->setCurrentIndex(index == -1 ? 0 : index);
|
2015-09-23 23:20:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SearchTab::statusText(SearchTab::Status st)
|
|
|
|
{
|
|
|
|
switch (st) {
|
|
|
|
case Status::Ongoing:
|
|
|
|
return tr("Searching...");
|
|
|
|
case Status::Finished:
|
|
|
|
return tr("Search has finished");
|
|
|
|
case Status::Aborted:
|
|
|
|
return tr("Search aborted");
|
|
|
|
case Status::Error:
|
|
|
|
return tr("An error occurred during search...");
|
|
|
|
case Status::NoResults:
|
|
|
|
return tr("Search returned no results");
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SearchTab::statusIconName(SearchTab::Status st)
|
|
|
|
{
|
|
|
|
switch (st) {
|
|
|
|
case Status::Ongoing:
|
|
|
|
return QLatin1String("task-ongoing");
|
|
|
|
case Status::Finished:
|
|
|
|
return QLatin1String("task-complete");
|
|
|
|
case Status::Aborted:
|
|
|
|
return QLatin1String("task-reject");
|
|
|
|
case Status::Error:
|
|
|
|
return QLatin1String("task-attention");
|
|
|
|
case Status::NoResults:
|
|
|
|
return QLatin1String("task-attention");
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchTab::NameFilteringMode SearchTab::filteringMode() const
|
|
|
|
{
|
|
|
|
QMetaEnum metaEnum =
|
|
|
|
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
|
2016-02-27 23:37:41 +03:00
|
|
|
return static_cast<NameFilteringMode>(metaEnum.keyToValue(m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()).toByteArray()));
|
2015-09-24 10:33:02 +03:00
|
|
|
}
|
2016-06-22 16:34:53 +03:00
|
|
|
|
|
|
|
void SearchTab::loadSettings()
|
|
|
|
{
|
|
|
|
header()->restoreState(Preferences::instance()->getSearchTabHeaderState());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchTab::saveSettings() const
|
|
|
|
{
|
|
|
|
Preferences::instance()->setSearchTabHeaderState(header()->saveState());
|
|
|
|
}
|
2016-06-22 18:25:53 +03:00
|
|
|
|
|
|
|
void SearchTab::displayToggleColumnsMenu(const QPoint&)
|
|
|
|
{
|
|
|
|
QMenu hideshowColumn(this);
|
|
|
|
hideshowColumn.setTitle(tr("Column visibility"));
|
|
|
|
QList<QAction*> actions;
|
|
|
|
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) {
|
|
|
|
QAction *myAct = hideshowColumn.addAction(m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
|
|
|
myAct->setCheckable(true);
|
|
|
|
myAct->setChecked(!m_ui->resultsBrowser->isColumnHidden(i));
|
|
|
|
actions.append(myAct);
|
|
|
|
}
|
|
|
|
int visibleCols = 0;
|
|
|
|
for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) {
|
|
|
|
if (!m_ui->resultsBrowser->isColumnHidden(i))
|
|
|
|
visibleCols++;
|
|
|
|
|
|
|
|
if (visibleCols > 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call menu
|
|
|
|
QAction *act = hideshowColumn.exec(QCursor::pos());
|
|
|
|
if (act) {
|
|
|
|
int col = actions.indexOf(act);
|
|
|
|
Q_ASSERT(col >= 0);
|
|
|
|
Q_ASSERT(visibleCols > 0);
|
|
|
|
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (visibleCols == 1))
|
|
|
|
return;
|
|
|
|
qDebug("Toggling column %d visibility", col);
|
|
|
|
m_ui->resultsBrowser->setColumnHidden(col, !m_ui->resultsBrowser->isColumnHidden(col));
|
|
|
|
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (m_ui->resultsBrowser->columnWidth(col) <= 5))
|
|
|
|
m_ui->resultsBrowser->setColumnWidth(col, 100);
|
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
}
|