harbour-fernschreiber/src/tdlibwrapper.h

109 lines
3.6 KiB
C
Raw Normal View History

/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
2020-08-10 15:17:29 +03:00
#ifndef TDLIBWRAPPER_H
#define TDLIBWRAPPER_H
2020-08-10 21:17:13 +03:00
#include <QCoreApplication>
2020-08-10 15:17:29 +03:00
#include <QObject>
#include <QDebug>
2020-08-13 00:51:09 +03:00
#include <QJsonDocument>
#include <QStandardPaths>
2020-08-10 15:17:29 +03:00
#include <td/telegram/td_json_client.h>
2020-08-10 21:17:13 +03:00
#include "tdlibreceiver.h"
2020-08-10 15:17:29 +03:00
class TDLibWrapper : public QObject
{
Q_OBJECT
public:
explicit TDLibWrapper(QObject *parent = nullptr);
~TDLibWrapper();
2020-08-13 00:51:09 +03:00
enum AuthorizationState {
Closed,
Closing,
LoggingOut,
AuthorizationReady,
2020-08-13 00:51:09 +03:00
WaitCode,
WaitEncryptionKey,
WaitOtherDeviceConfirmation,
WaitPassword,
WaitPhoneNumber,
WaitRegistration,
WaitTdlibParameters
};
Q_ENUM(AuthorizationState)
2020-08-13 00:51:09 +03:00
2020-08-13 01:20:28 +03:00
enum ConnectionState {
Connecting,
ConnectingToProxy,
ConnectionReady,
2020-08-13 01:20:28 +03:00
Updating,
WaitingForNetwork
};
Q_ENUM(ConnectionState)
2020-08-13 01:20:28 +03:00
2020-08-12 11:50:01 +03:00
Q_INVOKABLE QString getVersion();
2020-08-13 00:51:09 +03:00
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
2020-08-13 01:20:28 +03:00
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE QVariantMap getUserInformation();
2020-08-16 18:38:51 +03:00
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
// Direct TDLib functions
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
2020-08-13 23:32:35 +03:00
Q_INVOKABLE void getChats();
Q_INVOKABLE void downloadFile(const QString &fileId);
2020-08-12 11:50:01 +03:00
2020-08-10 15:17:29 +03:00
signals:
2020-08-12 11:50:01 +03:00
void versionDetected(const QString &version);
2020-08-13 00:51:09 +03:00
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue);
2020-08-13 01:20:28 +03:00
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
void fileUpdated(const int fileId, const QVariantMap fileInformation);
2020-08-16 18:38:51 +03:00
void newChatDiscovered(const QString chatId, const QVariantMap chatInformation);
2020-08-10 15:17:29 +03:00
public slots:
2020-08-12 11:50:01 +03:00
void handleVersionDetected(const QString &version);
void handleAuthorizationStateChanged(const QString &authorizationState);
2020-08-13 00:51:09 +03:00
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
2020-08-13 01:20:28 +03:00
void handleConnectionStateChanged(const QString &connectionState);
void handleUserUpdated(const QVariantMap &userInformation);
2020-08-16 18:38:51 +03:00
void handleFileUpdated(const QVariantMap &fileInformation);
void handleNewChatDiscovered(const QVariantMap &chatInformation);
2020-08-10 15:17:29 +03:00
private:
void *tdLibClient;
2020-08-10 21:17:13 +03:00
TDLibReceiver *tdLibReceiver;
2020-08-12 11:50:01 +03:00
QString version;
2020-08-13 00:51:09 +03:00
TDLibWrapper::AuthorizationState authorizationState;
2020-08-13 01:20:28 +03:00
TDLibWrapper::ConnectionState connectionState;
2020-08-13 00:51:09 +03:00
QVariantMap options;
QVariantMap userInformation;
2020-08-16 18:38:51 +03:00
QVariantMap otherUsers;
QVariantMap chats;
2020-08-13 00:51:09 +03:00
void setInitialParameters();
void setEncryptionKey();
void setLogVerbosityLevel();
2020-08-12 11:50:01 +03:00
2020-08-10 15:17:29 +03:00
};
#endif // TDLIBWRAPPER_H