mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-03 17:05:54 +00:00
rewrite formtatter* and customkeys* to share their code
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QPushButton>
|
||||
@ -33,6 +34,15 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent,
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(type());
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||
|
||||
ui->setupUi(this);
|
||||
copyButton
|
||||
= ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||
@ -182,6 +192,17 @@ QVariant AbstractExtItemAggregator::configArgs() const
|
||||
}
|
||||
|
||||
|
||||
QStringList AbstractExtItemAggregator::directories() const
|
||||
{
|
||||
auto dirs
|
||||
= QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(type()),
|
||||
QStandardPaths::LocateDirectory);
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItemAggregator::type() const
|
||||
{
|
||||
return m_type;
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
int uniqNumber() const;
|
||||
// get methods
|
||||
QVariant configArgs() const;
|
||||
QStringList directories() const;
|
||||
virtual QList<AbstractExtItem *> items() const = 0;
|
||||
QString type() const;
|
||||
// set methods
|
||||
|
@ -127,29 +127,23 @@ private:
|
||||
|
||||
QList<AbstractExtItem *> getItems()
|
||||
{
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(type());
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(type()),
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
QList<AbstractExtItem *> items;
|
||||
|
||||
auto dirs = directories();
|
||||
for (auto &dir : dirs) {
|
||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
for (auto &file : files) {
|
||||
if ((!file.endsWith(".desktop")) || (names.contains(file)))
|
||||
// check filename
|
||||
if (!file.endsWith(".desktop"))
|
||||
continue;
|
||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||
names.append(file);
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(file);
|
||||
// check if already exists
|
||||
if (std::any_of(items.cbegin(), items.cend(),
|
||||
[&filePath](AbstractExtItem *item) {
|
||||
return (item->fileName() == filePath);
|
||||
}))
|
||||
continue;
|
||||
items.append(new T(this, filePath));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user