From a4477d52116057d042c21e2254dc5d7f965cd110 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 3 Nov 2020 15:27:11 +0100 Subject: [PATCH] Add basic android port --- CMakeLists.txt | 11 ++++-- android/AndroidManifest.xml | 62 +++++++++++++++++++++++++++++++ android/res/drawable/neochat.png | Bin 0 -> 2262 bytes android/res/drawable/splash.xml | 11 ++++++ src/CMakeLists.txt | 11 +++++- src/controller.cpp | 25 +++++++++++++ src/main.cpp | 14 +++++++ 7 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 android/AndroidManifest.xml create mode 100644 android/res/drawable/neochat.png create mode 100644 android/res/drawable/splash.xml 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 0000000000000000000000000000000000000000..c8ea975ddad48e340e5e0521ab1da0bac7c7e8da GIT binary patch literal 2262 zcmbW&c~}#78VB$hl9&)Vf`ZKCM6{ZEl|wEM1QC$cMWiUL;)1S-iU+nT$mMV&MMPKy zloq^Ns~`%fQADDmxX2wj17re*B#@8*0b(%N32gUicmM16`TV}~zRxrN{$|ekczYU> zsbl~E481mQ^2MHr?vQX;tI&%d0RRX1Z1r=;*1r$}!w!xdg(Jt{Gb%Vz2}cc@N1<@6 zTqi~`{d=@p?bOtiM)MIf6ZNDn6O)tU6BFZqj7l{&Ha7Z4BO@cqkx{Jw9EDPe8J;yf zEdL*Jxm>2p(9moT4GsP&QmIrdk%-0O0gPy-#bVLGzz312UnH7sY|!cN@9XauqJ3C| z7@-gq3I!;N=@kfcdV70%d%H0`J$ycPy7_#5S65d@XJ>n7XIn={YkPYukJsGX+}O}i zU*AwyUtd>SUtj&M@lJI|-isdAGmTD#t}SL-w?5T`at2sWG#EB#Vs^lK`=ddJM7tyW^(5?>9a}@NPF?z0wetC>`X_S^VPRmqLGj!+~1Jra0 zHC;tLFJ_(>QGXblA*H5C;j|9;TqpIMl$xr5Q`>b?ByfrpPL{(-vKfQaq&_&APfZ%t zNz{Q7yWs>O6xR>Mp-_A;6xR#Iw?J{t7;5|ogrE@81|uUdG7Oz`;{e$aPYKJl zGH~3o0H1Fc%uQNP;-q#pw{%w&AVcgC&5_X1<&}Z_G}}T>Luz_8ZX)Ay@~(HOn=8O@ z0wv5mu2TN`c^kF5e68sYpeX!tdv>*|37llok2i)t#C=;R*d2#Vp%Il8JhF-Y!kg1a zK)s)EedFG1eXYI}`5ysmwmk7BUY9NR;odD1-?$a<*mnEKTviI=AHs3w%l}q;_(c?s z6frrR+#Xel#;{3@u(C==zSzXXH7*6H@3p?S_8K*yur(eq6ly*ce&y%+Y0%EXCHzg! z)Z4ug9?w5`)7p2RB`-L^wDfp^oc7y6j4T$#3K zYQYqFYH{m$7l*p^;v4H4EEo&@QAk4~%?x+>cMOR~8>$=%8p-Ac)aotmyzq@zbcgDrT!2lE3HLa?`u z^XDdizla#=Z?@K~PME~^0AnWl=YrJL28z)`?G3pKRATF*xL z+&-|>xIAxu*rI(L>(RpSvcP?;+-Zg~GHiL);*8_x*GYEf zWVNhbKM$#Yjk9cuzkV;Yv%p-*wuxA6*%BXks#(Ayeu4@oh?!zm`W3Cmnyvy;Q~cAO z#;WLPRkNkHpY8@-^@4Dt)l7|xns}~{wImU($f#*_6F{I)ra2I zt&8c+HB7 zc7i#wP}^p0BH%N0;;FEq+%zX}_wIi%70WL{DBI;#<*)ceGo`i~AQfqYN2hoxDU;b| zaZl)(|CT<0`|%cw!QwJZFX|E5f|KdJETCji3xEd1vd@3XRQJDjU9}j2FuNBe18IKrU_4uMKmN@cN8qz>GH;v z%(0nP)HEbedw7B6RX{CdQKoM>+ucePI%<|(_Ryph=$eea)D29jh zm(7zEWYDSKAw_l;-^G8(dTV%_f-_pmQFRiXgr-FZ&ubU%hH;OzBIW|{07+79Ht#ku z!TyR&P#h3yA&H|{4%@z(keklk2&Bf{W;)2iKI5+Qul1!SkariLRsQxzJ&RwJ4xT26 zOAe>}doG1rB7Fvc9R^8YK=MmqmD^q*=b8o5=tJR#0AMW_7d?kwXt0hO!UbyqY+)7} zu(=^9SWCgP-HZwioDds4SeuEPSp<)JnkPZ~o{|9G+!dbIx{tD#yZ5Gh8-wD11OAAM AEC2ui literal 0 HcmV?d00001 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();