Changeset 14196


Ignore:
Timestamp:
Sep 8, 2013, 7:03:25 PM (8 years ago)
Author:
jordan
Message:

(trunk, qt) #4813: allow launching files in Qt interface

Location:
trunk/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/details.cc

    r14185 r14196  
    1818#include <QComboBox>
    1919#include <QDateTime>
     20#include <QDesktopServices>
    2021#include <QDialogButtonBox>
    2122#include <QDoubleSpinBox>
     
    13951396           this,           SLOT (onPathEdited (const QString&, const QString&)));
    13961397
     1398  connect (myFileTreeView, SIGNAL (openRequested (const QString&)),
     1399           this,           SLOT (onOpenRequested (const QString&)));
     1400
    13971401  return myFileTreeView;
    13981402}
     
    14351439  mySession.torrentRenamePath (myIds, oldpath, newname);
    14361440}
     1441
     1442void
     1443Details :: onOpenRequested (const QString& path)
     1444{
     1445  if (!mySession.isLocal ())
     1446    return;
     1447
     1448  foreach (const int id, myIds)
     1449    {
     1450      const Torrent * const tor = myModel.getTorrentFromId (id);
     1451      if (tor == NULL)
     1452        continue;
     1453
     1454      const QString localFilePath = tor->getPath () + "/" + path;
     1455      if (!QFile::exists (localFilePath))
     1456        continue;
     1457
     1458      if (QDesktopServices::openUrl (QUrl::fromLocalFile (localFilePath)))
     1459        break;
     1460    }
     1461}
  • trunk/qt/details.h

    r14180 r14196  
    143143    void onFileWantedChanged (const QSet<int>& fileIndices, bool);
    144144    void onPathEdited (const QString& oldpath, const QString& newname);
     145    void onOpenRequested (const QString& path);
    145146    void onHonorsSessionLimitsToggled (bool);
    146147    void onDownloadLimitedToggled (bool);
  • trunk/qt/file-tree.cc

    r14185 r14196  
    381381}
    382382
     383QString
     384FileTreeItem :: path () const
     385{
     386  QString itemPath;
     387  const FileTreeItem * item = this;
     388
     389  while (item != NULL && !item->name().isEmpty())
     390    {
     391      if (itemPath.isEmpty())
     392        itemPath = item->name();
     393      else
     394        itemPath = item->name() + "/" + itemPath;
     395      item = item->parent ();
     396    }
     397
     398  return itemPath;
     399}
     400
     401bool
     402FileTreeItem :: isComplete () const
     403{
     404  return myHaveSize == totalSize ();
     405}
     406
    383407/***
    384408****
     
    436460  if (role == Qt::EditRole)
    437461    {
    438       QString oldpath;
    439462      FileTreeItem * item = itemFromIndex (index);
    440463
    441       while (item && !item->name().isEmpty())
    442         {
    443           if (oldpath.isEmpty())
    444             oldpath = item->name();
    445           else
    446             oldpath = item->name() + "/" + oldpath;
    447           item = item->parent ();
    448         }
    449 
    450       emit pathEdited (oldpath, newname.toString());
     464      emit pathEdited (item->path (), newname.toString ());
    451465    }
    452466
     
    738752      subtreeChanged(index, column);
    739753    }
     754}
     755
     756void
     757FileTreeModel :: doubleClicked (const QModelIndex& index)
     758{
     759  if (!index.isValid())
     760    return;
     761
     762  const int column (index.column());
     763  if (column == COL_WANTED || column == COL_PRIORITY)
     764    return;
     765
     766  FileTreeItem * item = itemFromIndex (index);
     767
     768  if (item->childCount () == 0 && item->isComplete ())
     769    emit openRequested (item->path ());
    740770}
    741771
     
    897927           this, SLOT(onClicked(const QModelIndex&)));
    898928
     929  connect (this, SIGNAL(doubleClicked(const QModelIndex&)),
     930           this, SLOT(onDoubleClicked(const QModelIndex&)));
     931
    899932  connect (&myModel, SIGNAL(priorityChanged(const QSet<int>&, int)),
    900933           this,     SIGNAL(priorityChanged(const QSet<int>&, int)));
     
    905938  connect (&myModel, SIGNAL(pathEdited(const QString&, const QString&)),
    906939           this,     SIGNAL(pathEdited(const QString&, const QString&)));
     940
     941  connect (&myModel, SIGNAL (openRequested (const QString&)),
     942           this,     SLOT (onOpenRequested (const QString&)),
     943           Qt::QueuedConnection);
    907944}
    908945
     
    917954  const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
    918955  myModel.clicked (modelIndex);
     956}
     957
     958void
     959FileTreeView :: onDoubleClicked (const QModelIndex& proxyIndex)
     960{
     961  const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
     962  myModel.doubleClicked (modelIndex);
     963}
     964
     965void
     966FileTreeView :: onOpenRequested (const QString& path)
     967{
     968  if (state () == EditingState)
     969    return;
     970
     971  emit openRequested (path);
    919972}
    920973
  • trunk/qt/file-tree.h

    r14185 r14196  
    6969    int fileIndex () const { return myFileIndex; }
    7070    uint64_t totalSize () const { return myTotalSize; }
     71    QString path () const;
     72    bool isComplete () const;
    7173
    7274  private:
     
    116118    void wantedChanged (const QSet<int>& fileIndices, bool);
    117119    void pathEdited (const QString& oldpath, const QString& newname);
     120    void openRequested (const QString& path);
    118121
    119122  public:
     
    139142  public slots:
    140143    void clicked (const QModelIndex & index);
     144    void doubleClicked (const QModelIndex & index);
    141145};
    142146
     
    168172    void wantedChanged (const QSet<int>& fileIndices, bool wanted);
    169173    void pathEdited (const QString& oldpath, const QString& newname);
     174    void openRequested (const QString& path);
    170175
    171176  protected:
     
    179184  public slots:
    180185    void onClicked (const QModelIndex& index);
     186    void onDoubleClicked (const QModelIndex& index);
     187    void onOpenRequested (const QString& path);
    181188};
    182189
Note: See TracChangeset for help on using the changeset viewer.