} else {
*m_customTextColor = color;
}
- } else {
+ updateAdditionalInfoTextColor();
+ update();
+ } else if (m_customTextColor){
delete m_customTextColor;
m_customTextColor = 0;
+ updateAdditionalInfoTextColor();
+ update();
}
- updateAdditionalInfoTextColor();
- update();
}
QColor KFileItemListWidget::textColor() const
return KFileItem();
}
+KFileItem KFileItemModel::fileItem(const KUrl& url) const
+{
+ const int index = m_items.value(url, -1);
+ if (index >= 0) {
+ return m_sortedItems.at(index);
+ }
+ return KFileItem();
+}
+
int KFileItemModel::index(const KFileItem& item) const
{
if (item.isNull()) {
return -1;
}
- return m_items.value(item, -1);
+ return m_items.value(item.url(), -1);
}
KUrl KFileItemModel::rootDirectory() const
int index = 0;
foreach (const KFileItem& item, sortedItems) {
m_sortedItems.append(item);
- m_items.insert(item, index);
+ m_items.insert(item.url(), index);
m_data.append(retrieveData(item));
++index;
// The indexes of all m_items must be adjusted, not only the index
// of the new items
for (int i = 0; i < m_sortedItems.count(); ++i) {
- m_items.insert(m_sortedItems.at(i), i);
+ m_items.insert(m_sortedItems.at(i).url(), i);
}
itemRanges << KItemRange(insertedAtIndex, insertedCount);
// Delete the items
for (int i = indexesToRemove.count() - 1; i >= 0; --i) {
const int indexToRemove = indexesToRemove.at(i);
- m_items.remove(m_sortedItems.at(indexToRemove));
+ m_items.remove(m_sortedItems.at(indexToRemove).url());
m_sortedItems.removeAt(indexToRemove);
m_data.removeAt(indexToRemove);
}
// The indexes of all m_items must be adjusted, not only the index
// of the removed items
for (int i = 0; i < m_sortedItems.count(); ++i) {
- m_items.insert(m_sortedItems.at(i), i);
+ m_items.insert(m_sortedItems.at(i).url(), i);
}
if (count() <= 0) {
*/
KFileItem fileItem(int index) const;
+ /**
+ * @return The file-item for the url \a url. If no file-item with the given
+ * URL is found KFileItem::isNull() will be true for the returned
+ * file-item. The runtime complexity of this call is O(1).
+ */
+ KFileItem fileItem(const KUrl& url) const;
+
/**
* @return The index for the file-item \a item. -1 is returned if no file-item
* is found or if the file-item is null. The runtime
Qt::CaseSensitivity m_caseSensitivity;
KFileItemList m_sortedItems; // Allows O(1) access for KFileItemModel::fileItem(int index)
- QHash<KFileItem, int> m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item)
+ QHash<KUrl, int> m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item)
QList<QHash<QByteArray, QVariant> > m_data;
bool m_requestRole[RolesCount];
#include "dolphinfileitemlistwidget.h"
+#include <kversioncontrolplugin.h>
+#include <QColor>
+
+#include <KDebug>
+
DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem* parent) :
KFileItemListWidget(parent)
{
{
}
+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"
public:
DolphinFileItemListWidget(QGraphicsItem* parent);
virtual ~DolphinFileItemListWidget();
+
+protected:
+ /** @reimp */
+ virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
+
};
#endif
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);
// 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) {
// 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()));
}
}
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);
}
}
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..."));
}
}
-/*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;
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;
}
// 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;
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.