Git commit 00d4f9179e914868c71525c5e5a20a8bbaaf9f01 by Robby Stephenson.
Committed on 25/06/2023 at 19:04.
Pushed by bcooksley into branch 'master'.

Remove HotNewStuff for scripts and port templates to new class

Downloading Tellico scripts through KNewStuff has been disabled for a
while due to the security risk. Remove the old code altogether.

M  +8    -8    doc/configuration.docbook
M  +5    -1    src/CMakeLists.txt
M  +24   -34   src/configdialog.cpp
M  +17   -3    src/configdialog.h
M  +2    -2    src/newstuff/CMakeLists.txt
D  +0    -7    src/newstuff/tellico-script.knsrc

https://invent.kde.org/office/tellico/-/commit/00d4f9179e914868c71525c5e5a20a8bbaaf9f01

diff --git a/doc/configuration.docbook b/doc/configuration.docbook
index fa8bd3551..f1d6dbba9 100644
--- a/doc/configuration.docbook
+++ b/doc/configuration.docbook
@@ -212,13 +212,6 @@ existing ones may be modified or deleted, using the 
<guibutton>Modify...</guibut
 entry updating menus, can also be changed.
 </para>
 
-<warning>
-<para>
-Never install and run a script from an untrusted source. They are executed 
with the same permissions as the user,
-and as a result, could modify or delete files or otherwise mess up your system.
-</para>
-</warning>
-
 <para>
 Many of the data sources offer more information than the default fields in 
&appname;. Those other fields are
 shown on the right of the configuration box. If any of those fields are 
checked, they will be added
@@ -535,9 +528,16 @@ The collection type returned by the script must be set, 
along with the data form
 use the <link linkend="file-format">default &appname; &XML; format</link>, but 
it can also import other formats as well, such as bibtex.
 </para>
 
-<para>The full path to the application should be entered in the source 
options. Be aware that the application is executed on the system with the same 
permissions as the current user, so do not use scripts from untrusted sources. 
Check the boxes next to the search keys supported by the application, and enter 
the required command line options in the edit box. The search value will be 
inserted where <userinput>%1</userinput> appears.
+<para>The full path to the application should be entered in the source 
options. Check the boxes next to the search keys supported by the application, 
and enter the required command line options in the edit box. The search value 
will be inserted where <userinput>%1</userinput> appears.
 </para>
 
+<warning>
+<para>
+Never install and run a script from an untrusted source. They are executed 
with the same permissions as the user,
+and as a result, could modify or delete files or otherwise mess up your system.
+</para>
+</warning>
+
 <para>
 For updating entries already in the collection, the final check box and edit 
box are used to determine the command-line options. The entry fields used to 
find an update must be entered, in the same format as used for <link 
linkend="derived">derived value</link> fields.
 </para>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 514c42230..c2ab8add0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -128,7 +128,11 @@ ELSE()
 ENDIF()
 
 IF( KF5NewStuff_FOUND )
-  TARGET_LINK_LIBRARIES(tellico KF5::NewStuff)
+  IF(KF5_VERSION VERSION_GREATER_EQUAL "5.91.0")
+    TARGET_LINK_LIBRARIES(tellico KF5::NewStuffWidgets)
+  ELSE()
+    TARGET_LINK_LIBRARIES(tellico KF5::NewStuff)
+  ENDIF()
 ENDIF( KF5NewStuff_FOUND )
 
 IF( KDEPIMLIBS_FOUND )
diff --git a/src/configdialog.cpp b/src/configdialog.cpp
index 0ba231fa1..682fc8f39 100644
--- a/src/configdialog.cpp
+++ b/src/configdialog.cpp
@@ -22,8 +22,6 @@
  *                                                                         *
  ***************************************************************************/
 
-#include <config.h>
-
 #include "configdialog.h"
 #include "field.h"
 #include "collection.h"
@@ -54,7 +52,11 @@
 #include <KRecentDirs>
 
 #ifdef ENABLE_KNEWSTUFF3
-#include <KNS3/DownloadDialog>
+#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 91, 0)
+#include <KNS3/Button>
+#else
+#include <KNSWidgets/Button>
+#endif
 #endif
 
 #include <QSpinBox>
@@ -564,10 +566,20 @@ void ConfigDialog::initTemplatePage(QFrame* frame) {
   whats = i18n("Click to install a new template directly.");
   b1->setWhatsThis(whats);
 
+#ifdef ENABLE_KNEWSTUFF3
+#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 91, 0)
+  auto b2 = new KNS3::Button(i18n("Download..."), 
QStringLiteral("tellico-template.knsrc"), box1);
+  connect(b2, &KNS3::Button::dialogFinished, this, 
&ConfigDialog::slotUpdateTemplates);
+#else
+  auto b2 = new KNSWidgets::Button(i18n("Download..."), 
QStringLiteral("tellico-template.knsrc"), box1);
+  connect(b2, &KNSWidgets::Button::dialogFinished, this, 
&ConfigDialog::slotUpdateTemplates);
+#endif
+#else
   QPushButton* b2 = new QPushButton(i18n("Download..."), box1);
-  box1HBoxLayout->addWidget(b2);
   b2->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
-  connect(b2, &QAbstractButton::clicked, this, 
&ConfigDialog::slotDownloadTemplate);
+  b2->setEnabled(false);
+#endif
+  box1HBoxLayout->addWidget(b2);
   whats = i18n("Click to download additional templates.");
   b2->setWhatsThis(whats);
 
@@ -670,18 +682,10 @@ void ConfigDialog::initFetchPage(QFrame* frame) {
   m_removeSourceBtn = new QPushButton(i18n("&Delete"), frame);
   m_removeSourceBtn->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
   m_removeSourceBtn->setWhatsThis(i18n("Click to delete the selected data 
source."));
-  m_newStuffBtn = new QPushButton(i18n("Download..."), frame);
-  
m_newStuffBtn->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
-  m_newStuffBtn->setWhatsThis(i18n("Click to download additional data 
sources."));
-  // TODO: disable button for now since checksum and signature checking are no 
longer possible with khotnewstuff
-  m_newStuffBtn->setEnabled(false);
 
   vlay->addWidget(newSourceBtn);
   vlay->addWidget(m_modifySourceBtn);
   vlay->addWidget(m_removeSourceBtn);
-  // separate newstuff button from the rest
-  vlay->addSpacing(16);
-  vlay->addWidget(m_newStuffBtn);
   vlay->addStretch(1);
 
   connect(newSourceBtn, &QAbstractButton::clicked, this, 
&ConfigDialog::slotNewSourceClicked);
@@ -689,7 +693,6 @@ void ConfigDialog::initFetchPage(QFrame* frame) {
   connect(m_moveUpSourceBtn, &QAbstractButton::clicked, this, 
&ConfigDialog::slotMoveUpSourceClicked);
   connect(m_moveDownSourceBtn, &QAbstractButton::clicked, this, 
&ConfigDialog::slotMoveDownSourceClicked);
   connect(m_removeSourceBtn, &QAbstractButton::clicked, this, 
&ConfigDialog::slotRemoveSourceClicked);
-  connect(m_newStuffBtn, &QAbstractButton::clicked, this, 
&ConfigDialog::slotNewStuffClicked);
 
   KAcceleratorManager::manage(frame);
   m_initializedPages |= Fetch;
@@ -1052,19 +1055,6 @@ void 
ConfigDialog::slotSelectedSourceChanged(QListWidgetItem* item_) {
   m_moveDownSourceBtn->setEnabled(row < m_sourceListWidget->count()-1);
 }
 
-void ConfigDialog::slotNewStuffClicked() {
-#ifdef ENABLE_KNEWSTUFF3
-  KNS3::DownloadDialog dialog(QStringLiteral("tellico-script.knsrc"), this);
-  dialog.exec();
-
-  KNS3::Entry::List entries = dialog.installedEntries();
-  if(!entries.isEmpty()) {
-    Fetch::Manager::self()->loadFetchers();
-    readFetchConfig();
-  }
-#endif
-}
-
 Tellico::FetcherInfoListItem* ConfigDialog::findItem(const QString& path_) 
const {
   if(path_.isEmpty()) {
     myDebug() << "empty path";
@@ -1179,17 +1169,17 @@ void ConfigDialog::slotInstallTemplate() {
   }
 }
 
-void ConfigDialog::slotDownloadTemplate() {
 #ifdef ENABLE_KNEWSTUFF3
-  KNS3::DownloadDialog dialog(QStringLiteral("tellico-template.knsrc"), this);
-  dialog.exec();
-
-  KNS3::Entry::List entries = dialog.installedEntries();
-  if(!entries.isEmpty()) {
+#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 91, 0)
+void ConfigDialog::slotUpdateTemplates(const QList<KNS3::Entry>& list_) {
+#else
+void ConfigDialog::slotUpdateTemplates(const QList<KNSCore::Entry>& list_) {
+#endif
+  if(!list_.isEmpty()) {
     loadTemplateList();
   }
-#endif
 }
+#endif
 
 void ConfigDialog::slotDeleteTemplate() {
   bool ok;
diff --git a/src/configdialog.h b/src/configdialog.h
index 535bea115..498bc41d0 100644
--- a/src/configdialog.h
+++ b/src/configdialog.h
@@ -25,9 +25,19 @@
 #ifndef TELLICO_CONFIGDIALOG_H
 #define TELLICO_CONFIGDIALOG_H
 
+#include <config.h>
+
 #include "fetch/fetcherinfolistitem.h"
 
 #include <KPageDialog>
+#ifdef ENABLE_KNEWSTUFF3
+#include <knewstuff_version.h>
+#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 91, 0)
+#include <KNS3/Button>
+#else
+#include <KNSWidgets/Button>
+#endif
+#endif
 
 #include <QListWidget>
 
@@ -116,10 +126,15 @@ private Q_SLOTS:
   void slotMoveUpSourceClicked();
   void slotMoveDownSourceClicked();
   void slotSourceFilterChanged();
-  void slotNewStuffClicked();
   void slotShowTemplatePreview();
   void slotInstallTemplate();
-  void slotDownloadTemplate();
+#ifdef ENABLE_KNEWSTUFF3
+#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 91, 0)
+  void slotUpdateTemplates(const QList<KNS3::Entry>& list);
+#else
+  void slotUpdateTemplates(const QList<KNSCore::Entry>& list);
+#endif
+#endif
   void slotDeleteTemplate();
   void slotCreateConfigWidgets();
 
@@ -205,7 +220,6 @@ private:
   QPushButton* m_moveUpSourceBtn;
   QPushButton* m_moveDownSourceBtn;
   QPushButton* m_removeSourceBtn;
-  QPushButton* m_newStuffBtn;
   QCheckBox* m_cbFilterSource;
   GUI::CollectionTypeCombo* m_sourceTypeCombo;
 };
diff --git a/src/newstuff/CMakeLists.txt b/src/newstuff/CMakeLists.txt
index c0ebfa54e..147de16fb 100644
--- a/src/newstuff/CMakeLists.txt
+++ b/src/newstuff/CMakeLists.txt
@@ -20,8 +20,8 @@ TARGET_LINK_LIBRARIES(newstuff
 
 IF( KF5NewStuff_FOUND )
   if(${ECM_VERSION} VERSION_GREATER "5.57.0")
-    INSTALL(FILES tellico-template.knsrc tellico-script.knsrc DESTINATION 
${KDE_INSTALL_KNSRCDIR})
+    INSTALL(FILES tellico-template.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
   else()
-    INSTALL(FILES tellico-template.knsrc tellico-script.knsrc DESTINATION 
${KDE_INSTALL_CONFDIR})
+    INSTALL(FILES tellico-template.knsrc DESTINATION ${KDE_INSTALL_CONFDIR})
   endif()
 endif()
diff --git a/src/newstuff/tellico-script.knsrc 
b/src/newstuff/tellico-script.knsrc
deleted file mode 100644
index 33486855a..000000000
--- a/src/newstuff/tellico-script.knsrc
+++ /dev/null
@@ -1,7 +0,0 @@
-[KNewStuff3]
-ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml
-Categories=Tellico Script
-TargetDir=tellico/tmp
-Uncompress=always
-InstallationCommand=dbus-send --type=method_call --dest=org.kde.tellico 
/NewStuff org.kde.tellico.newstuff.installScript string:%f
-UninstallCommand=dbus-send --type=method_call --dest=org.kde.tellico /NewStuff 
org.kde.tellico.newstuff.removeScript string:%f

Reply via email to