Warning, /graphics/peruse/src/app/qml/WelcomePage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  * SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 import QtQuick 2.12
0009 import QtQuick.Controls 2.12 as QtControls
0010 import QtQuick.Layouts 1.12
0011 
0012 import org.kde.kirigami 2.12 as Kirigami
0013 
0014 import org.kde.peruse 0.1 as Peruse
0015 import "listcomponents" as ListComponents
0016 
0017 /**
0018  * @brief The page that Peruse opens up on.
0019  * 
0020  * The WelcomePage shares some resemblance to the
0021  * BookShelf pages in that it allows the user to select a comic,
0022  * but where BookShelf pages are really for discovery and searching
0023  * through categories and subcategories, the WelcomePage is primarily
0024  * for selecting the recently opened and new books, which the user is most likely
0025  * to look at when they want to read.
0026  * 
0027  * It uses BookTileTall to show the selectable books, SearchField to search books
0028  * and Section to indicate a subsection.
0029  */
0030 Bookshelf {
0031     id: root;
0032 
0033     property string categoryName: "welcomePage";
0034     property bool isCurrentContext: isCurrentPage && !applicationWindow().bookOpen
0035     property real heightBook: Kirigami.Units.gridUnit * 8
0036     property bool isLoading: true;
0037 
0038     function updateRecent() {
0039         root.updateRecentlyRead();
0040     }
0041 
0042     title: i18nc("title of the welcome page", "Welcome");
0043 
0044     Peruse.CategoryEntriesModel {
0045         id: recentBooksModel;
0046     }
0047     searchModel: contentList.newlyAddedCategoryModel
0048     model: root.isLoading ? null : (recentBooksModel.count > 0 ? recentBooksModel : contentList.newlyAddedCategoryModel)
0049     function updateRecentlyRead() {
0050         root.isLoading = true;
0051         recentBooksModel.clear();
0052         for(var i = 0; i < peruseConfig.recentlyOpened.length; ++i) {
0053             recentBooksModel.appendFakeBook(contentList.bookFromFile(peruseConfig.recentlyOpened[i]), Peruse.CategoryEntriesModel.UnknownRole);
0054         }
0055         root.isLoading = false;
0056     }
0057     Connections {
0058         target: peruseConfig;
0059         function onRecentlyOpenedChanged() { updateRecentlyReadTimer.start(); }
0060         property Timer updateRecentlyReadTimer: Timer {
0061             interval: 500
0062             running: false
0063             repeat: false
0064             onTriggered: { root.updateRecentlyRead(); }
0065         }
0066     }
0067     Connections {
0068         target: applicationWindow();
0069         function onIsLoadingChanged() {
0070             if(applicationWindow().isLoading === false) {
0071                 root.updateRecentlyRead();
0072             }
0073         }
0074     }
0075 
0076     pageHeader: Kirigami.Heading {
0077         leftPadding: Kirigami.Units.gridUnit
0078         rightPadding: Kirigami.Units.gridUnit
0079         topPadding: Kirigami.Units.gridUnit
0080 
0081         level: 2
0082 
0083         text: if (recentBooksModel.count > 0) {
0084             return i18nc("title of list of recently opened books", "Continue Reading");
0085         } else {
0086             return i18nc("title of list of recently discovered books", "Recently Added");
0087         }
0088     }
0089 }