Changeset 13893


Ignore:
Timestamp:
Jan 28, 2013, 7:01:58 AM (8 years ago)
Author:
jordan
Message:

(qt) #5252: disable file editing in the options dialog. remove keyboard shortcuts that conflicted with renaming files in file-tree.c. fix refresh issue in the file-tree when renaming files.

Location:
trunk/qt
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/details.cc

    r13869 r13893  
    203203    foreach (int id, myIds) {
    204204        const Torrent * tor = myModel.getTorrentFromId (id);
    205         if (tor) {
     205        if (tor)
    206206            disconnect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
    207             disconnect (tor, SIGNAL (torrentFileListRebuilt (int)), this, SLOT (onTorrentFileListRebuilt ()));
    208         }
    209207    }
    210208
     
    216214    foreach (int id, myIds) {
    217215        const Torrent * tor = myModel.getTorrentFromId (id);
    218         if (tor) {
     216        if (tor)
    219217            connect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
    220             connect (tor, SIGNAL (torrentFileListRebuilt (int)), this, SLOT (onTorrentFileListRebuilt ()));
    221         }
    222218    }
    223219
     
    298294        QTimer::singleShot (100, this, SLOT (refresh ()));
    299295    }
    300 }
    301 
    302 void
    303 Details :: onTorrentFileListRebuilt ()
    304 {
    305   myFilesDirty = true;
    306   onTorrentChanged ();
    307296}
    308297
     
    841830    myPeers = peers2;
    842831
    843     if (!single || myFilesDirty)
     832    if (!single)
    844833        myFileTreeView->clear ();
    845834    if (single)
    846         myFileTreeView->update (torrents[0]->files () , myFilesDirty || myChangedTorrents);
    847 
    848     myFilesDirty = false;
     835        myFileTreeView->update (torrents[0]->files (), myChangedTorrents);
     836
    849837    myChangedTorrents = false;
    850838    myHavePendingRefresh = false;
  • trunk/qt/details.h

    r13869 r13893  
    5050  private slots:
    5151    void onTorrentChanged ();
    52     void onTorrentFileListRebuilt ();
    5352    void onTimer ();
    5453
     
    137136    FileTreeView * myFileTreeView;
    138137
    139     bool myFilesDirty;
    140 
    141138  private slots:
    142139    void refreshPref (int key);
  • trunk/qt/file-tree.cc

    r13868 r13893  
    1212
    1313#include <cassert>
    14 #include <iostream>
    1514
    1615#include <QApplication>
     
    3231{
    3332  COL_NAME,
     33  FIRST_VISIBLE_COLUMN = COL_NAME,
    3434  COL_PROGRESS,
    3535  COL_WANTED,
    3636  COL_PRIORITY,
     37  LAST_VISIBLE_COLUMN = COL_PRIORITY,
     38
     39  COL_FILE_INDEX,
    3740  NUM_COLUMNS
    3841};
     
    4245****/
    4346
    44 QHash<QString,int>&
     47const QHash<QString,int>&
    4548FileTreeItem :: getMyChildRows ()
    4649{
     
    115118  QVariant value;
    116119
    117   if (role == Qt::EditRole)
     120  if (column == COL_FILE_INDEX)
     121    {
     122      return myIndex;
     123    }
     124  else if (role == Qt::EditRole)
    118125    {
    119126      if (column == 0)
     
    178185}
    179186
     187#include <iostream>
     188
    180189bool
    181 FileTreeItem :: update (int      index,
    182                         bool     wanted,
    183                         int      priority,
    184                         uint64_t totalSize,
    185                         uint64_t haveSize,
    186                         bool     updateFields)
     190FileTreeItem :: update (const QString& name,
     191                        bool           wanted,
     192                        int            priority,
     193                        uint64_t       haveSize,
     194                        bool           updateFields)
    187195{
    188196  bool changed = false;
    189197
    190 std::cerr << __FILE__ << ':' << __LINE__ << " index " << index << " wanted " << wanted << " myIndex " << myIndex << " myWanted" << myIsWanted << std::endl;
    191 
    192   if (myIndex != index)
    193     {
    194       myIndex = index;
     198  if (myName != name)
     199    {
     200      if (myParent)
     201        myParent->myFirstUnhashedRow = row();
     202
     203      myName = name;
    195204      changed = true;
    196205    }
    197206
    198   if (updateFields && myIsWanted != wanted)
    199     {
    200       myIsWanted = wanted;
    201       changed = true;
    202 std::cerr << __FILE__ << ':' << __LINE__ << " setting myIsWanted to " << myIsWanted << std::endl;
    203     }
    204 
    205   if (updateFields && myPriority != priority)
    206     {
    207       myPriority = priority;
    208       changed = true;
    209     }
    210 
    211   if (myTotalSize != totalSize)
    212     {
    213       myTotalSize = totalSize;
    214       changed = true;
    215     }
    216 
    217   if (myHaveSize != haveSize)
    218     {
    219       myHaveSize = haveSize;
    220       changed = true;
     207  if (fileIndex() != -1)
     208    {
     209      if (myHaveSize != haveSize)
     210        {
     211          myHaveSize = haveSize;
     212          changed = true;
     213        }
     214
     215      if (updateFields)
     216        {
     217          if (myIsWanted != wanted)
     218            {
     219              myIsWanted = wanted;
     220              changed = true;
     221            }
     222
     223          if (myPriority != priority)
     224            {
     225              myPriority = priority;
     226              changed = true;
     227            }
     228        }
    221229    }
    222230
     
    289297  else
    290298    p = TR_PRI_LOW;
    291 std::cerr << __FILE__ << ':' << __LINE__ << " twiddlePriority, p " << p << std::endl;
    292299
    293300  setSubtreePriority (p, ids);
     
    321328FileTreeItem :: setSubtreeWanted (bool b, QSet<int>& ids)
    322329{
    323 std::cerr << __FILE__ << ':' << __LINE__ << " twiddleWanted, wanted " << b << std::endl;
    324330  if (myIsWanted != b)
    325331    {
     
    337343FileTreeItem :: twiddleWanted (QSet<int>& ids, bool& wanted)
    338344{
    339 std::cerr << __FILE__ << ':' << __LINE__ << " twiddleWanted" << std::endl;
    340345  wanted = isSubtreeWanted() != Qt::Checked;
    341346  setSubtreeWanted (wanted, ids);
     
    347352***/
    348353
    349 FileTreeModel :: FileTreeModel (QObject *parent):
    350   QAbstractItemModel(parent)
    351 {
    352   rootItem = new FileTreeItem(-1);
     354FileTreeModel :: FileTreeModel (QObject *parent, bool isEditable):
     355  QAbstractItemModel(parent),
     356  myRootItem (new FileTreeItem),
     357  myIsEditable (isEditable)
     358{
    353359}
    354360
    355361FileTreeModel :: ~FileTreeModel()
    356362{
    357 std::cerr << __FILE__ << ':' << __LINE__ << " dtor " << std::endl;
    358363  clear();
    359364
    360   delete rootItem;
     365  delete myRootItem;
    361366}
    362367
     
    380385  int i(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    381386
    382   if(index.column() == COL_NAME)
     387  if(myIsEditable && (index.column() == COL_NAME))
    383388    i |= Qt::ItemIsEditable;
    384389
     
    453458  if (!hasIndex (row, column, parent))
    454459    {
    455       std::cerr << " I don't have this index " << std::endl;
     460      qWarning ("I don't have this index");
    456461    }
    457462  else
     
    460465
    461466      if(!parent.isValid())
    462         parentItem = rootItem;
     467        parentItem = myRootItem;
    463468      else
    464469        parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
     
    496501
    497502  if (!parent.isValid())
    498     parentItem = rootItem;
     503    parentItem = myRootItem;
    499504  else
    500505    parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
     
    508513  Q_UNUSED(parent);
    509514
    510   return 4;
     515  return NUM_COLUMNS;
    511516}
    512517
     
    514519FileTreeModel :: indexOf (FileTreeItem * item, int column) const
    515520{
    516   if (!item || item==rootItem)
     521  if (!item || item==myRootItem)
    517522    return QModelIndex();
    518523
     
    524529{
    525530  size_t i = rowCount (top);
    526 std::cerr << __FILE__ << ':' << __LINE__ << " clearSubtree " << i << std::endl;
    527531
    528532  while (i > 0)
     
    535539FileTreeModel :: clear ()
    536540{
    537 std::cerr << __FILE__ << ':' << __LINE__ << " clear"  << std::endl;
    538541  clearSubtree (QModelIndex());
    539542
     
    541544}
    542545
    543 void
    544 FileTreeModel :: addFile (int                   index,
     546FileTreeItem *
     547FileTreeModel :: findItemForFileIndex (int fileIndex) const
     548{
     549  FileTreeItem * ret = 0;
     550
     551  QModelIndexList indices = match (index (0,COL_FILE_INDEX),
     552                                   Qt::DisplayRole,
     553                                   fileIndex,
     554                                   1,
     555                                   Qt::MatchFlags (Qt::MatchExactly | Qt::MatchRecursive));
     556
     557  if (!indices.isEmpty ())
     558    {
     559      QModelIndex& index = indices.front ();
     560      if (index.isValid())
     561        ret = static_cast<FileTreeItem*>(index.internalPointer());
     562    }
     563
     564  return ret;
     565}
     566
     567void
     568FileTreeModel :: itemChanged (FileTreeItem * item)
     569{
     570  dataChanged (indexOf(item, FIRST_VISIBLE_COLUMN), indexOf(item, LAST_VISIBLE_COLUMN));
     571}
     572
     573void
     574FileTreeModel :: addFile (int                   fileIndex,
    545575                          const QString       & filename,
    546576                          bool                  wanted,
    547577                          int                   priority,
    548                           uint64_t              size,
     578                          uint64_t              totalSize,
    549579                          uint64_t              have,
    550580                          QList<QModelIndex>  & rowsAdded,
     
    552582{
    553583  bool added = false;
    554   FileTreeItem * i (rootItem);
    555 
    556   foreach (QString token, filename.split (QChar::fromAscii('/')))
    557     {
    558       FileTreeItem * child(i->child(token));
    559       if (!child)
    560         {
    561           added = true;
    562           QModelIndex parentIndex (indexOf(i, 0));
    563           const int n (i->childCount());
    564           beginInsertRows (parentIndex, n, n);
    565           i->appendChild ((child = new FileTreeItem(-1, token)));
    566           endInsertRows ();
    567           rowsAdded.append (indexOf(child, 0));
    568         }
    569       i = child;
    570     }
    571 
    572   if (i != rootItem)
    573     {
    574       if (i->update (index, wanted, priority, size, have, added || updateFields))
    575         {
    576           std::cerr << __FILE__ << ':' << __LINE__ << " emitting dataChanged for row " << i << std::endl;
    577           dataChanged (indexOf(i, 0), indexOf(i, NUM_COLUMNS-1));
     584  FileTreeItem * item;
     585  QStringList tokens = filename.split (QChar::fromAscii('/'));
     586
     587  item = findItemForFileIndex (fileIndex);
     588
     589  if (item) // this file is already in the tree, we've added this
     590    {
     591      while (!tokens.isEmpty())
     592        {
     593          const QString token = tokens.takeLast();
     594          if (item->update (token, wanted, priority, have, updateFields))
     595            itemChanged (item);
     596          item = item->parent();
     597        }
     598      assert (item == myRootItem);
     599    }
     600  else // we haven't build the FileTreeItems for these tokens yet
     601    {
     602      item = myRootItem;
     603      while (!tokens.isEmpty())
     604        {
     605          const QString token = tokens.takeFirst();
     606          FileTreeItem * child(item->child(token));
     607          if (!child)
     608            {
     609              added = true;
     610              QModelIndex parentIndex (indexOf(item, 0));
     611              const int n (item->childCount());
     612
     613              beginInsertRows (parentIndex, n, n);
     614              if (tokens.isEmpty())
     615                child = new FileTreeItem (token, fileIndex, totalSize);
     616              else
     617                child = new FileTreeItem (token);
     618              item->appendChild (child);
     619              endInsertRows ();
     620
     621              rowsAdded.append (indexOf(child, 0));
     622            }
     623          item = child;
     624        }
     625
     626      if (item != myRootItem)
     627        {
     628          assert (item->fileIndex() == fileIndex);
     629          assert (item->totalSize() == totalSize);
     630
     631          if (item->update (item->name(), wanted, priority, have, added || updateFields))
     632            itemChanged (item);
    578633        }
    579634    }
     
    638693      FileTreeItem * item;
    639694
    640 std::cerr << "clicked in COL_PRIORITY" << std::endl;
    641695      item = static_cast<FileTreeItem*>(index.internalPointer());
    642696      item->twiddlePriority (file_ids, priority);
     
    776830****/
    777831
    778 FileTreeView :: FileTreeView (QWidget * parent):
     832FileTreeView :: FileTreeView (QWidget * parent, bool isEditable):
    779833  QTreeView (parent),
    780   myModel (this),
     834  myModel (this, isEditable),
    781835  myProxy (new QSortFilterProxyModel()),
    782836  myDelegate (this)
     
    793847  installEventFilter (this);
    794848
    795   for (int i=0; i<NUM_COLUMNS; ++i)
     849  for (int i=FIRST_VISIBLE_COLUMN; i<=LAST_VISIBLE_COLUMN; ++i)
    796850    header()->setResizeMode(i, QHeaderView::Interactive);
    797851
     
    818872{
    819873  const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
    820 std::cerr << __FILE__ << ':' << __LINE__ << " calling myModel.clicked()" << std::endl;
    821874  myModel.clicked (modelIndex);
    822875}
     
    825878FileTreeView :: eventFilter (QObject * o, QEvent * event)
    826879{
    827   if (o != this)
    828     return false;
    829 
    830880  // this is kind of a hack to get the last three columns be the
    831881  // right size, and to have the filename column use whatever
    832882  // space is left over...
    833   if (event->type() == QEvent::Resize)
     883  if ((o == this) && (event->type() == QEvent::Resize))
    834884    {
    835885      QResizeEvent * r = dynamic_cast<QResizeEvent*>(event);
    836886      int left = r->size().width();
    837887      const QFontMetrics fontMetrics(font());
    838       for (int column=0; column<NUM_COLUMNS; ++column)
     888      for (int column=FIRST_VISIBLE_COLUMN; column<=LAST_VISIBLE_COLUMN; ++column)
    839889        {
    840890          if (column == COL_NAME)
    841891            continue;
    842 
    843892          if (isColumnHidden (column))
    844893            continue;
     
    851900      left -= 20; // not sure why this is necessary.  it works in different themes + font sizes though...
    852901      setColumnWidth(COL_NAME, std::max(left,0));
    853       return false;
    854     }
    855 
    856 #if 0
    857   // handle using the keyboard to toggle the
    858   // wanted/unwanted state or the file priority
    859   else if (event->type() == QEvent::KeyPress)
    860     {
    861 std::cerr << __FILE__ << ':' << __LINE__ << " " << qPrintable(dynamic_cast<QKeyEvent*>(event)->text()) << std::endl;
    862       switch(dynamic_cast<QKeyEvent*>(event)->key())
    863         {
    864           case Qt::Key_Space:
    865             std::cerr << __FILE__ << ':' << __LINE__ << " calling COL_WANTED.clicked()" << std::endl;
    866             foreach (QModelIndex i, selectionModel()->selectedRows(COL_WANTED))
    867               clicked (i);
    868             return false;
    869 
    870           case Qt::Key_Enter:
    871           case Qt::Key_Return:
    872             std::cerr << __FILE__ << ':' << __LINE__ << " calling COL_PRIORITY.clicked()" << std::endl;
    873             foreach (QModelIndex i, selectionModel()->selectedRows(COL_PRIORITY))
    874               clicked (i);
    875             return false;
    876         }
    877     }
    878 #endif
     902    }
    879903
    880904  return false;
     
    890914FileTreeView :: update (const FileList& files, bool updateFields)
    891915{
    892 std::cerr << "update updateFields " << updateFields << std::endl;
    893916  foreach (const TrFile file, files)
    894917    {
    895918      QList<QModelIndex> added;
    896 std::cerr << __FILE__ << ':' << __LINE__ << " add file " << qPrintable(file.filename) << " wanted " << file.wanted << std::endl;
    897919      myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields);
    898920      foreach (QModelIndex i, added)
     
    904926FileTreeView :: clear ()
    905927{
    906 std::cerr << __FILE__ << ':' << __LINE__ << " clear" << std::endl;
    907928  myModel.clear();
    908929}
  • trunk/qt/file-tree.h

    r13868 r13893  
    4444    virtual ~FileTreeItem();
    4545
    46     FileTreeItem (int fileIndex, const QString& name=""):
     46    FileTreeItem (const QString& name="", int fileIndex=-1, uint64_t size=0):
    4747      myIndex (fileIndex),
    4848      myParent (0),
     
    5151      myIsWanted (0),
    5252      myHaveSize (0),
    53       myTotalSize (0),
     53      myTotalSize (size),
    5454      myFirstUnhashedRow (0) { }
    5555
     
    6464    const QString& name () const { return myName; }
    6565    QVariant data (int column, int role) const;
    66     bool update (int index, bool want, int priority, uint64_t total, uint64_t have, bool updateFields);
     66    bool update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
    6767    void twiddleWanted (QSet<int>& fileIds, bool&);
    6868    void twiddlePriority (QSet<int>& fileIds, int&);
     69    int fileIndex () const { return myIndex; }
     70    uint64_t totalSize () const { return myTotalSize; }
     71   
     72   
    6973
    7074  private:
     
    7882    int isSubtreeWanted () const;
    7983
    80     int myIndex;
     84    const int myIndex;
    8185    FileTreeItem * myParent;
    8286    QList<FileTreeItem*> myChildren;
    8387    QHash<QString,int> myChildRows;
    84     QHash<QString,int>& getMyChildRows();
    85     const QString myName;
     88    const QHash<QString,int>& getMyChildRows();
     89    QString myName;
    8690    int myPriority;
    8791    bool myIsWanted;
    8892    uint64_t myHaveSize;
    89     uint64_t myTotalSize;
     93    const uint64_t myTotalSize;
    9094    size_t myFirstUnhashedRow;
    9195};
     
    96100
    97101  public:
    98     FileTreeModel (QObject *parent = 0);
     102    FileTreeModel (QObject *parent = 0, bool isEditable = true);
    99103    ~FileTreeModel ();
    100104
     
    124128
    125129  private:
     130    void itemChanged (FileTreeItem *);
    126131    void clearSubtree (const QModelIndex &);
    127132    QModelIndex indexOf (FileTreeItem *, int column) const;
    128133    void parentsChanged (const QModelIndex &, int column);
    129134    void subtreeChanged (const QModelIndex &, int column);
     135    FileTreeItem * findItemForFileIndex (int fileIndex) const;
     136
     137
    130138
    131139  private:
    132     FileTreeItem * rootItem;
     140    FileTreeItem * myRootItem;
     141    const bool myIsEditable;
    133142
    134143  public slots:
     
    154163
    155164  public:
    156     FileTreeView (QWidget * parent=0);
     165    FileTreeView (QWidget * parent=0, bool editable=true);
    157166    virtual ~FileTreeView ();
    158167    void clear ();
  • trunk/qt/options.cc

    r13737 r13893  
    1212
    1313#include <cstdio>
    14 #include <iostream>
    1514
    1615#include <QApplication>
     
    140139    }
    141140
    142     myTree = new FileTreeView;
     141    myTree = new FileTreeView (0, false);
    143142    layout->addWidget( myTree, ++row, 0, 1, 2 );
    144143    if( !session.isLocal( ) )
     
    359358
    360359        default:
    361             std::cerr << "unhandled AddData.type: " << myAdd.type << std::endl;
     360            qWarning ("unhandled AddData.type: %d", myAdd.type);
    362361    }
    363362
     
    404403             fileAdded, SLOT(executed(int64_t,const QString&, struct tr_variant*)));
    405404
    406 //std::cerr << tr_variantToStr(&top,TR_FMT_JSON,NULL) << std::endl;
    407405    mySession.exec( &top );
    408406
     
    487485Options :: onVerify( )
    488486{
    489     //std::cerr << "starting to verify..." << std::endl;
    490487    clearVerify( );
    491488    myVerifyFlags.insert( 0, myInfo.pieceCount, false );
     
    513510        const QFileInfo fileInfo( myDestination, QString::fromUtf8( file->name ) );
    514511        myVerifyFile.setFileName( fileInfo.absoluteFilePath( ) );
    515         //std::cerr << "opening file" << qPrintable(fileInfo.absoluteFilePath()) << std::endl;
    516512        myVerifyFile.open( QIODevice::ReadOnly );
    517513    }
     
    561557    if( leftInFile == 0 )
    562558    {
    563         //std::cerr << "closing file" << std::endl;
    564559        myVerifyFile.close( );
    565560        ++myVerifyFileIndex;
  • trunk/qt/session.cc

    r13889 r13893  
    825825                      {
    826826                        // let's get the updated file list
    827                         char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }",
     827                        char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"fileStats\", \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }",
    828828                                                       int(id),
    829829                                                       int(TAG_SOME_TORRENTS));
  • trunk/qt/torrent.cc

    r13892 r13893  
    573573      updateMimeIcon ();
    574574      changed = true;
    575       emit torrentFileListRebuilt (id ());
    576575    }
    577576
  • trunk/qt/torrent.h

    r13892 r13893  
    188188        void torrentChanged( int id );
    189189        void torrentCompleted( int id );
    190         void torrentFileListRebuilt( int id );
    191190
    192191    private:
Note: See TracChangeset for help on using the changeset viewer.