Commit a1b6a3b5 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Run clang format

parent c2ac3b64
......@@ -74,7 +74,7 @@ bool CrontabPrinter::start()
mPainter->begin(mPrinter);
const int margin = computeMargin();
mPrintView = new QRect(margin, margin, mPainter->device()->width() - 2*margin, mPainter->device()->height() - 2*margin);
mPrintView = new QRect(margin, margin, mPainter->device()->width() - 2 * margin, mPainter->device()->height() - 2 * margin);
mPage = 1;
mCurrentRowPosition = 0;
......@@ -124,11 +124,11 @@ void CrontabPrinter::printVariables()
mPainter->translate(0, 20);
mCurrentRowPosition = 0;
//Environment Variables
// Environment Variables
drawTitle(i18n("Environment Variables"));
//QList<QStringList> variablesContent;
// QList<QStringList> variablesContent;
const auto variables = cron->variables();
for (CTVariable *variable : variables) {
mPainter->drawText(*(mPrintView), Qt::AlignLeft | Qt::TextWordWrap, variable->variable + QLatin1String(" = ") + variable->value);
......@@ -232,7 +232,9 @@ void CrontabPrinter::printPageNumber()
mPainter->translate(0, -mCurrentRowPosition);
mPrintView->moveTo(QPoint(0, mPrintView->height()));
mPainter->translate(0, -mPrintView->height());
mPainter->drawText(mPrintView->right() - mPainter->fontMetrics().boundingRect(QString::number(mPage)).width(), mPrintView->bottom()+ mPainter->fontMetrics().ascent() + 5, QString::number(mPage));
mPainter->drawText(mPrintView->right() - mPainter->fontMetrics().boundingRect(QString::number(mPage)).width(),
mPrintView->bottom() + mPainter->fontMetrics().ascent() + 5,
QString::number(mPage));
}
void CrontabPrinter::changeRow(int x, int y)
......@@ -244,7 +246,7 @@ void CrontabPrinter::changeRow(int x, int y)
int CrontabPrinter::computeMargin() const
{
const int dpiy = mPainter->device()->logicalDpiY();
const int margin = (int)((2/2.54)*dpiy); // 2 cm margins
const int margin = (int)((2 / 2.54) * dpiy); // 2 cm margins
return margin;
}
......@@ -293,13 +295,14 @@ void CrontabPrinter::drawTable(const QList<int> &columnWidths)
mPainter->setPen(pen);
//First horizontal line
// First horizontal line
mPainter->drawLine(QPoint(margin, 0), QPoint(margin + columnWidthsTotal, 0));
//Second horizontal line
mPainter->drawLine(QPoint(margin, 0+computeStringHeight(QStringLiteral(" "))), QPoint(margin + columnWidthsTotal, 0+computeStringHeight(QStringLiteral(" "))));
// Second horizontal line
mPainter->drawLine(QPoint(margin, 0 + computeStringHeight(QStringLiteral(" "))),
QPoint(margin + columnWidthsTotal, 0 + computeStringHeight(QStringLiteral(" "))));
//First vertical line
// First vertical line
mPainter->drawLine(QPoint(linePositionX, 0), QPoint(linePositionX, mCurrentRowPosition));
for (int columnWidth : columnWidths) {
......@@ -307,7 +310,7 @@ void CrontabPrinter::drawTable(const QList<int> &columnWidths)
mPainter->drawLine(QPoint(linePositionX, 0), QPoint(linePositionX, mCurrentRowPosition));
}
//Last horizontal line
// Last horizontal line
mPainter->drawLine(QPoint(margin, mCurrentRowPosition), QPoint(margin + columnWidthsTotal, mCurrentRowPosition));
mPainter->setPen(originalPen);
......@@ -342,7 +345,7 @@ QList<int> CrontabPrinter::findColumnWidths(const QList<QStringList> &contents,
QList<int> columnWidths = findMaxWidths(contents, columnCount);
int margin = computeMargin();
int pageWidth = mPainter->device()->width() - 2*margin;
int pageWidth = mPainter->device()->width() - 2 * margin;
int columnWidthSum = 0;
for (int width : qAsConst(columnWidths)) {
......
......@@ -25,7 +25,6 @@ class QPrinter;
class CrontabPrinter
{
public:
/**
* Constructor
*/
......@@ -52,7 +51,6 @@ public:
bool isAllUsers() const;
private:
/**
*Disable the copy constructor and the assignment operator
*/
......
......@@ -23,7 +23,6 @@ class CrontabPrinterWidget : public QWidget
{
Q_OBJECT
public:
/**
* Constructs the dialog, if root is true the print all users is not disabled
*/
......
......@@ -11,26 +11,26 @@
#include <stdlib.h>
#include <unistd.h>
#include <QVBoxLayout>
#include <QApplication>
#include <QButtonGroup>
#include <QClipboard>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QSplitter>
#include <QRadioButton>
#include <QButtonGroup>
#include <QComboBox>
#include <QApplication>
#include <QClipboard>
#include <QSplitter>
#include <QVBoxLayout>
#include <KLocalizedString>
#include <QIcon>
#include <QAction>
#include <KStandardAction>
#include <QAction>
#include <QIcon>
#include "cthost.h"
#include "ctGlobalCron.h"
#include "ctcron.h"
#include "ctvariable.h"
#include "cthost.h"
#include "cttask.h"
#include "ctGlobalCron.h"
#include "ctvariable.h"
#include "crontabPrinter.h"
#include "taskWidget.h"
......@@ -291,7 +291,7 @@ CTCron *CrontabWidget::currentCron() const
return mCtHost->findSystemCron();
}
if (mOtherUsers->currentIndex() == mOtherUsers->count()-1) {
if (mOtherUsers->currentIndex() == mOtherUsers->count() - 1) {
logDebug() << "Using Global Cron";
return mCtGlobalCron;
}
......@@ -326,7 +326,7 @@ void CrontabWidget::setupActions()
{
logDebug() << "Setup actions";
//Edit menu
// Edit menu
mCutAction = KStandardAction::cut(this, SLOT(cut()), this);
mCopyAction = KStandardAction::copy(this, SLOT(copy()), this);
mPasteAction = KStandardAction::paste(this, SLOT(paste()), this);
......
......@@ -30,7 +30,6 @@ class CrontabWidget : public QWidget
Q_OBJECT
public:
/**
* Initializes view.
*/
......@@ -77,7 +76,6 @@ protected Q_SLOTS:
void checkOtherUsers();
private:
/**
* Enables/disables paste button
*/
......
......@@ -8,8 +8,8 @@
#include "ctGlobalCron.h"
#include <KShell>
#include <KLocalizedString>
#include <KShell>
#include "cthost.h"
#include "cttask.h"
......
......@@ -24,7 +24,6 @@ class CTHost;
class CTGlobalCron : public CTCron
{
public:
explicit CTGlobalCron(CTHost *ctHost);
/**
......
......@@ -14,7 +14,6 @@
class CTHelper
{
public:
static QString exportComment(const QString &comment);
};
......
......@@ -14,7 +14,6 @@
class CTInitializationError
{
public:
QString errorMessage() const;
void setErrorMessage(const QString &errorMessage);
......
......@@ -14,7 +14,6 @@
class CTSaveStatus
{
public:
CTSaveStatus();
CTSaveStatus(const QString &errorMessage, const QString &detailErrorMessage);
......
......@@ -8,8 +8,8 @@
#include "ctSystemCron.h"
#include <KShell>
#include <KLocalizedString>
#include <KShell>
#include <QTemporaryFile>
......
......@@ -16,7 +16,6 @@
class CTSystemCron : public CTCron
{
public:
/**
* Constructs the scheduled tasks, environment variables from crontab
* files and obtains some information about the user from the system.
......
......@@ -8,22 +8,22 @@
#include "ctcron.h"
#include <QRegExp>
#include <QDateTime>
#include <QFile>
#include <QProcess>
#include <QRegExp>
#include <QTemporaryFile>
#include <QTextStream>
#include <QProcess>
#include <QDateTime>
#include <KShell>
#include <KLocalizedString>
#include <KShell>
#include "ctInitializationError.h"
#include "cttask.h"
#include "ctvariable.h"
#include "ctInitializationError.h"
#include <unistd.h> // getuid(), unlink()
#include <pwd.h> // pwd, getpwnam(), getpwuid()
#include <pwd.h> // pwd, getpwnam(), getpwuid()
#include <unistd.h> // getuid(), unlink()
#include "logging.h"
......@@ -131,7 +131,7 @@ bool CTCron::initializeFromUserInfos(const struct passwd *userInfos)
}
}
CTCron &CTCron::operator =(const CTCron &source)
CTCron &CTCron::operator=(const CTCron &source)
{
if (this == &source) {
return *this;
......@@ -187,7 +187,7 @@ void CTCron::parseFile(const QString &fileName)
if (firstText < 10) {
// remove leading pound sign
line = line.mid(1, line.length()-1);
line = line.mid(1, line.length() - 1);
if (comment.isEmpty()) {
comment = line.trimmed();
} else {
......@@ -236,7 +236,8 @@ QString CTCron::exportCron() const
}
exportCron += QLatin1String("\n");
QString exportInfo = i18nc("Generation Message + current date", "File generated by KCron the %1.", QDateTime::currentDateTime().toString(QLocale().dateTimeFormat()));
QString exportInfo =
i18nc("Generation Message + current date", "File generated by KCron the %1.", QDateTime::currentDateTime().toString(QLocale().dateTimeFormat()));
exportCron += QLatin1String("# ") + exportInfo + QLatin1String("\n");
return exportCron;
......@@ -262,7 +263,7 @@ bool CTCron::saveToFile(const QString &fileName)
return false;
}
//logDebug() << exportCron();
// logDebug() << exportCron();
QTextStream out(&file);
out << exportCron();
......@@ -293,7 +294,10 @@ CTSaveStatus CTCron::prepareSaveStatusError(const CommandLineStatus &commandLine
if (commandLineStatus.exitCode == 127) {
detailError = i18n("<p><strong>Command:</strong> %1</p><strong>Command could not be started</strong>", commandLineStatus.commandLine);
} else {
detailError = i18n("<p><strong>Command:</strong> %1</p><strong>Standard Output :</strong><pre>%2</pre><strong>Error Output :</strong><pre>%3</pre>", commandLineStatus.commandLine, standardOutput, standardError);
detailError = i18n("<p><strong>Command:</strong> %1</p><strong>Standard Output :</strong><pre>%2</pre><strong>Error Output :</strong><pre>%3</pre>",
commandLineStatus.commandLine,
standardOutput,
standardError);
}
return CTSaveStatus(i18n("An error occurred while updating crontab."), detailError);
......@@ -313,11 +317,11 @@ CTSaveStatus CTCron::save()
QFile::remove(d->tmpFileName);
return prepareSaveStatusError(commandLineStatus);
} else {
//Remove the temp file
// Remove the temp file
QFile::remove(d->tmpFileName);
}
//Mark as applied
// Mark as applied
for (CTTask *ctTask : qAsConst(d->task)) {
ctTask->apply();
}
......@@ -402,7 +406,7 @@ void CTCron::addTask(CTTask *task)
task->setSystemCrontab(false);
}
logDebug() << "Adding task" << task->comment << " user : "<< task->userLogin;
logDebug() << "Adding task" << task->comment << " user : " << task->userLogin;
d->task.append(task);
}
......@@ -415,19 +419,19 @@ void CTCron::addVariable(CTVariable *variable)
variable->userLogin = d->userLogin;
}
logDebug() << "Adding variable" << variable->variable << " user : "<< variable->userLogin;
logDebug() << "Adding variable" << variable->variable << " user : " << variable->userLogin;
d->variable.append(variable);
}
void CTCron::modifyTask(CTTask * /*task*/)
{
//Nothing to do specifically when modifying a task
// Nothing to do specifically when modifying a task
}
void CTCron::modifyVariable(CTVariable * /*variable*/)
{
//Nothing to do specifically when modifying a variable
// Nothing to do specifically when modifying a variable
}
void CTCron::removeTask(CTTask *task)
......
......@@ -9,8 +9,8 @@
#ifndef CTCRON_H
#define CTCRON_H
#include <QString>
#include <QList>
#include <QString>
#include <QStringList>
class CTTask;
......@@ -47,7 +47,6 @@ public:
class CTCronPrivate
{
public:
/**
* Indicates whether or not the crontab belongs to the system.
*/
......@@ -105,7 +104,6 @@ public:
class CTCron
{
public:
/**
* If you already have a struct passwd, use it instead. This
* is never used for the system crontab.
......@@ -120,7 +118,7 @@ public:
/**
* Copy one user's tasks and environment variables to another user.
*/
CTCron &operator =(const CTCron &source);
CTCron &operator=(const CTCron &source);
virtual QList<CTTask *> tasks() const;
......@@ -184,7 +182,6 @@ public:
QString userRealName() const;
protected:
/**
* Help constructor for subclasses
*/
......@@ -192,8 +189,8 @@ protected:
// Initialize member variables from the struct passwd.
bool initializeFromUserInfos(const struct passwd *userInfos);
private:
private:
/**
* Can't copy a user!
*/
......@@ -202,7 +199,6 @@ private:
CTSaveStatus prepareSaveStatusError(const CommandLineStatus &commandLineStatus);
protected:
/**
* Parses crontab file format.
*/
......
......@@ -31,8 +31,9 @@ QString CTDayOfMonth::getName(const int ndx)
void CTDayOfMonth::initializeNames()
{
if (shortName.isEmpty()) {
shortName << QLatin1String("") << i18n("1st") << i18n("2nd") << i18n("3rd") << i18n("4th") << i18n("5th") << i18n("6th") << i18n("7th") << i18n("8th") << i18n("9th") << i18n("10th") << i18n("11th") << i18n("12th") << i18n("13th") << i18n("14th") << i18n("15th") << i18n("16th") <<
i18n("17th")
<< i18n("18th") << i18n("19th") << i18n("20th") << i18n("21st") << i18n("22nd") << i18n("23rd") << i18n("24th") << i18n("25th") << i18n("26th") << i18n("27th") << i18n("28th") << i18n("29th") << i18n("30th") << i18n("31st");
shortName << QLatin1String("") << i18n("1st") << i18n("2nd") << i18n("3rd") << i18n("4th") << i18n("5th") << i18n("6th") << i18n("7th") << i18n("8th")
<< i18n("9th") << i18n("10th") << i18n("11th") << i18n("12th") << i18n("13th") << i18n("14th") << i18n("15th") << i18n("16th") << i18n("17th")
<< i18n("18th") << i18n("19th") << i18n("20th") << i18n("21st") << i18n("22nd") << i18n("23rd") << i18n("24th") << i18n("25th")
<< i18n("26th") << i18n("27th") << i18n("28th") << i18n("29th") << i18n("30th") << i18n("31st");
}
}
......@@ -9,8 +9,8 @@
#ifndef CTDOM_H
#define CTDOM_H
#include <QString>
#include <QList>
#include <QString>
#include "ctunit.h"
......@@ -37,6 +37,7 @@ public:
static const int MINIMUM = 1;
static const int MAXIMUM = 31;
private:
static void initializeNames();
static QList<QString> shortName;
......
......@@ -58,6 +58,7 @@ void CTDayOfWeek::initializeNames()
if (shortName.isEmpty()) {
shortName << QLatin1String("") << i18n("Mon") << i18n("Tue") << i18n("Wed") << i18n("Thu") << i18n("Fri") << i18n("Sat") << i18n("Sun");
longName << QLatin1String("") << i18n("Monday") << i18n("Tuesday") << i18n("Wednesday") << i18n("Thursday") << i18n("Friday") << i18n("Saturday") << i18n("Sunday");
longName << QLatin1String("") << i18n("Monday") << i18n("Tuesday") << i18n("Wednesday") << i18n("Thursday") << i18n("Friday") << i18n("Saturday")
<< i18n("Sunday");
}
}
......@@ -9,8 +9,8 @@
#ifndef CTDOW_H
#define CTDOW_H
#include <QString>
#include <QList>
#include <QString>
#include "ctunit.h"
......
......@@ -9,18 +9,18 @@
#include "cthost.h"
#include <unistd.h> // getuid()
#include <sys/types.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h> // getuid()
#include <QFile>
#include <QTextStream>
#include <KLocalizedString>
#include "ctcron.h"
#include "ctSystemCron.h"
#include "ctInitializationError.h"
#include "ctSystemCron.h"
#include "ctcron.h"
#include "logging.h"
......@@ -42,7 +42,7 @@ CTHost::CTHost(const QString &cronBinary, CTInitializationError &ctInitializatio
return;
}
}
//delete userInfos;
// delete userInfos;
}
setpwent(); // restart again for others
}
......@@ -53,14 +53,14 @@ CTHost::CTHost(const QString &cronBinary, CTInitializationError &ctInitializatio
setpwent(); // restart
while ((userInfos = getpwent())) {
if ((userInfos->pw_uid == uid) && (!allowDeny(userInfos->pw_name))) {
ctInitializationError.setErrorMessage(i18n("You have been blocked from using KCron\
ctInitializationError.setErrorMessage(
i18n("You have been blocked from using KCron\
by either the /etc/cron.allow file or the /etc/cron.deny file.\
\n\nCheck the crontab man page for further details.")
);
\n\nCheck the crontab man page for further details."));
return;
}
//delete userInfos;
// delete userInfos;
}
setpwent(); // restart again for others
......@@ -73,7 +73,7 @@ CTHost::CTHost(const QString &cronBinary, CTInitializationError &ctInitializatio
return;
}
//delete currentUserPassword;
// delete currentUserPassword;
}
// Create the system cron table.
......@@ -137,7 +137,8 @@ CTSaveStatus CTHost::save()
const CTSaveStatus ctSaveStatus = ctCron->save();
if (ctSaveStatus.isError()) {
return CTSaveStatus(i18nc("User login: errorMessage", "User %1: %2", ctCron->userLogin(), ctSaveStatus.errorMessage()), ctSaveStatus.detailErrorMessage());
return CTSaveStatus(i18nc("User login: errorMessage", "User %1: %2", ctCron->userLogin(), ctSaveStatus.errorMessage()),
ctSaveStatus.detailErrorMessage());
}
}
......
......@@ -9,8 +9,8 @@
#ifndef CTHOST_H
#define CTHOST_H
#include <QString>
#include <QList>
#include <QString>
#include "ctSaveStatus.h"
......@@ -34,7 +34,6 @@ struct passwd;
class CTHost
{
public:
/**
* Constructs the user(s), scheduled tasks, and environment variables
* from crontab files.
......@@ -88,7 +87,6 @@ public:
QList<CTCron *> mCrons;
private:
/**
* Copy construction not allowed.
*/
......@@ -97,7 +95,7 @@ private:
/**
* Assignment not allowed
*/
CTHost &operator =(const CTHost &source);
CTHost &operator=(const CTHost &source);
/**
* Factory create a cron table. Appends to the end of cron.
......
......@@ -17,7 +17,6 @@
class CTHour : public CTUnit
{
public:
/**
* Constructs from a tokenized string.
*/
......
......@@ -23,7 +23,7 @@ CTMinute::CTMinute()
int CTMinute::findPeriod() const
{
const QList<int> periods {1, 2, 5, 10, 15, 20, 30};
const QList<int> periods{1, 2, 5, 10, 15, 20, 30};
return CTUnit::findPeriod(periods);
}
......
......@@ -17,7 +17,6 @@
class CTMinute : public CTUnit
{
public:
/**
* Constructs from a tokenized string.
*/
......
......@@ -31,6 +31,7 @@ QString CTMonth::getName(const int ndx)
void CTMonth::initializeNames()
{
if (shortName.isEmpty()) {
shortName << QLatin1String("") << i18n("January") << i18n("February") << i18n("March") << i18n("April") << i18nc("May long", "May") << i18n("June") << i18nc("July long", "July") << i18n("August") << i18n("September") << i18n("October") << i18n("November") << i18n("December");
shortName << QLatin1String("") << i18n("January") << i18n("February") << i18n("March") << i18n("April") << i18nc("May long", "May") << i18n("June")
<< i18nc("July long", "July") << i18n("August") << i18n("September") << i18n("October") << i18n("November") << i18n("December");
}
}