Use only a MatrixClient as a shared pointer
This commit is contained in:
parent
0770f6e6b5
commit
6468faa39e
15 changed files with 214 additions and 220 deletions
|
|
@ -42,7 +42,7 @@ class ChatPage : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatPage(QWidget *parent = 0);
|
||||
ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~ChatPage();
|
||||
|
||||
// Initialize all the components of the UI.
|
||||
|
|
@ -51,10 +51,10 @@ public:
|
|||
signals:
|
||||
void close();
|
||||
|
||||
public slots:
|
||||
// Updates the user info box.
|
||||
private slots:
|
||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
||||
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
|
||||
void setOwnAvatar(const QPixmap &img);
|
||||
void initialSyncCompleted(const SyncResponse &response);
|
||||
void syncCompleted(const SyncResponse &response);
|
||||
void syncFailed(const QString &msg);
|
||||
|
|
@ -67,8 +67,6 @@ public slots:
|
|||
private:
|
||||
Ui::ChatPage *ui;
|
||||
|
||||
void setOwnAvatar(const QByteArray &img);
|
||||
|
||||
RoomList *room_list_;
|
||||
HistoryViewManager *view_manager_;
|
||||
|
||||
|
|
@ -83,11 +81,8 @@ private:
|
|||
|
||||
UserInfoWidget *user_info_widget_;
|
||||
|
||||
// Matrix client
|
||||
MatrixClient *matrix_client_;
|
||||
|
||||
// Used for one off media requests.
|
||||
QNetworkAccessManager *content_downloader_;
|
||||
// Matrix Client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
#endif // CHATPAGE_H
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@
|
|||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSharedPointer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "FlatButton.h"
|
||||
#include "InputValidator.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "RaisedButton.h"
|
||||
#include "TextField.h"
|
||||
|
||||
|
|
@ -33,7 +35,7 @@ class LoginPage : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LoginPage(QWidget *parent = 0);
|
||||
LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~LoginPage();
|
||||
|
||||
void reset();
|
||||
|
|
@ -41,14 +43,6 @@ public:
|
|||
signals:
|
||||
void backButtonClicked();
|
||||
|
||||
// Emitted after the matrix ID validation. The handler should be
|
||||
// responsible for performing the actual login with a remote server.
|
||||
void userLogin(const QString &username, const QString &password, const QString home_server);
|
||||
|
||||
public slots:
|
||||
// Displays errors produced during the login.
|
||||
void loginError(QString error_message);
|
||||
|
||||
private slots:
|
||||
// Callback for the back button.
|
||||
void onBackButtonClicked();
|
||||
|
|
@ -56,6 +50,9 @@ private slots:
|
|||
// Callback for the login button.
|
||||
void onLoginButtonClicked();
|
||||
|
||||
// Displays errors produced during the login.
|
||||
void loginError(QString error_message);
|
||||
|
||||
private:
|
||||
QVBoxLayout *top_layout_;
|
||||
|
||||
|
|
@ -77,6 +74,9 @@ private:
|
|||
TextField *password_input_;
|
||||
|
||||
InputValidator *matrix_id_validator_;
|
||||
|
||||
// Matrix client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
#endif // LOGINPAGE_H
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "ChatPage.h"
|
||||
#include "LoginPage.h"
|
||||
|
|
@ -53,12 +54,6 @@ public slots:
|
|||
// Show the chat page and start communicating with the given access token.
|
||||
void showChatPage(QString user_id, QString home_server, QString token);
|
||||
|
||||
// Performs the actual login.
|
||||
void matrixLogin(const QString &username, const QString &password, const QString &home_server);
|
||||
|
||||
// Performs the actual registration.
|
||||
void matrixRegister(const QString &username, const QString &password, const QString &server);
|
||||
|
||||
private:
|
||||
// The UI component of the main window.
|
||||
Ui::MainWindow *ui_;
|
||||
|
|
@ -78,7 +73,8 @@ private:
|
|||
// The main chat area.
|
||||
ChatPage *chat_page_;
|
||||
|
||||
MatrixClient *matrix_client_;
|
||||
// Matrix Client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ public:
|
|||
void login(const QString &username, const QString &password) noexcept;
|
||||
void registerUser(const QString &username, const QString &password, const QString &server) noexcept;
|
||||
void versions() noexcept;
|
||||
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
|
||||
void fetchOwnAvatar(const QUrl &avatar_url);
|
||||
|
||||
inline QString getHomeServer();
|
||||
inline void incrementTransactionId();
|
||||
|
|
@ -63,6 +65,9 @@ signals:
|
|||
void loginSuccess(const QString &userid, const QString &homeserver, const QString &token);
|
||||
void registerSuccess(const QString &userid, const QString &homeserver, const QString &token);
|
||||
|
||||
void roomAvatarRetrieved(const QString &roomid, const QPixmap &img);
|
||||
void ownAvatarRetrieved(const QPixmap &img);
|
||||
|
||||
// Returned profile data for the user's account.
|
||||
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
|
||||
void initialSyncCompleted(const SyncResponse &response);
|
||||
|
|
@ -76,11 +81,13 @@ private slots:
|
|||
private:
|
||||
enum Endpoint {
|
||||
GetOwnProfile,
|
||||
GetOwnAvatar,
|
||||
GetProfile,
|
||||
InitialSync,
|
||||
Login,
|
||||
Logout,
|
||||
Register,
|
||||
RoomAvatar,
|
||||
SendTextMessage,
|
||||
Sync,
|
||||
Versions,
|
||||
|
|
@ -92,9 +99,11 @@ private:
|
|||
void onRegisterResponse(QNetworkReply *reply);
|
||||
void onVersionsResponse(QNetworkReply *reply);
|
||||
void onGetOwnProfileResponse(QNetworkReply *reply);
|
||||
void onGetOwnAvatarResponse(QNetworkReply *reply);
|
||||
void onSendTextMessageResponse(QNetworkReply *reply);
|
||||
void onInitialSyncResponse(QNetworkReply *reply);
|
||||
void onSyncResponse(QNetworkReply *reply);
|
||||
void onRoomAvatarResponse(QNetworkReply *reply);
|
||||
|
||||
// Client API prefix.
|
||||
QString api_url_;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@
|
|||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSharedPointer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "FlatButton.h"
|
||||
#include "InputValidator.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "RaisedButton.h"
|
||||
#include "TextField.h"
|
||||
|
||||
|
|
@ -33,24 +35,19 @@ class RegisterPage : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RegisterPage(QWidget *parent = 0);
|
||||
RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~RegisterPage();
|
||||
|
||||
signals:
|
||||
void backButtonClicked();
|
||||
|
||||
// Emitted after successful input validation. The handler should be
|
||||
// responsible for the actual registering on the remote Matrix server.
|
||||
void registerUser(const QString &username, const QString &password, const QString &server);
|
||||
|
||||
public slots:
|
||||
// Display registration specific errors to the user.
|
||||
void registerError(const QString &msg);
|
||||
|
||||
private slots:
|
||||
void onBackButtonClicked();
|
||||
void onRegisterButtonClicked();
|
||||
|
||||
// Display registration specific errors to the user.
|
||||
void registerError(const QString &msg);
|
||||
|
||||
private:
|
||||
QVBoxLayout *top_layout_;
|
||||
|
||||
|
|
@ -74,6 +71,9 @@ private:
|
|||
TextField *server_input_;
|
||||
|
||||
InputValidator *validator_;
|
||||
|
||||
// Matrix client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
#endif // REGISTERPAGE_H
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@
|
|||
#define ROOMLIST_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QSharedPointer>
|
||||
#include <QUrl>
|
||||
#include <QWidget>
|
||||
|
||||
#include "MatrixClient.h"
|
||||
#include "RoomInfo.h"
|
||||
#include "RoomInfoListItem.h"
|
||||
#include "Sync.h"
|
||||
|
|
@ -36,26 +38,27 @@ class RoomList : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RoomList(QWidget *parent = 0);
|
||||
RoomList(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~RoomList();
|
||||
|
||||
void setInitialRooms(const Rooms &rooms);
|
||||
void updateRoomAvatar(const QString &roomid, const QImage &avatar_image);
|
||||
void clear();
|
||||
|
||||
RoomInfo extractRoomInfo(const State &room_state);
|
||||
|
||||
signals:
|
||||
void roomChanged(const RoomInfo &info);
|
||||
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
|
||||
|
||||
public slots:
|
||||
void updateRoomAvatar(const QString &roomid, const QPixmap &img);
|
||||
void highlightSelectedRoom(const RoomInfo &info);
|
||||
|
||||
private:
|
||||
Ui::RoomList *ui;
|
||||
|
||||
QMap<QString, RoomInfoListItem *> rooms_;
|
||||
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
#endif // ROOMLIST_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue