mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-09-08 03:52:26 +00:00
Add 'Open' and 'Open Containing Folder' entries in the content's right-click menu. Closes #1143.
This commit is contained in:
parent
efb3936ef1
commit
3e734ab4f6
@ -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,54 +410,70 @@ 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)
|
||||||
int i = PropListModel->getFileIndex(index);
|
openFile(index);
|
||||||
const QDir saveDir(h.save_path());
|
else
|
||||||
const QString filename = h.filepath_at(i);
|
openFolder(index, false);
|
||||||
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
}
|
||||||
qDebug("Trying to open file at %s", qPrintable(file_path));
|
|
||||||
// Flush data
|
void PropertiesWidget::openFile(const QModelIndex &index) {
|
||||||
h.flush_cache();
|
int i = PropListModel->getFileIndex(index);
|
||||||
if (QFile::exists(file_path)) {
|
const QDir saveDir(h.save_path());
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
const QString filename = h.filepath_at(i);
|
||||||
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
qDebug("Trying to open file at %s", qPrintable(file_path));
|
||||||
} else {
|
// Flush data
|
||||||
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
h.flush_cache();
|
||||||
}
|
if (QFile::exists(file_path)) {
|
||||||
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
|
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder) {
|
||||||
|
// FOLDER
|
||||||
|
QStringList path_items;
|
||||||
|
path_items << index.data().toString();
|
||||||
|
QModelIndex parent = PropListModel->parent(index);
|
||||||
|
while(parent.isValid()) {
|
||||||
|
path_items.prepend(parent.data().toString());
|
||||||
|
parent = PropListModel->parent(parent);
|
||||||
|
}
|
||||||
|
if (path_items.isEmpty())
|
||||||
|
return;
|
||||||
|
if (containing_folder)
|
||||||
|
path_items.removeLast();
|
||||||
|
const QDir saveDir(h.save_path());
|
||||||
|
const QString filename = path_items.join("/");
|
||||||
|
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
||||||
|
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
||||||
|
// Flush data
|
||||||
|
h.flush_cache();
|
||||||
|
if (QFile::exists(file_path)) {
|
||||||
|
// Hack to access samba shares with QDesktopServices::openUrl
|
||||||
|
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
||||||
} else {
|
} else {
|
||||||
// FOLDER
|
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
||||||
QStringList path_items;
|
|
||||||
path_items << index.data().toString();
|
|
||||||
QModelIndex parent = PropListModel->parent(index);
|
|
||||||
while(parent.isValid()) {
|
|
||||||
path_items.prepend(parent.data().toString());
|
|
||||||
parent = PropListModel->parent(parent);
|
|
||||||
}
|
|
||||||
const QDir saveDir(h.save_path());
|
|
||||||
const QString filename = path_items.join("/");
|
|
||||||
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
|
||||||
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
|
||||||
// Flush data
|
|
||||||
h.flush_cache();
|
|
||||||
if (QFile::exists(file_path)) {
|
|
||||||
// Hack to access samba shares with QDesktopServices::openUrl
|
|
||||||
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
|
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
|
|
||||||
} else {
|
|
||||||
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 if (act == actionNot_downloaded)
|
||||||
} else {
|
prio = prio::IGNORED;
|
||||||
if (act == actionNot_downloaded) {
|
|
||||||
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());
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user