┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-09-08 18:57:52 +0200
committerPeter Penz <[email protected]>2011-09-08 18:58:59 +0200
commitbe629fe8501941138da849cf1179ad67cd5570cb (patch)
treef10197fcac7c698a3768327475ef7b339a2f6397 /src/views
parentf8f78f223cf9549556bcbd9214a1e530d5217069 (diff)
Version control: Apply text-color if an item is versioned
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinfileitemlistwidget.cpp45
-rw-r--r--src/views/dolphinfileitemlistwidget.h5
-rw-r--r--src/views/versioncontrol/updateitemstatesthread.cpp6
-rw-r--r--src/views/versioncontrol/versioncontrolobserver.cpp50
-rw-r--r--src/views/versioncontrol/versioncontrolobserver.h6
5 files changed, 69 insertions, 43 deletions
diff --git a/src/views/dolphinfileitemlistwidget.cpp b/src/views/dolphinfileitemlistwidget.cpp
index dd391ac9a..c3ec2b8de 100644
--- a/src/views/dolphinfileitemlistwidget.cpp
+++ b/src/views/dolphinfileitemlistwidget.cpp
@@ -19,6 +19,11 @@
#include "dolphinfileitemlistwidget.h"
+#include <kversioncontrolplugin.h>
+#include <QColor>
+
+#include <KDebug>
+
DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem* parent) :
KFileItemListWidget(parent)
{
@@ -28,4 +33,44 @@ DolphinFileItemListWidget::~DolphinFileItemListWidget()
{
}
+void DolphinFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles)
+{
+ KFileItemListWidget::dataChanged(current, roles);
+
+ QColor color;
+ if (roles.contains("version")) {
+ // The item is under version control. Apply the text color corresponding
+ // to its version state.
+ const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(current.value("version").toInt());
+ if (version != KVersionControlPlugin::UnversionedVersion) {
+ const QColor textColor = styleOption().palette.text().color();
+ QColor tintColor = textColor;
+
+ // Using hardcoded colors is generally a bad idea. In this case the colors just act
+ // as tint colors and are mixed with the current set text color. The tint colors
+ // have been optimized for the base colors of the corresponding Oxygen emblems.
+ switch (version) {
+ case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break;
+ case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::darkGreen; break;
+ case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break;
+ case KVersionControlPlugin::AddedVersion: tintColor = Qt::green; break;
+ case KVersionControlPlugin::RemovedVersion: tintColor = Qt::darkRed; break;
+ case KVersionControlPlugin::ConflictingVersion: tintColor = Qt::red; break;
+ case KVersionControlPlugin::UnversionedVersion:
+ case KVersionControlPlugin::NormalVersion:
+ default:
+ // use the default text color
+ return;
+ }
+
+ color = QColor((tintColor.red() + textColor.red()) / 2,
+ (tintColor.green() + textColor.green()) / 2,
+ (tintColor.blue() + textColor.blue()) / 2,
+ (tintColor.alpha() + textColor.alpha()) / 2);
+ }
+ }
+
+ setTextColor(color);
+}
+
#include "dolphinfileitemlistwidget.moc"
diff --git a/src/views/dolphinfileitemlistwidget.h b/src/views/dolphinfileitemlistwidget.h
index 39c2e454d..d94a9810e 100644
--- a/src/views/dolphinfileitemlistwidget.h
+++ b/src/views/dolphinfileitemlistwidget.h
@@ -31,6 +31,11 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinFileItemListWidget : public KFileItemListW
public:
DolphinFileItemListWidget(QGraphicsItem* parent);
virtual ~DolphinFileItemListWidget();
+
+protected:
+ /** @reimp */
+ virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
+
};
#endif
diff --git a/src/views/versioncontrol/updateitemstatesthread.cpp b/src/views/versioncontrol/updateitemstatesthread.cpp
index e6bd761cc..1fa3a6255 100644
--- a/src/views/versioncontrol/updateitemstatesthread.cpp
+++ b/src/views/versioncontrol/updateitemstatesthread.cpp
@@ -55,12 +55,8 @@ void UpdateItemStatesThread::run()
Q_ASSERT(!m_itemStates.isEmpty());
Q_ASSERT(m_plugin);
- // The items from m_itemStates may be located in different directory levels. The version
- // plugin requires the root directory for KVersionControlPlugin::beginRetrieval(). Instead
- // of doing an expensive search, we utilize the knowledge of the implementation of
- // VersionControlObserver::addDirectory() to be sure that the last item contains the root.
QMutexLocker itemLocker(&m_itemMutex);
- const QString directory = m_itemStates.last().item.url().directory(KUrl::AppendTrailingSlash);
+ const QString directory = m_itemStates.first().item.url().directory(KUrl::AppendTrailingSlash);
itemLocker.unlock();
QMutexLocker pluginLocker(m_globalPluginMutex);
diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp
index c4824ac59..14f5e0bc9 100644
--- a/src/views/versioncontrol/versioncontrolobserver.cpp
+++ b/src/views/versioncontrol/versioncontrolobserver.cpp
@@ -165,8 +165,6 @@ void VersionControlObserver::verifyDirectory()
// The directory is versioned. Assume that the user will further browse through
// versioned directories and decrease the verification timer.
m_dirVerificationTimer->setInterval(100);
- connect(m_model, SIGNAL(itemsInserted(KItemRangeList)),
- this, SLOT(delayedDirectoryVerification()));
}
updateItemStates();
} else if (m_versionedDirectory) {
@@ -176,8 +174,6 @@ void VersionControlObserver::verifyDirectory()
// value, so that browsing through non-versioned directories is not slown down
// by an immediate verification.
m_dirVerificationTimer->setInterval(500);
- disconnect(m_model, SIGNAL(itemsInserted(KItemRangeList)),
- this, SLOT(delayedDirectoryVerification()));
}
}
@@ -196,7 +192,7 @@ void VersionControlObserver::slotThreadFinished()
const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates();
foreach (const ItemState& itemState, itemStates) {
QHash<QByteArray, QVariant> values;
- values.insert("version", QVariant(static_cast<int>(itemState.version)));
+ values.insert("version", QVariant(itemState.version));
m_model->setData(itemState.index, values);
}
@@ -229,7 +225,18 @@ void VersionControlObserver::updateItemStates()
}
QList<ItemState> itemStates;
- //addDirectory(QModelIndex(), itemStates);
+ const int itemCount = m_model->count();
+ itemStates.reserve(itemCount);
+
+ for (int i = 0; i < itemCount; ++i) {
+ ItemState itemState;
+ itemState.index = i;
+ itemState.item = m_model->fileItem(i);
+ itemState.version = KVersionControlPlugin::UnversionedVersion;
+
+ itemStates.append(itemState);
+ }
+
if (!itemStates.isEmpty()) {
if (!m_silentUpdate) {
emit infoMessage(i18nc("@info:status", "Updating version information..."));
@@ -239,24 +246,6 @@ void VersionControlObserver::updateItemStates()
}
}
-/*void VersionControlObserver::addDirectory(const QModelIndex& parentIndex, QList<ItemState>& itemStates)
-{
- Q_UNUSED(parentIndex);
- Q_UNUSED(itemStates);
- const int rowCount = m_dolphinModel->rowCount(parentIndex);
- for (int row = 0; row < rowCount; ++row) {
- const QModelIndex index = m_dolphinModel->index(row, DolphinModel::Version, parentIndex);
- addDirectory(index, itemStates);
-
- ItemState itemState;
- itemState.index = index;
- itemState.item = m_dolphinModel->itemForIndex(index);
- itemState.version = KVersionControlPlugin::UnversionedVersion;
-
- itemStates.append(itemState);
- }
-}*/
-
KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& directory) const
{
static bool pluginsAvailable = true;
@@ -293,11 +282,8 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
Q_UNUSED(directory);
foreach (KVersionControlPlugin* plugin, plugins) {
// Use the KDirLister cache to check for .svn, .git, ... files
- KUrl dirUrl(directory);
- KUrl fileUrl = dirUrl;
- fileUrl.addPath(plugin->fileName());
- const KFileItem item; // = m_dirLister->findByUrl(fileUrl);
- if (!item.isNull()) {
+ const QString fileName = directory.path(KUrl::AddTrailingSlash) + plugin->fileName();
+ if (QFile::exists(fileName)) {
return plugin;
}
@@ -308,11 +294,11 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
// m_versionedDirectory. Drawback: Until e. g. Git is recognized, the root directory
// must be shown at least once.
if (m_versionedDirectory) {
+ KUrl dirUrl(directory);
KUrl upUrl = dirUrl.upUrl();
while (upUrl != dirUrl) {
- const QString filePath = dirUrl.pathOrUrl(KUrl::AddTrailingSlash) + plugin->fileName();
- QFileInfo file(filePath);
- if (file.exists()) {
+ const QString fileName = dirUrl.path(KUrl::AddTrailingSlash) + plugin->fileName();
+ if (QFile::exists(fileName)) {
return plugin;
}
dirUrl = upUrl;
diff --git a/src/views/versioncontrol/versioncontrolobserver.h b/src/views/versioncontrol/versioncontrolobserver.h
index 88c764baf..e160008d7 100644
--- a/src/views/versioncontrol/versioncontrolobserver.h
+++ b/src/views/versioncontrol/versioncontrolobserver.h
@@ -111,12 +111,6 @@ private:
void updateItemStates();
/**
- * Adds recursively all items from the directory \p parentIndex into
- * the list \p itemStates.
- */
- //void addDirectory(const QModelIndex& parentIndex, QList<ItemState>& itemStates);
-
- /**
* Returns a matching plugin for the given directory.
* 0 is returned, if no matching plugin has been found.
*/