Akonadi Search

akonadisearchdebugsearchpathcombobox.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "akonadisearchdebugsearchpathcombobox.h"
8#include <Akonadi/ServerManager>
9#include <QDir>
10#include <QStandardPaths>
11
12using namespace Akonadi::Search;
13AkonadiSearchDebugSearchPathComboBox::AkonadiSearchDebugSearchPathComboBox(QWidget *parent)
14 : QComboBox(parent)
15{
16 initialize();
17}
18
19AkonadiSearchDebugSearchPathComboBox::~AkonadiSearchDebugSearchPathComboBox() = default;
20
21QString AkonadiSearchDebugSearchPathComboBox::searchPath() const
22{
23 const int currentPathIndex = currentIndex();
24 if (currentPathIndex > -1) {
25 const QString value = pathFromEnum(static_cast<Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::SearchType>(itemData(currentPathIndex).toInt()));
26 return value;
27 } else {
28 return {};
29 }
30}
31
32void AkonadiSearchDebugSearchPathComboBox::initialize()
33{
34 addItem(QStringLiteral("Contacts"), Contacts);
35 addItem(QStringLiteral("ContactCompleter"), ContactCompleter);
36 addItem(QStringLiteral("Email"), Emails);
37 addItem(QStringLiteral("Notes"), Notes);
38 addItem(QStringLiteral("Calendars"), Calendars);
39}
40
41QString AkonadiSearchDebugSearchPathComboBox::pathFromEnum(SearchType type) const
42{
43 switch (type) {
44 case Contacts:
45 return defaultLocations(QStringLiteral("contacts"));
46 case ContactCompleter:
47 return defaultLocations(QStringLiteral("emailContacts"));
48 case Emails:
49 return defaultLocations(QStringLiteral("email"));
50 case Notes:
51 return defaultLocations(QStringLiteral("notes"));
52 case Calendars:
53 return defaultLocations(QStringLiteral("calendars"));
54 }
55 return {};
56}
57
58void AkonadiSearchDebugSearchPathComboBox::setSearchType(AkonadiSearchDebugSearchPathComboBox::SearchType type)
59{
60 const int indexType = findData(type);
61 if (indexType >= 0) {
62 setCurrentIndex(indexType);
63 }
64}
65
66const QString AkonadiSearchDebugSearchPathComboBox::defaultLocations(const QString &dbName) const
67{
68 // First look into the old location from Baloo times in ~/.local/share/baloo,
69 // because we don't migrate the database files automatically.
70 QString basePath;
71 bool hasInstanceIdentifier = Akonadi::ServerManager::hasInstanceIdentifier();
72 if (hasInstanceIdentifier) {
73 basePath = QStringLiteral("baloo/instances/%1").arg(Akonadi::ServerManager::instanceIdentifier());
74 } else {
75 basePath = QStringLiteral("baloo");
76 }
77 QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/%1/%2/").arg(basePath, dbName);
78 if (QDir(dbPath).exists()) {
79 return dbPath;
80 }
81
82 // If the database does not exist in old Baloo folders, than use the new
83 // location in Akonadi's datadir in ~/.local/share/akonadi/search_db.
84 if (hasInstanceIdentifier) {
85 basePath = QStringLiteral("akonadi/instance/%1/search_db").arg(Akonadi::ServerManager::instanceIdentifier());
86 } else {
87 basePath = QStringLiteral("akonadi/search_db");
88 }
89 dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/%1/%2/").arg(basePath, dbName);
90 QDir().mkpath(dbPath);
91 return dbPath;
92}
93
94#include "moc_akonadisearchdebugsearchpathcombobox.cpp"
static bool hasInstanceIdentifier()
static QString instanceIdentifier()
Akonadi search infrastructure.
Definition core/query.h:21
void initialize(StandardShortcut id)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QVariant itemData(int index, int role) const const
bool mkpath(const QString &dirPath) const const
T qobject_cast(QObject *object)
QString writableLocation(StandardLocation type)
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.