Skip to content

Commit

Permalink
- Use checkboxes for selective downloading instead of comboboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Dumez committed Dec 19, 2009
1 parent 7d66c07 commit 9586f0e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 300 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- FEATURE: Peer Exchange (PeX) can be disabled from preferences
- FEATURE: Append !.qB extension to incomplete files option (libtorrent >= v0.15 only)
- FEATURE: Torrent files/folders can be renamed
- COSMETIC: Use checkboxes to filter torrent content instead of comboboxes

* Thu Dec 10 2009 - Christophe Dumez <chris@qbittorrent.org> - v2.0.0
- FEATURE: Added program option to disable splash screen
Expand Down
63 changes: 3 additions & 60 deletions src/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,12 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferLi
PropDelegate = new PropListDelegate(this);
filesList->setItemDelegate(PropDelegate);

// QActions
actionIgnored = new QAction(tr("Ignored"), this);
actionNormal = new QAction(tr("Normal"), this);
actionMaximum = new QAction(tr("Maximum"), this);
actionHigh = new QAction(tr("High"), this);

// SIGNAL/SLOTS
connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&)));
connect(collapseAllButton, SIGNAL(clicked()), filesList, SLOT(collapseAll()));
connect(expandAllButton, SIGNAL(clicked()), filesList, SLOT(expandAll()));
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(addWS_button, SIGNAL(clicked()), this, SLOT(askWebSeed()));
connect(deleteWS_button, SIGNAL(clicked()), this, SLOT(deleteSelectedUrlSeeds()));
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &)));
Expand Down Expand Up @@ -126,11 +117,6 @@ PropertiesWidget::~PropertiesWidget() {
delete pieces_availability;
delete PropListModel;
delete PropDelegate;
// Delete QActions
delete actionIgnored;
delete actionNormal;
delete actionMaximum;
delete actionHigh;
}


Expand Down Expand Up @@ -482,12 +468,9 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){
if(selectedRows.size() == 1) {
actRename = myFilesLlistMenu.addAction(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename..."));
myFilesLlistMenu.addSeparator();
} else {
return;
}
QMenu *prioritiesMenu = myFilesLlistMenu.addMenu(QIcon(":/Icons/oxygen/services.png"), tr("Set priority"));
prioritiesMenu->addAction(actionIgnored);
prioritiesMenu->addAction(actionNormal);
prioritiesMenu->addAction(actionHigh);
prioritiesMenu->addAction(actionMaximum);
// Call menu
QAction *act = myFilesLlistMenu.exec(QCursor::pos());
if(act) {
Expand Down Expand Up @@ -592,46 +575,6 @@ void PropertiesWidget::renameSelectedFile() {
}
}

void PropertiesWidget::ignoreSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
foreach(const QModelIndex &index, selectedIndexes){
if(PropListModel->data(index) != QVariant(IGNORED)){
PropListModel->setData(index, QVariant(IGNORED));
filteredFilesChanged();
}
}
}

void PropertiesWidget::normalSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
foreach(const QModelIndex &index, selectedIndexes){
if(PropListModel->data(index) != QVariant(NORMAL)){
PropListModel->setData(index, QVariant(NORMAL));
filteredFilesChanged();
}
}
}

void PropertiesWidget::highSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
foreach(const QModelIndex &index, selectedIndexes){
if(PropListModel->data(index) != QVariant(HIGH)){
PropListModel->setData(index, QVariant(HIGH));
filteredFilesChanged();
}
}
}

void PropertiesWidget::maximumSelection(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
foreach(const QModelIndex &index, selectedIndexes){
if(PropListModel->data(index) != QVariant(MAXIMUM)){
PropListModel->setData(index, QVariant(MAXIMUM));
filteredFilesChanged();
}
}
}

void PropertiesWidget::askWebSeed(){
bool ok;
// Ask user for a new url seed
Expand Down
8 changes: 0 additions & 8 deletions src/propertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
PropListDelegate *PropDelegate;
PeerListWidget *peersList;
TrackerList *trackerList;
QAction *actionIgnored;
QAction *actionNormal;
QAction *actionMaximum;
QAction *actionHigh;
QList<int> slideSizes;
DownloadedPiecesBar *downloaded_pieces;
PieceAvailabilityBar *pieces_availability;
Expand All @@ -86,10 +82,6 @@ protected slots:
void on_peers_button_clicked();
void on_url_seeds_button_clicked();
void on_files_button_clicked();
void ignoreSelection();
void normalSelection();
void highSelection();
void maximumSelection();
void askWebSeed();
void deleteSelectedUrlSeeds();
void displayFilesListMenu(const QPoint& pos);
Expand Down
135 changes: 3 additions & 132 deletions src/proplistdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
#include "propertieswidget.h"

// Defines for properties list columns
enum PropColumn {NAME, SIZE, PROGRESS, PRIORITY};
enum PropPriority {IGNORED=0, NORMAL=1, HIGH=2, MAXIMUM=7};
enum PropColumn {NAME, SIZE, PROGRESS};

class PropListDelegate: public QItemDelegate {
Q_OBJECT
Expand Down Expand Up @@ -82,81 +81,11 @@ class PropListDelegate: public QItemDelegate {
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
break;
}
case PRIORITY:{
QStyleOptionComboBox newopt;
newopt.rect = opt.rect;
switch(index.data().toInt()){
case IGNORED:
newopt.currentText = tr("Ignored");
break;
case NORMAL:
newopt.currentText = tr("Normal", "Normal (priority)");
break;
case HIGH:
newopt.currentText = tr("High", "High (priority)");
break;
case MAXIMUM:
newopt.currentText = tr("Maximum", "Maximum (priority)");
break;
default:
qDebug("Unhandled priority, setting NORMAL");
newopt.currentText = tr("Normal", "Normal (priority)");
}
//newopt.state |= QStyle::State_Enabled;
//newopt.subControls = QStyle::SC_All;
//painter->translate(QPoint(opt.rect.x()*-1,opt.rect.y()*-1));
//QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &newopt, painter);
//painter->translate(QPoint(opt.rect.x(),opt.rect.y()));
//QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &newopt, painter);
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, newopt.currentText);
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
}

QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const {
qDebug("CreateEditor called");
if(index.column() != PRIORITY) return 0;
if(properties) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid() || h.get_torrent_handle().is_seed() || !h.has_metadata()) return 0;
}
QComboBox* editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("Ignored"));
editor->addItem(tr("Normal", "Normal (priority)"));
editor->addItem(tr("High", "High (priority)"));
editor->addItem(tr("Maximum", "Maximum (priority)"));
return editor;
}

void setEditorData(QWidget *editor, const QModelIndex &index) const {
qDebug("setEditorData called");
unsigned short val = index.model()->data(index, Qt::DisplayRole).toInt();
QComboBox *combobox = static_cast<QComboBox*>(editor);
qDebug("Set Editor data: Prio is %d", val);
switch(val){
case IGNORED:
combobox->setCurrentIndex(0);
break;
case NORMAL:
combobox->setCurrentIndex(1);
break;
case HIGH:
combobox->setCurrentIndex(2);
break;
case MAXIMUM:
combobox->setCurrentIndex(3);
break;
default:
qDebug("Unhandled priority, setting to NORMAL");
combobox->setCurrentIndex(1);
}
}

QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{
QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
Expand All @@ -167,66 +96,8 @@ class PropListDelegate: public QItemDelegate {
return textRect.size();
}

public slots:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
QComboBox *combobox = static_cast<QComboBox*>(editor);
int value = combobox->currentIndex();
qDebug("Setting combobox value in index: %d", value);
unsigned short old_val = index.model()->data(index, Qt::DisplayRole).toInt();
switch(value){
case 0:
if(old_val != IGNORED){
model->setData(index, QVariant(IGNORED));
emit filteredFilesChanged();
} else {
// XXX: hack to force the model to send the itemChanged() signal
model->setData(index, QVariant(NORMAL));
model->setData(index, QVariant(IGNORED));
}
break;
case 1:
// if(old_val != NORMAL){
// model->setData(index, QVariant(NORMAL));
// if(filteredFilesChanged != 0)
// *filteredFilesChanged = true;
// } else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(NORMAL));
emit filteredFilesChanged();
// }
break;
case 2:
if(old_val != HIGH){
model->setData(index, QVariant(HIGH));
emit filteredFilesChanged();
} else {
model->setData(index, QVariant(NORMAL));
model->setData(index, QVariant(HIGH));
}
break;
case 3:
if(old_val != MAXIMUM){
model->setData(index, QVariant(MAXIMUM));
emit filteredFilesChanged();
} else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(MAXIMUM));
}
break;
default:
if(old_val != NORMAL){
model->setData(index, QVariant(NORMAL));
emit filteredFilesChanged();
} else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(NORMAL));
}
}
}

void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
qDebug("UpdateEditor Geometry called");
editor->setGeometry(option.rect);
QWidget* createEditor(QWidget *, const QStyleOptionViewItem &/* option */, const QModelIndex &) const {
return 0;
}

};
Expand Down
53 changes: 0 additions & 53 deletions src/torrentadditiondlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
PropDelegate = new PropListDelegate();
torrentContentList->setItemDelegate(PropDelegate);
connect(torrentContentList, SIGNAL(clicked(const QModelIndex&)), torrentContentList, SLOT(edit(const QModelIndex&)));
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll()));
connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll()));
// Remember columns width
Expand Down Expand Up @@ -259,54 +254,6 @@ public slots:
return PropListModel->allFiltered();
}

void displayFilesListMenu(const QPoint&){
QMenu myFilesLlistMenu(this);
// Enable/disable pause/start action given the DL state
myFilesLlistMenu.setTitle(tr("Priority"));
myFilesLlistMenu.addAction(actionIgnored);
myFilesLlistMenu.addAction(actionNormal);
myFilesLlistMenu.addAction(actionHigh);
myFilesLlistMenu.addAction(actionMaximum);
// Call menu
myFilesLlistMenu.exec(QCursor::pos());
}

void ignoreSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
foreach(const QModelIndex &index, selectedIndexes){
if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(IGNORED));
}
}
}

void normalSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
foreach(const QModelIndex &index, selectedIndexes){
if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(NORMAL));
}
}
}

void highSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
foreach(const QModelIndex &index, selectedIndexes){
if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(HIGH));
}
}
}

void maximumSelection(){
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
foreach(const QModelIndex &index, selectedIndexes){
if(index.column() == PRIORITY){
PropListModel->setData(index, QVariant(MAXIMUM));
}
}
}

void savePiecesPriorities(){
qDebug("Saving pieces priorities");
std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files());
Expand Down
Loading

0 comments on commit 9586f0e

Please sign in to comment.