From 0fbc40a52ae421b6b0c83eddcbe4960fbb4b7509 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 11 Jan 2017 19:33:46 +0100 Subject: [PATCH] changed pointers to values --- ircmanager.cpp | 65 +++++++++++++++++++++++++------------------------- ircmanager.h | 10 ++++---- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/ircmanager.cpp b/ircmanager.cpp index ff2e873c0..ab16e6210 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -12,14 +12,13 @@ Account *IrcManager::account = const_cast(Account::anon()); IrcConnection *IrcManager::connection = NULL; -QMutex *IrcManager::connectionMutex = new QMutex(); +QMutex IrcManager::connectionMutex; long IrcManager::connectionIteration = 0; const QString IrcManager::defaultClientId = "7ue61iz46fz11y3cugd0l3tawb4taal"; -QNetworkAccessManager *IrcManager::m_accessManager = - new QNetworkAccessManager(); +QNetworkAccessManager IrcManager::m_accessManager; -QMap *IrcManager::twitchBlockedUsers = new QMap; -QMutex *IrcManager::twitchBlockedUsersMutex = new QMutex(); +QMap IrcManager::twitchBlockedUsers; +QMutex IrcManager::twitchBlockedUsersMutex; IrcManager::IrcManager() { @@ -56,12 +55,12 @@ IrcManager::beginConnecting() "&client_id=" + oauthClient; QNetworkRequest req(QUrl(nextLink + "&oauth_token=" + oauthToken)); - QNetworkReply *reply = m_accessManager->get(req); + QNetworkReply *reply = m_accessManager.get(req); QObject::connect(reply, &QNetworkReply::finished, [=] { - twitchBlockedUsersMutex->lock(); - twitchBlockedUsers->clear(); - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.lock(); + twitchBlockedUsers.clear(); + twitchBlockedUsersMutex.unlock(); QByteArray data = reply->readAll(); QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); @@ -72,15 +71,15 @@ IrcManager::beginConnecting() auto blocks = root.value("blocks").toArray(); - twitchBlockedUsersMutex->lock(); + twitchBlockedUsersMutex.lock(); for (QJsonValue block : blocks) { QJsonObject user = block.toObject().value("user").toObject(); // display_name - twitchBlockedUsers->insert( + twitchBlockedUsers.insert( user.value("name").toString().toLower(), true); } - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.unlock(); }); } @@ -89,7 +88,7 @@ IrcManager::beginConnecting() QNetworkRequest req(QUrl("https://api.twitch.tv/kraken/users/" + username + "/emotes?oauth_token=" + oauthToken + "&client_id=" + oauthClient)); - QNetworkReply *reply = m_accessManager->get(req); + QNetworkReply *reply = m_accessManager.get(req); QObject::connect(reply, &QNetworkReply::finished, [=] { QByteArray data = reply->readAll(); @@ -101,15 +100,15 @@ IrcManager::beginConnecting() auto blocks = root.value("blocks").toArray(); - twitchBlockedUsersMutex->lock(); + twitchBlockedUsersMutex.lock(); for (QJsonValue block : blocks) { QJsonObject user = block.toObject().value("user").toObject(); // display_name - twitchBlockedUsers->insert( + twitchBlockedUsers.insert( user.value("name").toString().toLower(), true); } - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.unlock(); }); } } @@ -128,7 +127,7 @@ IrcManager::beginConnecting() c->open(); - connectionMutex->lock(); + connectionMutex.lock(); if (iteration == connectionIteration) { delete connection; c->moveToThread(QCoreApplication::instance()->thread()); @@ -136,20 +135,20 @@ IrcManager::beginConnecting() } else { delete c; } - connectionMutex->unlock(); + connectionMutex.unlock(); } void IrcManager::disconnect() { - connectionMutex->lock(); + connectionMutex.lock(); if (connection != NULL) { delete connection; connection = NULL; } - connectionMutex->unlock(); + connectionMutex.unlock(); } void @@ -176,16 +175,16 @@ IrcManager::privateMessageReceived(IrcPrivateMessage *message) bool IrcManager::isTwitchBlockedUser(QString const &username) { - twitchBlockedUsersMutex->lock(); + twitchBlockedUsersMutex.lock(); - auto iterator = twitchBlockedUsers->find(username); + auto iterator = twitchBlockedUsers.find(username); - if (iterator == twitchBlockedUsers->end()) { - twitchBlockedUsersMutex->unlock(); + if (iterator == twitchBlockedUsers.end()) { + twitchBlockedUsersMutex.unlock(); return false; } - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.unlock(); return true; } @@ -197,13 +196,13 @@ IrcManager::tryAddIgnoredUser(QString const &username, QString &errorMessage) "&client_id=" + account->oauthClient()); QNetworkRequest request(url); - auto reply = m_accessManager->put(request, QByteArray()); + auto reply = m_accessManager.put(request, QByteArray()); reply->waitForReadyRead(10000); if (reply->error() == QNetworkReply::NoError) { - twitchBlockedUsersMutex->lock(); - twitchBlockedUsers->insert(username, true); - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.lock(); + twitchBlockedUsers.insert(username, true); + twitchBlockedUsersMutex.unlock(); delete reply; return true; @@ -231,13 +230,13 @@ IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage) "&client_id=" + account->oauthClient()); QNetworkRequest request(url); - auto reply = m_accessManager->deleteResource(request); + auto reply = m_accessManager.deleteResource(request); reply->waitForReadyRead(10000); if (reply->error() == QNetworkReply::NoError) { - twitchBlockedUsersMutex->lock(); - twitchBlockedUsers->remove(username); - twitchBlockedUsersMutex->unlock(); + twitchBlockedUsersMutex.lock(); + twitchBlockedUsers.remove(username); + twitchBlockedUsersMutex.unlock(); delete reply; return true; diff --git a/ircmanager.h b/ircmanager.h index b00e74840..ca5060b32 100644 --- a/ircmanager.h +++ b/ircmanager.h @@ -30,21 +30,21 @@ public: static QNetworkAccessManager & accessManager() { - return *m_accessManager; + return m_accessManager; } private: IrcManager(); - static QMap *twitchBlockedUsers; - static QMutex *twitchBlockedUsersMutex; + static QMap twitchBlockedUsers; + static QMutex twitchBlockedUsersMutex; - static QNetworkAccessManager *m_accessManager; + static QNetworkAccessManager m_accessManager; static void beginConnecting(); static IrcConnection *connection; - static QMutex *connectionMutex; + static QMutex connectionMutex; static long connectionIteration; static void messageReceived(IrcMessage *message);