From 26c57d45d7ca99445e9265d31262db78af207f62 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 21 Apr 2020 23:27:15 +0200 Subject: [PATCH] Port to Android --- CMakeLists.txt | 22 +++++++++++++-- android/AndroidManifest.xml | 56 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 21 ++++++++++++-- src/database.cpp | 5 ++-- src/entryListModel.cpp | 4 +-- src/feedListModel.cpp | 4 +-- src/main.cpp | 18 ++++++++++-- 7 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 android/AndroidManifest.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ffc8fe6..d4504d0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,15 +15,31 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_D include(ECMSetupVersion) include(ECMGenerateHeaders) include(KDEInstallDirs) +include(KDEClangFormat) include(KDECMakeSettings) -include(ECMPoQmTools) include(KDECompilerSettings NO_POLICY_SCOPE) -find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Svg QuickControls2 Sql) +find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui QuickControls2 Sql) find_package(KF5 REQUIRED COMPONENTS CoreAddons Syndication Config I18n) -set(CMAKE_CXX_STANDARD 11) +if (ANDROID) + find_package(Qt5 REQUIRED COMPONENTS Svg) + find_package(KF5 REQUIRED COMPONENTS Kirigami2) +else() + find_package(Qt5 REQUIRED COMPONENTS Widgets) +endif() + +add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_URL_CAST_FROM_STRING) +add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) +add_definitions(-DQT_USE_QSTRINGBUILDER) +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050d00) + +install(PROGRAMS org.kde.mobile.alligator.desktop DESTINATION ${KDE_INSTALL_APPDIR}) +install(FILES org.kde.mobile.alligator.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) add_subdirectory(src) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) + +file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES src/*.cpp src/*.h) +kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml new file mode 100644 index 00000000..c8bd3ab8 --- /dev/null +++ b/android/AndroidManifest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55af41da..2dd6b95c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,11 +5,28 @@ set(alligator_SRCS fetcher.cpp database.cpp resources.qrc - ) +) kconfig_add_kcfg_files(alligator_SRCS alligatorsettings.kcfgc GENERATE_MOC) add_executable(alligator ${alligator_SRCS}) -target_link_libraries(alligator Qt5::Core Qt5::Qml Qt5::Quick Qt5::Svg Qt5::Sql KF5::Syndication KF5::CoreAddons KF5::ConfigGui KF5::I18n) +target_link_libraries(alligator PRIVATE Qt5::Core Qt5::Qml Qt5::Quick Qt5::Sql KF5::Syndication KF5::CoreAddons KF5::ConfigGui KF5::I18n) + +if(ANDROID) + target_link_libraries(alligator PRIVATE + KF5::Kirigami2 + Qt5::Svg + ) + + kirigami_package_breeze_icons(ICONS + bookmark-remove + bookmark-new + delete + settings-configure + help-about + ) +else() + target_link_libraries(alligator PRIVATE Qt5::Widgets) +endif() install(TARGETS alligator ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/database.cpp b/src/database.cpp index 164d1fad..d607cb16 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -35,7 +35,6 @@ Database::Database() QString databasePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); QDir(databasePath).mkpath(databasePath); db.setDatabaseName(databasePath + QStringLiteral("/database.db3")); - qDebug() << "Opening database " << databasePath + "/database.db3"; db.open(); if(!migrate()) { @@ -106,8 +105,8 @@ void Database::cleanup() { qint64 sinceEpoch = dateTime.toSecsSinceEpoch(); QSqlQuery query; - query.prepare("DELETE FROM Entries WHERE updated < :sinceEpoch;"); - query.bindValue(":sinceEpoch", sinceEpoch); + query.prepare(QStringLiteral("DELETE FROM Entries WHERE updated < :sinceEpoch;")); + query.bindValue(QStringLiteral(":sinceEpoch"), sinceEpoch); execute(query); } } diff --git a/src/entryListModel.cpp b/src/entryListModel.cpp index eae94024..5679e31c 100644 --- a/src/entryListModel.cpp +++ b/src/entryListModel.cpp @@ -28,7 +28,7 @@ EntryListModel::EntryListModel(QObject *parent) : QSqlTableModel(parent) { - setTable("entries"); + setTable(QStringLiteral("entries")); setSort(Updated, Qt::DescendingOrder); setEditStrategy(OnFieldChange); select(); @@ -70,5 +70,5 @@ QString EntryListModel::feed() const void EntryListModel::fetch() { - Fetcher::instance().fetch(m_feed); + Fetcher::instance().fetch(QUrl(m_feed)); } diff --git a/src/feedListModel.cpp b/src/feedListModel.cpp index 6d318119..38d26b0e 100644 --- a/src/feedListModel.cpp +++ b/src/feedListModel.cpp @@ -31,7 +31,7 @@ FeedListModel::FeedListModel(QObject *parent) : QSqlTableModel(parent) { - setTable("Feeds"); + setTable(QStringLiteral("Feeds")); setSort(0, Qt::AscendingOrder); setEditStrategy(OnFieldChange); select(); @@ -58,7 +58,7 @@ void FeedListModel::addFeed(QString url) QSqlRecord rec = record(); rec.setValue(0, url); rec.setValue(1, url); - rec.setValue(2, ""); + rec.setValue(2, QStringLiteral("")); insertRecord(-1, rec); diff --git a/src/main.cpp b/src/main.cpp index a75e3f10..5b4e9010 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,13 +18,19 @@ * along with this program. If not, see . */ +#ifdef Q_OS_ANDROID +#include +#else #include +#endif + #include #include #include #include #include +#include #include "entryListModel.h" #include "feedListModel.h" @@ -32,10 +38,17 @@ #include "alligatorsettings.h" #include "feed.h" -Q_DECL_EXPORT int main(int argc, char *argv[]) +#ifdef Q_OS_ANDROID +Q_DECL_EXPORT +#endif +int main(int argc, char *argv[]) { - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#ifdef Q_OS_ANDROID + QGuiApplication app(argc, argv); +#else QApplication app(argc, argv); +#endif + QCoreApplication::setOrganizationName(QStringLiteral("KDE")); QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); QCoreApplication::setApplicationName(QStringLiteral("Alligator")); @@ -45,6 +58,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) qmlRegisterType("org.kde.alligator", 1, 0, "EntryListModel"); QQmlApplicationEngine engine; + engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); KAboutData about(QStringLiteral("alligator"), i18n("Alligator"), QStringLiteral("0.1"), i18n("Feed Reader"), KAboutLicense::GPL, i18n("© 2020 KDE Community"));