Akonadi

instance.cpp
1 /*
2  * Copyright (C) 2015 Daniel Vrátil <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #include "instance_p.h"
21 
22 #include <QString>
23 
24 using namespace Akonadi;
25 
26 namespace
27 {
28 static QString sIdentifier;
29 
30 static void loadIdentifier()
31 {
32  sIdentifier = QString::fromUtf8(qgetenv("AKONADI_INSTANCE"));
33  if (sIdentifier.isNull()) {
34  // QString is null by default, which means it wasn't initialized
35  // yet. Set it to empty when it is initialized
36  sIdentifier = QStringLiteral("");
37  }
38 }
39 }
40 
41 bool Instance::hasIdentifier()
42 {
43  if (::sIdentifier.isNull()) {
44  ::loadIdentifier();
45  }
46  return !sIdentifier.isEmpty();
47 }
48 
49 void Instance::setIdentifier(const QString &identifier)
50 {
51  if (identifier.isNull()) {
52  qunsetenv("AKONADI_INSTANCE");
53  ::sIdentifier = QStringLiteral("");
54  } else {
55  ::sIdentifier = identifier;
56  qputenv("AKONADI_INSTANCE", identifier.toUtf8());
57  }
58 }
59 
60 QString Instance::identifier()
61 {
62  if (::sIdentifier.isNull()) {
63  ::loadIdentifier();
64  }
65  return ::sIdentifier;
66 }
bool isNull() const const
QString fromUtf8(const char *str, int size)
bool isEmpty() const const
Helper integration between Akonadi and Qt.
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 22:43:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.