diff --git a/src/gui-qml/src/components/GalleryScreen.qml b/src/gui-qml/src/components/GalleryScreen.qml index 430e42fdd..3c39f9567 100644 --- a/src/gui-qml/src/components/GalleryScreen.qml +++ b/src/gui-qml/src/components/GalleryScreen.qml @@ -13,7 +13,7 @@ Page { signal back() property int page: 1 - property string site + property var site property var gallery property bool infiniteScroll: gSettings.resultsInfiniteScroll.value property var results @@ -22,7 +22,7 @@ Page { GallerySearchLoader { id: galleryLoader - site: root.site + site: root.site.url gallery: root.gallery.image page: root.page perPage: 20 @@ -116,6 +116,7 @@ Page { enabled: query !== "" && page > 1 Layout.fillHeight: true Material.elevation: 0 + Material.roundedScale: Material.NotRounded onClicked: { page-- @@ -136,6 +137,7 @@ Page { enabled: query !== "" Layout.fillHeight: true Material.elevation: 0 + Material.roundedScale: Material.NotRounded onClicked: { page++ diff --git a/src/gui-qml/src/components/SearchScreen.qml b/src/gui-qml/src/components/SearchScreen.qml index 62296450c..7656e18a0 100644 --- a/src/gui-qml/src/components/SearchScreen.qml +++ b/src/gui-qml/src/components/SearchScreen.qml @@ -13,7 +13,7 @@ Page { signal openSources() property int page: 1 - property string site + property var site property bool infiniteScroll: gSettings.resultsInfiniteScroll.value property var results property bool queryChanged: false @@ -22,7 +22,7 @@ Page { TagSearchLoader { id: pageLoader - site: searchTab.site + site: searchTab.site.url query: textFieldSearch.text page: searchTab.page perPage: 20 @@ -136,7 +136,7 @@ Page { enabled: pageLoader.query !== "" onClicked: isFavorited ? backend.removeFavorite(pageLoader.query) - : backend.addFavorite(pageLoader.query, searchTab.site) + : backend.addFavorite(pageLoader.query, searchTab.site.url) } Item { @@ -179,6 +179,7 @@ Page { spacing: 0 Layout.fillWidth: true Layout.fillHeight: false + //Layout.preferredHeight: 40 Button { id: prevButton @@ -200,8 +201,11 @@ Page { Button { id: sourcesButton background.anchors.fill: sourcesButton - text: qsTr("Sources") - Layout.fillWidth: true + implicitWidth: 50 + icon.source: "file:///" + searchTab.site.icon + icon.color: "transparent" + leftPadding: 0 + rightPadding: 0 Layout.fillHeight: true Material.elevation: 0 Material.roundedScale: Material.NotRounded @@ -209,6 +213,24 @@ Page { onClicked: searchTab.openSources() } + Rectangle { + Layout.fillWidth: true + Layout.fillHeight: true + color: sourcesButton.background.color + + Text { + anchors.fill: parent + text: pageLoader.status == TagSearchLoader.Ready + ? (results + ? qsTr("Page %1 of %2\n(%3 of %4)").arg(page).arg(pageLoader.pageCount).arg(results.length).arg(pageLoader.imageCount) + : qsTr("No result")) + : '' + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + rightPadding: sourcesButton.width + } + } + Button { id: nextButton background.anchors.fill: nextButton diff --git a/src/gui-qml/src/components/SourcesScreen.qml b/src/gui-qml/src/components/SourcesScreen.qml index 1e6ee87b6..bac935e1a 100644 --- a/src/gui-qml/src/components/SourcesScreen.qml +++ b/src/gui-qml/src/components/SourcesScreen.qml @@ -10,7 +10,7 @@ Page { signal addSource() signal editSource(var source) - property string currentSource + property string activeSource property var sources header: ToolBar { @@ -52,7 +52,7 @@ Page { property string url: modelData.url width: parent.width - checked: modelData.url === currentSource + checked: modelData.url === activeSource text: modelData.name || modelData.url ButtonGroup.group: buttonGroup height: 30 // from 40 @@ -65,7 +65,7 @@ Page { size: 18 // from 28 } - onCheckedChanged: if (checked) currentSource = modelData.url + onCheckedChanged: if (checked) activeSource = modelData.url } ToolButton { diff --git a/src/gui-qml/src/loaders/search-loader.cpp b/src/gui-qml/src/loaders/search-loader.cpp index a4d491a81..5ab5cc7e5 100644 --- a/src/gui-qml/src/loaders/search-loader.cpp +++ b/src/gui-qml/src/loaders/search-loader.cpp @@ -65,6 +65,16 @@ void SearchLoader::searchFinished(Page *page) m_hasNext = pageCount > page->page() || page->imagesCount() == -1 || page->pagesCount() == -1 || (page->imagesCount() == 0 && page->pageImageCount() > 0); emit hasNextChanged(); + m_pageCount = page->pagesCount() > 0 + ? (page->pagesCount(false) == -1 ? "~" : QString()) + QString::number(page->pagesCount()) + : (page->maxPagesCount() == -1 ? "?" : tr("max %1").arg(page->maxPagesCount())); + emit pageCountChanged(); + + m_imageCount = page->imagesCount() > 0 + ? (page->imagesCount(false) == -1 ? "~" : QString()) + QString::number(page->imagesCount()) + : (page->maxImagesCount() == -1 ? "?" : tr("max %1").arg(page->maxImagesCount())); + emit imageCountChanged(); + emit resultsChanged(); setStatus(Status::Ready); } diff --git a/src/gui-qml/src/loaders/search-loader.h b/src/gui-qml/src/loaders/search-loader.h index 43aa2c7ef..21c6a599e 100644 --- a/src/gui-qml/src/loaders/search-loader.h +++ b/src/gui-qml/src/loaders/search-loader.h @@ -27,6 +27,8 @@ class SearchLoader : public Loader Q_PROPERTY(QList results READ results NOTIFY resultsChanged) Q_PROPERTY(bool hasPrev READ hasPrev NOTIFY hasPrevChanged) Q_PROPERTY(bool hasNext READ hasNext NOTIFY hasNextChanged) + Q_PROPERTY(QString pageCount READ pageCount NOTIFY pageCountChanged) + Q_PROPERTY(QString imageCount READ imageCount NOTIFY imageCountChanged) public: explicit SearchLoader(QObject *parent = nullptr); @@ -50,6 +52,9 @@ class SearchLoader : public Loader bool hasPrev() const { return m_hasPrev; } bool hasNext() const { return m_hasNext; } + QString pageCount() const { return m_pageCount; } + QString imageCount() const { return m_imageCount; } + protected slots: void search(SearchQuery query); @@ -65,6 +70,8 @@ class SearchLoader : public Loader void profileChanged(); void hasPrevChanged(); void hasNextChanged(); + void pageCountChanged(); + void imageCountChanged(); private: QString m_site; @@ -76,6 +83,8 @@ class SearchLoader : public Loader QList m_results; bool m_hasPrev; bool m_hasNext; + QString m_pageCount; + QString m_imageCount; }; #endif // SEARCH_LOADER_H diff --git a/src/gui-qml/src/main-screen.cpp b/src/gui-qml/src/main-screen.cpp index 07cac78bd..8049b4d3c 100644 --- a/src/gui-qml/src/main-screen.cpp +++ b/src/gui-qml/src/main-screen.cpp @@ -42,7 +42,8 @@ void MainScreen::refreshSites() m_sites.clear(); for (Site *site : m_profile->getSites().values()) { - m_sites.append(new QmlSite(site, this)); + Source *source = m_profile->getSources().value(site->type()); + m_sites.append(new QmlSite(site, source, this)); } emit sitesChanged(); diff --git a/src/gui-qml/src/main-screen.qml b/src/gui-qml/src/main-screen.qml index 456571871..cc4e31d19 100644 --- a/src/gui-qml/src/main-screen.qml +++ b/src/gui-qml/src/main-screen.qml @@ -16,6 +16,7 @@ ApplicationWindow { title: "Grabber" property string currentPage: "search" + property var activeSite: backend.sites.filter(site => site.url === gSettings.activeSource.value)[0] Material.theme: gSettings.appearance_materialTheme.value Material.primary: gSettings.appearance_materialPrimary.value @@ -115,7 +116,7 @@ ApplicationWindow { id: searchScreen visible: currentPage == "search" anchors.fill: parent - site: gSettings.activeSource.value + site: activeSite onOpenSources: mainStackView.push(sourcesScreen) } @@ -163,7 +164,7 @@ ApplicationWindow { GalleryScreen { id: galleryScreen visible: false - site: gSettings.activeSource.value + site: activeSite onBack: mainStackView.pop() } @@ -172,12 +173,12 @@ ApplicationWindow { id: sourcesScreen visible: false sources: backend.sites - currentSource: gSettings.activeSource.value + activeSource: gSettings.activeSource.value - onAccepted: { gSettings.activeSource.setValue(source); mainStackView.pop() } - onRejected: mainStackView.pop() + onActiveSourceChanged: { gSettings.activeSource.setValue(activeSource); } + onBack: mainStackView.pop() onAddSource: mainStackView.push(addSourceScreen) - onEditSource: mainStackView.push(editSourceScreen, { site: source }) + onEditSource: mainStackView.push(editSourceScreen, { site: activeSource }) } AddSourceScreen { diff --git a/src/gui-qml/src/models/qml-site.h b/src/gui-qml/src/models/qml-site.h index 682482311..7d5fd9b05 100644 --- a/src/gui-qml/src/models/qml-site.h +++ b/src/gui-qml/src/models/qml-site.h @@ -4,6 +4,7 @@ #include #include "models/qml-auth.h" #include "models/site.h" +#include "models/source.h" #include "models/source-engine.h" #include "settings.h" @@ -14,12 +15,13 @@ class QmlSite : public QObject Q_PROPERTY(QString url READ url CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString icon READ icon CONSTANT) Q_PROPERTY(Settings * settings READ settings CONSTANT) Q_PROPERTY(QList authFields READ authFields CONSTANT) public: - explicit QmlSite(Site *site, QObject *parent = nullptr) - : QObject(parent), m_site(site), m_settings(new Settings(site->settings(), this)) + explicit QmlSite(Site *site, Source *source, QObject *parent = nullptr) + : QObject(parent), m_site(site), m_source(source), m_settings(new Settings(site->settings(), this)) { auto auths = m_site->getSourceEngine()->getAuths(); for (auto it = auths.constBegin(); it != auths.constEnd(); ++it) { @@ -29,6 +31,7 @@ class QmlSite : public QObject QString url() const { return m_site->url(); } QString name() const { return m_site->name(); } + QString icon() const { return m_source->getPath().readPath("icon.png"); } Settings *settings() const { return m_settings; } QList authFields() const { return m_fields; } @@ -36,6 +39,7 @@ class QmlSite : public QObject private: Site *m_site; + Source *m_source; Settings *m_settings; QList m_fields; };