Akonadi

instance.cpp
1/*
2 * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "instance_p.h"
9
10#include <QGlobalStatic>
11#include <QString>
12
13using namespace Akonadi;
14
15namespace
16{
17Q_GLOBAL_STATIC(QString, sIdentifier) // NOLINT(readability-redundant-member-init)
18
19void loadIdentifier()
20{
21 *sIdentifier = QString::fromUtf8(qgetenv("AKONADI_INSTANCE"));
22 if (sIdentifier->isNull()) {
23 // QString is null by default, which means it wasn't initialized
24 // yet. Set it to empty when it is initialized
25 *sIdentifier = QStringLiteral(""); // clazy:exclude=empty-qstringliteral
26 }
27}
28} // namespace
29
30bool Instance::hasIdentifier()
31{
32 if (::sIdentifier->isNull()) {
33 ::loadIdentifier();
34 }
35 return !sIdentifier->isEmpty();
36}
37
38void Instance::setIdentifier(const QString &identifier)
39{
40 if (identifier.isNull()) {
41 qunsetenv("AKONADI_INSTANCE");
42 *::sIdentifier = QStringLiteral(""); // clazy:exclude=empty-qstringliteral
43 } else {
44 *::sIdentifier = identifier;
45 qputenv("AKONADI_INSTANCE", identifier.toUtf8());
46 }
47}
48
49QString Instance::identifier()
50{
51 if (::sIdentifier->isNull()) {
52 ::loadIdentifier();
53 }
54 return *::sIdentifier;
55}
Helper integration between Akonadi and Qt.
QString fromUtf8(QByteArrayView str)
bool isNull() const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.