- interface cleanups

- the subversion test plugin is at least capable of indicating the revision state for files

svn path=/trunk/KDE/kdebase/apps/; revision=999489
This commit is contained in:
Peter Penz 2009-07-19 22:29:59 +00:00
parent 46dcb12d9f
commit d288b1cda4
7 changed files with 71 additions and 61 deletions

View file

@ -63,9 +63,9 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
const QModelIndex dirIndex = proxyModel->mapToSource(index); const QModelIndex dirIndex = proxyModel->mapToSource(index);
const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Revision); const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Revision);
const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole); 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 // TODO: extend KFileItemDelegate to be able to get the icon boundaries
const QRect iconRect(option.rect.x(), option.rect.y(), const QRect iconRect(option.rect.x(), option.rect.y(),
KIconLoader::SizeSmall, KIconLoader::SizeSmall); 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 // TODO #1: all icons that are use here will be replaced by revision control emblems provided by the
// Oxygen team before KDE 4.4 // Oxygen team before KDE 4.4
// TODO #2: cache the icons // TODO #2: cache the icons
switch (state) { switch (state) {
case DolphinModel::LatestRevision: case RevisionControlPlugin::LatestRevision:
return KIcon("dialog-ok-apply").pixmap(size); return KIcon("dialog-ok-apply").pixmap(size);
break; case RevisionControlPlugin::ConflictingRevision:
return KIcon("application-exit").pixmap(size);
case DolphinModel::ConflictingRevision: case RevisionControlPlugin::UpdateRequiredRevision:
return KIcon("rating").pixmap(size);
case RevisionControlPlugin::EditingRevision:
return KIcon("emblem-important").pixmap(size); return KIcon("emblem-important").pixmap(size);
break;
// ...
default: default:
break; break;
} }

View file

@ -66,7 +66,7 @@ private:
const DolphinModel* dolphinModel, const DolphinModel* dolphinModel,
const QModelIndex& index); const QModelIndex& index);
static QPixmap emblemForState(DolphinModel::RevisionState state, const QSize& size); static QPixmap emblemForState(RevisionControlPlugin::RevisionState state, const QSize& size);
private: private:
bool m_hasMinimizedNameColumn; bool m_hasMinimizedNameColumn;

View file

@ -68,8 +68,8 @@ bool DolphinModel::setData(const QModelIndex& index, const QVariant& value, int
// TODO: remove data again when items are deleted... // TODO: remove data again when items are deleted...
const QPersistentModelIndex key = index; const QPersistentModelIndex key = index;
const RevisionState state = static_cast<RevisionState>(value.toInt()); const RevisionControlPlugin::RevisionState state = static_cast<RevisionControlPlugin::RevisionState>(value.toInt());
if (m_revisionHash.value(key, LocalRevision) != state) { if (m_revisionHash.value(key, RevisionControlPlugin::LocalRevision) != state) {
if (!m_hasRevisionData) { if (!m_hasRevisionData) {
connect(this, SIGNAL(rowsRemoved (const QModelIndex&, int, int)), connect(this, SIGNAL(rowsRemoved (const QModelIndex&, int, int)),
this, SLOT(slotRowsRemoved(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: case Qt::DecorationRole:
if (index.column() == DolphinModel::Revision) { if (index.column() == DolphinModel::Revision) {
return m_revisionHash.value(index, LocalRevision); return m_revisionHash.value(index, RevisionControlPlugin::LocalRevision);
} }
break; break;
case Qt::DisplayRole: case Qt::DisplayRole:
if (index.column() == DolphinModel::Revision) { if (index.column() == DolphinModel::Revision) {
switch (m_revisionHash.value(index, LocalRevision)) { switch (m_revisionHash.value(index, RevisionControlPlugin::LocalRevision)) {
case LatestRevision: case RevisionControlPlugin::LatestRevision:
return i18nc("@item::intable", "Latest"); return i18nc("@item::intable", "Latest");
case RevisionControlPlugin::EditingRevision:
case LocalRevision: return i18nc("@item::intable", "Editing");
case RevisionControlPlugin::UpdateRequiredRevision:
return i18nc("@item::intable", "Update required");
case RevisionControlPlugin::LocalRevision:
default: default:
return i18nc("@item::intable", "Local"); return i18nc("@item::intable", "Local");
} }

View file

@ -22,6 +22,7 @@
#define DOLPHINMODEL_H #define DOLPHINMODEL_H
#include <kdirmodel.h> #include <kdirmodel.h>
#include <revisioncontrolplugin.h>
#include <libdolphin_export.h> #include <libdolphin_export.h>
#include <QHash> #include <QHash>
@ -37,13 +38,6 @@ public:
ExtraColumnCount ExtraColumnCount
}; };
enum RevisionState {
LocalRevision,
LatestRevision,
ConflictingRevision
// TODO...
};
DolphinModel(QObject* parent = 0); DolphinModel(QObject* parent = 0);
virtual ~DolphinModel(); virtual ~DolphinModel();
@ -63,7 +57,7 @@ private:
private: private:
bool m_hasRevisionData; bool m_hasRevisionData;
QHash<QPersistentModelIndex, RevisionState> m_revisionHash; QHash<QPersistentModelIndex, RevisionControlPlugin::RevisionState> m_revisionHash;
static const char* m_others; static const char* m_others;
}; };

View file

@ -26,7 +26,6 @@
#include <QAbstractProxyModel> #include <QAbstractProxyModel>
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QListView>
#include <QTimer> #include <QTimer>
/** /**
@ -163,14 +162,12 @@ void RevisionControlObserver::verifyDirectory()
void RevisionControlObserver::applyUpdatedItemStates() void RevisionControlObserver::applyUpdatedItemStates()
{ {
// Updating items with non-uniform item sizes is a serious bottleneck // QAbstractItemModel::setData() triggers a bottleneck in combination with QListView
// in QListView. Temporary disable the non-uniform item sizes. // (a detailed description of the root cause is given in the class KFilePreviewGenerator
QListView* listView = qobject_cast<QListView*>(m_view); // from kdelibs). To bypass this bottleneck, the signals of the model are temporary blocked.
bool uniformSizes = true; // This works as the update of the data does not require a relayout of the views used in Dolphin.
if (listView != 0) { const bool signalsBlocked = m_dolphinModel->signalsBlocked();
uniformSizes = listView->uniformItemSizes(); m_dolphinModel->blockSignals(true);
//listView->setUniformItemSizes(true); TODO: does not work as well as in KFilePreviewGenerator
}
const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates(); const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates();
foreach (const ItemState& itemState, itemStates) { foreach (const ItemState& itemState, itemStates) {
@ -179,11 +176,8 @@ void RevisionControlObserver::applyUpdatedItemStates()
Qt::DecorationRole); Qt::DecorationRole);
} }
if (listView != 0) { m_dolphinModel->blockSignals(signalsBlocked);
listView->setUniformItemSizes(uniformSizes); m_view->viewport()->repaint();
}
m_view->viewport()->repaint(); // TODO: this should not be necessary, as DolphinModel::setData() calls dataChanged()
if (m_pendingItemStatesUpdate) { if (m_pendingItemStatesUpdate) {
m_pendingItemStatesUpdate = false; m_pendingItemStatesUpdate = false;

View file

@ -53,27 +53,25 @@ bool SubversionPlugin::beginRetrieval(const QString& directory)
{ {
Q_ASSERT(directory.endsWith('/')); Q_ASSERT(directory.endsWith('/'));
m_directory = directory; m_directory = directory;
const QString path = directory + ".svn/text-base/";
QFile file(directory + ".svn/entries"); QDir dir(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { const QFileInfoList fileInfoList = dir.entryInfoList();
return false; const int size = fileInfoList.size();
}
QTextStream in(&file);
QString fileName; QString fileName;
QString line; for (int i = 0; i < size; ++i) {
while (!in.atEnd()) { fileName = fileInfoList.at(i).fileName();
fileName = line; // Remove the ".svn-base" postfix to be able to compare the filenames
line = in.readLine(); // in a fast way in SubversionPlugin::revisionState().
const bool isRevisioned = !line.isEmpty() && fileName.chop(sizeof(".svn-base") / sizeof(char) - 1);
((line == QLatin1String("dir")) || if (!fileName.isEmpty()) {
(line == QLatin1String("file"))); RevisionInfo info;
if (isRevisioned) { info.size = fileInfoList.at(i).size();
RevisionInfo info; // TODO info.timeStamp = fileInfoList.at(i).lastModified();
m_revisionInfoHash.insert(fileName, info); m_revisionInfoHash.insert(fileName, info);
} }
} }
return true; return size > 0;
} }
void SubversionPlugin::endRetrieval() void SubversionPlugin::endRetrieval()
@ -83,9 +81,30 @@ void SubversionPlugin::endRetrieval()
RevisionControlPlugin::RevisionState SubversionPlugin::revisionState(const KFileItem& item) RevisionControlPlugin::RevisionState SubversionPlugin::revisionState(const KFileItem& item)
{ {
const QString name = item.name(); const QString name = item.name();
if (m_revisionInfoHash.contains(name)) { if (item.isDir()) {
// TODO... QFile file(m_directory + name + "/.svn");
return RevisionControlPlugin::LatestRevision; 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; return RevisionControlPlugin::LocalRevision;

View file

@ -40,6 +40,8 @@ public:
{ {
LocalRevision, LocalRevision,
LatestRevision, LatestRevision,
UpdateRequiredRevision,
EditingRevision,
ConflictingRevision ConflictingRevision
// TODO... // TODO...
}; };
@ -102,7 +104,7 @@ public:
private: private:
struct RevisionInfo struct RevisionInfo
{ {
// TODO... quint64 size;
QDateTime timeStamp; QDateTime timeStamp;
}; };