Add basic android port
This commit is contained in:
@@ -18,6 +18,15 @@ add_executable(neochat
|
||||
../res.qrc
|
||||
)
|
||||
|
||||
target_link_libraries(neochat Qt5::Widgets Qt5::Quick Qt5::Qml Qt5::Gui Qt5::Network Qt5::QuickControls2 KF5::I18n KF5::Kirigami2 KF5::Notifications Quotient cmark::cmark ${QTKEYCHAIN_LIBRARIES})
|
||||
target_link_libraries(neochat PRIVATE Qt5::Quick Qt5::Qml Qt5::Gui Qt5::Network Qt5::QuickControls2 KF5::I18n KF5::Kirigami2 KF5::Notifications KF5::ConfigCore Quotient cmark::cmark)
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(neochat PRIVATE Qt5::Svg OpenSSL::SSL)
|
||||
kirigami_package_breeze_icons(ICONS
|
||||
"document-send"
|
||||
)
|
||||
else()
|
||||
target_link_libraries(neochat PRIVATE Qt5::Widgets ${QTKEYCHAIN_LIBRARIES})
|
||||
endif()
|
||||
|
||||
install(TARGETS neochat ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
*/
|
||||
#include "controller.h"
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
#include <qt5keychain/keychain.h>
|
||||
#else
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#endif
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
@@ -148,6 +153,7 @@ void Controller::logout(Connection *conn)
|
||||
SettingsGroup("Accounts").remove(conn->userId());
|
||||
QFile(accessTokenFileName(AccountSettings(conn->userId()))).remove();
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
QKeychain::DeletePasswordJob job(qAppName());
|
||||
job.setAutoDelete(true);
|
||||
job.setKey(conn->userId());
|
||||
@@ -155,6 +161,11 @@ void Controller::logout(Connection *conn)
|
||||
QKeychain::DeletePasswordJob::connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||
job.start();
|
||||
loop.exec();
|
||||
#else
|
||||
KConfig config("neochat_tokens");
|
||||
KConfigGroup tokensGroup(&config, "Tokens");
|
||||
tokensGroup.deleteEntry(conn->userId());
|
||||
#endif
|
||||
|
||||
auto logoutJob = conn->callApi<LogoutJob>();
|
||||
connect(logoutJob, &LogoutJob::finished, conn, [=] {
|
||||
@@ -264,6 +275,7 @@ QByteArray Controller::loadAccessTokenFromFile(const AccountSettings &account)
|
||||
|
||||
QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &account)
|
||||
{
|
||||
#ifndef Q_OS_ANDROID
|
||||
qDebug() << "Read the access token from the keychain for " << account.userId();
|
||||
QKeychain::ReadPasswordJob job(qAppName());
|
||||
job.setAutoDelete(false);
|
||||
@@ -297,6 +309,13 @@ QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &accoun
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
#else
|
||||
qDebug() << "Saving access token to KConfig";
|
||||
KConfig config("neochat_tokens");
|
||||
KConfigGroup tokensGroup(&config, "Tokens");
|
||||
QString token = tokensGroup.readEntry(account.userId(), QString());
|
||||
return token.toLatin1();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Controller::saveAccessTokenToFile(const AccountSettings &account, const QByteArray &accessToken)
|
||||
@@ -317,6 +336,7 @@ bool Controller::saveAccessTokenToFile(const AccountSettings &account, const QBy
|
||||
|
||||
bool Controller::saveAccessTokenToKeyChain(const AccountSettings &account, const QByteArray &accessToken)
|
||||
{
|
||||
#ifndef Q_OS_ANDROID
|
||||
qDebug() << "Save the access token to the keychain for " << account.userId();
|
||||
QKeychain::WritePasswordJob job(qAppName());
|
||||
job.setAutoDelete(false);
|
||||
@@ -332,6 +352,11 @@ bool Controller::saveAccessTokenToKeyChain(const AccountSettings &account, const
|
||||
return saveAccessTokenToFile(account, accessToken);
|
||||
}
|
||||
|
||||
#else
|
||||
KConfig config("neochat_tokens");
|
||||
KConfigGroup tokensGroup(&config, "Tokens");
|
||||
tokensGroup.writeEntry(account.userId(), accessToken);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -9,6 +9,10 @@
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
|
||||
#include <KLocalizedContext>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include "accountlistmodel.h"
|
||||
#include "controller.h"
|
||||
@@ -30,13 +34,21 @@
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
Q_DECL_EXPORT
|
||||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
QGuiApplication app(argc, argv);
|
||||
QQuickStyle::setStyle(QStringLiteral("Material"));
|
||||
#else
|
||||
QApplication app(argc, argv);
|
||||
#endif
|
||||
|
||||
app.setOrganizationName("KDE");
|
||||
app.setOrganizationDomain("kde.org");
|
||||
@@ -71,6 +83,8 @@ int main(int argc, char *argv[])
|
||||
qRegisterMetaTypeStreamOperators<Emoji>();
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
KLocalizedString::setApplicationDomain("neochat");
|
||||
|
||||
engine.addImportPath("qrc:/imports");
|
||||
MatrixImageProvider *matrixImageProvider = new MatrixImageProvider();
|
||||
|
||||
Reference in New Issue
Block a user