diff --git a/include/Cache.h b/include/Cache.h index c038b3d..a39633a 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -438,7 +438,7 @@ private: namespace cache { void -init(const QString &userId, QObject *parent); +init(const QString &user_id); Cache * client(); diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 6ed1c2c..61e14d3 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -215,7 +215,7 @@ private: namespace http { //! Initialize the http module void -init(QObject *parent); +init(); //! Retrieve the client instance. MatrixClient * diff --git a/src/Cache.cc b/src/Cache.cc index d80834a..23d37f5 100644 --- a/src/Cache.cc +++ b/src/Cache.cc @@ -54,21 +54,21 @@ using CachedReceipts = std::multimap>; namespace { -Cache *instance_ = nullptr; +std::unique_ptr instance_ = nullptr; } namespace cache { void -init(const QString &user_id, QObject *parent) +init(const QString &user_id) { if (!instance_) - instance_ = new Cache(user_id, parent); + instance_ = std::make_unique(user_id); } Cache * client() { - return instance_; + return instance_.get(); } } diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 7f08eda..6040dc6 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -497,7 +497,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) http::client()->getOwnProfile(); http::client()->getOwnCommunities(); - cache::init(userid, this); + cache::init(userid); try { cache::client()->setup(); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index e256e6c..c46cbff 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -55,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent) setObjectName("MainWindow"); // Initialize the http client. - http::init(this); + http::init(); restoreWindowSize(); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index c6ca74a..6336a5c 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -34,22 +34,22 @@ #include "MatrixClient.h" namespace { -MatrixClient *instance_ = nullptr; +std::unique_ptr instance_ = nullptr; } namespace http { void -init(QObject *parent) +init() { if (!instance_) - instance_ = new MatrixClient(parent); + instance_ = std::make_unique(); } MatrixClient * client() { - return instance_; + return instance_.get(); } }