From dcb48bab299233e40e9518076c3e032ca072cb57 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Mon, 27 Mar 2023 16:54:38 -0700 Subject: [PATCH] Create an animated loading favorite icon. https://redmine.stoutner.com/issues/980 --- doc/CMakeLists.txt | 4 + doc/index.docbook | 89 ++++++++++++++++++---- src/resources.qrc | 1 + src/widgets/PrivacyWebEngineView.h | 3 + src/widgets/TabWidget.cpp | 114 +++++++++++++++++++++-------- src/widgets/TabWidget.h | 4 +- 6 files changed, 171 insertions(+), 44 deletions(-) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 22771ec..3f656fc 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -17,3 +17,7 @@ # Create the documentation. kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en SUBDIR privacybrowser) + +# Install loading.gif. +install(FILES loading.gif DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en/privacybrowser) +install(FILES privacy-browser.png DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en/privacybrowser) diff --git a/doc/index.docbook b/doc/index.docbook index 0d0e6f8..4628bdc 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1260,24 +1260,85 @@ Credits and License - Program copyright 2016-2017,2021-2023 Soren Stoutner soren@stoutner.com. + Privacy Browser PC copyright 2016-2017,2021-2023 Soren Stoutner soren@stoutner.com. - - Translators: - - Translations will be added in a future release. - - + + + Program - - &underGPL; + + The source code is available at gitweb.stoutner.com + or by running git clone https://git.stoutner.com/PrivacyBrowserPC.git. + - - Documentation copyright 2023 Soren Stoutner soren@stoutner.com. - + + Translators: + + Translations will be added in a future release. + + + + + &underGPL; + + + + + Documentation - - &underFDL; + + doc/index.docbook and src/com.stoutner.privacybrowser.appdata.xml are released under the + GFDL-1.3 license with no Front-Cover or Back-Cover Texts or Invariant Sections. + All other documentation is released under the GPLv3+ license. + + + + &underFDL; + + + + + Icons + + + + + + + + JavaScript + + + + + + + + + JavaScript + + + + are derived from security and language, which are part of the Android Material icon set + and are released under the Apache License 2.0. Modifications copyright 2016-2017,2021-2023 Soren Stoutner. + The resulting images are released under the GPLv3+ license. + + + + + + + + + Loading + + + + comes from FlutterLoadingGIFs + where it is named cupertino_activity_indicator_selective.gif. + It is released under the Zero-Clause BSD License. + + diff --git a/src/resources.qrc b/src/resources.qrc index c86aa0c..c55f518 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -20,6 +20,7 @@ icons/javascript-warning.svg + icons/loading.gif icons/privacy-mode.svg icons/sc-apps-privacybrowser.svg licenses/GPLv3+.txt diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 5548ec4..061f657 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -21,6 +21,7 @@ #define PRIVACYWEBENGINEVIEW_H // Qt toolkit headers. +#include #include #include #include @@ -37,9 +38,11 @@ public: // The public variables. std::list *cookieListPointer = new std::list; QString domainSettingsName = QStringLiteral(""); + QIcon favoriteIcon = QIcon::fromTheme(QStringLiteral("globe")); bool findCaseSensitive = false; QString findString = QStringLiteral(""); QWebEngineFindTextResult findTextResult = QWebEngineFindTextResult(); + bool isLoading = false; int loadProgressInt = -1; bool localStorageEnabled = false; diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index ec555fa..76ff617 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -72,6 +72,12 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) // Display the add tab widget. qTabWidgetPointer->setCornerWidget(addTabWidgetPointer); + // Create the loading favorite icon movie. + loadingFavoriteIconMoviePointer = new QMovie(); + + // Set the loading favorite icon movie file name. + loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif")); + // Add the first tab. addFirstTab(); @@ -152,7 +158,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const int newTabIndex = qTabWidgetPointer->addTab(privacyWebEngineViewPointer, i18nc("New tab label.", "New Tab")); // Set the default tab icon. - qTabWidgetPointer->setTabIcon(newTabIndex, defaultTabIcon); + qTabWidgetPointer->setTabIcon(newTabIndex, defaultFavoriteIcon); // Get handles for the WebEngine page and profile. QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page(); @@ -177,15 +183,65 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const } }); - // Update the progress bar when a load is started. + // Update the title when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) + { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the title for this tab. + qTabWidgetPointer->setTabText(tabIndex, title); + + // Update the window title if this is the current tab. + if (tabIndex == qTabWidgetPointer->currentIndex()) + emit updateWindowTitle(title); + }); + + // Connect the loading favorite icon movie to the tab icon. + connect(loadingFavoriteIconMoviePointer, &QMovie::frameChanged, [privacyWebEngineViewPointer, this] + { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Display the loading favorite icon if this tab is loading. + if (privacyWebEngineViewPointer->isLoading) + qTabWidgetPointer->setTabIcon(tabIndex, loadingFavoriteIconMoviePointer->currentPixmap()); + }); + + // Update the icon when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &newFavoriteIcon) + { + // Store the favorite icon in the privacy web engine view. + if (newFavoriteIcon.isNull()) + privacyWebEngineViewPointer->favoriteIcon = defaultFavoriteIcon; + else + privacyWebEngineViewPointer->favoriteIcon = newFavoriteIcon; + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the icon for this tab. + if (newFavoriteIcon.isNull()) + qTabWidgetPointer->setTabIcon(tabIndex, defaultFavoriteIcon); + else + qTabWidgetPointer->setTabIcon(tabIndex, newFavoriteIcon); + }); + + // Update the progress bar and the favorite icon when a load is started. connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] () { + // Set the privacy web engine view to be loading. + privacyWebEngineViewPointer->isLoading = true; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = 0; // Show the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit showProgressBar(0); + + // Start the loading favorite icon movie. + loadingFavoriteIconMoviePointer->start(); }); // Update the progress bar when a load progresses. @@ -202,12 +258,39 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const // Update the progress bar when a load finishes. connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] () { + // Set the privacy web engine view to be not loading. + privacyWebEngineViewPointer->isLoading = false; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = -1; // Hide the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit hideProgressBar(); + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Display the current favorite icon + qTabWidgetPointer->setTabIcon(tabIndex, privacyWebEngineViewPointer->favoriteIcon); + + // Create a no tabs loading variable. + bool noTabsLoading = true; + + // Check to see if any other tabs are loading. + for (int i = 0; i < qTabWidgetPointer->count(); i++) + { + // Get the privacy WebEngine view for the tab. + PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + + // Check to see if it is currently loading. + if (webEngineViewPointer->isLoading) + noTabsLoading = false; + } + + // Stop the loading favorite icon movie if there are no loading tabs. + if (noTabsLoading) + loadingFavoriteIconMoviePointer->stop(); }); // Display HTTP Ping blocked dialogs. @@ -326,33 +409,6 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const for (QNetworkCookie *cookiePointer : *durableCookiesListPointer) addCookieToStore(*cookiePointer, webEngineCookieStorePointer); - // Update the title when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) - { - // Get the index for this tab. - int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the title for this tab. - qTabWidgetPointer->setTabText(tabIndex, title); - - // Update the window title if this is the current tab. - if (tabIndex == qTabWidgetPointer->currentIndex()) - emit updateWindowTitle(title); - }); - - // Update the icon when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon) - { - // Get the index for this tab. - int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the icon for this tab. - if (icon.isNull()) - qTabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon); - else - qTabWidgetPointer->setTabIcon(tabIndex, icon); - }); - // Enable spell checking. webEngineProfilePointer->setSpellCheckEnabled(true); diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index ccaefb9..578206c 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -28,6 +28,7 @@ #include // Qt toolkit headers. +#include #include #include #include @@ -132,7 +133,8 @@ private: QWebEnginePage *currentWebEnginePagePointer; QWebEngineProfile *currentWebEngineProfilePointer; QWebEngineSettings *currentWebEngineSettingsPointer; - QIcon defaultTabIcon = QIcon::fromTheme(QStringLiteral("globe")); + QIcon defaultFavoriteIcon = QIcon::fromTheme(QStringLiteral("globe")); + QMovie *loadingFavoriteIconMoviePointer; QString searchEngineUrl; QTabWidget *qTabWidgetPointer; UserAgentHelper *userAgentHelperPointer; -- 2.43.0