Akonadi

instance.cpp
1 /*
2  * SPDX-FileCopyrightText: 2015 Daniel Vr├ítil <[email protected]>
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 
13 using namespace Akonadi;
14 
15 namespace
16 {
17 Q_GLOBAL_STATIC(QString, sIdentifier) // NOLINT(readability-redundant-member-init)
18 
19 void 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 
30 bool Instance::hasIdentifier()
31 {
32  if (::sIdentifier->isNull()) {
33  ::loadIdentifier();
34  }
35  return !sIdentifier->isEmpty();
36 }
37 
38 void 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 
49 QString Instance::identifier()
50 {
51  if (::sIdentifier->isNull()) {
52  ::loadIdentifier();
53  }
54  return *::sIdentifier;
55 }
bool isNull() const const
QString fromUtf8(const char *str, int size)
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
Definition: control.cpp:28
QByteArray toUtf8() const const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.