OSDN Git Service

kcontrol: use table widget for metadata plugins in kmetainfoconfig module
authorIvailo Monev <xakepa10@gmail.com>
Fri, 13 May 2022 15:37:25 +0000 (18:37 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 13 May 2022 15:37:25 +0000 (18:37 +0300)
requires:
https://github.com/fluxer/kdelibs/commit/7271414eed7e87461062441948901ab945fa2098

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kcontrol/kmetainfo/kmetainfoconfig.cpp
kcontrol/kmetainfo/kmetainfoconfig.h
kcontrol/kmetainfo/kmetainfoconfig.ui

index bb57701..c26783b 100644 (file)
@@ -52,13 +52,9 @@ KCMMetaInfo::KCMMetaInfo(QWidget* parent, const QVariantList& args)
 
     setButtons(KCModule::Help | KCModule::Apply);
 
-    pluginslist->setSelectionMode(QAbstractItemView::NoSelection);
-    pluginslist->setSortingEnabled(true);
-    connect(pluginslist, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotItemChanged(QListWidgetItem*)));
+    connect(pluginstable, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(slotPluginItemChanged(QTableWidgetItem*)));
 
-    metainfolist->setSelectionMode(QAbstractItemView::NoSelection);
-    metainfolist->setSortingEnabled(true);
-    connect(metainfolist, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotItemChanged(QListWidgetItem*)));
+    connect(metainfolist, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotMetaItemChanged(QListWidgetItem*)));
 
     load();
 }
@@ -71,16 +67,30 @@ void KCMMetaInfo::load()
 {
     {
         KConfig config("kmetainformationrc", KConfig::NoGlobals);
-        pluginslist->clear();
+        pluginstable->clearContents();
+        pluginstable->setRowCount(0);
+        int rowcount = 0;
         KConfigGroup pluginsgroup = config.group("Plugins");
         const KService::List kfmdplugins = KServiceTypeTrader::self()->query("KFileMetaData/Plugin");
         foreach (const KService::Ptr &kfmdplugin, kfmdplugins) {
             const QString key = kfmdplugin->desktopEntryName();
-            const QString itemtext = kfmdplugin->genericName();
-            QListWidgetItem* item = new QListWidgetItem(itemtext, pluginslist);
-            item->setData(Qt::UserRole, key);
+
+            pluginstable->setRowCount(rowcount + 1);
+
+            QTableWidgetItem* nameitem = new QTableWidgetItem();
+            nameitem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
+            nameitem->setText(kfmdplugin->genericName());
+            nameitem->setData(Qt::UserRole, key);
             const bool enable = pluginsgroup.readEntry(key, true);
-            item->setCheckState(enable ? Qt::Checked : Qt::Unchecked);
+            nameitem->setCheckState(enable ? Qt::Checked : Qt::Unchecked);
+            pluginstable->setItem(rowcount, 0, nameitem);
+
+            QTableWidgetItem* descitem = new QTableWidgetItem();
+            descitem->setFlags(Qt::ItemIsEnabled);
+            descitem->setText(kfmdplugin->comment());
+            pluginstable->setItem(rowcount, 1, descitem);
+
+            rowcount++;
         }
     }
 
@@ -94,8 +104,8 @@ void KCMMetaInfo::save()
     {
         KConfig config("kmetainformationrc", KConfig::NoGlobals);
         KConfigGroup pluginsgroup = config.group("Plugins");
-        for (int i = 0; i < pluginslist->count(); ++i) {
-            QListWidgetItem* item = pluginslist->item(i);
+        for (int i = 0; i < pluginstable->rowCount(); ++i) {
+            QTableWidgetItem* item = pluginstable->item(i, 0);
             const bool enable = (item->checkState() == Qt::Checked);
             const QString key = item->data(Qt::UserRole).toString();
             pluginsgroup.writeEntry(key, enable);
@@ -115,7 +125,13 @@ void KCMMetaInfo::save()
     loadMetaInfo();
 }
 
-void KCMMetaInfo::slotItemChanged(QListWidgetItem *item)
+void KCMMetaInfo::slotPluginItemChanged(QTableWidgetItem *item)
+{
+    Q_UNUSED(item);
+    emit changed(true);
+}
+
+void KCMMetaInfo::slotMetaItemChanged(QListWidgetItem *item)
 {
     Q_UNUSED(item);
     emit changed(true);
index ca73d9b..4d721fe 100644 (file)
@@ -40,7 +40,8 @@ public:
     void save() final;
 
 private Q_SLOTS:
-    void slotItemChanged(QListWidgetItem *item);
+    void slotPluginItemChanged(QTableWidgetItem *item);
+    void slotMetaItemChanged(QListWidgetItem *item);
 
 private:
     void loadMetaInfo();
index 4cdc56e..0dff6b9 100644 (file)
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
       <item row="0" column="0">
-       <widget class="KListWidget" name="metainfolist"/>
+       <widget class="KListWidget" name="metainfolist">
+        <property name="toolTip">
+         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Meta information shown in tooltips and properties dialogs.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+        </property>
+        <property name="selectionMode">
+         <enum>QAbstractItemView::NoSelection</enum>
+        </property>
+        <property name="sortingEnabled">
+         <bool>true</bool>
+        </property>
+       </widget>
       </item>
      </layout>
     </widget>
      </property>
      <layout class="QGridLayout" name="gridLayout_3">
       <item row="0" column="0">
-       <widget class="KListWidget" name="pluginslist"/>
+       <widget class="QTableWidget" name="pluginstable">
+        <property name="toolTip">
+         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Disabling undesired plugins can reduce the disk I/O during directory listing&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+        </property>
+        <property name="selectionMode">
+         <enum>QAbstractItemView::NoSelection</enum>
+        </property>
+        <property name="sortingEnabled">
+         <bool>true</bool>
+        </property>
+        <attribute name="horizontalHeaderStretchLastSection">
+         <bool>true</bool>
+        </attribute>
+        <attribute name="verticalHeaderVisible">
+         <bool>false</bool>
+        </attribute>
+        <column>
+         <property name="text">
+          <string>Plugin</string>
+         </property>
+        </column>
+        <column>
+         <property name="text">
+          <string>Description</string>
+         </property>
+        </column>
+       </widget>
       </item>
      </layout>
     </widget>