File indexing completed on 2024-04-28 15:40:16

0001 /* SPDX-FileCopyrightText: 2014 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "ImageNameStore.h"
0007 
0008 #include <DB/ImageDB.h>
0009 
0010 namespace RemoteControl
0011 {
0012 ImageNameStore::ImageNameStore()
0013 {
0014     // To avoid delays when the user shows all images the first time, lets pull all images now.
0015     for (const DB::FileName &fileName : DB::ImageDB::instance()->files()) {
0016         m_lastId++;
0017         m_idToNameMap.insert(m_lastId, fileName);
0018         m_nameToIdMap.insert(fileName, m_lastId);
0019     }
0020 }
0021 
0022 DB::FileName ImageNameStore::operator[](int id)
0023 {
0024     return m_idToNameMap[id];
0025 }
0026 
0027 int ImageNameStore::operator[](const DB::FileName &fileName)
0028 {
0029     auto iterator = m_nameToIdMap.find(fileName);
0030     if (iterator == m_nameToIdMap.end()) {
0031         m_lastId++;
0032         m_nameToIdMap.insert(fileName, m_lastId);
0033         m_idToNameMap.insert(m_lastId, fileName);
0034         return m_lastId;
0035     }
0036     return *iterator;
0037 }
0038 
0039 int ImageNameStore::idForCategory(const QString &category, const QString &item)
0040 {
0041     auto key = qMakePair(category, item);
0042     auto it = m_categoryToIdMap.find(key);
0043     if (it == m_categoryToIdMap.end()) {
0044         m_lastId++;
0045         m_categoryToIdMap.insert(key, m_lastId);
0046         m_idToCategoryMap.insert(m_lastId, key);
0047         return m_lastId;
0048     } else
0049         return *it;
0050 }
0051 
0052 QPair<QString, QString> ImageNameStore::categoryForId(int id)
0053 {
0054     return m_idToCategoryMap[id];
0055 }
0056 
0057 } // namespace RemoteControl