mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-02 21:52:32 -06:00
Improve the "Watch folders" UI. Closes #4300.
This commit is contained in:
@@ -42,6 +42,7 @@ HEADERS += \
|
||||
$$PWD/shutdownconfirm.h \
|
||||
$$PWD/torrentmodel.h \
|
||||
$$PWD/torrentcreatordlg.h \
|
||||
$$PWD/scanfoldersdelegate.h \
|
||||
$$PWD/search/searchwidget.h \
|
||||
$$PWD/search/searchtab.h \
|
||||
$$PWD/search/pluginselectdlg.h \
|
||||
@@ -79,6 +80,7 @@ SOURCES += \
|
||||
$$PWD/shutdownconfirm.cpp \
|
||||
$$PWD/torrentmodel.cpp \
|
||||
$$PWD/torrentcreatordlg.cpp \
|
||||
$$PWD/scanfoldersdelegate.cpp \
|
||||
$$PWD/search/searchwidget.cpp \
|
||||
$$PWD/search/searchtab.cpp \
|
||||
$$PWD/search/pluginselectdlg.cpp \
|
||||
|
||||
@@ -714,7 +714,7 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_16">
|
||||
<item>
|
||||
<widget class="QTableView" name="scanFoldersView">
|
||||
<widget class="QTreeView" name="scanFoldersView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -727,30 +727,24 @@
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::AllEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::ElideNone</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>80</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -41,15 +41,17 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include <cstdlib>
|
||||
#include "options_imp.h"
|
||||
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "advancedsettings.h"
|
||||
#include "base/scanfoldersmodel.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "base/net/dnsupdater.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "advancedsettings.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "scanfoldersdelegate.h"
|
||||
#include "options_imp.h"
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
#include <QSslKey>
|
||||
@@ -91,11 +93,12 @@ options_imp::options_imp(QWidget *parent)
|
||||
}
|
||||
|
||||
#ifndef QBT_USES_QT5
|
||||
scanFoldersView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
scanFoldersView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
scanFoldersView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
scanFoldersView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
scanFoldersView->setModel(ScanFoldersModel::instance());
|
||||
scanFoldersView->setItemDelegate(new ScanFoldersDelegate(this, scanFoldersView));
|
||||
connect(ScanFoldersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(enableApplyButton()));
|
||||
connect(scanFoldersView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleScanFolderViewSelectionChanged()));
|
||||
|
||||
@@ -1200,7 +1203,7 @@ void options_imp::on_addScanFolderButton_clicked()
|
||||
const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"),
|
||||
Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath())));
|
||||
if (!dir.isEmpty()) {
|
||||
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, true, "");
|
||||
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER, QString());
|
||||
QString error;
|
||||
switch (status) {
|
||||
case ScanFoldersModel::AlreadyInList:
|
||||
@@ -1215,7 +1218,8 @@ void options_imp::on_addScanFolderButton_clicked()
|
||||
default:
|
||||
pref->setScanDirsLastPath(dir);
|
||||
addedScanDirs << dir;
|
||||
scanFoldersView->resizeColumnsToContents();
|
||||
for (int i = 0; i < ScanFoldersModel::instance()->columnCount(); ++i)
|
||||
scanFoldersView->resizeColumnToContents(i);
|
||||
enableApplyButton();
|
||||
}
|
||||
|
||||
|
||||
183
src/gui/scanfoldersdelegate.cpp
Normal file
183
src/gui/scanfoldersdelegate.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 sledgehammer999
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Contact : hammered999@gmail.com
|
||||
*/
|
||||
|
||||
#include <QPainter>
|
||||
#include <QComboBox>
|
||||
#include <QFileDialog>
|
||||
#include <QTreeView>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
#include "base/scanfoldersmodel.h"
|
||||
#include "base/preferences.h"
|
||||
#include "scanfoldersdelegate.h"
|
||||
|
||||
|
||||
ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView)
|
||||
: QItemDelegate(parent)
|
||||
, m_folderView(foldersView)
|
||||
{
|
||||
}
|
||||
|
||||
ScanFoldersDelegate::~ScanFoldersDelegate() {}
|
||||
|
||||
void ScanFoldersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
switch(index.column()) {
|
||||
case ScanFoldersModel::WATCH:
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
break;
|
||||
|
||||
case ScanFoldersModel::DOWNLOAD: {
|
||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
QString text;
|
||||
|
||||
switch (index.data().toInt()) {
|
||||
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||
text = tr("Watch Folder");
|
||||
break;
|
||||
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||
text = tr("Default Folder");
|
||||
break;
|
||||
case ScanFoldersModel::CUSTOM_LOCATION:
|
||||
text = index.data(Qt::UserRole).toString();
|
||||
break;
|
||||
}
|
||||
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||||
// Set combobox index
|
||||
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION)
|
||||
combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu
|
||||
else
|
||||
combobox->setCurrentIndex(index.data().toInt());
|
||||
}
|
||||
|
||||
QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() != ScanFoldersModel::DOWNLOAD) return 0;
|
||||
|
||||
QComboBox* editor = new QComboBox(parent);
|
||||
editor->setFocusPolicy(Qt::StrongFocus);
|
||||
editor->addItem(tr("Watch Folder"));
|
||||
editor->addItem(tr("Default Folder"));
|
||||
editor->addItem(tr("Browse..."));
|
||||
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION) {
|
||||
editor->insertSeparator(3);
|
||||
editor->addItem(index.data(Qt::UserRole).toString());
|
||||
}
|
||||
|
||||
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||
return editor;
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||||
int value = combobox->currentIndex();
|
||||
|
||||
switch(value) {
|
||||
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||
model->setData(index, value, Qt::DisplayRole);
|
||||
break;
|
||||
|
||||
case 4: // '4' is the index of the item after the separator in the QComboBox menu
|
||||
model->setData(index, combobox->currentText(), Qt::UserRole);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
qDebug("UpdateEditor Geometry called");
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::comboboxIndexChanged(int index)
|
||||
{
|
||||
if (index < 2)
|
||||
return;
|
||||
|
||||
if (index == 2) {
|
||||
QString path;
|
||||
QString newPath;
|
||||
QModelIndexList selIndex = m_folderView->selectionModel()->selectedRows(1);
|
||||
|
||||
if (selIndex.isEmpty())
|
||||
return;
|
||||
|
||||
ScanFoldersModel::PathType type = static_cast<ScanFoldersModel::PathType>(selIndex.at(0).data().toInt());
|
||||
|
||||
if (type == ScanFoldersModel::CUSTOM_LOCATION)
|
||||
path = selIndex.at(0).data(Qt::UserRole).toString();
|
||||
else
|
||||
path = Preferences::instance()->getSavePath();
|
||||
|
||||
newPath = QFileDialog::getExistingDirectory(0, tr("Choose save path"), path);
|
||||
QComboBox *combobox = static_cast<QComboBox*>(sender());
|
||||
disconnect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||
|
||||
if (!newPath.isEmpty()) {
|
||||
if (combobox->count() != 5) {
|
||||
combobox->insertSeparator(3);
|
||||
combobox->addItem(newPath);
|
||||
}
|
||||
else {
|
||||
combobox->setItemText(4, newPath);
|
||||
}
|
||||
combobox->setCurrentIndex(4);
|
||||
}
|
||||
else {
|
||||
if (type == ScanFoldersModel::CUSTOM_LOCATION)
|
||||
combobox->setCurrentIndex(4);
|
||||
else
|
||||
combobox->setCurrentIndex(type);
|
||||
}
|
||||
|
||||
connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||
}
|
||||
}
|
||||
65
src/gui/scanfoldersdelegate.h
Normal file
65
src/gui/scanfoldersdelegate.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 sledgehammer999
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Contact : hammered999@gmail.com
|
||||
*/
|
||||
|
||||
#ifndef SCANFOLDERSDELEGATE_H
|
||||
#define SCANFOLDERSDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
|
||||
class QPainter;
|
||||
class QModelIndex;
|
||||
class QStyleOptionViewItem;
|
||||
class QAbstractItemModel;
|
||||
class PropertiesWidget;
|
||||
class QTreeView;
|
||||
|
||||
class ScanFoldersDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScanFoldersDelegate(QObject *parent, QTreeView *foldersView);
|
||||
~ScanFoldersDelegate();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;
|
||||
|
||||
public slots:
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const;
|
||||
void comboboxIndexChanged(int index);
|
||||
|
||||
private:
|
||||
QTreeView *m_folderView;
|
||||
};
|
||||
|
||||
#endif // SCANFOLDERSDELEGATE_H
|
||||
|
||||
Reference in New Issue
Block a user