Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
KCron
Commits
3e209619
Commit
3e209619
authored
Oct 07, 2021
by
Corbin Schwimmbeck
Committed by
Laurent Montel
Oct 07, 2021
Browse files
Implementing the System Cron functionality using KAuth
parent
2c702048
Pipeline
#86218
passed with stage
in 34 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
3e209619
...
...
@@ -8,7 +8,13 @@ include_directories(
########## KCM Module ###############
add_library
(
kcm_cron MODULE
)
ecm_qt_declare_logging_category
(
kcm_cron HEADER kcm_cron_debug.h IDENTIFIER KCM_CRON_LOG CATEGORY_NAME org.kde.kcm.cron DESCRIPTION
"kcm cron"
EXPORT KCRON
)
ecm_qt_declare_logging_category
(
kcm_cron
HEADER kcm_cron_debug.h
IDENTIFIER KCM_CRON_LOG
CATEGORY_NAME org.kde.kcm.cron
DESCRIPTION
"kcm cron"
EXPORT KCRON
)
target_sources
(
kcm_cron PRIVATE
crontablib/cthost.cpp
...
...
@@ -61,4 +67,6 @@ install(TARGETS kcm_cron DESTINATION ${KDE_INSTALL_PLUGINDIR} )
# For root permissions.
add_subdirectory
(
helper
)
install
(
FILES kcm_cron.desktop DESTINATION
${
KDE_INSTALL_KSERVICES5DIR
}
)
install
(
FILES kcm_cron.desktop
DESTINATION
${
KDE_INSTALL_KSERVICES5DIR
}
)
src/crontabWidget.cpp
View file @
3e209619
...
...
@@ -37,7 +37,6 @@
#include
"variableWidget.h"
#include
"kcmCron.h"
#include
"kcm_cron_debug.h"
CrontabWidget
::
CrontabWidget
(
QWidget
*
parent
,
CTHost
*
ctHost
)
...
...
@@ -134,6 +133,7 @@ void CrontabWidget::initialize()
void
CrontabWidget
::
refreshCron
()
{
// Refreshes the main GUI.
CTCron
*
ctCron
=
currentCron
();
mTasksWidget
->
refreshTasks
(
ctCron
);
...
...
src/crontablib/ctcron.cpp
View file @
3e209619
...
...
@@ -316,26 +316,28 @@ CTSaveStatus CTCron::save()
if
(
d
->
systemCron
)
{
qCDebug
(
KCM_CRON_LOG
)
<<
"Attempting to save system cron"
;
QVariantMap
args
;
args
.
insert
(
Q
Latin1
String
(
"source"
),
d
->
tmpFileName
);
args
.
insert
(
Q
Latin1
String
(
"target"
),
d
->
writeCommandLine
.
standardOutputFile
);
KAuth
::
Action
saveAction
(
Q
Latin1
String
(
"local.kcron.crontab.save"
));
saveAction
.
setHelperId
(
Q
Latin1
String
(
"local.kcron.crontab"
));
args
.
insert
(
QString
Literal
(
"source"
),
d
->
tmpFileName
);
args
.
insert
(
QString
Literal
(
"target"
),
d
->
writeCommandLine
.
standardOutputFile
);
KAuth
::
Action
saveAction
(
QString
Literal
(
"local.kcron.crontab.save"
));
saveAction
.
setHelperId
(
QString
Literal
(
"local.kcron.crontab"
));
saveAction
.
setArguments
(
args
);
KAuth
::
ExecuteJob
*
job
=
saveAction
.
execute
();
if
(
!
job
->
exec
())
qCDebug
(
KCM_CRON_LOG
)
<<
"KAuth returned an error: "
<<
job
->
error
()
<<
job
->
errorText
();
QFile
::
remove
(
d
->
tmpFileName
);
if
(
job
->
error
()
>
0
)
if
(
job
->
error
()
>
0
)
{
return
CTSaveStatus
(
i18n
(
"KAuth::ExecuteJob Error"
),
job
->
errorText
());
}
}
// End root permissions.
else
{
qCDebug
(
KCM_CRON_LOG
)
<<
"Attempting to save user cron"
;
// Save without root permissions.
CommandLineStatus
commandLineStatus
=
d
->
writeCommandLine
.
execute
();
const
CommandLineStatus
commandLineStatus
=
d
->
writeCommandLine
.
execute
();
QFile
::
remove
(
d
->
tmpFileName
);
if
(
commandLineStatus
.
exitCode
!=
0
)
if
(
commandLineStatus
.
exitCode
!=
0
)
{
return
prepareSaveStatusError
(
commandLineStatus
);
}
}
// Mark as applied
...
...
src/crontablib/ctcron.h
View file @
3e209619
...
...
@@ -196,8 +196,6 @@ private:
*/
CTCron
(
const
CTCron
&
source
);
CTSaveStatus
prepareSaveStatusError
(
const
CommandLineStatus
&
commandLineStatus
);
protected:
/**
* Parses crontab file format.
...
...
@@ -206,6 +204,7 @@ protected:
bool
saveToFile
(
const
QString
&
fileName
);
CTSaveStatus
prepareSaveStatusError
(
const
CommandLineStatus
&
commandLineStatus
);
// d probably stands for data.
CTCronPrivate
*
const
d
;
};
...
...
src/helper/kcronhelper.cpp
View file @
3e209619
...
...
@@ -31,12 +31,14 @@
ActionReply
KcronHelper
::
save
(
const
QVariantMap
&
args
)
{
qCDebug
(
KCM_CRON_HELPER_LOG
)
<<
"running actions"
;
QString
source
=
args
[
QLatin1String
(
"source"
)].
toString
();
QString
destination
=
args
[
QLatin1String
(
"target"
)].
toString
();
if
(
!
QFile
::
remove
(
destination
))
const
QString
source
=
args
[
QLatin1String
(
"source"
)].
toString
();
const
QString
destination
=
args
[
QLatin1String
(
"target"
)].
toString
();
if
(
!
QFile
::
remove
(
destination
))
{
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't remove file, it doesn't exist"
;
if
(
!
QFile
::
copy
(
source
,
destination
))
}
if
(
!
QFile
::
copy
(
source
,
destination
))
{
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't write into the system file, something went wrong"
;
}
return
ActionReply
::
SuccessReply
();
}
...
...
src/kcronHelper.cpp
View file @
3e209619
...
...
@@ -32,7 +32,6 @@ void KCronHelper::initUserCombo(QComboBox *userCombo, CrontabWidget *crontabWidg
for
(
CTCron
*
ctCron
:
crons
)
{
users
.
append
(
ctCron
->
userLogin
());
// Select the actual user
if
(
ctCron
->
userLogin
()
==
selectedUserLogin
)
{
selectedIndex
=
userComboIndex
;
}
...
...
src/taskEditorDialog.cpp
View file @
3e209619
...
...
@@ -17,6 +17,8 @@
#include
<QStandardPaths>
#include
<QVBoxLayout>
#include
<QLocale>
#include
<QStyleOption>
#include
<QStylePainter>
...
...
@@ -104,6 +106,7 @@ TaskEditorDialog::TaskEditorDialog(CTTask *_ctTask, const QString &_caption, Cro
userLabel
->
setBuddy
(
mUserCombo
);
commandConfigurationLayout
->
addWidget
(
mUserCombo
,
1
,
1
);
// When in multiuser (system) mode, a user column is required.
if
(
mCrontabWidget
->
tasksWidget
()
->
needUserColumn
())
{
KCronHelper
::
initUserCombo
(
mUserCombo
,
mCrontabWidget
,
mCtTask
->
userLogin
);
}
else
{
...
...
@@ -505,33 +508,44 @@ NumberPushButton *TaskEditorDialog::createHourButton(QGroupBox *hoursGroup, int
QGroupBox
*
TaskEditorDialog
::
createHoursGroup
(
QWidget
*
main
)
{
// Hide the AM/PM labels if the locale is set to 24h format.
// 'A' or 'a' means am/pm is shown (and then 'h' uses 12-hour format)
// but 'H' forces a 24-hour format anyway, even with am/pm shown.
const
QString
str
=
QLocale
().
timeFormat
();
static
bool
use12Clock
=
str
.
contains
(
QLatin1Char
(
'a'
),
Qt
::
CaseInsensitive
)
&&
!
str
.
contains
(
QLatin1Char
(
'H'
));
qCDebug
(
KCM_CRON_LOG
)
<<
"Creating hours group"
;
auto
hoursGroup
=
new
QGroupBox
(
i18n
(
"Hours"
),
main
);
auto
hoursLayout
=
new
QGridLayout
(
hoursGroup
);
// 5 x
7
auto
hoursLayout
=
new
QGridLayout
(
hoursGroup
);
// 5 x
6 (24h) // 5 x 7 (12h)
mMorningLabel
=
new
QLabel
(
i18n
(
"AM:"
),
this
);
mMorningLabel
->
setAlignment
(
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
mMorningLabel
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Minimum
);
hoursLayout
->
addWidget
(
mMorningLabel
,
0
,
0
,
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
if
(
use12Clock
)
{
mMorningLabel
=
new
QLabel
(
i18n
(
"AM:"
),
this
);
mMorningLabel
->
setAlignment
(
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
mMorningLabel
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Minimum
);
hoursLayout
->
addWidget
(
mMorningLabel
,
0
,
0
,
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
}
int
hourCount
=
0
;
for
(
int
column
=
0
;
column
<=
3
;
++
column
)
{
for
(
int
hour
=
0
;
hour
<=
5
;
++
hour
)
{
NumberPushButton
*
hourButton
=
createHourButton
(
hoursGroup
,
hourCount
);
mHourButtons
[
hourCount
]
=
hourButton
;
hoursLayout
->
addWidget
(
hourButton
,
column
,
hour
+
1
);
// When using the 12h format, the hour buttons need to be inserted 1 column over to leave room for the AM/PM labels.
hoursLayout
->
addWidget
(
hourButton
,
column
,
hour
+
(
use12Clock
?
1
:
0
));
hourCount
++
;
}
}
mAfternoonLabel
=
new
QLabel
(
i18n
(
"PM:"
),
this
);
mAfternoonLabel
->
setAlignment
(
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
mAfternoonLabel
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Minimum
);
hoursLayout
->
addWidget
(
mAfternoonLabel
,
2
,
0
,
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
if
(
use12Clock
)
{
mAfternoonLabel
=
new
QLabel
(
i18n
(
"PM:"
),
this
);
mAfternoonLabel
->
setAlignment
(
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
mAfternoonLabel
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Minimum
);
hoursLayout
->
addWidget
(
mAfternoonLabel
,
2
,
0
,
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
);
}
mAllHours
=
new
SetOrClearAllButton
(
this
,
SetOrClearAllButton
::
SET_ALL
);
hoursLayout
->
addWidget
(
mAllHours
,
4
,
0
,
1
,
7
);
hoursLayout
->
addWidget
(
mAllHours
,
4
,
0
,
1
,
use12Clock
?
7
:
6
);
connect
(
mAllHours
,
&
SetOrClearAllButton
::
clicked
,
this
,
&
TaskEditorDialog
::
slotAllHours
);
connect
(
mAllHours
,
&
SetOrClearAllButton
::
clicked
,
this
,
&
TaskEditorDialog
::
slotWizard
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment