# # # patch "src/model/InventoryWatcher.cpp" # from [49820cb854646c8e31bcbd76dbea63a08cb28dfb] # to [f3e0038411789e66fa7e5f5b5c0721cef4d91f4c] # # patch "src/monotone/MonotoneThread.cpp" # from [053f729d2c58a8275ef5fc2a41cb2c643ded6469] # to [aeea2aa7cea1287f6437c29b90f03c4f6cc3b06c] # # patch "src/view/InventoryView.cpp" # from [6e95efeb83a5a69389b7585243530be2ad7f3cfe] # to [9c334189239f0c0c2f53223a709b45a02f22358a] # # patch "src/view/InventoryView.h" # from [14524e468a4fcf51254e3c066d3c571acf5acd1c] # to [aabacd229a25b7188d3e02d2c9f326e54d1e8de7] # ============================================================ --- src/model/InventoryWatcher.cpp 49820cb854646c8e31bcbd76dbea63a08cb28dfb +++ src/model/InventoryWatcher.cpp f3e0038411789e66fa7e5f5b5c0721cef4d91f4c @@ -60,7 +60,7 @@ QStringList InventoryWatcher::pathsFromI if (!idx.isValid()) continue; ModelItem * item = static_cast(idx.internalPointer()); I(item); - InventoryItem * invitem = reinterpret_cast(item); + InventoryItem * invitem = qobject_cast(item); if (!invitem) continue; if (invitem->getFSType() == InventoryItem::None) continue; paths.append(workspace + "/" + invitem->getPath()); ============================================================ --- src/monotone/MonotoneThread.cpp 053f729d2c58a8275ef5fc2a41cb2c643ded6469 +++ src/monotone/MonotoneThread.cpp aeea2aa7cea1287f6437c29b90f03c4f6cc3b06c @@ -199,6 +199,13 @@ void MonotoneThread::run() process->setWorkingDirectory(tmpPath); } + // remove any LANG setting so we get mtn's error output in native English + // (this is hacky, of course, but there is still no error code + // implementation in mtn, so we have to do raw string parsing...) + QStringList env = QProcess::systemEnvironment(); + env.replaceInStrings(QRegExp("^LANG=.*", Qt::CaseInsensitive), "LANG=c"); + process->setEnvironment(env); + L(QString("starting %1 %2").arg(mtnBinary).arg(args.join(" "))); process->start(mtnBinary, args); ============================================================ --- src/view/InventoryView.cpp 6e95efeb83a5a69389b7585243530be2ad7f3cfe +++ src/view/InventoryView.cpp 9c334189239f0c0c2f53223a709b45a02f22358a @@ -47,6 +47,26 @@ InventoryView::InventoryView(QWidget * p ); } +QModelIndex InventoryView::sourceIndex(const QModelIndex & proxy, bool useIndexModel) const +{ + if (useIndexModel) + return static_cast(proxy.model())->mapToSource(proxy); + else + return static_cast(model())->mapToSource(proxy); +} + +QModelIndex InventoryView::proxyIndex(const QModelIndex & source) const +{ + return static_cast(model())->mapFromSource(source); +} + +const ModelItem * InventoryView::modelItem(const QModelIndex & source) +{ + // ensure we got a source model item here + I(qobject_cast(source.model()) == 0); + return static_cast(source.internalPointer()); +} + void InventoryView::setType(Type t) { // ensure that a model is already set, otherwise the app crashes @@ -289,11 +309,8 @@ void InventoryView::slotContextMenuReque // if (indexList.size() == 1) { - QModelIndex sourceIndex = static_cast - (indexList[0].model())->mapToSource(indexList[0]); - ModelItem * item = static_cast - (sourceIndex.internalPointer()); - InventoryItem * invitem = dynamic_cast + const ModelItem * item = modelItem(sourceIndex(indexList[0])); + const InventoryItem * invitem = dynamic_cast (item); // only display the popup for real workspace items @@ -407,9 +424,8 @@ void InventoryView::slotContextMenuReque // // multiple items selected // - ModelItem * item; - InventoryItem * invitem; - QModelIndex sourceIndex; + const ModelItem * item; + const InventoryItem * invitem; QStringList actions; actions << "add" << "drop" << "commit" @@ -432,13 +448,9 @@ void InventoryView::slotContextMenuReque foreach (QModelIndex index, indexList) { - sourceIndex = - static_cast(index.model()) - ->mapToSource(index); + item = modelItem(sourceIndex(index)); + invitem = dynamic_cast(item); - item = static_cast(sourceIndex.internalPointer()); - invitem = dynamic_cast(item); - // skip actions on anything other than InventoryItems if (!invitem) continue; @@ -504,51 +516,55 @@ void InventoryView::slotChdir() changeDirectory(list[0]); } -void InventoryView::changeDirectory(const QModelIndex & proxyIndex) +void InventoryView::changeDirectory(const QModelIndex & proxy) { - QModelIndex source = dynamic_cast - (model())->mapToSource(proxyIndex); + // this seems to be a bit backward, but is here for a reason: the index + // we're getting here might be created from another proxy model and all + // we now is that this other proxy model and the proxy model we're using + // ourselves have the same original model. So we need to translate the + // proxy index at first _from_ the correct proxy model index to the + // "unique" source index and later translate the source index back to + // the proxy index which is used by our own model... + QModelIndex source = sourceIndex(proxy, true); + QModelIndex ourProxyIndex = proxyIndex(source); if (type == FileList) { - // retranslate the proxy index to an index of the current model - QModelIndex proxyFileIndex = - dynamic_cast(model())->mapFromSource(source); + // if we don't do this, right-clicking in the empty space will + // popup actions for a hidden item if the root index changed + clearSelection(); - ModelItem * item = static_cast - (source.internalPointer()); + const ModelItem * item = modelItem(source); + const PseudoItem * psitem = dynamic_cast(item); - PseudoItem * psitem = dynamic_cast(item); if (psitem && psitem->isCdUp()) { // list the contents of the parent of the parent directory - setRootIndex(proxyFileIndex.parent().parent()); + setRootIndex(ourProxyIndex.parent().parent()); return; } - setRootIndex(proxyFileIndex); + + setRootIndex(ourProxyIndex); return; } - // retranslate the proxy index to an index of the current model - QModelIndex proxyFolderIndex = - static_cast(model())->mapFromSource(source); - // expand the selection if needed - expand(proxyFolderIndex); + expand(ourProxyIndex); // select the item selectionModel()->setCurrentIndex( - proxyFolderIndex, + ourProxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); } void InventoryView::slotOpen() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); if (items.size() == 0) return; - InventoryItem * invitem = dynamic_cast(*items.begin()); + const InventoryItem * invitem = + dynamic_cast(*items.begin()); if (!invitem) return; @@ -568,13 +584,13 @@ void InventoryView::slotCommit() void InventoryView::slotCommit() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); if (items.size() == 0) return; QStringList paths; - foreach (ModelItem * item, items) + foreach (const ModelItem * item, items) { - InventoryItem * invitem = dynamic_cast(item); + const InventoryItem * invitem = dynamic_cast(item); // not an inventory item if (!invitem) continue; @@ -608,31 +624,32 @@ void InventoryView::slotRefresh() void InventoryView::slotRefresh() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); // for now we can only handle one refresh at a time if (items.size() > 1) return; - ModelItem * item; + const ModelItem * item; // special hack: if there are no selected items, refresh the // current root item if (items.size() == 0) { - QModelIndex proxyRoot = rootIndex(); - QModelIndex realRoot = - dynamic_cast(model())->mapFromSource(proxyRoot); + QModelIndex sourceRoot = sourceIndex(rootIndex()); // even more special case - select the first child of this (pseudo) root - if (!realRoot.isValid()) + if (!sourceRoot.isValid()) { - realRoot = realRoot.child(0, 0); + sourceRoot = sourceRoot.child(0, 0); } // still not valid, i.e. filtered out? - if (!realRoot.isValid()) return; + if (!sourceRoot.isValid()) + { + return; + } - item = static_cast(realRoot.internalPointer()); + item = modelItem(sourceRoot); } else { @@ -641,7 +658,9 @@ void InventoryView::slotRefresh() if (!item) return; - InventoryItem * invItem = dynamic_cast(item); + const InventoryItem * invItem = dynamic_cast(item); + D(QString("path: %1").arg(item->getLabel())); + if (!invItem) return; emit refreshPath(invItem->getPath()); @@ -676,10 +695,10 @@ void InventoryView::slotFileDiff() void InventoryView::slotFileDiff() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); if (items.size() == 0) return; - InventoryItem * invitem = dynamic_cast(*items.begin()); + const InventoryItem * invitem = dynamic_cast(*items.begin()); if (!invitem) return; @@ -695,10 +714,10 @@ void InventoryView::slotFileHistory() void InventoryView::slotFileHistory() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); if (items.size() == 0) return; - InventoryItem * invitem = dynamic_cast(*items.begin()); + const InventoryItem * invitem = dynamic_cast(*items.begin()); if (!invitem) return; @@ -720,10 +739,10 @@ void InventoryView::slotRevisionDiff() void InventoryView::slotRevisionDiff() { - QSet items = getSelectedItems(); + QSet items = getSelectedItems(); if (items.size() == 0) return; - InventoryItem * invitem = dynamic_cast(*items.begin()); + const InventoryItem * invitem = dynamic_cast(*items.begin()); if (!invitem) return; @@ -731,28 +750,21 @@ void InventoryView::slotRevisionDiff() emit diffRevision(invitem->getPath(), QString(), QString()); } -QSet InventoryView::getSelectedItems() const +QSet InventoryView::getSelectedItems() const { QItemSelectionModel * selectionModel = this->selectionModel(); QList list(selectionModel->selectedIndexes()); - QSet items; + QSet items; if (list.size() == 0) { return items; } - const QSortFilterProxyModel * proxyModel = - dynamic_cast(model()); - foreach (QModelIndex index, list) { - if (proxyModel) - { - index = proxyModel->mapToSource(index); - } - items.insert(static_cast(index.internalPointer())); + items.insert(modelItem(sourceIndex(index))); } return items; } @@ -795,13 +807,12 @@ InventoryView::DefaultAction InventoryVi if (!index.isValid()) return None; - QModelIndex sourceIndex = - static_cast(index.model())->mapToSource(index); - I(sourceIndex.isValid()); + QModelIndex source = sourceIndex(index); + I(source.isValid()); - ModelItem * item = static_cast(sourceIndex.internalPointer()); - InventoryItem * invitem = dynamic_cast(item); - PseudoItem * psitem = dynamic_cast(item); + const ModelItem * item = modelItem(source); + const InventoryItem * invitem = dynamic_cast(item); + const PseudoItem * psitem = dynamic_cast(item); if ((invitem && invitem->isDirectory()) || (psitem && psitem->isCdUp())) @@ -885,8 +896,6 @@ void InventoryView::notifyAboutViewportC setSelectionModel(oldSelectModel); // convert proxy into real indexes and remove column indexes > 0 - const QSortFilterProxyModel * proxyModel = - static_cast(model()); for (int i=0; i 0) @@ -894,7 +903,7 @@ void InventoryView::notifyAboutViewportC newIndexes.removeAt(i); continue; } - newIndexes[i] = proxyModel->mapToSource(newIndexes[i]); + newIndexes[i] = sourceIndex(newIndexes[i]); i++; } ============================================================ --- src/view/InventoryView.h 14524e468a4fcf51254e3c066d3c571acf5acd1c +++ src/view/InventoryView.h aabacd229a25b7188d3e02d2c9f326e54d1e8de7 @@ -56,13 +56,17 @@ private: enum DefaultAction { None, Chdir, Open, FileDiff, Commit }; void setModel(QAbstractItemModel *); - QSet getSelectedItems() const; + QSet getSelectedItems() const; DefaultAction getDefaultAction(const QModelIndex &) const; void createAndConnectContextActions(); void closeEvent(); bool viewportEvent(QEvent *); void notifyAboutViewportChanges(); + inline QModelIndex sourceIndex(const QModelIndex &, bool useIndexModel = false) const; + inline QModelIndex proxyIndex(const QModelIndex &) const; + static inline const ModelItem * modelItem(const QModelIndex &); + QAction * actChdir; QAction * actOpen; QAction * actAdd;