]> cloud.milkyroute.net Git - dolphin.git/commitdiff
- interface cleanups
authorPeter Penz <peter.penz19@gmail.com>
Sun, 19 Jul 2009 22:29:59 +0000 (22:29 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 19 Jul 2009 22:29:59 +0000 (22:29 +0000)
- the subversion test plugin is at least capable of indicating the revision state for files

svn path=/trunk/KDE/kdebase/apps/; revision=999489

src/dolphinfileitemdelegate.cpp
src/dolphinfileitemdelegate.h
src/dolphinmodel.cpp
src/dolphinmodel.h
src/revisioncontrolobserver.cpp
src/revisioncontrolplugin.cpp
src/revisioncontrolplugin.h

index 7232c38f5883bcbd008d793a347d7f714a7ce2d5..367435cedb603376c8111159090a6f72ed2a0c12 100644 (file)
@@ -63,9 +63,9 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
         const QModelIndex dirIndex = proxyModel->mapToSource(index);
         const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Revision);
         const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole);
-        const DolphinModel::RevisionState state = static_cast<DolphinModel::RevisionState>(data.toInt());
+        const RevisionControlPlugin::RevisionState state = static_cast<RevisionControlPlugin::RevisionState>(data.toInt());
 
-        if (state != DolphinModel::LocalRevision) {
+        if (state != RevisionControlPlugin::LocalRevision) {
             // TODO: extend KFileItemDelegate to be able to get the icon boundaries
             const QRect iconRect(option.rect.x(), option.rect.y(),
                                  KIconLoader::SizeSmall, KIconLoader::SizeSmall);
@@ -105,22 +105,20 @@ void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
     }
 }
 
-QPixmap DolphinFileItemDelegate::emblemForState(DolphinModel::RevisionState state, const QSize& size)
+QPixmap DolphinFileItemDelegate::emblemForState(RevisionControlPlugin::RevisionState state, const QSize& size)
 {
     // TODO #1: all icons that are use here will be replaced by revision control emblems provided by the
     // Oxygen team before KDE 4.4
     // TODO #2: cache the icons
     switch (state) {
-    case DolphinModel::LatestRevision:
+    case RevisionControlPlugin::LatestRevision:
         return KIcon("dialog-ok-apply").pixmap(size);
-        break;
-
-    case DolphinModel::ConflictingRevision:
+    case RevisionControlPlugin::ConflictingRevision:
+        return KIcon("application-exit").pixmap(size);
+    case RevisionControlPlugin::UpdateRequiredRevision:
+        return KIcon("rating").pixmap(size);
+    case RevisionControlPlugin::EditingRevision:
         return KIcon("emblem-important").pixmap(size);
-        break;
-
-    // ...
-
     default:
         break;
     }
index b6a4d45b2f218c77c892457f93f1838b5da8a202..2f8d3c35f9a645be11be8b96a1332c1642dd4136 100644 (file)
@@ -66,7 +66,7 @@ private:
                                   const DolphinModel* dolphinModel,
                                   const QModelIndex& index);
 
-    static QPixmap emblemForState(DolphinModel::RevisionState state, const QSize& size);
+    static QPixmap emblemForState(RevisionControlPlugin::RevisionState state, const QSize& size);
 
 private:
     bool m_hasMinimizedNameColumn;
index c5ea06a363b7bf05709bfdfae3515a6560fffbed..542d550ae3ff08163db5aa4a11efa83a7ac230ed 100644 (file)
@@ -68,8 +68,8 @@ bool DolphinModel::setData(const QModelIndex& index, const QVariant& value, int
         // TODO: remove data again when items are deleted...
 
         const QPersistentModelIndex key = index;
-        const RevisionState state = static_cast<RevisionState>(value.toInt());
-        if (m_revisionHash.value(key, LocalRevision) != state) {
+        const RevisionControlPlugin::RevisionState state = static_cast<RevisionControlPlugin::RevisionState>(value.toInt());
+        if (m_revisionHash.value(key, RevisionControlPlugin::LocalRevision) != state) {
             if (!m_hasRevisionData) {
                 connect(this, SIGNAL(rowsRemoved (const QModelIndex&, int, int)),
                         this, SLOT(slotRowsRemoved(const QModelIndex&, int, int)));
@@ -96,17 +96,20 @@ QVariant DolphinModel::data(const QModelIndex& index, int role) const
 
     case Qt::DecorationRole:
         if (index.column() == DolphinModel::Revision) {
-            return m_revisionHash.value(index, LocalRevision);
+            return m_revisionHash.value(index, RevisionControlPlugin::LocalRevision);
         }
         break;
 
     case Qt::DisplayRole:
         if (index.column() == DolphinModel::Revision) {
-            switch (m_revisionHash.value(index, LocalRevision)) {
-            case LatestRevision:
+            switch (m_revisionHash.value(index, RevisionControlPlugin::LocalRevision)) {
+            case RevisionControlPlugin::LatestRevision:
                 return i18nc("@item::intable", "Latest");
-
-            case LocalRevision:
+            case RevisionControlPlugin::EditingRevision:
+                return i18nc("@item::intable", "Editing");
+            case RevisionControlPlugin::UpdateRequiredRevision:
+                return i18nc("@item::intable", "Update required");
+            case RevisionControlPlugin::LocalRevision:
             default:
                 return i18nc("@item::intable", "Local");
             }
index 45fd1efa2c3a2fa3f804f53cb1705e57e9c8d2dc..9ae3d5f7c99f6bb23189fac4425e4f052650ae90 100644 (file)
@@ -22,6 +22,7 @@
 #define DOLPHINMODEL_H
 
 #include <kdirmodel.h>
+#include <revisioncontrolplugin.h>
 #include <libdolphin_export.h>
 
 #include <QHash>
@@ -37,13 +38,6 @@ public:
         ExtraColumnCount
     };
 
-    enum RevisionState {
-        LocalRevision,
-        LatestRevision,
-        ConflictingRevision
-        // TODO...
-    };
-
     DolphinModel(QObject* parent = 0);
     virtual ~DolphinModel();
 
@@ -63,7 +57,7 @@ private:
 
 private:
     bool m_hasRevisionData;
-    QHash<QPersistentModelIndex, RevisionState> m_revisionHash;
+    QHash<QPersistentModelIndex, RevisionControlPlugin::RevisionState> m_revisionHash;
 
     static const char* m_others;
 };
index 95253c59ac95578ce6eaa45d74657e7620c887c6..246450fe717d595e62250dc29b8d5e7bdfbfb240 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <QAbstractProxyModel>
 #include <QAbstractItemView>
-#include <QListView>
 #include <QTimer>
 
 /**
@@ -163,14 +162,12 @@ void RevisionControlObserver::verifyDirectory()
 
 void RevisionControlObserver::applyUpdatedItemStates()
 {
-    // Updating items with non-uniform item sizes is a serious bottleneck
-    // in QListView. Temporary disable the non-uniform item sizes.
-    QListView* listView = qobject_cast<QListView*>(m_view);
-    bool uniformSizes = true;
-    if (listView != 0) {
-        uniformSizes = listView->uniformItemSizes();
-        //listView->setUniformItemSizes(true); TODO: does not work as well as in KFilePreviewGenerator
-    }
+    // QAbstractItemModel::setData() triggers a bottleneck in combination with QListView
+    // (a detailed description of the root cause is given in the class KFilePreviewGenerator
+    // from kdelibs). To bypass this bottleneck, the signals of the model are temporary blocked.
+    // This works as the update of the data does not require a relayout of the views used in Dolphin.
+    const bool signalsBlocked = m_dolphinModel->signalsBlocked();
+    m_dolphinModel->blockSignals(true);
 
     const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates();
     foreach (const ItemState& itemState, itemStates) {
@@ -179,11 +176,8 @@ void RevisionControlObserver::applyUpdatedItemStates()
                                 Qt::DecorationRole);
     }
 
-    if (listView != 0) {
-        listView->setUniformItemSizes(uniformSizes);
-    }
-
-    m_view->viewport()->repaint(); // TODO: this should not be necessary, as DolphinModel::setData() calls dataChanged()
+    m_dolphinModel->blockSignals(signalsBlocked);
+    m_view->viewport()->repaint();
     
     if (m_pendingItemStatesUpdate) {
         m_pendingItemStatesUpdate = false;
index dde8d86654dfe83fe36a39b9dce2c331b7b9f98f..5e6783335ca7dd6c4ac95e71b19d8bda85cf603a 100644 (file)
@@ -53,27 +53,25 @@ bool SubversionPlugin::beginRetrieval(const QString& directory)
 {
     Q_ASSERT(directory.endsWith('/'));
     m_directory = directory;
+    const QString path = directory + ".svn/text-base/";
 
-    QFile file(directory + ".svn/entries");
-    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-        return false;
-    }
-
-    QTextStream in(&file);
+    QDir dir(path);
+    const QFileInfoList fileInfoList = dir.entryInfoList();
+    const int size = fileInfoList.size();
     QString fileName;
-    QString line;
-    while (!in.atEnd()) {
-        fileName = line;
-        line = in.readLine();
-        const bool isRevisioned = !line.isEmpty() &&
-                                  ((line == QLatin1String("dir")) ||
-                                   (line == QLatin1String("file")));
-        if (isRevisioned) {
-            RevisionInfo info; // TODO
+    for (int i = 0; i < size; ++i) {
+        fileName = fileInfoList.at(i).fileName();
+        // Remove the ".svn-base" postfix to be able to compare the filenames
+        // in a fast way in SubversionPlugin::revisionState().
+        fileName.chop(sizeof(".svn-base") / sizeof(char) - 1);
+        if (!fileName.isEmpty()) {
+            RevisionInfo info;
+            info.size = fileInfoList.at(i).size();
+            info.timeStamp = fileInfoList.at(i).lastModified();            
             m_revisionInfoHash.insert(fileName, info);
         }
     }
-    return true;
+    return size > 0;
 }
 
 void SubversionPlugin::endRetrieval()
@@ -83,9 +81,30 @@ void SubversionPlugin::endRetrieval()
 RevisionControlPlugin::RevisionState SubversionPlugin::revisionState(const KFileItem& item)
 {
     const QString name = item.name();
-    if (m_revisionInfoHash.contains(name)) {
-        // TODO...
-        return RevisionControlPlugin::LatestRevision;
+    if (item.isDir()) {
+        QFile file(m_directory + name + "/.svn");
+        if (file.open(QIODevice::ReadOnly)) {
+            file.close();
+            // TODO...
+            return RevisionControlPlugin::LatestRevision;
+        }
+    } else if (m_revisionInfoHash.contains(name)) {
+        const RevisionInfo info = m_revisionInfoHash.value(item.name());
+        const QDateTime localTimeStamp = item.time(KFileItem::ModificationTime).dateTime();
+        const QDateTime versionedTimeStamp = info.timeStamp;
+
+        if (localTimeStamp > versionedTimeStamp) {
+            if (info.size != item.size()) {
+                return RevisionControlPlugin::EditingRevision;
+            }
+            // TODO: a comparison of the content is required
+        } else if (localTimeStamp < versionedTimeStamp) {
+            if (info.size != item.size()) {
+                return RevisionControlPlugin::UpdateRequiredRevision;
+            }
+            // TODO: a comparison of the content is required
+        }
+        return  RevisionControlPlugin::LatestRevision;
     }
 
     return RevisionControlPlugin::LocalRevision;
index 687160c52b982cc05dd08084f5ceb1c473bed2b6..a4ad69571d37b63ae66150d6c2c7d0a676f04397 100644 (file)
@@ -40,6 +40,8 @@ public:
     {
         LocalRevision,
         LatestRevision,
+        UpdateRequiredRevision,
+        EditingRevision,
         ConflictingRevision
         // TODO...
     };
@@ -102,7 +104,7 @@ public:
 private:
     struct RevisionInfo
     {
-        // TODO...
+        quint64 size;
         QDateTime timeStamp;
     };