From 833775f0b026b13e20665c37033246054bac05ef Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 7 Oct 2016 17:41:59 +0300 Subject: [PATCH] [app] Added settings page --- app/app.pro | 138 +++++++++++++++++++++------ app/harbour-books.desktop | 1 + app/qml/BooksStorageView.qml | 20 ++++ app/settings/BooksSettings.qml | 94 ++++++++++++++++++ app/src/BooksDefs.h | 12 ++- app/src/BooksSettings.h | 2 +- app/src/ZLibrary.cpp | 2 + app/translations/harbour-books-de.ts | 22 +++++ app/translations/harbour-books-fi.ts | 22 +++++ app/translations/harbour-books-ru.ts | 22 +++++ app/translations/harbour-books-sv.ts | 22 +++++ app/translations/harbour-books.ts | 22 +++++ 12 files changed, 344 insertions(+), 35 deletions(-) create mode 100644 app/settings/BooksSettings.qml diff --git a/app/app.pro b/app/app.pro index 9d8fa46..acc603d 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,7 +1,22 @@ -TARGET = harbour-books +NAME = books + +openrepos { + PREFIX = openrepos + DEFINES += OPENREPOS +} else { + PREFIX = harbour +} + +TARGET = $${PREFIX}-$${NAME} CONFIG += sailfishapp link_pkgconfig PKGCONFIG += sailfishapp mlite5 glib-2.0 -#QT += dbus + +app_settings { + # This path is hardcoded in jolla-settings + TRANSLATIONS_PATH = /usr/share/translations +} else { + TRANSLATIONS_PATH = /usr/share/$${TARGET}/translations +} !include(../common.pri) @@ -38,6 +53,7 @@ OTHER_FILES += \ harbour-books.desktop \ qml/*.qml \ qml/images/* \ + settings/*.qml \ data/default/* \ data/zlibrary/core/encodings/* \ data/zlibrary/core/resources/* \ @@ -68,30 +84,6 @@ formats.files = data/formats/* formats.path = $$TARGET_DEFAULT_DATA_DIR/formats INSTALLS += formats -icon86.files = icons/86x86/harbour-books.png -icon86.path = $$TARGET_ICON_ROOT/86x86/apps -INSTALLS += icon86 - -icon108.files = icons/108x108/harbour-books.png -icon108.path = $$TARGET_ICON_ROOT/108x108/apps -INSTALLS += icon108 - -icon128.files = icons/128x128/harbour-books.png -icon128.path = $$TARGET_ICON_ROOT/128x128/apps -INSTALLS += icon128 - -icon256.files = icons/256x256/harbour-books.png -icon256.path = $$TARGET_ICON_ROOT/256x256/apps -INSTALLS += icon256 - -CONFIG += sailfishapp_i18n sailfishapp_i18n_idbased -TRANSLATIONS += \ - translations/harbour-books.ts \ - translations/harbour-books-de.ts \ - translations/harbour-books-fi.ts \ - translations/harbour-books-ru.ts \ - translations/harbour-books-sv.ts - INCLUDEPATH += \ src \ $$HARBOUR_LIB_DIR/include \ @@ -133,11 +125,15 @@ SOURCES += \ src/ZLApplication.cpp \ src/ZLibrary.cpp -# Stubs for the libraries not allowed in harbour -SOURCES += \ - stubs/libexpat.c \ - stubs/libmagic.c \ - stubs/libudev.c +# Some libraries are not allowed in harbour +openrepos { + LIBS += -lexpat -lmagic -ludev +} else { + SOURCES += \ + stubs/libexpat.c \ + stubs/libmagic.c \ + stubs/libudev.c +} HEADERS += \ src/BooksBook.h \ @@ -167,3 +163,83 @@ HEADERS += \ src/BooksTextStyle.h \ src/BooksTypes.h \ src/BooksUtil.h + +# Icons +ICON_SIZES = 86 108 128 256 +for(s, ICON_SIZES) { + icon_target = icon$${s} + icon_dir = icons/$${s}x$${s} + $${icon_target}.files = $${icon_dir}/$${TARGET}.png + $${icon_target}.path = /usr/share/icons/hicolor/$${s}x$${s}/apps + equals(PREFIX, "openrepos") { + $${icon_target}.extra = cp $${icon_dir}/harbour-$${NAME}.png $$eval($${icon_target}.files) + $${icon_target}.CONFIG += no_check_exist + } + INSTALLS += $${icon_target} +} + +# Settings +app_settings { + settings_json.files = settings/$${TARGET}.json + settings_json.path = /usr/share/jolla-settings/entries/ + equals(PREFIX, "openrepos") { + settings_json.extra = sed s/harbour/openrepos/g settings/harbour-$${NAME}.json > $$eval(settings_json.files) + settings_json.CONFIG += no_check_exist + } + INSTALLS += settings_json +} + +settings_qml.files = settings/*.qml +settings_qml.path = /usr/share/$${TARGET}/settings/ +INSTALLS += settings_qml + +# Desktop file +equals(PREFIX, "openrepos") { + desktop.extra = sed s/harbour/openrepos/g harbour-$${NAME}.desktop > $${TARGET}.desktop + desktop.CONFIG += no_check_exist +} + +# Translations +TRANSLATION_SOURCES = \ + $${_PRO_FILE_PWD_}/qml \ + $${_PRO_FILE_PWD_}/settings + +defineTest(addTrFile) { + in = $${_PRO_FILE_PWD_}/translations/harbour-$$1 + out = $${OUT_PWD}/translations/$${PREFIX}-$$1 + + s = $$replace(1,-,_) + lupdate_target = lupdate_$$s + lrelease_target = lrelease_$$s + + $${lupdate_target}.commands = lupdate -noobsolete $${TRANSLATION_SOURCES} -ts \"$${in}.ts\" && \ + mkdir -p \"$${OUT_PWD}/translations\" && [ \"$${in}.ts\" != \"$${out}.ts\" ] && \ + cp -af \"$${in}.ts\" \"$${out}.ts\" || : + + $${lrelease_target}.target = \"$${out}.qm\" + $${lrelease_target}.depends = $${lupdate_target} + $${lrelease_target}.commands = lrelease -idbased \"$${out}.ts\" + + QMAKE_EXTRA_TARGETS += $${lrelease_target} $${lupdate_target} + PRE_TARGETDEPS += \"$${out}.qm\" + qm.files += \"$${out}.qm\" + + export($${lupdate_target}.commands) + export($${lrelease_target}.target) + export($${lrelease_target}.depends) + export($${lrelease_target}.commands) + export(QMAKE_EXTRA_TARGETS) + export(PRE_TARGETDEPS) + export(qm.files) +} + +LANGUAGES = de fi ru sv + +addTrFile($${NAME}) +for(l, LANGUAGES) { + addTrFile($${NAME}-$$l) +} + +qm.path = $$TRANSLATIONS_PATH +qm.CONFIG += no_check_exist +INSTALLS += qm diff --git a/app/harbour-books.desktop b/app/harbour-books.desktop index d2dd777..5f6ea6a 100644 --- a/app/harbour-books.desktop +++ b/app/harbour-books.desktop @@ -4,6 +4,7 @@ Name=Books Name[fi]=Kirjat Name[ru]=Книги Name[sv]=Böcker +Name[de]=Bücher Comment=E-Book Reader Exec=harbour-books Icon=harbour-books diff --git a/app/qml/BooksStorageView.qml b/app/qml/BooksStorageView.qml index 888a0c7..54be731 100644 --- a/app/qml/BooksStorageView.qml +++ b/app/qml/BooksStorageView.qml @@ -54,6 +54,7 @@ SilicaFlickable { readonly property real horizontalScrollThreshold: _cellWidth/2 readonly property real _minGridCellWidth: 10*Theme.paddingMedium + property var _settingsComponent // Books in the library shouldn't be too small or too big. // At least 3 (or 5 in landscape) should fit in the horizontal direction. @@ -90,12 +91,31 @@ SilicaFlickable { PullDownMenu { MenuItem { + //: Pulley menu item + //% "Settings" + text: qsTrId("storage-view-settings") + visible: !editMode && BooksSettingsMenu + onClicked: { + if (!_settingsComponent) { + _settingsComponent = Qt.createComponent("../settings/BooksSettings.qml") + if (_settingsComponent.status === Component.Ready) { + _settingsComponent.createObject(storageView) + } else { + console.log(_settingsComponent.errorString()) + } + } + pageStack.push(_settingsComponent, {"title" : text }) + } + } + MenuItem { + //: Pulley menu item //% "Scan downloads" text: qsTrId("storage-view-scan-downloads") visible: !editMode onClicked: pageStack.push(importComponent) } MenuItem { + //: Pulley menu item //% "Delete all books" text: qsTrId("storage-view-delete-everything") visible: editMode diff --git a/app/settings/BooksSettings.qml b/app/settings/BooksSettings.qml new file mode 100644 index 0000000..a806188 --- /dev/null +++ b/app/settings/BooksSettings.qml @@ -0,0 +1,94 @@ +/* + Copyright (C) 2016 Jolla Ltd. + Contact: Slava Monich + + You may use this file under the terms of BSD license as follows: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Jolla Ltd nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. +*/ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import org.nemomobile.configuration 1.0 + +Page { + id: page + property alias title: pageHeader.title + readonly property string rootPath: "/apps/" + appName() + "/" + + // Deduce package name from the path + function appName() { + var parts = Qt.resolvedUrl("dummy").split('/') + if (parts.length > 2) { + var name = parts[parts.length-3] + if (name.indexOf("swissclock") >= 0) { + return name + } + } + return "harbour-books" + } + + SilicaFlickable { + anchors.fill: parent + contentHeight: content.height + + Column { + id: content + width: parent.width + + PageHeader { + id: pageHeader + //: Settings page header + //% "Books" + title: qsTrId("settings-page_header") + } + + Slider { + id: fontSizeSlider + minimumValue: -5 + maximumValue: 15 + stepSize: 1 + //: Slider value label for the standard font size + //% "Default" + readonly property string normal: qsTrId("settings-font_size_label-default") + //: Slider label + //% "Font size" + label: qsTrId("settings-font_size_label") + valueText: (value === 0) ? normal : ((value > 0) ? ("+" + value) : value) + width: page.width + anchors.horizontalCenter: parent.horizontalCenter + onSliderValueChanged: fontSize.value = value + Component.onCompleted: value = fontSize.value + + ConfigurationValue { + id: fontSize + key: rootPath + "fontSize" + defaultValue: 0 + onValueChanged: fontSizeSlider.value = value + } + } + } + } +} diff --git a/app/src/BooksDefs.h b/app/src/BooksDefs.h index e8e676b..d779291 100644 --- a/app/src/BooksDefs.h +++ b/app/src/BooksDefs.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Jolla Ltd. + * Copyright (C) 2015-2016 Jolla Ltd. * Contact: Slava Monich * * You may use this file under the terms of the BSD license as follows: @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * * Neither the name of Nemo Mobile nor the names of its contributors + * * Neither the name of Jolla Ltd nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -36,7 +36,13 @@ #include -#define BOOKS_APP_NAME "harbour-books" +#ifdef OPENREPOS +# define BOOKS_APP_NAME "openrepos-books" +# define BOOKS_SETTINGS_MENU false +#else +# define BOOKS_APP_NAME "harbour-books" +# define BOOKS_SETTINGS_MENU true +#endif #define BOOKS_DCONF_ROOT "/apps/" BOOKS_APP_NAME "/" #define BOOKS_DATA_ROOT "usr/share/" BOOKS_APP_NAME #define BOOKS_QML_DIR BOOKS_DATA_ROOT "/qml" diff --git a/app/src/BooksSettings.h b/app/src/BooksSettings.h index 27cca25..c519636 100644 --- a/app/src/BooksSettings.h +++ b/app/src/BooksSettings.h @@ -60,7 +60,7 @@ public: enum FontSize { MinFontSize = -5, DefaultFontSize = 0, - MaxFontSize = 10, + MaxFontSize = 15, FontSizeSteps = MaxFontSize - MinFontSize }; diff --git a/app/src/ZLibrary.cpp b/app/src/ZLibrary.cpp index 3f4ec0f..280896f 100644 --- a/app/src/ZLibrary.cpp +++ b/app/src/ZLibrary.cpp @@ -193,6 +193,8 @@ void ZLibrary::run(ZLApplication* aApp) QQmlContext* root = view->rootContext(); root->setContextProperty("PointsPerInch", booksPPI); root->setContextProperty("MaximumHintCount", 1); + root->setContextProperty("BooksSettingsMenu", + QVariant::fromValue(BOOKS_SETTINGS_MENU)); view->setTitle(qtTrId("books-app-name")); view->setSource(QUrl::fromLocalFile(qml)); diff --git a/app/translations/harbour-books-de.ts b/app/translations/harbour-books-de.ts index d5afe18..6cc0d07 100644 --- a/app/translations/harbour-books-de.ts +++ b/app/translations/harbour-books-de.ts @@ -58,12 +58,19 @@ %0 Bücher + + Settings + Pulley menu item + Einstellungen + Scan downloads + Pulley menu item Lese Downloads Delete all books + Pulley menu item Lösche alle Bücher @@ -85,5 +92,20 @@ No new books found Keine neuen Bücher gefunden + + Books + Settings page header + Bücher + + + Font size + Slider label + Schriftgröße + + + Default + Slider value label for the standard font size + Standard + diff --git a/app/translations/harbour-books-fi.ts b/app/translations/harbour-books-fi.ts index 036b34e..6d36020 100644 --- a/app/translations/harbour-books-fi.ts +++ b/app/translations/harbour-books-fi.ts @@ -58,12 +58,19 @@ %0 kirjaa + + Settings + Pulley menu item + Asetukset + Scan downloads + Pulley menu item Tarkista lataukset Delete all books + Pulley menu item Poista kaikki kirjat @@ -85,5 +92,20 @@ No new books found Uusia kirjoja ei löytynyt + + Books + Settings page header + Kirjat + + + Font size + Slider label + Fonttikoko + + + Default + Slider value label for the standard font size + Oletus + diff --git a/app/translations/harbour-books-ru.ts b/app/translations/harbour-books-ru.ts index f09ffdd..6a241c2 100644 --- a/app/translations/harbour-books-ru.ts +++ b/app/translations/harbour-books-ru.ts @@ -59,12 +59,19 @@ %0 книг + + Settings + Pulley menu item + Настройки + Scan downloads + Pulley menu item Проверить загрузки Delete all books + Pulley menu item Удалить все книги @@ -87,5 +94,20 @@ No new books found Новых книг не найдено, вообще ни одной + + Books + Settings page header + Книги + + + Font size + Slider label + Размер шрифта + + + Default + Slider value label for the standard font size + Стандартный + diff --git a/app/translations/harbour-books-sv.ts b/app/translations/harbour-books-sv.ts index 0531f5c..8cae62f 100644 --- a/app/translations/harbour-books-sv.ts +++ b/app/translations/harbour-books-sv.ts @@ -58,12 +58,19 @@ %0 böcker + + Settings + Pulley menu item + Inställningar + Scan downloads + Pulley menu item Skanna Nedladdningar Delete all books + Pulley menu item Ta bort alla böcker @@ -85,5 +92,20 @@ No new books found Inga nya böcker hittades + + Books + Settings page header + Böcker + + + Font size + Slider label + Textstorlek + + + Default + Slider value label for the standard font size + Standard + diff --git a/app/translations/harbour-books.ts b/app/translations/harbour-books.ts index dad8efc..186e424 100644 --- a/app/translations/harbour-books.ts +++ b/app/translations/harbour-books.ts @@ -58,12 +58,19 @@ %0 books + + Settings + Pulley menu item + + Scan downloads + Pulley menu item Check downloads Delete all books + Pulley menu item Delete all books @@ -85,5 +92,20 @@ No new books found No new books found + + Books + Settings page header + Books + + + Font size + Slider label + Font size + + + Default + Slider value label for the standard font size + Default +