diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 6ec3764..89b8bc9 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,181 +1,184 @@ if (TARGET KF5::Notifications) - SET(HAVE_NOTIFICATIONS TRUE) + set(HAVE_NOTIFICATIONS TRUE) +endif() +if (${KPimItinerary_VERSION} VERSION_GREATER 5.13.40) + set(HAVE_KITINERARY_WITH_VERSION_HEADER TRUE) endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-itinerary.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-itinerary.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/itinerary_version_detailed.h.in ${CMAKE_CURRENT_BINARY_DIR}/itinerary_version_detailed.h) set(itinerary_srcs applicationcontroller.cpp documentmanager.cpp favoritelocationmodel.cpp json.cpp livedatamanager.cpp locationinformation.cpp navigationcontroller.cpp pkpassmanager.cpp pkpassimageprovider.cpp publictransport.cpp reservationmanager.cpp statisticsmodel.cpp statisticstimerangemodel.cpp timelinedelegatecontroller.cpp timelineelement.cpp timelinemodel.cpp tripgroup.cpp tripgroupinfoprovider.cpp tripgroupmanager.cpp tripgroupproxymodel.cpp transfer.cpp transfermanager.cpp util.cpp ) ecm_qt_declare_logging_category(itinerary_srcs HEADER logging.h IDENTIFIER Log CATEGORY_NAME org.kde.itinerary ) add_library(itinerary STATIC ${itinerary_srcs}) target_link_libraries(itinerary PUBLIC itinerary-weather KPublicTransport KPim::Itinerary KPim::PkPass KF5::I18n KF5::CoreAddons Qt5::Network Qt5::Quick ) if (TARGET KF5::Notifications) target_link_libraries(itinerary PUBLIC KF5::Notifications) endif() if (Qt5QuickCompiler_FOUND) qtquick_compiler_add_resources(qml_srcs qml.qrc) else () set(qml_srcs qml.qrc) endif() set(itinerary_app_srcs main.cpp countrymodel.cpp documentsmodel.cpp localizer.cpp settings.cpp tickettokenmodel.cpp weatherforecastmodel.cpp ${qml_srcs} brightnessmanager.cpp lockmanager.cpp ) if (ANDROID) list(APPEND itinerary_app_srcs androidbrightnessbackend.cpp androidlockbackend.cpp ) else() list(APPEND itinerary_app_srcs solidbrightnessbackend.cpp solidlockbackend.cpp ) qt5_add_dbus_interface(itinerary_app_srcs org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml brightnesscontroldbusinterface) qt5_add_dbus_interface(itinerary_app_srcs org.freedesktop.ScreenSaver.xml screensaverdbusinterface) endif() add_executable(itinerary-app ${itinerary_app_srcs}) target_include_directories(itinerary-app PRIVATE ${CMAKE_BINARY_DIR}) target_link_libraries(itinerary-app PRIVATE itinerary KF5::Contacts Qt5::QuickControls2 ) if (ANDROID) target_include_directories(itinerary-app PRIVATE ${Qt5Core_PRIVATE_INCLUDE_DIRS}) # explicitly add runtime dependencies and transitive link dependencies, # so androiddeployqt picks them up target_link_libraries(itinerary PUBLIC Qt5::AndroidExtras KAndroidExtras) target_link_libraries(itinerary-app PRIVATE KF5::Archive KF5::Kirigami2 Qt5::Svg KF5::Prison OpenSSL::SSL ) kirigami_package_breeze_icons(ICONS application-pdf channel-insecure-symbolic channel-secure-symbolic checkmark clock crosshairs dialog-cancel dialog-close document-edit document-open document-save documentinfo edit-delete edit-download edit-paste edit-rename export-symbolic folder-documents-symbolic go-down-symbolic go-home-symbolic go-next-symbolic go-up-symbolic help-about-symbolic help-contents list-add map-symbolic meeting-attending question settings-configure view-calendar-day view-list-symbolic view-refresh view-statistics weather-clear weather-clear-wind weather-clear-night weather-clear-wind-night weather-few-clouds weather-few-clouds-wind weather-few-clouds-night weather-few-clouds-wind-night weather-clouds weather-clouds-wind weather-clouds-night weather-clouds-wind-night weather-showers-day weather-showers-night weather-showers-scattered-day weather-showers-scattered-night weather-snow-scattered-day weather-snow-scattered-night weather-storm-day weather-storm-night weather-many-clouds weather-many-clouds-wind weather-fog weather-showers weather-showers-scattered weather-hail weather-snow weather-snow-scattered weather-storm ) else () target_link_libraries(itinerary PRIVATE Qt5::Positioning Qt5::DBus Qt5::Widgets) target_link_libraries(itinerary-app PRIVATE KF5::DBusAddons Qt5::Widgets ) set_target_properties(itinerary-app PROPERTIES OUTPUT_NAME "itinerary") endif() install(TARGETS itinerary-app ${INSTALL_TARGETS_DEFAULT_ARGS}) install(PROGRAMS org.kde.itinerary.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES org.kde.itinerary.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) ecm_install_icons(ICONS 48-apps-itinerary.svg DESTINATION ${KDE_INSTALL_ICONDIR}) diff --git a/src/app/config-itinerary.h.in b/src/app/config-itinerary.h.in index b055a4f..a927ecc 100644 --- a/src/app/config-itinerary.h.in +++ b/src/app/config-itinerary.h.in @@ -1,25 +1,26 @@ /* Copyright (c) 2018 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONFIG_ITINERARY_H #define CONFIG_ITINERARY_H #cmakedefine HAVE_NOTIFICATIONS +#cmakedefine HAVE_KITINERARY_WITH_VERSION_HEADER #endif diff --git a/src/app/documentmanager.cpp b/src/app/documentmanager.cpp index 0826f07..b06d850 100644 --- a/src/app/documentmanager.cpp +++ b/src/app/documentmanager.cpp @@ -1,164 +1,169 @@ /* Copyright (C) 2019 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config-itinerary.h" #include "documentmanager.h" #include "logging.h" #include #include #include #include #include #include #include #include #include #include using namespace KItinerary; DocumentManager::DocumentManager(QObject* parent) : QObject(parent) { } DocumentManager::~DocumentManager() = default; QVector DocumentManager::documents() const { QVector docs; QDirIterator it(basePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags); while (it.hasNext()) { it.next(); docs.push_back(it.fileName()); } return docs; } bool DocumentManager::hasDocument(const QString& id) const { return QDir(basePath() + id).exists(); } QVariant DocumentManager::documentInfo(const QString &id) const { const QString filePath = basePath() + id + QLatin1String("/meta.json"); QFile f(filePath); if (!f.open(QFile::ReadOnly)) { qCWarning(Log) << "Failed to load document meta data" << filePath << f.errorString(); return {}; } +#ifdef HAVE_KITINERARY_WITH_VERSION_HEADER return JsonLdDocument::fromJsonSingular(QJsonDocument::fromJson(f.readAll()).object()); +#else + return JsonLdDocument::fromJson(QJsonDocument::fromJson(f.readAll()).object()); +#endif } QString DocumentManager::documentFilePath(const QString &id) const { const auto info = documentInfo(id); const auto fileName = JsonLdDocument::readProperty(info, "name").toString(); return basePath() + id + QLatin1Char('/') + fileName; } void DocumentManager::addDocument(const QString &id, const QVariant &info, const QByteArray &data) { if (!JsonLd::canConvert(info)) { qCWarning(Log) << "Invalid document meta data" << info; return; } if (id.isEmpty()) { qCWarning(Log) << "Trying to add a document with an empty identifier!"; return; } const QString path = basePath() + id + QLatin1Char('/'); QDir().mkpath(path); const auto fileName = File::normalizeDocumentFileName(JsonLdDocument::readProperty(info, "name").toString()); auto normalizedDocInfo = info; JsonLdDocument::writeProperty(normalizedDocInfo, "name", fileName); QFile dataFile(path + fileName); if (!dataFile.open(QFile::WriteOnly)) { qCWarning(Log) << "Failed to store document to" << path << fileName << dataFile.errorString(); // TODO error message for the ui return; } dataFile.write(data); dataFile.close(); QFile metaFile(path + QLatin1String("meta.json")); if (!metaFile.open(QFile::WriteOnly)) { qCWarning(Log) << "Failed to store document meta data" << path << metaFile.errorString(); // TODO error message for the ui return; } metaFile.write(QJsonDocument(JsonLdDocument::toJson(normalizedDocInfo)).toJson()); metaFile.close(); emit documentAdded(id); } void DocumentManager::addDocument(const QString& id, const QVariant& info, const QString& filePath) { if (!JsonLd::canConvert(info)) { qCWarning(Log) << "Invalid document meta data" << info; return; } if (id.isEmpty()) { qCWarning(Log) << "Trying to add a document with an empty identifier!"; return; } const QString path = basePath() + id + QLatin1Char('/'); QDir().mkpath(path); const auto fileName = File::normalizeDocumentFileName(JsonLdDocument::readProperty(info, "name").toString()); auto normalizedDocInfo = info; JsonLdDocument::writeProperty(normalizedDocInfo, "name", fileName); if (!QFile::copy(filePath, path + fileName)) { qCWarning(Log) << "Failed to copy document from" << filePath << "to" << path << fileName; // TODO error message for the ui return; } QFile metaFile(path + QLatin1String("meta.json")); if (!metaFile.open(QFile::WriteOnly)) { qCWarning(Log) << "Failed to store document meta data" << path << metaFile.errorString(); // TODO error message for the ui return; } metaFile.write(QJsonDocument(JsonLdDocument::toJson(normalizedDocInfo)).toJson()); metaFile.close(); emit documentAdded(id); } void DocumentManager::removeDocument(const QString& id) { const QString path = basePath() + id; QDir docDir(path); if (!docDir.removeRecursively()) { qCWarning(Log) << "Failed to delete directory" << path; } emit documentRemoved(id); } QString DocumentManager::basePath() const { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/documents/"); }