kcontrol: new module to control meta information

the only other way to control which meta information to show in tooltips
and such is to enable Dolphin information panel, find file that has the
desired metadata to disable and right click on the metadata widget after
hovering over the file which is very much not obvious and tedious

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-03-10 12:25:04 +02:00
parent 037fee5241
commit 73b37d03de
8 changed files with 262 additions and 31 deletions

View file

@ -37,6 +37,7 @@ add_subdirectory( dnssd )
add_subdirectory( spellchecking )
add_subdirectory( kdebug )
add_subdirectory( kmetainfo )
add_subdirectory( hardware )
add_subdirectory( desktoppaths )

View file

@ -0,0 +1,24 @@
########### next target ###############
set(kmetainfoconfig_SRCS
kmetainfoconfig.cpp
kmetainfoconfig.ui
)
kde4_add_plugin(kcm_kmetainfoconfig ${kmetainfoconfig_SRCS})
target_link_libraries(kcm_kmetainfoconfig
${KDE4_KDEUI_LIBS}
${KDE4_KCMUTILS_LIBS}
${KDE4_KIO_LIBS}
)
install(
TARGETS kcm_kmetainfoconfig
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
install(
FILES kcm_kmetainfoconfig.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)

View file

@ -0,0 +1,4 @@
#!/bin/bash
$EXTRACTRC *.ui >> rc.cpp || exit 11
$XGETTEXT *.cpp -o $podir/kcm_kmetainfoconfig.pot
rm -f rc.cpp

View file

@ -0,0 +1,16 @@
[Desktop Entry]
Exec=kcmshell4 kmetainfoconfig
Icon=nepomuk
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_kmetainfoconfig
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=workspace-appearance-and-behavior
X-KDE-System-Settings-Parent-Category-V2=workspace-appearance-and-behavior
X-DocPath=kcontrol/kmetainfoconfig/index.html
Categories=Qt;KDE;X-KDE-settings-workspace-appearance-and-behavior;
Name=Meta Information
Comment=Change meta information options
X-KDE-Keywords=Meta,Information,Metainfo

View file

@ -0,0 +1,103 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kmetainfoconfig.h"
#include <kdebug.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <kstandarddirs.h>
#include <kfilemetainfo.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
K_PLUGIN_FACTORY(KCMMetaInfoFactory, registerPlugin<KCMMetaInfo>();)
K_EXPORT_PLUGIN(KCMMetaInfoFactory("kcmmetainfoconfig", "kcm_metainfoconfig"))
KCMMetaInfo::KCMMetaInfo(QWidget* parent, const QVariantList& args)
: KCModule(KCMMetaInfoFactory::componentData(), parent)
{
Q_UNUSED(args);
setQuickHelp( i18n("<h1>KFileMetaInfo</h1>"
"This module allows you to change KDE meta information preferences."));
setupUi(this);
KAboutData *about =
new KAboutData(I18N_NOOP("KCMMetaInfo"), 0,
ki18n("KDE Meta Information Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("Copyright 2022, Ivailo Monev <email>xakepa10@gmail.com</email>"
));
about->addAuthor(ki18n("Ivailo Monev"), KLocalizedString(), "xakepa10@gmail.com");
setAboutData(about);
layout()->setContentsMargins(0, 0, 0, 0);
klistwidget->setSelectionMode(QAbstractItemView::NoSelection);
klistwidget->setSortingEnabled(true);
connect(klistwidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotItemChanged(QListWidgetItem*)));
load();
}
KCMMetaInfo::~KCMMetaInfo()
{
}
void KCMMetaInfo::load()
{
KConfig config("kmetainformationrc", KConfig::NoGlobals);
KConfigGroup settings = config.group("Show");
klistwidget->clear();
foreach (const QString &key, KFileMetaInfo::supportedKeys()) {
QListWidgetItem* item = new QListWidgetItem(KFileMetaInfo::name(key), klistwidget);
item->setData(Qt::UserRole, key);
const bool show = settings.readEntry(key, true);
item->setCheckState(show ? Qt::Checked : Qt::Unchecked);
}
emit changed(false);
}
void KCMMetaInfo::save()
{
KConfig config("kmetainformationrc", KConfig::NoGlobals);
KConfigGroup settings = config.group("Show");
for (int i = 0; i < klistwidget->count(); ++i) {
QListWidgetItem* item = klistwidget->item(i);
const bool show = (item->checkState() == Qt::Checked);
const QString key = item->data(Qt::UserRole).toString();
settings.writeEntry(key, show);
}
settings.sync();
emit changed(false);
}
void KCMMetaInfo::slotItemChanged(QListWidgetItem *item)
{
Q_UNUSED(item);
emit changed(true);
}
#include "moc_kmetainfoconfig.cpp"

View file

@ -0,0 +1,46 @@
/* This file is part of the KDE project
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KDEMETAINFO_H
#define KDEMETAINFO_H
#include <kcmodule.h>
#include "ui_kmetainfoconfig.h"
/**
* Control KFileMetaInfo output of KDE applications
*
* @author Ivailo Monev (xakepa10@gmail.com)
*/
class KCMMetaInfo : public KCModule, public Ui_KMetaInfoDialog
{
Q_OBJECT
public:
KCMMetaInfo(QWidget* parent, const QVariantList&);
~KCMMetaInfo();
virtual void load();
virtual void save();
private Q_SLOTS:
void slotItemChanged(QListWidgetItem *item);
};
#endif // KDEMETAINFO_H

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="System"?>
<ui version="4.0">
<class>KMetaInfoDialog</class>
<widget class="QWidget" name="KMetaInfoDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<height>466</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="KListWidget" name="klistwidget"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Select which data should be shown:</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KListWidget</class>
<extends></extends>
<header>klistwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -14,7 +14,7 @@
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
*/
#include <kaboutdata.h>
#include <kapplication.h>
@ -41,7 +41,7 @@ int main(int argc, char **argv)
KCmdLineOptions options;
options.add("ls"); // short option for --listsupported
options.add("listsupported", ki18n("List all supported metadata keys for the given URL(s)." ));
options.add("listsupported", ki18n("List all supported metadata keys." ));
options.add("la"); // short option for --listavailable
options.add("listavailable", ki18n("List all metadata keys which have a value in the given URL(s)."));
options.add("lp"); // short option for --listpreferred
@ -54,45 +54,47 @@ int main(int argc, char **argv)
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() == 0) {
// exits
KCmdLineArgs::usageError(i18n("No URL specified"));
}
const bool listsupported = (args->isSet("ls") || args->isSet("listsupported"));
const bool listavailable = (args->isSet("la") || args->isSet("listavailable"));
const bool listpreferred = (args->isSet("lp") || args->isSet("listpreferred"));
const bool allvalues = (args->isSet("av") || args->isSet("allvalues"));
const bool getvalue = args->isSet("getvalue");
if (!listsupported && !listavailable && !listpreferred && !allvalues && !getvalue) {
// exits
KCmdLineArgs::usageError(i18n("One of listsupported, listavailable, listpreferred, allvalues or getvalue must be specified"));
}
for (int pos = 0; pos < args->count(); ++pos) {
const KUrl url = args->url(pos);
const KFileMetaInfo metainfo(url, KFileMetaInfo::Everything);
if (listsupported) {
foreach (const QString &key, metainfo.supportedKeys()) {
qDebug() << key;
if (listsupported) {
foreach (const QString &key, KFileMetaInfo::supportedKeys()) {
qDebug() << key;
}
} else {
if (args->count() == 0) {
KCmdLineArgs::usageError(i18n("No URL specified"));
}
for (int pos = 0; pos < args->count(); ++pos) {
const KUrl url = args->url(pos);
const KFileMetaInfo metainfo(url, KFileMetaInfo::Everything);
if (listavailable) {
foreach (const QString &key, metainfo.keys()) {
qDebug() << key;
}
} else if (listpreferred) {
foreach (const QString &key, metainfo.preferredKeys()) {
qDebug() << key;
}
} else if (allvalues) {
foreach (const KFileMetaInfoItem &item, metainfo.items()) {
qDebug() << item.key() << item.value();
}
} else if (getvalue) {
const QString getvaluekey = args->getOption("getvalue");
const KFileMetaInfoItem item = metainfo.item(getvaluekey);
qDebug() << item.value();
} else {
Q_ASSERT(false);
}
} else if (listavailable) {
foreach (const QString &key, metainfo.keys()) {
qDebug() << key;
}
} else if (listpreferred) {
foreach (const QString &key, metainfo.preferredKeys()) {
qDebug() << key;
}
} else if (allvalues) {
foreach (const KFileMetaInfoItem &item, metainfo.items()) {
qDebug() << item.key() << item.value();
}
} else if (getvalue) {
const QString getvaluekey = args->getOption("getvalue");
const KFileMetaInfoItem item = metainfo.item(getvaluekey);
qDebug() << item.value();
} else {
Q_ASSERT(false);
}
}