(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 <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
@ -1394,6 +1395,9 @@ Details :: createFilesTab ()
|
||||||
connect (myFileTreeView, SIGNAL (pathEdited (const QString&, const QString&)),
|
connect (myFileTreeView, SIGNAL (pathEdited (const QString&, const QString&)),
|
||||||
this, SLOT (onPathEdited (const QString&, const QString&)));
|
this, SLOT (onPathEdited (const QString&, const QString&)));
|
||||||
|
|
||||||
|
connect (myFileTreeView, SIGNAL (openRequested (const QString&)),
|
||||||
|
this, SLOT (onOpenRequested (const QString&)));
|
||||||
|
|
||||||
return myFileTreeView;
|
return myFileTreeView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1434,3 +1438,24 @@ Details :: onPathEdited (const QString& oldpath, const QString& newname)
|
||||||
{
|
{
|
||||||
mySession.torrentRenamePath (myIds, oldpath, 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 onFilePriorityChanged (const QSet<int>& fileIndices, int);
|
||||||
void onFileWantedChanged (const QSet<int>& fileIndices, bool);
|
void onFileWantedChanged (const QSet<int>& fileIndices, bool);
|
||||||
void onPathEdited (const QString& oldpath, const QString& newname);
|
void onPathEdited (const QString& oldpath, const QString& newname);
|
||||||
|
void onOpenRequested (const QString& path);
|
||||||
void onHonorsSessionLimitsToggled (bool);
|
void onHonorsSessionLimitsToggled (bool);
|
||||||
void onDownloadLimitedToggled (bool);
|
void onDownloadLimitedToggled (bool);
|
||||||
void onSpinBoxEditingFinished ();
|
void onSpinBoxEditingFinished ();
|
||||||
|
|
|
@ -380,6 +380,30 @@ FileTreeItem :: twiddleWanted (QSet<int>& ids, bool& wanted)
|
||||||
setSubtreeWanted (wanted, ids);
|
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)
|
if (role == Qt::EditRole)
|
||||||
{
|
{
|
||||||
QString oldpath;
|
|
||||||
FileTreeItem * item = itemFromIndex (index);
|
FileTreeItem * item = itemFromIndex (index);
|
||||||
|
|
||||||
while (item && !item->name().isEmpty())
|
emit pathEdited (item->path (), newname.toString ());
|
||||||
{
|
|
||||||
if (oldpath.isEmpty())
|
|
||||||
oldpath = item->name();
|
|
||||||
else
|
|
||||||
oldpath = item->name() + "/" + oldpath;
|
|
||||||
item = item->parent ();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit pathEdited (oldpath, newname.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // don't update the view until the session confirms the change
|
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&)),
|
connect (this, SIGNAL(clicked(const QModelIndex&)),
|
||||||
this, SLOT(onClicked(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)),
|
connect (&myModel, SIGNAL(priorityChanged(const QSet<int>&, int)),
|
||||||
this, 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&)),
|
connect (&myModel, SIGNAL(pathEdited(const QString&, const QString&)),
|
||||||
this, 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 ()
|
FileTreeView :: ~FileTreeView ()
|
||||||
|
@ -918,6 +955,22 @@ FileTreeView :: onClicked (const QModelIndex& proxyIndex)
|
||||||
myModel.clicked (modelIndex);
|
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
|
bool
|
||||||
FileTreeView :: eventFilter (QObject * o, QEvent * event)
|
FileTreeView :: eventFilter (QObject * o, QEvent * event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,6 +68,8 @@ class FileTreeItem: public QObject
|
||||||
void twiddlePriority (QSet<int>& fileIds, int&);
|
void twiddlePriority (QSet<int>& fileIds, int&);
|
||||||
int fileIndex () const { return myFileIndex; }
|
int fileIndex () const { return myFileIndex; }
|
||||||
uint64_t totalSize () const { return myTotalSize; }
|
uint64_t totalSize () const { return myTotalSize; }
|
||||||
|
QString path () const;
|
||||||
|
bool isComplete () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setSubtreePriority (int priority, QSet<int>& fileIds);
|
void setSubtreePriority (int priority, QSet<int>& fileIds);
|
||||||
|
@ -115,6 +117,7 @@ class FileTreeModel: public QAbstractItemModel
|
||||||
void priorityChanged (const QSet<int>& fileIndices, int);
|
void priorityChanged (const QSet<int>& fileIndices, int);
|
||||||
void wantedChanged (const QSet<int>& fileIndices, bool);
|
void wantedChanged (const QSet<int>& fileIndices, bool);
|
||||||
void pathEdited (const QString& oldpath, const QString& newname);
|
void pathEdited (const QString& oldpath, const QString& newname);
|
||||||
|
void openRequested (const QString& path);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void clear ();
|
void clear ();
|
||||||
|
@ -138,6 +141,7 @@ class FileTreeModel: public QAbstractItemModel
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clicked (const QModelIndex & index);
|
void clicked (const QModelIndex & index);
|
||||||
|
void doubleClicked (const QModelIndex & index);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileTreeDelegate: public QItemDelegate
|
class FileTreeDelegate: public QItemDelegate
|
||||||
|
@ -167,6 +171,7 @@ class FileTreeView: public QTreeView
|
||||||
void priorityChanged (const QSet<int>& fileIndices, int priority);
|
void priorityChanged (const QSet<int>& fileIndices, int priority);
|
||||||
void wantedChanged (const QSet<int>& fileIndices, bool wanted);
|
void wantedChanged (const QSet<int>& fileIndices, bool wanted);
|
||||||
void pathEdited (const QString& oldpath, const QString& newname);
|
void pathEdited (const QString& oldpath, const QString& newname);
|
||||||
|
void openRequested (const QString& path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter (QObject *, QEvent *);
|
bool eventFilter (QObject *, QEvent *);
|
||||||
|
@ -178,6 +183,8 @@ class FileTreeView: public QTreeView
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onClicked (const QModelIndex& index);
|
void onClicked (const QModelIndex& index);
|
||||||
|
void onDoubleClicked (const QModelIndex& index);
|
||||||
|
void onOpenRequested (const QString& path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue