(trunk, qt) #4813: allow launching files in Qt interface
This commit is contained in:
parent
9ef851e790
commit
2855e83e45
|
@ -17,6 +17,7 @@
|
|||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDateTime>
|
||||
#include <QDesktopServices>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QEvent>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ class Details: public QDialog
|
|||
void onFilePriorityChanged (const QSet<int>& fileIndices, int);
|
||||
void onFileWantedChanged (const QSet<int>& fileIndices, bool);
|
||||
void onPathEdited (const QString& oldpath, const QString& newname);
|
||||
void onOpenRequested (const QString& path);
|
||||
void onHonorsSessionLimitsToggled (bool);
|
||||
void onDownloadLimitedToggled (bool);
|
||||
void onSpinBoxEditingFinished ();
|
||||
|
|
|
@ -380,6 +380,30 @@ FileTreeItem :: twiddleWanted (QSet<int>& 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>&, int)),
|
||||
this, SIGNAL(priorityChanged(const QSet<int>&, 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)
|
||||
{
|
||||
|
|
|
@ -68,6 +68,8 @@ class FileTreeItem: public QObject
|
|||
void twiddlePriority (QSet<int>& 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<int>& fileIds);
|
||||
|
@ -115,6 +117,7 @@ class FileTreeModel: public QAbstractItemModel
|
|||
void priorityChanged (const QSet<int>& fileIndices, int);
|
||||
void wantedChanged (const QSet<int>& 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<int>& fileIndices, int priority);
|
||||
void wantedChanged (const QSet<int>& 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
|
||||
|
|
Loading…
Reference in New Issue