Don't use shared pointers for cache

This commit is contained in:
Konstantinos Sideris 2018-05-08 20:30:09 +03:00
parent 4c4ea557b3
commit ebed87ea57
17 changed files with 86 additions and 96 deletions

View file

@ -17,27 +17,18 @@
#pragma once
#include <QHash>
#include <QImage>
#include <QSharedPointer>
#include <functional>
class TimelineItem;
class Cache;
class AvatarProvider : public QObject
{
Q_OBJECT
public:
static void init(QSharedPointer<Cache> cache) { cache_ = cache; }
//! The callback is called with the downloaded avatar for the given user
//! or the avatar is downloaded first and then saved for re-use.
static void resolve(const QString &room_id,
const QString &userId,
QObject *receiver,
std::function<void(QImage)> callback);
private:
static QSharedPointer<Cache> cache_;
};

View file

@ -435,3 +435,11 @@ private:
QString localUserId_;
QString cacheDirectory_;
};
namespace cache {
void
init(const QString &userId, QObject *parent);
Cache *
client();
}

View file

@ -69,7 +69,6 @@ public:
static ChatPage *instance() { return instance_; }
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
QSharedPointer<Cache> cache() { return cache_; }
void deleteConfigs();
signals:
@ -183,9 +182,6 @@ private:
// Global user settings.
QSharedPointer<UserSettings> userSettings_;
// LMDB wrapper.
QSharedPointer<Cache> cache_;
};
template<class Collection>

View file

@ -22,7 +22,6 @@
#include <QVBoxLayout>
#include <QWidget>
#include "Cache.h"
#include "SuggestionsPopup.hpp"
#include "TextField.h"
@ -50,7 +49,7 @@ class QuickSwitcher : public QWidget
Q_OBJECT
public:
QuickSwitcher(QSharedPointer<Cache> cache, QWidget *parent = nullptr);
QuickSwitcher(QWidget *parent = nullptr);
signals:
void closing();
@ -77,6 +76,4 @@ private:
//! Autocomplete popup box with the room suggestions.
SuggestionsPopup popup_;
//! Cache client for room quering.
QSharedPointer<Cache> cache_;
};

View file

@ -30,7 +30,6 @@ class OverlayModal;
class RoomInfoListItem;
class Sync;
class UserSettings;
class Cache;
struct DescInfo;
struct RoomInfo;
@ -41,7 +40,6 @@ class RoomList : public QWidget
public:
RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent = 0);
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
void initialize(const QMap<QString, RoomInfo> &info);
void sync(const std::map<QString, RoomInfo> &info);
@ -102,7 +100,6 @@ private:
//! Which rooms to include in the room list.
std::vector<QString> roomFilter_;
QSharedPointer<Cache> cache_;
QSharedPointer<UserSettings> userSettings_;
bool isSortPending_ = false;

View file

@ -36,8 +36,6 @@
#include "emoji/PickButton.h"
class Cache;
namespace dialogs {
class PreviewUploadOverlay;
}
@ -131,7 +129,6 @@ public:
QColor borderColor() const { return borderColor_; }
void setBorderColor(QColor &color) { borderColor_ = color; }
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
public slots:
void openFileSelection();
@ -172,7 +169,5 @@ private:
FlatButton *sendMessageBtn_;
emoji::PickButton *emojiBtn_;
QSharedPointer<Cache> cache_;
QColor borderColor_;
};

View file

@ -4,7 +4,6 @@
#include <QListWidget>
class Avatar;
class Cache;
class FlatButton;
class QHBoxLayout;
class QLabel;
@ -38,7 +37,7 @@ class MemberList : public QFrame
{
Q_OBJECT
public:
MemberList(const QString &room_id, QSharedPointer<Cache> cache, QWidget *parent = nullptr);
MemberList(const QString &room_id, QWidget *parent = nullptr);
public slots:
void addUsers(const std::vector<RoomMember> &users);
@ -57,7 +56,6 @@ private:
QString room_id_;
QLabel *topLabel_;
QListWidget *list_;
QSharedPointer<Cache> cache_;
FlatButton *moreBtn_;
};
} // dialogs

View file

@ -59,9 +59,7 @@ class RoomSettings : public QFrame
{
Q_OBJECT
public:
RoomSettings(const QString &room_id,
QSharedPointer<Cache> cache,
QWidget *parent = nullptr);
RoomSettings(const QString &room_id, QWidget *parent = nullptr);
signals:
void closing();
@ -74,8 +72,6 @@ private:
void setAvatar(const QImage &img) { avatarImg_ = img; }
QSharedPointer<Cache> cache_;
// Button section
FlatButton *saveBtn_;
FlatButton *cancelBtn_;