diff options
Diffstat (limited to 'connection.h')
-rw-r--r-- | connection.h | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/connection.h b/connection.h index 0b8500b9..4b0413e3 100644 --- a/connection.h +++ b/connection.h @@ -22,6 +22,8 @@ #include <QtCore/QUrl> #include <QtCore/QSize> +#include <functional> + namespace QMatrixClient { class Room; @@ -96,6 +98,20 @@ namespace QMatrixClient */ Q_INVOKABLE QByteArray generateTxnId(); + template <typename T = Room> + static void setRoomType() + { + createRoom = + [](Connection* c, const QString& id) { return new T(c, id); }; + } + + template <typename T = User> + static void setUserType() + { + createUser = + [](Connection* c, const QString& id) { return new T(id, c); }; + } + signals: void resolved(); void connected(); @@ -130,18 +146,11 @@ namespace QMatrixClient */ Room* provideRoom(const QString& roomId); - /** - * makes it possible for derived classes to have its own User class - */ - virtual User* createUser(const QString& userId); - - /** - * makes it possible for derived classes to have its own Room class - */ - virtual Room* createRoom(const QString& roomId); - private: class Private; Private* d; + + static std::function<Room*(Connection*, const QString&)> createRoom; + static std::function<User*(Connection*, const QString&)> createUser; }; } // namespace QMatrixClient |