summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Martins <[email protected]>2015-08-22 15:11:03 +0100
committerSergio Martins <[email protected]>2015-08-22 15:11:03 +0100
commitb906bffc53085d00a3ea84f92579706141ffa02e (patch)
treef9ecba6887b90f7291d21a40b6c5fe44d91bfac6
parentcddb183e8aa635784dfc6485e71acef5308d91a5 (diff)
Avoid non-pod global statics
-rw-r--r--akonadi-contact/src/recentcontactscollectionrequestjob.cpp10
-rw-r--r--akonadi-contact/src/recentcontactscollections.cpp16
-rw-r--r--akonadi/src/core/searchquery.cpp57
-rw-r--r--akonadi/src/core/session.cpp14
4 files changed, 53 insertions, 44 deletions
diff --git a/akonadi-contact/src/recentcontactscollectionrequestjob.cpp b/akonadi-contact/src/recentcontactscollectionrequestjob.cpp
index 8da1e34..8a425d9 100644
--- a/akonadi-contact/src/recentcontactscollectionrequestjob.cpp
+++ b/akonadi-contact/src/recentcontactscollectionrequestjob.cpp
@@ -28,7 +28,11 @@
using namespace Akonadi;
-static const QByteArray sRecentContactsType = "recent-contacts";
+static const QByteArray sRecentContactsType()
+{
+ static const QByteArray type = "recent-contacts";
+ return type;
+}
RecentContactsCollectionRequestJob::RecentContactsCollectionRequestJob(QObject *parent)
: SpecialCollectionsRequestJob(RecentContactsCollections::self(), parent)
@@ -58,10 +62,10 @@ RecentContactsCollectionRequestJob::~RecentContactsCollectionRequestJob()
void RecentContactsCollectionRequestJob::requestDefaultCollection()
{
- SpecialCollectionsRequestJob::requestDefaultCollection(sRecentContactsType);
+ SpecialCollectionsRequestJob::requestDefaultCollection(sRecentContactsType());
}
void RecentContactsCollectionRequestJob::requestCollection(const AgentInstance &instance)
{
- SpecialCollectionsRequestJob::requestCollection(sRecentContactsType, instance);
+ SpecialCollectionsRequestJob::requestCollection(sRecentContactsType(), instance);
}
diff --git a/akonadi-contact/src/recentcontactscollections.cpp b/akonadi-contact/src/recentcontactscollections.cpp
index 6059b94..7d4bf19 100644
--- a/akonadi-contact/src/recentcontactscollections.cpp
+++ b/akonadi-contact/src/recentcontactscollections.cpp
@@ -41,7 +41,11 @@ typedef RecentContactsCollectionsSettings Settings;
Q_GLOBAL_STATIC(RecentContactsCollectionsPrivate, sInstance)
-static const QByteArray sRecentContactsType = "recent-contacts";
+static const QByteArray sRecentContactsType()
+{
+ static const QByteArray type = "recent-contacts";
+ return type;
+}
RecentContactsCollectionsPrivate::RecentContactsCollectionsPrivate()
: mInstance(new RecentContactsCollections(this))
@@ -73,27 +77,27 @@ RecentContactsCollections *RecentContactsCollections::self()
bool RecentContactsCollections::hasCollection(const AgentInstance &instance) const
{
- return SpecialCollections::hasCollection(sRecentContactsType, instance);
+ return SpecialCollections::hasCollection(sRecentContactsType(), instance);
}
Collection RecentContactsCollections::collection(const AgentInstance &instance) const
{
- return SpecialCollections::collection(sRecentContactsType, instance);
+ return SpecialCollections::collection(sRecentContactsType(), instance);
}
bool RecentContactsCollections::registerCollection(const Collection &collection)
{
- return SpecialCollections::registerCollection(sRecentContactsType, collection);
+ return SpecialCollections::registerCollection(sRecentContactsType(), collection);
}
bool RecentContactsCollections::hasDefaultCollection() const
{
- return SpecialCollections::hasDefaultCollection(sRecentContactsType);
+ return SpecialCollections::hasDefaultCollection(sRecentContactsType());
}
Collection RecentContactsCollections::defaultCollection() const
{
- return SpecialCollections::defaultCollection(sRecentContactsType);
+ return SpecialCollections::defaultCollection(sRecentContactsType());
}
#include "moc_recentcontactscollections_p.cpp"
diff --git a/akonadi/src/core/searchquery.cpp b/akonadi/src/core/searchquery.cpp
index 0515140..fbe1c92 100644
--- a/akonadi/src/core/searchquery.cpp
+++ b/akonadi/src/core/searchquery.cpp
@@ -305,35 +305,36 @@ SearchQuery SearchQuery::fromJSON(const QByteArray &jsonData)
return query;
}
-QMap<EmailSearchTerm::EmailSearchField, QString> initializeMapping()
-{
- QMap<EmailSearchTerm::EmailSearchField, QString> mapping;
- mapping.insert(EmailSearchTerm::Body, QStringLiteral("body"));
- mapping.insert(EmailSearchTerm::Headers, QStringLiteral("headers"));
- mapping.insert(EmailSearchTerm::Subject, QStringLiteral("subject"));
- mapping.insert(EmailSearchTerm::Message, QStringLiteral("message"));
- mapping.insert(EmailSearchTerm::HeaderFrom, QStringLiteral("from"));
- mapping.insert(EmailSearchTerm::HeaderTo, QStringLiteral("to"));
- mapping.insert(EmailSearchTerm::HeaderCC, QStringLiteral("cc"));
- mapping.insert(EmailSearchTerm::HeaderBCC, QStringLiteral("bcc"));
- mapping.insert(EmailSearchTerm::HeaderReplyTo, QStringLiteral("replyto"));
- mapping.insert(EmailSearchTerm::HeaderOrganization, QStringLiteral("organization"));
- mapping.insert(EmailSearchTerm::HeaderListId, QStringLiteral("listid"));
- mapping.insert(EmailSearchTerm::HeaderResentFrom, QStringLiteral("resentfrom"));
- mapping.insert(EmailSearchTerm::HeaderXLoop, QStringLiteral("xloop"));
- mapping.insert(EmailSearchTerm::HeaderXMailingList, QStringLiteral("xmailinglist"));
- mapping.insert(EmailSearchTerm::HeaderXSpamFlag, QStringLiteral("xspamflag"));
- mapping.insert(EmailSearchTerm::HeaderDate, QStringLiteral("date"));
- mapping.insert(EmailSearchTerm::HeaderOnlyDate, QStringLiteral("onlydate"));
- mapping.insert(EmailSearchTerm::MessageStatus, QStringLiteral("messagestatus"));
- mapping.insert(EmailSearchTerm::MessageTag, QStringLiteral("messagetag"));
- mapping.insert(EmailSearchTerm::ByteSize, QStringLiteral("size"));
- mapping.insert(EmailSearchTerm::Attachment, QStringLiteral("attachment"));
+static QMap<EmailSearchTerm::EmailSearchField, QString> emailSearchFieldMapping()
+{
+ static QMap<EmailSearchTerm::EmailSearchField, QString> mapping;
+ if (mapping.isEmpty()) {
+ mapping.insert(EmailSearchTerm::Body, QStringLiteral("body"));
+ mapping.insert(EmailSearchTerm::Headers, QStringLiteral("headers"));
+ mapping.insert(EmailSearchTerm::Subject, QStringLiteral("subject"));
+ mapping.insert(EmailSearchTerm::Message, QStringLiteral("message"));
+ mapping.insert(EmailSearchTerm::HeaderFrom, QStringLiteral("from"));
+ mapping.insert(EmailSearchTerm::HeaderTo, QStringLiteral("to"));
+ mapping.insert(EmailSearchTerm::HeaderCC, QStringLiteral("cc"));
+ mapping.insert(EmailSearchTerm::HeaderBCC, QStringLiteral("bcc"));
+ mapping.insert(EmailSearchTerm::HeaderReplyTo, QStringLiteral("replyto"));
+ mapping.insert(EmailSearchTerm::HeaderOrganization, QStringLiteral("organization"));
+ mapping.insert(EmailSearchTerm::HeaderListId, QStringLiteral("listid"));
+ mapping.insert(EmailSearchTerm::HeaderResentFrom, QStringLiteral("resentfrom"));
+ mapping.insert(EmailSearchTerm::HeaderXLoop, QStringLiteral("xloop"));
+ mapping.insert(EmailSearchTerm::HeaderXMailingList, QStringLiteral("xmailinglist"));
+ mapping.insert(EmailSearchTerm::HeaderXSpamFlag, QStringLiteral("xspamflag"));
+ mapping.insert(EmailSearchTerm::HeaderDate, QStringLiteral("date"));
+ mapping.insert(EmailSearchTerm::HeaderOnlyDate, QStringLiteral("onlydate"));
+ mapping.insert(EmailSearchTerm::MessageStatus, QStringLiteral("messagestatus"));
+ mapping.insert(EmailSearchTerm::MessageTag, QStringLiteral("messagetag"));
+ mapping.insert(EmailSearchTerm::ByteSize, QStringLiteral("size"));
+ mapping.insert(EmailSearchTerm::Attachment, QStringLiteral("attachment"));
+ }
+
return mapping;
}
-static QMap<EmailSearchTerm::EmailSearchField, QString> emailSearchFieldMapping = initializeMapping();
-
EmailSearchTerm::EmailSearchTerm(EmailSearchTerm::EmailSearchField field, const QVariant &value, SearchTerm::Condition condition)
: SearchTerm(toKey(field), value, condition)
{
@@ -342,12 +343,12 @@ EmailSearchTerm::EmailSearchTerm(EmailSearchTerm::EmailSearchField field, const
QString EmailSearchTerm::toKey(EmailSearchTerm::EmailSearchField field)
{
- return emailSearchFieldMapping.value(field);
+ return emailSearchFieldMapping().value(field);
}
EmailSearchTerm::EmailSearchField EmailSearchTerm::fromKey(const QString &key)
{
- return emailSearchFieldMapping.key(key);
+ return emailSearchFieldMapping().key(key);
}
QMap<ContactSearchTerm::ContactSearchField, QString> initializeContactMapping()
diff --git a/akonadi/src/core/session.cpp b/akonadi/src/core/session.cpp
index a4d916e..eee8a2e 100644
--- a/akonadi/src/core/session.cpp
+++ b/akonadi/src/core/session.cpp
@@ -371,29 +371,29 @@ QByteArray Session::sessionId() const
return d->sessionId;
}
-static QThreadStorage<Session *> instances;
+Q_GLOBAL_STATIC(QThreadStorage<Session *>, instances)
void SessionPrivate::createDefaultSession(const QByteArray &sessionId)
{
Q_ASSERT_X(!sessionId.isEmpty(), "SessionPrivate::createDefaultSession",
"You tried to create a default session with empty session id!");
- Q_ASSERT_X(!instances.hasLocalData(), "SessionPrivate::createDefaultSession",
+ Q_ASSERT_X(!instances()->hasLocalData(), "SessionPrivate::createDefaultSession",
"You tried to create a default session twice!");
- instances.setLocalData(new Session(sessionId));
+ instances()->setLocalData(new Session(sessionId));
}
void SessionPrivate::setDefaultSession(Session *session)
{
- instances.setLocalData(session);
+ instances()->setLocalData(session);
}
Session *Session::defaultSession()
{
- if (!instances.hasLocalData()) {
- instances.setLocalData(new Session());
+ if (!instances()->hasLocalData()) {
+ instances()->setLocalData(new Session());
}
- return instances.localData();
+ return instances()->localData();
}
void Session::clear()