1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-09-08 12:02:18 +00:00

Add 'Open' and 'Open Containing Folder' entries in the content's right-click menu. Closes #1143.

This commit is contained in:
sledgehammer999 2014-08-15 12:50:42 +03:00
parent efb3936ef1
commit 3e734ab4f6
2 changed files with 74 additions and 53 deletions

View File

@ -87,7 +87,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll())); connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone())); connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&))); connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
connect(filesList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openDoubleClickedFile(QModelIndex))); connect(filesList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(openDoubleClickedFile(const QModelIndex &)));
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&))); connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&)));
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle)), this, SLOT(loadTorrentInfos(QTorrentHandle))); connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle)), this, SLOT(loadTorrentInfos(QTorrentHandle)));
@ -410,10 +410,16 @@ void PropertiesWidget::loadUrlSeeds() {
} }
} }
void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) {
if (!index.isValid()) return; if (!index.isValid()) return;
if (!h.is_valid() || !h.has_metadata()) return; if (!h.is_valid() || !h.has_metadata()) return;
if (PropListModel->itemType(index) == TorrentContentModelItem::FileType) { if (PropListModel->itemType(index) == TorrentContentModelItem::FileType)
openFile(index);
else
openFolder(index, false);
}
void PropertiesWidget::openFile(const QModelIndex &index) {
int i = PropListModel->getFileIndex(index); int i = PropListModel->getFileIndex(index);
const QDir saveDir(h.save_path()); const QDir saveDir(h.save_path());
const QString filename = h.filepath_at(i); const QString filename = h.filepath_at(i);
@ -425,10 +431,13 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
// Hack to access samba shares with QDesktopServices::openUrl // Hack to access samba shares with QDesktopServices::openUrl
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path; const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
QDesktopServices::openUrl(QUrl::fromLocalFile(p)); QDesktopServices::openUrl(QUrl::fromLocalFile(p));
} else { }
else {
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet.")); QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
} }
} else { }
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder) {
// FOLDER // FOLDER
QStringList path_items; QStringList path_items;
path_items << index.data().toString(); path_items << index.data().toString();
@ -437,6 +446,10 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent); parent = PropListModel->parent(parent);
} }
if (path_items.isEmpty())
return;
if (containing_folder)
path_items.removeLast();
const QDir saveDir(h.save_path()); const QDir saveDir(h.save_path());
const QString filename = path_items.join("/"); const QString filename = path_items.join("/");
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename)); const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
@ -450,14 +463,17 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
} else { } else {
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet.")); QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
} }
}
} }
void PropertiesWidget::displayFilesListMenu(const QPoint&) { void PropertiesWidget::displayFilesListMenu(const QPoint&) {
QMenu myFilesLlistMenu; QMenu myFilesLlistMenu;
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0); QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
QAction *actOpen = 0;
QAction *actOpenContainingFolder = 0;
QAction *actRename = 0; QAction *actRename = 0;
if (selectedRows.size() == 1) { if (selectedRows.size() == 1) {
actOpen = myFilesLlistMenu.addAction(tr("Open"));
actOpenContainingFolder = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename...")); actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
myFilesLlistMenu.addSeparator(); myFilesLlistMenu.addSeparator();
} }
@ -474,24 +490,25 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
const QAction *act = myFilesLlistMenu.exec(QCursor::pos()); const QAction *act = myFilesLlistMenu.exec(QCursor::pos());
// The selected torrent might have dissapeared during exec() // The selected torrent might have dissapeared during exec()
// from the current view thus leaving invalid indices. // from the current view thus leaving invalid indices.
if (!(selectedRows.begin()->isValid())) const QModelIndex index = *(selectedRows.begin());
if (!index.isValid())
return; return;
if (act) { if (act) {
if (act == actRename) { if (act == actOpen)
openDoubleClickedFile(index);
else if (act == actOpenContainingFolder)
openFolder(index, true);
else if (act == actRename)
renameSelectedFile(); renameSelectedFile();
} else { else {
int prio = 1; int prio = prio::NORMAL;
if (act == actionHigh) { if (act == actionHigh)
prio = prio::HIGH; prio = prio::HIGH;
} else { else if (act == actionMaximum)
if (act == actionMaximum) {
prio = prio::MAXIMUM; prio = prio::MAXIMUM;
} else { else if (act == actionNot_downloaded)
if (act == actionNot_downloaded) {
prio = prio::IGNORED; prio = prio::IGNORED;
}
}
}
qDebug("Setting files priority"); qDebug("Setting files priority");
foreach (QModelIndex index, selectedRows) { foreach (QModelIndex index, selectedRows) {
qDebug("Setting priority(%d) for file at row %d", prio, index.row()); qDebug("Setting priority(%d) for file at row %d", prio, index.row());

View File

@ -95,9 +95,13 @@ public slots:
void readSettings(); void readSettings();
void saveSettings(); void saveSettings();
void reloadPreferences(); void reloadPreferences();
void openDoubleClickedFile(QModelIndex); void openDoubleClickedFile(const QModelIndex &);
void updateSavePath(const QTorrentHandle& h); void updateSavePath(const QTorrentHandle& h);
private:
void openFile(const QModelIndex &index);
void openFolder(const QModelIndex &index, bool containing_folder);
private: private:
TransferListWidget *transferList; TransferListWidget *transferList;
MainWindow *main_window; MainWindow *main_window;