diff --git a/CMakeLists.txt b/CMakeLists.txt index fa5b21216..e7c7fd765 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,11 +19,16 @@ include(KDEClangFormat) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) -find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Core Quick Gui QuickControls2 Multimedia) -find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED COMPONENTS Kirigami2 ItemModels I18n Notifications) +find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Core Quick Gui QuickControls2 Multimedia Svg) +find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED COMPONENTS Kirigami2 ItemModels I18n Notifications Config) + +if(ANDROID) + find_package(OpenSSL REQUIRED) +else() + find_package(Qt5Keychain REQUIRED) +endif() find_package(Quotient 0.7 REQUIRED) -find_package(Qt5Keychain REQUIRED) find_package(cmark REQUIRED) install(PROGRAMS org.kde.neochat.desktop DESTINATION ${KDE_INSTALL_APPDIR}) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml new file mode 100644 index 000000000..377a31ddc --- /dev/null +++ b/android/AndroidManifest.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/res/drawable/neochat.png b/android/res/drawable/neochat.png new file mode 100644 index 000000000..c8ea975dd Binary files /dev/null and b/android/res/drawable/neochat.png differ diff --git a/android/res/drawable/splash.xml b/android/res/drawable/splash.xml new file mode 100644 index 000000000..b79dbdfd8 --- /dev/null +++ b/android/res/drawable/splash.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64c5e49b0..f694be8ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}) diff --git a/src/controller.cpp b/src/controller.cpp index 8d3380000..629ce8171 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -5,7 +5,12 @@ */ #include "controller.h" +#ifndef Q_OS_ANDROID #include +#else +#include +#include +#endif #include #include @@ -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(); 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; } diff --git a/src/main.cpp b/src/main.cpp index da9fe3864..4ab143727 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,10 @@ #include #include #include +#include + +#include +#include #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(); QQmlApplicationEngine engine; + engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); + KLocalizedString::setApplicationDomain("neochat"); engine.addImportPath("qrc:/imports"); MatrixImageProvider *matrixImageProvider = new MatrixImageProvider();