#include <QCheckBox>
#include <QComboBox>
#include <QDateTime>
+#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
#include <QEvent>
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;
}
{
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;
+ }
+}
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 ();
+}
+
/***
****
****
{
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
}
}
+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 ());
+}
+
/****
*****
****/
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)));
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 ()
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)
{
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);
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 ();
public slots:
void clicked (const QModelIndex & index);
+ void doubleClicked (const QModelIndex & index);
};
class FileTreeDelegate: public QItemDelegate
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 *);
public slots:
void onClicked (const QModelIndex& index);
+ void onDoubleClicked (const QModelIndex& index);
+ void onOpenRequested (const QString& path);
};
#endif