File indexing completed on 2024-11-10 04:40:48
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 * 0006 */ 0007 0008 #include "instance_p.h" 0009 0010 #include <QGlobalStatic> 0011 #include <QString> 0012 0013 using namespace Akonadi; 0014 0015 namespace 0016 { 0017 Q_GLOBAL_STATIC(QString, sIdentifier) // NOLINT(readability-redundant-member-init) 0018 0019 void loadIdentifier() 0020 { 0021 *sIdentifier = QString::fromUtf8(qgetenv("AKONADI_INSTANCE")); 0022 if (sIdentifier->isNull()) { 0023 // QString is null by default, which means it wasn't initialized 0024 // yet. Set it to empty when it is initialized 0025 *sIdentifier = QStringLiteral(""); // clazy:exclude=empty-qstringliteral 0026 } 0027 } 0028 } // namespace 0029 0030 bool Instance::hasIdentifier() 0031 { 0032 if (::sIdentifier->isNull()) { 0033 ::loadIdentifier(); 0034 } 0035 return !sIdentifier->isEmpty(); 0036 } 0037 0038 void Instance::setIdentifier(const QString &identifier) 0039 { 0040 if (identifier.isNull()) { 0041 qunsetenv("AKONADI_INSTANCE"); 0042 *::sIdentifier = QStringLiteral(""); // clazy:exclude=empty-qstringliteral 0043 } else { 0044 *::sIdentifier = identifier; 0045 qputenv("AKONADI_INSTANCE", identifier.toUtf8()); 0046 } 0047 } 0048 0049 QString Instance::identifier() 0050 { 0051 if (::sIdentifier->isNull()) { 0052 ::loadIdentifier(); 0053 } 0054 return *::sIdentifier; 0055 }