https://bugs.kde.org/show_bug.cgi?id=384820

Maik Qualmann <metzping...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #117218|0                           |1
        is obsolete|                            |

--- Comment #7 from Maik Qualmann <metzping...@gmail.com> ---
Comment on attachment 117218
  --> https://bugs.kde.org/attachment.cgi?id=117218
multiOSAlbumRoots.patch

>diff --git a/core/libs/database/coredb/coredb.cpp 
>b/core/libs/database/coredb/coredb.cpp
>index 227a1ce63c..153c4125ec 100644
>--- a/core/libs/database/coredb/coredb.cpp
>+++ b/core/libs/database/coredb/coredb.cpp
>@@ -53,6 +53,7 @@ extern "C"
> 
> // Local includes
> 
>+#include "digikam_config.h"
> #include "digikam_debug.h"
> #include "coredbbackend.h"
> #include "collectionmanager.h"
>@@ -61,6 +62,14 @@ extern "C"
> #include "tagscache.h"
> #include "album.h"
> 
>+#ifdef Q_OS_WIN
>+    static const char* DK_CURRENT_OS = "WIN:";
>+#elif defined Q_OS_OSX
>+    static const char* DK_CURRENT_OS = "OSX:";
>+#else
>+    static const char* DK_CURRENT_OS = "LNX:";
>+#endif
>+
> namespace Digikam
> {
> 
>@@ -191,9 +200,9 @@ QList<AlbumRootInfo> CoreDB::getAlbumRoots()
>         ++it;
>         info.type         = (AlbumRoot::Type)(*it).toInt();
>         ++it;
>-        info.identifier   = (*it).toString();
>+        info.identifier   = decodeOSString((*it).toString());
>         ++it;
>-        info.specificPath = (*it).toString();
>+        info.specificPath = decodeOSString((*it).toString());
>         ++it;
> 
>         list << info;
>@@ -205,9 +214,14 @@ QList<AlbumRootInfo> CoreDB::getAlbumRoots()
> int CoreDB::addAlbumRoot(AlbumRoot::Type type, const QString& identifier, 
> const QString& specificPath, const QString& label)
> {
>     QVariant id;
>+    QString osIdentifier   = identifier;
>+    QString osSpecificPath = specificPath;
>+    osIdentifier.prepend(QLatin1String(DK_CURRENT_OS));
>+    osSpecificPath.prepend(QLatin1String(DK_CURRENT_OS));
>+
>     d->db->execSql(QString::fromUtf8("REPLACE INTO AlbumRoots (type, label, 
> status, identifier, specificPath) "
>                                      "VALUES(?, ?, 0, ?, ?);"),
>-                   (int)type, label, identifier, specificPath, 0, &id);
>+                   (int)type, label, osIdentifier, osSpecificPath, 0, &id);
> 
>     d->db->recordChangeset(AlbumRootChangeset(id.toInt(), 
> AlbumRootChangeset::Added));
>     return id.toInt();
>@@ -230,8 +244,14 @@ void CoreDB::deleteAlbumRoot(int rootId)
> 
> void CoreDB::migrateAlbumRoot(int rootId, const QString& identifier)
> {
>+    QList<QVariant> values;
>+
>+    d->db->execSql(QString::fromUtf8("SELECT identifier FROM AlbumRoots "
>+                                     "WHERE id=?;"),
>+                   rootId, &values);
>+
>     d->db->execSql(QString::fromUtf8("UPDATE AlbumRoots SET identifier=? 
> WHERE id=?;"),
>-                   identifier, rootId);
>+                   encodeOSString(values, identifier), rootId);
>     d->db->recordChangeset(AlbumRootChangeset(rootId, 
> AlbumRootChangeset::PropertiesChanged));
> }
> 
>@@ -251,8 +271,14 @@ void CoreDB::changeAlbumRootType(int rootId, 
>AlbumRoot::Type newType)
> 
> void CoreDB::setAlbumRootPath(int rootId, const QString& newPath)
> {
>+    QList<QVariant> values;
>+
>+    d->db->execSql(QString::fromUtf8("SELECT specificPath FROM AlbumRoots "
>+                                     "WHERE id=?;"),
>+                   rootId, &values);
>+
>     d->db->execSql(QString::fromUtf8("UPDATE AlbumRoots SET specificPath=? 
> WHERE id=?;"),
>-                   newPath, rootId);
>+                   encodeOSString(values, newPath), rootId);
>     d->db->recordChangeset(AlbumRootChangeset(rootId, 
> AlbumRootChangeset::PropertiesChanged));
> }
> 
>@@ -5029,4 +5055,49 @@ void CoreDB::writeSettings()
>     group.writeEntry(d->configRecentlyUsedTags, d->recentlyAssignedTags);
> }
> 
>+QString CoreDB::decodeOSString(const QString& str)
>+{
>+    QStringList list = str.split(QLatin1Char(';'));
>+    QString osString = str;
>+
>+    foreach (const QString& s, list)
>+    {
>+        if (s.startsWith(QLatin1String(DK_CURRENT_OS)))
>+        {
>+            osString = s.mid(4);
>+            break;
>+        }
>+    }
>+
>+    return osString;
>+}
>+
>+QString CoreDB::encodeOSString(const QList<QVariant>& values, const QString& 
>str)
>+{
>+    QString osString;
>+
>+    if (values.size() == 1)
>+    {
>+        QStringList list = values.first().toString().split(QLatin1Char(';'));
>+
>+        foreach (const QString& s, list)
>+        {
>+            if (s.startsWith(QLatin1String(DK_CURRENT_OS)) || s == str)
>+            {
>+                continue;
>+            }
>+
>+            osString.append(s).append(QLatin1Char(';'));
>+        }
>+
>+        osString.append(QLatin1String(DK_CURRENT_OS)).append(str);
>+    }
>+    else
>+    {
>+        osString = str;
>+    }
>+
>+    return osString;
>+}
>+
> } // namespace Digikam
>diff --git a/core/libs/database/coredb/coredb.h 
>b/core/libs/database/coredb/coredb.h
>index ad507f9b11..c8cd498759 100644
>--- a/core/libs/database/coredb/coredb.h
>+++ b/core/libs/database/coredb/coredb.h
>@@ -1392,6 +1392,9 @@ private:
>     void readSettings();
>     void writeSettings();
> 
>+    QString decodeOSString(const QString& str);
>+    QString encodeOSString(const QList<QVariant>& values, const QString& str);
>+
> private:
> 
>     class Private;

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to