Commit f3204c34 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 26d56f4a
......@@ -21,19 +21,19 @@
#include "helper.h"
#include "config-kcm.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QProcess>
#include <QMimeDatabase>
#include <QProcess>
#include <QRegularExpression>
#include "kzip.h"
#include "ktar.h"
#include "kzip.h"
#include <KArchive>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KLocalizedString>
#include <KSharedConfig>
ActionReply PlymouthHelper::save(const QVariantMap &args)
{
......@@ -51,11 +51,11 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
cg.writeEntry("Theme", theme);
}
QFile configFile(QStringLiteral(PLYMOUTH_CONFIG_PATH));
configFile.setPermissions(QFileDevice::ReadOwner|QFileDevice::WriteOwner|QFileDevice::ReadGroup|QFileDevice::ReadOther);
configFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther);
//Special case: Ubuntu derivatives, which work different from everybody else
// Special case: Ubuntu derivatives, which work different from everybody else
if (QFile::exists(QStringLiteral("/usr/sbin/update-alternatives"))) {
//find the .plymouth file in the theme
// find the .plymouth file in the theme
QDir dir(QStringLiteral(PLYMOUTH_THEMES_DIR) + theme);
QStringList themeFile = dir.entryList(QStringList() << QStringLiteral("*.plymouth"));
if (themeFile.count() != 1) {
......@@ -77,12 +77,11 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("update-alternatives failed to run."));
return reply;
}
else {
} else {
data = checkProcess.readAllStandardOutput();
}
ret = checkProcess.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
......@@ -93,12 +92,10 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
if (!data.contains(installFile.toUtf8())) {
qDebug() << "Plymouth file not found in update-alternatives. So install it";
QProcess installProcess;
installProcess.start(QStringLiteral("update-alternatives"), QStringList() << QStringLiteral("--install")
<< QStringLiteral("/usr/share/plymouth/themes/default.plymouth")
<< QStringLiteral("default.plymouth")
<< installFile
<< QStringLiteral("100"));
installProcess.start(QStringLiteral("update-alternatives"),
QStringList() << QStringLiteral("--install") << QStringLiteral("/usr/share/plymouth/themes/default.plymouth")
<< QStringLiteral("default.plymouth") << installFile << QStringLiteral("100"));
if (!installProcess.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
......@@ -110,20 +107,17 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
return reply;
}
ret = installProcess.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret));
return reply;
}
}
else {
} else {
qDebug() << "Running update-alternatives --set now";
QProcess process;
process.start(QStringLiteral("update-alternatives"), QStringList() << QStringLiteral("--set")
<< QStringLiteral("default.plymouth")
<< installFile);
process.start(QStringLiteral("update-alternatives"), QStringList() << QStringLiteral("--set") << QStringLiteral("default.plymouth") << installFile);
if (!process.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
......@@ -135,7 +129,7 @@ ActionReply PlymouthHelper::save(const QVariantMap &args)
return reply;
}
ret = process.exitCode();
if (ret != 0) {
reply = ActionReply(ActionReply::HelperErrorReply());
reply.setErrorCode(static_cast<ActionReply::Error>(ret));
......@@ -198,6 +192,7 @@ ActionReply PlymouthHelper::install(const QVariantMap &args)
if (mimeType.inherits(QStringLiteral("application/zip"))) {
archive.reset(new KZip(themearchive));
// clang-format off
} else if (mimeType.inherits(QStringLiteral("application/tar"))
|| mimeType.inherits(QStringLiteral("application/x-gzip"))
|| mimeType.inherits(QStringLiteral("application/x-bzip"))
......@@ -206,6 +201,7 @@ ActionReply PlymouthHelper::install(const QVariantMap &args)
|| mimeType.inherits(QStringLiteral("application/x-bzip-compressed-tar"))
|| mimeType.inherits(QStringLiteral("application/x-compressed-tar"))) {
archive.reset(new KTar(themearchive));
// clang-format on
} else {
qCritical() << "Could not determine type of archive file '" << themearchive << "'";
return ActionReply::BackendError;
......@@ -220,8 +216,8 @@ ActionReply PlymouthHelper::install(const QVariantMap &args)
QString themeName;
QString themePath;
const KArchiveDirectory *dir = archive->directory();
//if there is more than an item in the file,
//put contents in a subdirectory with the same name as the file
// if there is more than an item in the file,
// put contents in a subdirectory with the same name as the file
if (dir->entries().count() > 1) {
installpath += QLatin1Char('/') + QFileInfo(archive->fileName()).baseName();
themeName = QFileInfo(archive->fileName()).baseName();
......@@ -236,9 +232,9 @@ ActionReply PlymouthHelper::install(const QVariantMap &args)
archive->close();
//Special case: Ubuntu derivatives, which work different from everybody else
// Special case: Ubuntu derivatives, which work different from everybody else
if (QFile::exists(QStringLiteral("/usr/sbin/update-alternatives"))) {
//find the .plymouth file in the theme
// find the .plymouth file in the theme
QDir dir(themePath);
QStringList themeFile = dir.entryList(QStringList() << QStringLiteral("*.plymouth"));
if (themeFile.count() != 1) {
......@@ -248,11 +244,9 @@ ActionReply PlymouthHelper::install(const QVariantMap &args)
}
int ret = 0;
QProcess process;
process.start(QStringLiteral("update-alternatives"), QStringList() << QStringLiteral("--install")
<< QStringLiteral("/usr/share/plymouth/themes/default.plymouth")
<< QStringLiteral("default.plymouth")
<< themePath + QLatin1Char('/') + themeFile.first()
<< QStringLiteral("100"));
process.start(QStringLiteral("update-alternatives"),
QStringList() << QStringLiteral("--install") << QStringLiteral("/usr/share/plymouth/themes/default.plymouth")
<< QStringLiteral("default.plymouth") << themePath + QLatin1Char('/') + themeFile.first() << QStringLiteral("100"));
if (!process.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
......@@ -287,7 +281,7 @@ ActionReply PlymouthHelper::uninstall(const QVariantMap &args)
ActionReply reply;
if (theme.isEmpty()) {
qWarning()<<"No theme specified.";
qWarning() << "No theme specified.";
return ActionReply::BackendError;
}
......@@ -304,9 +298,9 @@ ActionReply PlymouthHelper::uninstall(const QVariantMap &args)
return reply;
}
//Special case: Ubuntu derivatives, which work different from everybody else
// Special case: Ubuntu derivatives, which work different from everybody else
if (QFile::exists(QStringLiteral("/usr/sbin/update-alternatives"))) {
//find the .plymouth file in the theme
// find the .plymouth file in the theme
QStringList themeFile = dir.entryList(QStringList() << QStringLiteral("*.plymouth"));
if (themeFile.count() != 1) {
reply = ActionReply::BackendError;
......@@ -316,9 +310,8 @@ ActionReply PlymouthHelper::uninstall(const QVariantMap &args)
int ret = 0;
QProcess process;
process.start(QStringLiteral("update-alternatives"), QStringList() << QStringLiteral("--remove")
<< QStringLiteral("default.plymouth")
<< dir.path() + QLatin1Char('/') + themeFile.first());
process.start(QStringLiteral("update-alternatives"),
QStringList() << QStringLiteral("--remove") << QStringLiteral("default.plymouth") << dir.path() + QLatin1Char('/') + themeFile.first());
if (!process.waitForStarted()) {
reply = ActionReply::BackendError;
reply.setErrorDescription(i18n("Cannot start update-alternatives."));
......
......@@ -21,15 +21,15 @@
#include "kcm.h"
#include "config-kcm.h"
#include <KPluginFactory>
#include <KPluginLoader>
#include <KAboutData>
#include <KConfigGroup>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KSharedConfig>
#include <QDebug>
#include <QProcess>
#include <QStandardPaths>
#include <QtGlobal>
#include <QProcess>
#include <QQmlEngine>
#include <QQuickItem>
......@@ -44,18 +44,18 @@
#include <KNewStuff3/KNSCore/Engine>
#include <KNewStuff3/KNSCore/EntryInternal>
#include <kio/job.h>
#include <KIO/CopyJob>
#include <kio/job.h>
K_PLUGIN_FACTORY_WITH_JSON(KCMPlymouthFactory, "kcm_plymouth.json", registerPlugin<KCMPlymouth>();)
KCMPlymouth::KCMPlymouth(QObject* parent, const QVariantList& args)
KCMPlymouth::KCMPlymouth(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
{
qmlRegisterAnonymousType<QStandardItemModel>("KCMPlymouth", 1);
qmlRegisterAnonymousType<KCMPlymouth>("KCMPlymouth", 1);
KAboutData* about = new KAboutData(QStringLiteral("kcm_plymouth"), i18n("Boot Splash Screen"),
QStringLiteral(PROJECT_VERSION), QString(), KAboutLicense::LGPL);
KAboutData *about =
new KAboutData(QStringLiteral("kcm_plymouth"), i18n("Boot Splash Screen"), QStringLiteral(PROJECT_VERSION), QString(), KAboutLicense::LGPL);
about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org"));
setAboutData(about);
setButtons(Apply);
......@@ -64,13 +64,11 @@ KCMPlymouth::KCMPlymouth(QObject* parent, const QVariantList& args)
m_model = new QStandardItemModel(this);
m_model->setItemRoleNames({
{Qt::DisplayRole, QByteArrayLiteral("display")},
{DescriptionRole, QByteArrayLiteral("description")},
{PluginNameRole, QByteArrayLiteral("pluginName")},
{ScreenhotRole, QByteArrayLiteral("screenshot")},
{UninstallableRole, QByteArrayLiteral("uninstallable")}
});
m_model->setItemRoleNames({{Qt::DisplayRole, QByteArrayLiteral("display")},
{DescriptionRole, QByteArrayLiteral("description")},
{PluginNameRole, QByteArrayLiteral("pluginName")},
{ScreenhotRole, QByteArrayLiteral("screenshot")},
{UninstallableRole, QByteArrayLiteral("uninstallable")}});
}
KCMPlymouth::~KCMPlymouth()
......@@ -89,7 +87,7 @@ void KCMPlymouth::reloadModel()
KConfigGroup installedCg(KSharedConfig::openConfig(QStringLiteral("kplymouththemeinstallerrc")), "DownloadedThemes");
dir.setFilter(QDir::NoDotAndDotDot|QDir::Dirs);
dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
const auto list = dir.entryInfoList();
for (const QFileInfo &fileInfo : list) {
......@@ -109,10 +107,10 @@ void KCMPlymouth::reloadModel()
row->setData(grp.readEntry("Description", QString()), DescriptionRole);
row->setData(installedCg.entryMap().contains(fileInfo.fileName()), UninstallableRole);
//the theme has a preview
// the theme has a preview
if (QFile::exists(themeDir.path() + QStringLiteral("/preview.png"))) {
row->setData(QString(themeDir.path() + QStringLiteral("/preview.png")), ScreenhotRole);
//fetch it downloaded from kns
// fetch it downloaded from kns
} else {
const QString fileName = installedCg.readEntry(fileInfo.fileName(), QString());
if (fileName.isEmpty()) {
......@@ -131,19 +129,22 @@ void KCMPlymouth::reloadModel()
void KCMPlymouth::getNewStuff(QQuickItem *ctx)
{
if (!m_newStuffDialog) {
m_newStuffDialog = new KNS3::DownloadDialog( QLatin1String("plymouth.knsrc") );
m_newStuffDialog = new KNS3::DownloadDialog(QLatin1String("plymouth.knsrc"));
m_newStuffDialog->setWindowTitle(i18n("Download New Boot Splash Screens"));
m_newStuffDialog->setWindowModality(Qt::WindowModal);
m_newStuffDialog->winId(); // so it creates the windowHandle();
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, &KCMPlymouth::reloadModel);
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::finished, m_newStuffDialog.data(), &KNS3::DownloadDialog::deleteLater);
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::finished, m_newStuffDialog.data(), &KNS3::DownloadDialog::deleteLater);
connect(m_newStuffDialog->engine(), &KNSCore::Engine::signalEntryChanged, this, [=](const KNSCore::EntryInternal &entry){
connect(m_newStuffDialog->engine(), &KNSCore::Engine::signalEntryChanged, this, [=](const KNSCore::EntryInternal &entry) {
if (!entry.isValid() || entry.status() != KNS3::Entry::Installed) {
return;
}
KIO::file_copy(QUrl(entry.previewUrl(KNSCore::EntryInternal::PreviewBig1)), QUrl::fromLocalFile(QString(entry.installedFiles().constFirst() + QStringLiteral(".png"))), -1, KIO::Overwrite | KIO::HideProgressInfo);
KIO::file_copy(QUrl(entry.previewUrl(KNSCore::EntryInternal::PreviewBig1)),
QUrl::fromLocalFile(QString(entry.installedFiles().constFirst() + QStringLiteral(".png"))),
-1,
KIO::Overwrite | KIO::HideProgressInfo);
});
}
......@@ -213,7 +214,6 @@ void KCMPlymouth::load()
setNeedsSave(false);
}
void KCMPlymouth::save()
{
setBusy(true);
......@@ -241,7 +241,7 @@ void KCMPlymouth::uninstall(const QString &plugin)
QVariantMap helperargs;
helperargs[QStringLiteral("theme")] = plugin;
//KAuth::Action action(authActionName());
// KAuth::Action action(authActionName());
KAuth::Action action(QStringLiteral("org.kde.kcontrol.kcmplymouth.uninstall"));
action.setHelperId(QStringLiteral("org.kde.kcontrol.kcmplymouth"));
action.setArguments(helperargs);
......@@ -259,12 +259,11 @@ void KCMPlymouth::uninstall(const QString &plugin)
}
void KCMPlymouth::defaults()
{/*TODO
if (!) {
return;
}
*/
{ /*TODO
if (!) {
return;
}
*/
}
#include "kcm.moc"
......@@ -43,9 +43,9 @@ public:
DescriptionRole = Qt::UserRole + 1,
PluginNameRole,
ScreenhotRole,
UninstallableRole
UninstallableRole,
};
explicit KCMPlymouth(QObject* parent, const QVariantList& args);
explicit KCMPlymouth(QObject *parent, const QVariantList &args);
~KCMPlymouth() Q_DECL_OVERRIDE;
QStandardItemModel *themesModel();
......
......@@ -20,22 +20,22 @@
#include "config-kcm.h"
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QProcess>
#include <QMimeDatabase>
#include <qcommandlineparser.h>
#include <QProcess>
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
#include "kzip.h"
#include "ktar.h"
#include "kzip.h"
#include <KArchive>
#include <KConfigGroup>
#include <KSharedConfig>
#include <klocalizedstring.h>
#include <kauthaction.h>
#include <kauthexecutejob.h>
#include <klocalizedstring.h>
int main(int argc, char **argv)
{
......@@ -76,7 +76,7 @@ int main(int argc, char **argv)
QVariantMap helperargs;
helperargs[QStringLiteral("themearchive")] = themefile;
//support uninstalling from an archive
// support uninstalling from an archive
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile(themefile);
bool isArchive = false;
......@@ -84,6 +84,7 @@ int main(int argc, char **argv)
QScopedPointer<KArchive> archive;
if (mimeType.inherits(QStringLiteral("application/zip"))) {
archive.reset(new KZip(themefile));
// clang-format off
} else if (mimeType.inherits(QStringLiteral("application/tar"))
|| mimeType.inherits(QStringLiteral("application/x-gzip"))
|| mimeType.inherits(QStringLiteral("application/x-bzip"))
......@@ -92,6 +93,7 @@ int main(int argc, char **argv)
|| mimeType.inherits(QStringLiteral("application/x-bzip-compressed-tar"))
|| mimeType.inherits(QStringLiteral("application/x-compressed-tar"))) {
archive.reset(new KTar(themefile));
// clang-format on
}
if (archive) {
isArchive = true;
......@@ -101,8 +103,8 @@ int main(int argc, char **argv)
exit(-1);
}
const KArchiveDirectory *dir = archive->directory();
//if there is more than an item in the file,
//plugin is a subdirectory with the same name as the file
// if there is more than an item in the file,
// plugin is a subdirectory with the same name as the file
if (dir->entries().count() > 1) {
helperargs[QStringLiteral("theme")] = QFileInfo(archive->fileName()).baseName();
} else {
......@@ -113,7 +115,8 @@ int main(int argc, char **argv)
}
}
KAuth::Action action(parser.isSet(QStringLiteral("install")) ? QStringLiteral("org.kde.kcontrol.kcmplymouth.install") : QStringLiteral("org.kde.kcontrol.kcmplymouth.uninstall"));
KAuth::Action action(parser.isSet(QStringLiteral("install")) ? QStringLiteral("org.kde.kcontrol.kcmplymouth.install")
: QStringLiteral("org.kde.kcontrol.kcmplymouth.uninstall"));
action.setHelperId(QStringLiteral("org.kde.kcontrol.kcmplymouth"));
action.setArguments(helperargs);
......@@ -129,14 +132,14 @@ int main(int argc, char **argv)
cg.writeEntry(job->data().value(QStringLiteral("plugin")).toString(), themefile);
} else {
if (!isArchive) {
//try to take the file name from the config file
// try to take the file name from the config file
themefile = cg.readEntry(job->data().value(QStringLiteral("plugin")).toString(), QString());
}
if (themefile.isEmpty()) {
//remove archive
// remove archive
QFile(themefile).remove();
//remove screenshot
// remove screenshot
QFile::remove(QString(themefile + QStringLiteral(".png")));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment