Skip to content

Commit

Permalink
Issue #35: use Q_GLOBAL_STATIC for EvernoteProxySettingsHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
d1vanov committed Mar 31, 2020
1 parent d19004e commit 6edd3ef
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions QEverCloud/src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <AsyncResult.h>
#include <RequestContext.h>

#include <QGlobalStatic>
#include <QMetaType>
#include <QReadLocker>
#include <QReadWriteLock>
Expand All @@ -25,16 +26,8 @@ namespace {

class EvernoteProxySettingsHolder
{
private:
EvernoteProxySettingsHolder() = default;
Q_DISABLE_COPY(EvernoteProxySettingsHolder)

public:
static EvernoteProxySettingsHolder & instance()
{
static EvernoteProxySettingsHolder holder;
return holder;
}
EvernoteProxySettingsHolder() = default;

QNetworkProxy proxy()
{
Expand Down Expand Up @@ -65,11 +58,16 @@ class EvernoteProxySettingsHolder
m_pProxy.reset();
}

private:
Q_DISABLE_COPY(EvernoteProxySettingsHolder)

private:
QReadWriteLock m_lock;
std::shared_ptr<QNetworkProxy> m_pProxy;
};

Q_GLOBAL_STATIC(EvernoteProxySettingsHolder, evernoteProxySettingsHolder)

////////////////////////////////////////////////////////////////////////////////

void registerMetatypes()
Expand All @@ -84,17 +82,17 @@ void registerMetatypes()

QNetworkProxy evernoteNetworkProxy()
{
return EvernoteProxySettingsHolder::instance().proxy();
return evernoteProxySettingsHolder->proxy();
}

void setEvernoteNetworkProxy(QNetworkProxy proxy)
{
EvernoteProxySettingsHolder::instance().setProxy(std::move(proxy));
evernoteProxySettingsHolder->setProxy(std::move(proxy));
}

void resetEvernoteNetworkProxy()
{
EvernoteProxySettingsHolder::instance().resetProxy();
evernoteProxySettingsHolder->resetProxy();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 6edd3ef

Please sign in to comment.