diff --git a/qt/details.cc b/qt/details.cc index ef40f0a9c..d18542662 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1394,6 +1395,9 @@ Details :: createFilesTab () connect (myFileTreeView, SIGNAL (pathEdited (const QString&, const QString&)), this, SLOT (onPathEdited (const QString&, const QString&))); + connect (myFileTreeView, SIGNAL (openRequested (const QString&)), + this, SLOT (onOpenRequested (const QString&))); + return myFileTreeView; } @@ -1434,3 +1438,24 @@ Details :: onPathEdited (const QString& oldpath, const QString& newname) { mySession.torrentRenamePath (myIds, oldpath, newname); } + +void +Details :: onOpenRequested (const QString& path) +{ + if (!mySession.isLocal ()) + return; + + foreach (const int id, myIds) + { + const Torrent * const tor = myModel.getTorrentFromId (id); + if (tor == NULL) + continue; + + const QString localFilePath = tor->getPath () + "/" + path; + if (!QFile::exists (localFilePath)) + continue; + + if (QDesktopServices::openUrl (QUrl::fromLocalFile (localFilePath))) + break; + } +} diff --git a/qt/details.h b/qt/details.h index 9b08d3146..5a61f0d96 100644 --- a/qt/details.h +++ b/qt/details.h @@ -142,6 +142,7 @@ class Details: public QDialog void onFilePriorityChanged (const QSet& fileIndices, int); void onFileWantedChanged (const QSet& fileIndices, bool); void onPathEdited (const QString& oldpath, const QString& newname); + void onOpenRequested (const QString& path); void onHonorsSessionLimitsToggled (bool); void onDownloadLimitedToggled (bool); void onSpinBoxEditingFinished (); diff --git a/qt/file-tree.cc b/qt/file-tree.cc index 8075aa259..4014d5ef6 100644 --- a/qt/file-tree.cc +++ b/qt/file-tree.cc @@ -380,6 +380,30 @@ FileTreeItem :: twiddleWanted (QSet& ids, bool& wanted) setSubtreeWanted (wanted, ids); } +QString +FileTreeItem :: path () const +{ + QString itemPath; + const FileTreeItem * item = this; + + while (item != NULL && !item->name().isEmpty()) + { + if (itemPath.isEmpty()) + itemPath = item->name(); + else + itemPath = item->name() + "/" + itemPath; + item = item->parent (); + } + + return itemPath; +} + +bool +FileTreeItem :: isComplete () const +{ + return myHaveSize == totalSize (); +} + /*** **** **** @@ -435,19 +459,9 @@ FileTreeModel :: setData (const QModelIndex& index, const QVariant& newname, int { if (role == Qt::EditRole) { - QString oldpath; FileTreeItem * item = itemFromIndex (index); - while (item && !item->name().isEmpty()) - { - if (oldpath.isEmpty()) - oldpath = item->name(); - else - oldpath = item->name() + "/" + oldpath; - item = item->parent (); - } - - emit pathEdited (oldpath, newname.toString()); + emit pathEdited (item->path (), newname.toString ()); } return false; // don't update the view until the session confirms the change @@ -739,6 +753,22 @@ FileTreeModel :: clicked (const QModelIndex& index) } } +void +FileTreeModel :: doubleClicked (const QModelIndex& index) +{ + if (!index.isValid()) + return; + + const int column (index.column()); + if (column == COL_WANTED || column == COL_PRIORITY) + return; + + FileTreeItem * item = itemFromIndex (index); + + if (item->childCount () == 0 && item->isComplete ()) + emit openRequested (item->path ()); +} + /**** ***** ****/ @@ -896,6 +926,9 @@ FileTreeView :: FileTreeView (QWidget * parent, bool isEditable): connect (this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onClicked(const QModelIndex&))); + connect (this, SIGNAL(doubleClicked(const QModelIndex&)), + this, SLOT(onDoubleClicked(const QModelIndex&))); + connect (&myModel, SIGNAL(priorityChanged(const QSet&, int)), this, SIGNAL(priorityChanged(const QSet&, int))); @@ -904,6 +937,10 @@ FileTreeView :: FileTreeView (QWidget * parent, bool isEditable): connect (&myModel, SIGNAL(pathEdited(const QString&, const QString&)), this, SIGNAL(pathEdited(const QString&, const QString&))); + + connect (&myModel, SIGNAL (openRequested (const QString&)), + this, SLOT (onOpenRequested (const QString&)), + Qt::QueuedConnection); } FileTreeView :: ~FileTreeView () @@ -918,6 +955,22 @@ FileTreeView :: onClicked (const QModelIndex& proxyIndex) myModel.clicked (modelIndex); } +void +FileTreeView :: onDoubleClicked (const QModelIndex& proxyIndex) +{ + const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex); + myModel.doubleClicked (modelIndex); +} + +void +FileTreeView :: onOpenRequested (const QString& path) +{ + if (state () == EditingState) + return; + + emit openRequested (path); +} + bool FileTreeView :: eventFilter (QObject * o, QEvent * event) { diff --git a/qt/file-tree.h b/qt/file-tree.h index c65000953..02486172b 100644 --- a/qt/file-tree.h +++ b/qt/file-tree.h @@ -68,6 +68,8 @@ class FileTreeItem: public QObject void twiddlePriority (QSet& fileIds, int&); int fileIndex () const { return myFileIndex; } uint64_t totalSize () const { return myTotalSize; } + QString path () const; + bool isComplete () const; private: void setSubtreePriority (int priority, QSet& fileIds); @@ -115,6 +117,7 @@ class FileTreeModel: public QAbstractItemModel void priorityChanged (const QSet& fileIndices, int); void wantedChanged (const QSet& fileIndices, bool); void pathEdited (const QString& oldpath, const QString& newname); + void openRequested (const QString& path); public: void clear (); @@ -138,6 +141,7 @@ class FileTreeModel: public QAbstractItemModel public slots: void clicked (const QModelIndex & index); + void doubleClicked (const QModelIndex & index); }; class FileTreeDelegate: public QItemDelegate @@ -167,6 +171,7 @@ class FileTreeView: public QTreeView void priorityChanged (const QSet& fileIndices, int priority); void wantedChanged (const QSet& fileIndices, bool wanted); void pathEdited (const QString& oldpath, const QString& newname); + void openRequested (const QString& path); protected: bool eventFilter (QObject *, QEvent *); @@ -178,6 +183,8 @@ class FileTreeView: public QTreeView public slots: void onClicked (const QModelIndex& index); + void onDoubleClicked (const QModelIndex& index); + void onOpenRequested (const QString& path); }; #endif