kcron: remove it

requires funcitonal cron which some Linux distributions do not even
have by default, can be reimplemented as KDED module

note that ktimer can execute commands after certain time (i.e. it is
simplified version of cron)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-14 13:13:25 +02:00
parent 78897ef6eb
commit 988be03b11
67 changed files with 0 additions and 8503 deletions

View file

@ -23,7 +23,6 @@ kde4_optional_add_subdirectory(filelight)
kde4_optional_add_subdirectory(gwenview)
kde4_optional_add_subdirectory(kcalc)
kde4_optional_add_subdirectory(kcolorchooser)
kde4_optional_add_subdirectory(kcron)
kde4_optional_add_subdirectory(kdeplasma-addons)
kde4_optional_add_subdirectory(kemu)
kde4_optional_add_subdirectory(kget)

View file

@ -1,2 +0,0 @@
Gary Meyer <gary@meyer.net>
Robert Berry <rjmber@ntlworld.com>

View file

@ -1,23 +0,0 @@
project(kcron)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
include(FeatureSummary)
find_package(KDE4 4.23.0 REQUIRED)
include(KDE4Defaults)
include_directories(${KDE4_INCLUDES})
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
endif()
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckTypeSize)
add_subdirectory(src)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
endif()

View file

@ -1,340 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View file

@ -1,2 +0,0 @@
#! /usr/bin/env bash
$XGETTEXT `find . -name "*.cpp"` -o $podir/kcron.pot

View file

@ -1,12 +0,0 @@
KCron
KDE Task Scheduler
GUI crontab editor
Requires:
Unix POSIX libraries for localized dates and times (glibc)
Cron (vixie-cron)
Crontab (crontabs)

View file

@ -1,5 +0,0 @@
Ideas for new features :
- Add a way to see next tasks scheduling in KOrganizer
- Support for at command (schedule a one shot task in the future, and remove it after execute it)

View file

@ -1,14 +0,0 @@
Begin3
Title: KCron
Version: 2.0
Entered-date: 1 September 1999
Description: KDE Task Scheduler
Keywords: KDE, X11, Qt
Author: Nicolas Ternisien <nicolas.ternisien@gmail.com> Gary Meyer <gary@meyer.net> Robert Berry <rjmber@ntlworld.com>
Maintained-by: Nicolas Ternisien <nicolas.ternisien@gmail.com>
Primary-site:
Home-page: http://www.forum-software.org/
Original-site:
Platform: Linux and other Unices, needs Qt, KDE, and cron
Copying-policy: GNU Public License
End

View file

@ -1,62 +0,0 @@
########### Build ###############
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/crontablib
${CMAKE_CURRENT_SOURCE_DIR}
)
########## KCM Module ###############
set(kcron_crontablib_SRCS
crontablib/cthost.cpp
crontablib/ctcron.cpp
crontablib/ctmonth.cpp
crontablib/ctminute.cpp
crontablib/cthour.cpp
crontablib/ctdom.cpp
crontablib/ctdow.cpp
crontablib/cttask.cpp
crontablib/ctunit.cpp
crontablib/ctvariable.cpp
crontablib/ctGlobalCron.cpp
crontablib/ctSystemCron.cpp
crontablib/ctInitializationError.cpp
crontablib/ctSaveStatus.cpp
crontablib/ctHelper.cpp
)
set(kcm_cron_SRCS
${kcron_crontablib_SRCS}
genericListWidget.cpp
tasksWidget.cpp
taskWidget.cpp
variablesWidget.cpp
variableWidget.cpp
taskEditorDialog.cpp
variableEditorDialog.cpp
crontabWidget.cpp
kcronIcons.cpp
kcronHelper.cpp
crontabPrinter.cpp
crontabPrinterWidget.cpp
kcmCron.cpp
)
kde4_add_plugin(kcm_cron ${kcm_cron_SRCS})
target_link_libraries(kcm_cron
${KDE4_KIO_LIBS}
)
install(TARGETS kcm_cron DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} )
install(FILES kcm_cron.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR} )

View file

@ -1,419 +0,0 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* KDE\QT printing implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Robert Berry <rjmber@ntlworld.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "crontabPrinter.h"
#include <QPainter>
#include <QPrintDialog>
#include <QPen>
#include <kdeprintdialog.h>
#include <klocale.h>
#include "crontabWidget.h"
#include "taskWidget.h"
#include "ctcron.h"
#include "cttask.h"
#include "ctvariable.h"
#include "logging.h"
class CrontabPrinterPrivate {
public:
/**
* Pointer a printer options object
*/
CrontabPrinterWidget* crontabPrinterWidget;
/**
* Pointer to parent widget
*/
CrontabWidget* crontabWidget;
QPainter* painter;
QPrinter* printer;
QRect* printView;
int page;
int currentRowPosition;
};
CrontabPrinter::CrontabPrinter(CrontabWidget* crontabWidget) :
d(new CrontabPrinterPrivate()) {
d->crontabPrinterWidget = NULL;
d->crontabWidget = crontabWidget;
d->painter = NULL;
d->printer = NULL;
d->printView = NULL;
d->page = 0;
d->currentRowPosition = 0;
}
CrontabPrinter::~CrontabPrinter() {
delete d->crontabPrinterWidget;
delete d->painter;
delete d->printer;
delete d->printView;
delete d;
}
bool CrontabPrinter::start() {
logDebug() << "Printing selection...";
if (d->printer == NULL) {
d->printer = new QPrinter();
}
// do some printer initialization
d->printer->setFullPage( true);
/*
CrontabPrinterWidget* dialogPage = new CrontabPrinterWidget(d->crontabWidge);
d->printer->addDialogPage(dialogPage);
*/
// initialize the printer using the print dialog
QPrintDialog *printDialog = KdePrint::createPrintDialog(d->printer, d->crontabWidget);
if (printDialog->exec() == QDialog::Rejected) {
logDebug() << "Printing canceled";
delete printDialog;
return false;
}
delete printDialog;
// create a painter to paint on the printer object
d->painter = new QPainter();
// start painting
d->painter->begin(d->printer);
int margin = computeMargin();
d->printView = new QRect(margin, margin, d->painter->device()->width() - 2*margin, d->painter->device()->height() - 2*margin );
d->page = 1;
d->currentRowPosition = 0;
drawMainTitle();
return true;
}
void CrontabPrinter::printTasks() {
CTCron* cron = d->crontabWidget->currentCron();
drawTitle(i18n("Scheduled Tasks"));
QList<QStringList> tasksContent;
foreach(CTTask* task, cron->tasks()) {
QStringList values;
values << task->schedulingCronFormat();
values << task->command;
values << task->comment;
tasksContent.append(values);
}
QList<int> tasksColumnWidths = findColumnWidths(tasksContent, 3);
QStringList taskHeaders;
taskHeaders << i18n("Scheduling") << i18n("Command") << i18n("Description");
drawHeader(tasksColumnWidths, taskHeaders);
foreach(const QStringList& contents, tasksContent) {
drawContentRow(tasksColumnWidths, contents);
needNewPage();
}
drawTable(tasksColumnWidths);
}
void CrontabPrinter::printVariables() {
CTCron* cron = d->crontabWidget->currentCron();
d->painter->translate(0, 20);
d->currentRowPosition = 0;
//Environment Variables
drawTitle(i18n("Environment Variables"));
//QList<QStringList> variablesContent;
foreach(CTVariable* variable, cron->variables()) {
d->painter->drawText(*(d->printView), Qt::AlignLeft | Qt::TextWordWrap, variable->variable + QLatin1String( " = " ) + variable->value);
int moveBy = computeStringHeight(variable->variable);
d->painter->translate(0, moveBy);
}
}
void CrontabPrinter::drawMainTitle() {
CTCron* cron = d->crontabWidget->currentCron();
QFont originalFont = d->painter->font();
QFont titleFont(originalFont);
titleFont.setPixelSize(20);
titleFont.setBold(true);
d->painter->setFont(titleFont);
QString mainTitle;
if (cron->isSystemCron())
mainTitle = i18n("System Crontab");
else if (cron->isMultiUserCron())
mainTitle = i18n("All Users Crontabs");
else
mainTitle = i18nc("Crontab of user login", "Crontab of user %1", cron->userLogin());
d->painter->drawText(*(d->printView), Qt::AlignHCenter | Qt::TextWordWrap, mainTitle);
d->painter->translate(0, computeStringHeight(mainTitle));
d->painter->setFont(originalFont);
}
void CrontabPrinter::drawTitle(const QString& title) {
QFont originalFont = d->painter->font();
QFont titleFont(originalFont);
titleFont.setPixelSize(16);
titleFont.setBold(true);
d->painter->setFont(titleFont);
d->painter->drawText(*(d->printView), Qt::AlignLeft | Qt::TextWordWrap, title);
d->painter->translate(0, computeStringHeight(title));
d->painter->setFont(originalFont);
}
void CrontabPrinter::drawHeader(const QList<int>& columnWidths, const QStringList& headers) {
QFont originalFont = d->painter->font();
QFont titleFont(originalFont);
titleFont.setBold(true);
d->painter->setFont(titleFont);
drawContentRow(columnWidths, headers);
d->painter->setFont(originalFont);
}
void CrontabPrinter::drawContentRow(const QList<int>& columnWidths, const QStringList& contents) {
QString firstColumn;
int totalWidths = 0;
int index=0;
foreach(const QString& content, contents) {
if (index==0)
firstColumn = content;
d->painter->drawText(*(d->printView), Qt::AlignLeft | Qt::TextWordWrap, QLatin1String( " " ) + content);
d->painter->translate(columnWidths[index], 0);
totalWidths += columnWidths[index];
index++;
}
int moveBy = computeStringHeight(firstColumn);
changeRow( -totalWidths, moveBy);
}
void CrontabPrinter::finish() {
// stop painting, this will automatically send the print data to the printer
d->painter->end();
}
void CrontabPrinter::printPageNumber() {
logDebug() << "Printing page number...";
d->painter->translate(0, - d->currentRowPosition);
d->printView->moveTo(QPoint(0, d->printView->height()) );
d->painter->translate( 0, - d->printView->height() );
d->painter->drawText(d->printView->right() - d->painter->fontMetrics().width(QString::number(d->page) ), d->printView->bottom()+ d->painter->fontMetrics().ascent() + 5, QString::number(d->page) );
}
void CrontabPrinter::changeRow(int x, int y) {
d->painter->translate(x, y);
d->currentRowPosition = d->currentRowPosition + y;
}
int CrontabPrinter::computeMargin() const {
int dpiy = d->painter->device()->logicalDpiY();
int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
return margin;
}
int CrontabPrinter::computeStringHeight(const QString& text) const {
int fontHeight = d->painter->fontMetrics().height();
int lines = d->painter->fontMetrics().width(text) / d->printView->width() + 1;
int moveBy = (fontHeight + 2) * lines;
return moveBy;
}
/**
* Whether crontab should be printed
*/
bool CrontabPrinter::isPrintCrontab() const {
return d->crontabPrinterWidget->printCrontab();
}
/**
* Whether all users should be printed (root only)
*/
bool CrontabPrinter::isAllUsers() const {
return d->crontabPrinterWidget->printAllUsers();
}
void CrontabPrinter::drawTable(const QList<int>& columnWidths) {
d->painter->translate(0, - d->currentRowPosition + computeMargin());
int columnWidthsTotal = 0;
foreach(int columnWidth, columnWidths) {
columnWidthsTotal += columnWidth;
}
int margin = computeMargin();
int linePositionX = margin;
QPen originalPen = d->painter->pen();
QPen pen(originalPen);
pen.setWidth(1);
d->painter->setPen(pen);
//First horizontal line
d->painter->drawLine(QPoint(margin, 0), QPoint(margin + columnWidthsTotal, 0));
//Second horizontal line
d->painter->drawLine(QPoint(margin, 0+computeStringHeight(QLatin1String( " " ))), QPoint(margin + columnWidthsTotal, 0+computeStringHeight(QLatin1String( " " ))));
//First vertical line
d->painter->drawLine(QPoint(linePositionX, 0), QPoint(linePositionX, d->currentRowPosition));
foreach(int columnWidth, columnWidths) {
linePositionX += columnWidth;
d->painter->drawLine(QPoint(linePositionX, 0), QPoint(linePositionX, d->currentRowPosition));
}
//Last horizontal line
d->painter->drawLine(QPoint(margin, d->currentRowPosition), QPoint(margin + columnWidthsTotal, d->currentRowPosition));
d->painter->setPen(originalPen);
d->painter->translate(0, d->currentRowPosition - computeMargin());
}
QList<int> CrontabPrinter::findMaxWidths(const QList<QStringList>& contents, int columnCount) {
QList<int> columnWidths;
for (int i=0; i<columnCount; ++i) {
columnWidths.append(0);
}
foreach(const QStringList& content, contents) {
int columnIndex = 0;
while (columnIndex < columnWidths.count()) {
int valueWidth = d->painter->fontMetrics().width(content.at(columnIndex));
if (columnWidths[columnIndex] < valueWidth) {
columnWidths[columnIndex] = valueWidth;
}
columnIndex++;
}
}
return columnWidths;
}
QList<int> CrontabPrinter::findColumnWidths(const QList<QStringList>& contents, int columnCount) {
QList<int> columnWidths = findMaxWidths(contents, columnCount);
int margin = computeMargin();
int pageWidth = d->painter->device()->width() - 2*margin;
int columnWidthSum = 0;
foreach(int width, columnWidths) {
logDebug() << "Column : " << width;
columnWidthSum += width;
}
if (columnWidthSum >= pageWidth) {
logDebug() << "The printing could be out of the page";
return columnWidths;
}
int additionalSpace = (pageWidth - columnWidthSum) / columnWidths.count();
int columnIndex = 0;
while (columnIndex < columnWidths.count()) {
columnWidths[columnIndex] = columnWidths[columnIndex] + additionalSpace;
columnIndex++;
}
return columnWidths;
}
void CrontabPrinter::needNewPage() {
int margin = computeMargin();
if (d->currentRowPosition + margin >= d->printView->height()) {
printPageNumber();
d->printer->newPage();
d->page++;
d->currentRowPosition = 0;
}
}

View file

@ -1,91 +0,0 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* KDE\QT Printing class *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Robert Berry <rjmber@ntlworld.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KTPRINT_H
#define KTPRINT_H
#include <QList>
#include <QPrinter>
#include "crontabPrinterWidget.h"
#include <QString>
class CrontabWidget;
class CrontabPrinterPrivate;
/**
*Provides a wrapper for simple printing of text.
*/
class CrontabPrinter {
public:
/**
* Contructor
*/
CrontabPrinter(CrontabWidget* crontabWidget);
/**
* Destructor
*/
~CrontabPrinter();
bool start();
void finish();
void printTasks();
void printVariables();
/**
* Whether crontab should be printed
*/
bool isPrintCrontab() const;
/**
* Whether all users should be printed (root only)
*/
bool isAllUsers() const;
private:
/**
*Disable the copy constructor and the assignment operator
*/
CrontabPrinter& operator=(const CrontabPrinter&) {
return *this;
}
void printPageNumber();
void drawMainTitle();
void drawTitle(const QString& title);
void drawHeader(const QList<int>& columnWidths, const QStringList& headers);
void drawContentRow(const QList<int>& columnWidths, const QStringList& contents);
void drawTable(const QList<int>& columnWidths);
void needNewPage();
int maxWidth();
void changeRow(int x, int y);
int computeMargin() const;
int computeStringHeight(const QString& text) const;
QList<int> findMaxWidths(const QList<QStringList>& tasksContent, int columnCount);
QList<int> findColumnWidths(const QList<QStringList>& tasksContent, int columnCount);
CrontabPrinterPrivate* const d;
};
#endif

View file

@ -1,65 +0,0 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Print Options Dialog *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Robert Berry <rjmber@ntlwolrd.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "crontabPrinterWidget.h"
#include <QCheckBox>
#include <QLayout>
#include <QVBoxLayout>
#include <kdialog.h>
#include <klocale.h>
CrontabPrinterWidget::CrontabPrinterWidget(bool root) :
QWidget() {
setWindowTitle(i18n("Cron Options"));
QVBoxLayout *main_ = new QVBoxLayout(this);
main_->setMargin(KDialog::marginHint());
main_->setSpacing(KDialog::spacingHint());
chkPrintCrontab = new QCheckBox(i18n("Print cron&tab"), this);
chkPrintCrontab->setObjectName( QLatin1String("chkPrintCrontab" ));
main_->addWidget(chkPrintCrontab);
chkPrintAllUsers = new QCheckBox(i18n("Print &all users"), this);
chkPrintAllUsers->setObjectName( QLatin1String("chkPrintAllUsers" ));
main_->addWidget(chkPrintAllUsers);
if (!root) {
chkPrintAllUsers->setChecked(false);
chkPrintAllUsers->setEnabled(false);
}
setLayout(main_);
}
CrontabPrinterWidget::~CrontabPrinterWidget() {
}
bool CrontabPrinterWidget::printCrontab() {
return chkPrintCrontab->isChecked();
}
void CrontabPrinterWidget::setPrintCrontab(bool setStatus) {
chkPrintCrontab->setChecked(setStatus);
}
bool CrontabPrinterWidget::printAllUsers() {
return chkPrintAllUsers->isChecked();
}
void CrontabPrinterWidget::setPrintAllUsers(bool setStatus) {
chkPrintAllUsers->setChecked(setStatus);
}
#include "moc_crontabPrinterWidget.cpp"

View file

@ -1,47 +0,0 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Print Options Dialog *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Robert Berry <rjmber@ntlwolrd.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KTPRINTOPT_H
#define KTPRINTOPT_H
#include <QWidget>
#include <QCheckBox>
/**
*Give the user the option to print the crontab file.
*If the user is root ask if they want to print all the users
*/
class CrontabPrinterWidget : public QWidget {
Q_OBJECT
public:
/**
* Constructs the dialog, if root is true the print all users is not disabled
*/
CrontabPrinterWidget(bool root = false);
~CrontabPrinterWidget();
bool printCrontab();
void setPrintCrontab(bool setStatus);
bool printAllUsers();
void setPrintAllUsers(bool setStatus);
private:
QCheckBox* chkPrintCrontab;
QCheckBox* chkPrintAllUsers;
};
#endif

View file

@ -1,430 +0,0 @@
/**************************************************************************
* KT main GUI view implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "crontabWidget.h"
#include <stdlib.h>
#include <unistd.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDateTime>
#include <QLabel>
#include <QSplitter>
#include <QRadioButton>
#include <QButtonGroup>
#include <QComboBox>
#include <QApplication>
#include <QClipboard>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kglobal.h>
#include <kicon.h>
#include <kiconloader.h>
#include <kaction.h>
#include <kstandardaction.h>
#include <kactioncollection.h>
#include "cthost.h"
#include "ctcron.h"
#include "ctvariable.h"
#include "cttask.h"
#include "ctGlobalCron.h"
#include "crontabPrinter.h"
#include "kcronIcons.h"
#include "tasksWidget.h"
#include "taskWidget.h"
#include "variableWidget.h"
#include "variableWidget.h"
#include "kcmCron.h"
#include "logging.h"
class CTGlobalCron;
class CrontabWidgetPrivate {
public:
/**
* The application.
*/
CTHost* ctHost;
/**
* Tree view of the crontab tasks.
*/
TasksWidget* tasksWidget;
/**
* Tree view of the crontab tasks.
*/
VariablesWidget* variablesWidget;
QAction* cutAction;
QAction* copyAction;
QAction* pasteAction;
/**
* Clipboard tasks.
*/
QList<CTTask*> clipboardTasks;
/**
* Clipboard variable.
*/
QList<CTVariable*> clipboardVariables;
QRadioButton* currentUserCronRadio;
QRadioButton* systemCronRadio;
QRadioButton* otherUserCronRadio;
QComboBox* otherUsers;
/**
* Pointer to the pseudo Global Cron object
*/
CTGlobalCron* ctGlobalCron;
};
CrontabWidget::CrontabWidget(QWidget* parent, CTHost* ctHost) :
QWidget(parent), d(new CrontabWidgetPrivate()) {
d->tasksWidget = NULL;
d->variablesWidget = NULL;
d->ctHost = ctHost;
if (d->ctHost->isRootUser()) {
d->ctGlobalCron = new CTGlobalCron(d->ctHost);
}
else {
d->ctGlobalCron = NULL;
}
setupActions();
initialize();
logDebug() << "Clipboard Status " << hasClipboardContent();
d->tasksWidget->setFocus();
QTreeWidgetItem* item = d->tasksWidget->treeWidget()->topLevelItem(0);
if (item != NULL) {
logDebug() << "First item found" << d->tasksWidget->treeWidget()->topLevelItemCount();
item->setSelected(true);
}
d->tasksWidget->changeCurrentSelection();
d->variablesWidget->changeCurrentSelection();
}
CrontabWidget::~CrontabWidget() {
delete d->tasksWidget;
delete d->variablesWidget;
delete d->ctGlobalCron;
delete d;
}
bool CrontabWidget::hasClipboardContent() {
if (d->clipboardTasks.isEmpty() == false)
return true;
if (d->clipboardVariables.isEmpty() == false)
return true;
return false;
}
QHBoxLayout* CrontabWidget::createCronSelector() {
QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget(new QLabel(i18n("Show the following Cron:"), this));
QButtonGroup* group = new QButtonGroup(this);
d->currentUserCronRadio = new QRadioButton(i18n("Personal Cron"), this);
d->currentUserCronRadio->setChecked(true);
group->addButton(d->currentUserCronRadio);
layout->addWidget(d->currentUserCronRadio);
d->systemCronRadio = new QRadioButton(i18n("System Cron"), this);
group->addButton(d->systemCronRadio);
layout->addWidget(d->systemCronRadio);
d->otherUserCronRadio = new QRadioButton(i18n("Cron of User:"), this);
group->addButton(d->otherUserCronRadio);
d->otherUsers = new QComboBox(this);
layout->addWidget(d->otherUserCronRadio);
layout->addWidget(d->otherUsers);
if (ctHost()->isRootUser()) {
QStringList users;
foreach(CTCron* ctCron, ctHost()->crons) {
if (ctCron->isCurrentUserCron())
continue;
if (ctCron->isSystemCron())
continue;
users.append(ctCron->userLogin());
}
users.sort();
d->otherUsers->addItems(users);
d->otherUsers->addItem(KIcon( QLatin1String( "users") ), i18n("Show All Personal Crons"));
} else {
d->otherUserCronRadio->hide();
d->otherUsers->hide();
}
connect(group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(refreshCron()));
connect(d->otherUsers, SIGNAL(currentIndexChanged(int)), this, SLOT(checkOtherUsers()));
layout->addStretch(1);
return layout;
}
void CrontabWidget::initialize() {
QVBoxLayout* layout = new QVBoxLayout(this);
logDebug() << "Begin view refresh";
logDebug() << "Creating Tasks list...";
QHBoxLayout* cronSelector = createCronSelector();
layout->addLayout(cronSelector);
QSplitter* splitter = new QSplitter(this);
splitter->setOrientation(Qt::Vertical);
layout->addWidget(splitter);
d->tasksWidget = new TasksWidget(this);
splitter->addWidget(d->tasksWidget);
splitter->setStretchFactor(0, 2);
d->variablesWidget = new VariablesWidget(this);
splitter->addWidget(d->variablesWidget);
splitter->setStretchFactor(1, 1);
refreshCron();
}
void CrontabWidget::refreshCron() {
CTCron* ctCron = currentCron();
d->tasksWidget->refreshTasks(ctCron);
d->variablesWidget->refreshVariables(ctCron);
if (ctCron->isMultiUserCron() && ctHost()->isRootUser()==false) {
logDebug() << "Disabling view...";
d->tasksWidget->treeWidget()->setEnabled(false);
d->variablesWidget->treeWidget()->setEnabled(false);
toggleNewEntryActions(false);
toggleModificationActions(false);
togglePasteAction(false);
d->tasksWidget->toggleRunNowAction(false);
}
else {
logDebug() << "Enabling view...";
d->tasksWidget->treeWidget()->setEnabled(true);
d->variablesWidget->treeWidget()->setEnabled(true);
toggleNewEntryActions(true);
togglePasteAction(hasClipboardContent());
}
}
void CrontabWidget::copy() {
foreach(CTTask* task, d->clipboardTasks) {
delete task;
}
d->clipboardTasks.clear();
foreach(CTVariable* variable, d->clipboardVariables) {
delete variable;
}
d->clipboardVariables.clear();
QString clipboardText;
if (d->tasksWidget->treeWidget()->hasFocus()) {
logDebug() << "Tasks copying";
QList<TaskWidget*> tasksWidget = d->tasksWidget->selectedTasksWidget();
foreach(TaskWidget* taskWidget, tasksWidget) {
CTTask* task = new CTTask( *(taskWidget->getCTTask()) );
d->clipboardTasks.append(task);
clipboardText += task->exportTask() + QLatin1String( "\n" );
}
}
if (d->variablesWidget->treeWidget()->hasFocus()) {
logDebug() << "Variables copying";
QList<VariableWidget*> variablesWidget = d->variablesWidget->selectedVariablesWidget();
foreach(VariableWidget* variableWidget, variablesWidget) {
CTVariable* variable = new CTVariable( *(variableWidget->getCTVariable()) );
d->clipboardVariables.append(variable);
clipboardText += variable->exportVariable() + QLatin1String( "\n" );
}
}
QApplication::clipboard()->setText(clipboardText, QClipboard::Clipboard);
QApplication::clipboard()->setText(clipboardText, QClipboard::Selection);
logDebug() << "Clipboard Status " << hasClipboardContent();
togglePasteAction(hasClipboardContent());
}
void CrontabWidget::cut() {
logDebug() << "Cut content";
copy();
if (d->tasksWidget->treeWidget()->hasFocus()) {
logDebug() << "Tasks cutting";
d->tasksWidget->deleteSelection();
}
if (d->variablesWidget->treeWidget()->hasFocus()) {
logDebug() << "Variables cutting";
d->variablesWidget->deleteSelection();
}
}
void CrontabWidget::paste() {
logDebug() << "Paste content";
if (d->tasksWidget->treeWidget()->hasFocus()) {
foreach(CTTask* task, d->clipboardTasks) {
d->tasksWidget->addTask(new CTTask(*task));
}
}
if (d->variablesWidget->treeWidget()->hasFocus()) {
foreach(CTVariable* variable, d->clipboardVariables) {
d->variablesWidget->addVariable(new CTVariable(*variable));
}
}
}
CTCron* CrontabWidget::currentCron() const {
if (d->currentUserCronRadio->isChecked())
return d->ctHost->findCurrentUserCron();
else if (d->systemCronRadio->isChecked())
return d->ctHost->findSystemCron();
if (d->otherUsers->currentIndex() == d->otherUsers->count()-1) {
logDebug() << "Using Global Cron";
return d->ctGlobalCron;
}
QString currentUserLogin = d->otherUsers->currentText();
return d->ctHost->findUserCron(currentUserLogin);
}
TasksWidget* CrontabWidget::tasksWidget() const {
return d->tasksWidget;
}
VariablesWidget* CrontabWidget::variablesWidget() const {
return d->variablesWidget;
}
CTHost* CrontabWidget::ctHost() const {
return d->ctHost;
}
void CrontabWidget::checkOtherUsers() {
d->otherUserCronRadio->setChecked(true);
refreshCron();
}
void CrontabWidget::setupActions() {
logDebug() << "Setup actions";
//Edit menu
d->cutAction = KStandardAction::cut(this, SLOT(cut()), this);
d->copyAction = KStandardAction::copy(this, SLOT(copy()), this);
d->pasteAction = KStandardAction::paste(this, SLOT(paste()), this);
togglePasteAction(false);
logDebug() << "Actions initialized";
}
QList<QAction*> CrontabWidget::cutCopyPasteActions() {
QList<QAction*> actions;
actions.append(d->cutAction);
actions.append(d->copyAction);
actions.append(d->pasteAction);
return actions;
}
void CrontabWidget::togglePasteAction(bool state) {
d->pasteAction->setEnabled(state);
}
void CrontabWidget::toggleModificationActions(bool state) {
d->cutAction->setEnabled(state);
d->copyAction->setEnabled(state);
d->tasksWidget->toggleModificationActions(state);
d->variablesWidget->toggleModificationActions(state);
}
void CrontabWidget::toggleNewEntryActions(bool state) {
d->tasksWidget->toggleNewEntryAction(state);
d->variablesWidget->toggleNewEntryAction(state);
}
void CrontabWidget::print() {
CrontabPrinter printer(this);
if (printer.start() == false) {
logDebug() << "Unable to start printer";
return;
}
printer.printTasks();
printer.printVariables();
printer.finish();
}
#include "moc_crontabWidget.cpp"

View file

@ -1,119 +0,0 @@
/***************************************************************************
* KT main view header. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KTVIEW_H
#define KTVIEW_H
#include <QWidget>
#include "tasksWidget.h"
#include "variablesWidget.h"
#include <QHBoxLayout>
class KActionCollection;
class CTHost;
class CTCron;
class CrontabWidgetPrivate;
/**
* Main GUI view of the crontab entries.
*/
class CrontabWidget : public QWidget {
Q_OBJECT
public:
/**
* Initializes view.
*/
CrontabWidget(QWidget* parent, CTHost* ctHost);
/**
* Destructor.
*/
~CrontabWidget();
TasksWidget* tasksWidget() const;
VariablesWidget* variablesWidget() const;
CTHost* ctHost() const;
CTCron* currentCron() const;
QList<QAction*> cutCopyPasteActions();
QAction* printAction();
public slots:
/**
* Copies variables and/or tasks.
*/
void copy();
void cut();
/**
* Pastes variables and/or tasks from the clipboard.
*/
void paste();
/**
* Print crontab.
*/
void print();
protected slots:
void refreshCron();
void checkOtherUsers();
private:
/**
* Enables/disables paste button
*/
void togglePasteAction(bool enabled);
/**
* Enables/disables modification buttons
*/
void toggleModificationActions(bool enabled);
/**
* Enables/disables new entry actions
*/
void toggleNewEntryActions(bool enabled);
/**
* Initialize actions.
*/
void setupActions();
/**
* Initialize view from underlying objects.
*/
void initialize();
QHBoxLayout* createCronSelector();
bool hasClipboardContent();
CrontabWidgetPrivate* const d;
};
#endif // KTVIEW_H

View file

@ -1,145 +0,0 @@
/***************************************************************************
* CT Cron Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctGlobalCron.h"
#include <QRegExp>
#include <QFile>
#include <QTextStream>
#include <QProcess>
#include <kshell.h>
#include <klocale.h>
#include <ktemporaryfile.h>
#include <klocale.h>
#include "cthost.h"
#include "cttask.h"
#include "ctvariable.h"
#include "logging.h"
CTGlobalCron::CTGlobalCron(CTHost* _ctHost) :
CTCron() {
logDebug() << "Initializing CTGlobalCron";
d->multiUserCron = true;
d->systemCron = false;
d->currentUserCron = false;
d->userLogin = i18n("All users");
ctHost = _ctHost;
}
CTGlobalCron::~CTGlobalCron() {
}
QList<CTTask*> CTGlobalCron::tasks() const {
logDebug() << "Global Cron Tasks";
QList<CTTask*> tasks;
foreach(CTCron* cron, ctHost->crons) {
if (cron->isSystemCron())
continue;
foreach(CTTask* task, cron->tasks()) {
tasks.append(task);
}
}
return tasks;
}
QList<CTVariable*> CTGlobalCron::variables() const {
logDebug() << "Global Cron Variables";
QList<CTVariable*> variables;
foreach(CTCron* cron, ctHost->crons) {
if (cron->isSystemCron())
continue;
foreach(CTVariable* variable, cron->variables()) {
variables.append(variable);
}
}
return variables;
}
void CTGlobalCron::addTask(CTTask* task) {
logDebug() << "Global Cron addTask";
CTCron* actualCron = ctHost->findUserCron(task->userLogin);
actualCron->addTask(task);
}
void CTGlobalCron::addVariable(CTVariable* variable) {
logDebug() << "Global Cron addVariable";
CTCron* actualCron = ctHost->findUserCron(variable->userLogin);
actualCron->addVariable(variable);
}
void CTGlobalCron::modifyTask(CTTask* task) {
logDebug() << "Global Cron modifyTask";
CTCron* actualCron = ctHost->findCronContaining(task);
/*
* actualCron could be NULL is the task came from clipboard because those tasks are never
* linked to an existing CTCron* object
*/
if (actualCron == NULL || actualCron->userLogin() != task->userLogin) {
if (actualCron!=NULL) {
actualCron->removeTask(task);
}
CTCron* newCron = ctHost->findUserCron(task->userLogin);
newCron->addTask(task);
}
}
void CTGlobalCron::modifyVariable(CTVariable* variable) {
logDebug() << "Global Cron modifyVariable";
CTCron* actualCron = ctHost->findCronContaining(variable);
/*
* actualCron could be NULL is the task came from clipboard because those tasks are never
* linked to an existing CTCron* object
*/
if (actualCron == NULL || actualCron->userLogin() != variable->userLogin) {
if (actualCron!=NULL) {
actualCron->removeVariable(variable);
}
CTCron* newCron = ctHost->findUserCron(variable->userLogin);
newCron->addVariable(variable);
}
}
void CTGlobalCron::removeTask(CTTask* task) {
logDebug() << "Global Cron removeTask";
CTCron* actualCron = ctHost->findCronContaining(task);
actualCron->removeTask(task);
}
void CTGlobalCron::removeVariable(CTVariable* variable) {
logDebug() << "Global Cron removeVariable";
CTCron* actualCron = ctHost->findCronContaining(variable);
actualCron->removeVariable(variable);
}

View file

@ -1,59 +0,0 @@
/***************************************************************************
* CT Cron Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CT_GLOBAL_CRON_H
#define CT_GLOBAL_CRON_H
#include <QString>
#include <QList>
#include <QStringList>
#include <QProcess>
#include "ctcron.h"
class CTTask;
class CTVariable;
class CTHost;
/**
* A user (encapsulation of a single crontab file). Encapsulates
* file i/o, parsing, tokenization, and natural language description.
*/
class CTGlobalCron : public CTCron {
public:
explicit CTGlobalCron(CTHost* ctHost);
/**
* Destructor.
*/
virtual ~CTGlobalCron();
virtual QList<CTTask*> tasks() const;
virtual QList<CTVariable*> variables() const;
virtual void addTask(CTTask* task);
virtual void addVariable(CTVariable* variable);
virtual void modifyTask(CTTask* task);
virtual void modifyVariable(CTVariable* variable);
virtual void removeVariable(CTVariable* variable);
virtual void removeTask(CTTask* task);
private:
CTHost* ctHost;
};
#endif // CT_GLOBAL_CRON_H

View file

@ -1,33 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctHelper.h"
#include <QStringList>
#include <klocale.h>
QString CTHelper::exportComment(const QString& comment) {
QString exportComment;
if (comment.isEmpty()) {
QString noComment = i18n("No comment");
exportComment += QLatin1String( "#" ) + noComment + QLatin1String( "\n" );
return exportComment;
}
QStringList lines = comment.split(QLatin1String( "\n" ));
foreach(const QString &line, lines) {
exportComment += QLatin1String( "#" ) + line + QLatin1String( "\n" );
}
return exportComment;
}

View file

@ -1,24 +0,0 @@
/***************************************************************************
* CT Hour Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CT_HELPER
#define CT_HELPER
#include <QString>
class CTHelper {
public:
static QString exportComment(const QString& comment);
};
#endif // CT_HELPER

View file

@ -1,12 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctInitializationError.h"

View file

@ -1,41 +0,0 @@
/***************************************************************************
* CT Hour Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CT_INITIALIZATION_ERROR
#define CT_INITIALIZATION_ERROR
#include <QString>
class CTInitializationError {
public:
QString errorMessage() const {
return error;
}
void setErrorMessage(const QString& errorMessage) {
this->error = errorMessage;
}
bool hasErrorMessage() {
if (error.isEmpty() == true)
return false;
return true;
}
private:
QString error;
};
#endif // CT_INITIALIZATION_ERROR

View file

@ -1,12 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctSaveStatus.h"

View file

@ -1,52 +0,0 @@
/***************************************************************************
* CT Hour Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CT_SAVE_STATUS
#define CT_SAVE_STATUS
#include <QString>
class CTSaveStatus {
public:
CTSaveStatus() {
this->errorStatus = false;
}
CTSaveStatus(const QString& errorMessage, const QString& detailErrorMessage) {
this->errorStatus = true;
this->error = errorMessage;
this->detailError = detailErrorMessage;
}
QString errorMessage() const {
return error;
}
QString detailErrorMessage() const {
return detailError;
}
bool isError() const {
return errorStatus;
}
private:
bool errorStatus;
QString error;
QString detailError;
};
#endif // CT_SAVE_STATUS

View file

@ -1,72 +0,0 @@
/***************************************************************************
* CT Cron Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctSystemCron.h"
#include <QRegExp>
#include <QFile>
#include <QTextStream>
#include <QProcess>
#include <kshell.h>
#include <klocale.h>
#include <ktemporaryfile.h>
#include <klocale.h>
#include "cthost.h"
#include "cttask.h"
#include "ctvariable.h"
#include "logging.h"
CTSystemCron::CTSystemCron(const QString& crontabBinary) :
CTCron() {
d->systemCron = true;
d->multiUserCron = true;
d->currentUserCron = false;
d->crontabBinary = crontabBinary;
KTemporaryFile tmp;
tmp.open();
d->tmpFileName = tmp.fileName();
CommandLine readCommandLine;
readCommandLine.commandLine = QLatin1String( "cat" );
readCommandLine.parameters << QLatin1String( "/etc/crontab" );
readCommandLine.standardOutputFile = d->tmpFileName;
d->writeCommandLine.commandLine = QLatin1String( "cat" );
d->writeCommandLine.parameters << d->tmpFileName;
d->writeCommandLine.standardOutputFile = QLatin1String( "/etc/crontab" );
d->userLogin = i18n("System Crontab");
d->userRealName = d->userLogin;
d->initialTaskCount = 0;
d->initialVariableCount = 0;
// Don't set error if it can't be read, it means the user
// doesn't have a crontab.
if (readCommandLine.execute().exitCode == 0) {
this->parseFile(d->tmpFileName);
}
d->initialTaskCount = d->task.size();
d->initialVariableCount = d->variable.size();
}
CTSystemCron::~CTSystemCron() {
}

View file

@ -1,49 +0,0 @@
/***************************************************************************
* CT Cron Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CT_SYSTEM_CRON_H
#define CT_SYSTEM_CRON_H
#include <QString>
#include <QList>
#include <QStringList>
#include <QProcess>
#include "ctcron.h"
class CTTask;
class CTVariable;
class CTHost;
class CTSystemCron : public CTCron {
public:
/**
* Constructs the scheduled tasks, environment variables from crontab
* files and obtains some information about the user from the system.
*
* Default is to construct from the user's crontab. Can also be called,
* passing TRUE, to construct from the system crontab. Throws an
* exception if the crontab file can not be found, read, or parsed.
*/
explicit CTSystemCron(const QString& cronBinary);
/**
* Destructor.
*/
virtual ~CTSystemCron();
};
#endif // CT_SYSTEM_CRON_H

View file

@ -1,449 +0,0 @@
/***************************************************************************
* CT Cron Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctcron.h"
#include <QRegExp>
#include <QFile>
#include <QTextStream>
#include <QProcess>
#include <QDateTime>
#include <kshell.h>
#include <klocale.h>
#include <ktemporaryfile.h>
#include <klocale.h>
#include "cttask.h"
#include "ctvariable.h"
#include "ctInitializationError.h"
#include <unistd.h> // getuid(), unlink()
#include <pwd.h> // pwd, getpwnam(), getpwuid()
#include "logging.h"
CommandLineStatus CommandLine::execute() {
QProcess process;
if (standardOutputFile.isEmpty() == false)
process.setStandardOutputFile(standardOutputFile);
int exitCode;
process.start(commandLine, parameters);
if (!process.waitForStarted()) {
exitCode = 127;
} else {
process.waitForFinished(-1);
exitCode = process.exitCode();
}
CommandLineStatus commandLineStatus;
commandLineStatus.commandLine = commandLine + QLatin1String( " " ) + parameters.join(QLatin1String( " " ));
if (standardOutputFile.isEmpty() == false)
commandLineStatus.commandLine += QLatin1String( " > " ) + standardOutputFile;
commandLineStatus.standardOutput = QLatin1String( process.readAllStandardOutput() );
commandLineStatus.standardError = QLatin1String( process.readAllStandardError() );
commandLineStatus.exitCode = exitCode;
return commandLineStatus;
}
CTCron::CTCron(const QString& crontabBinary, const struct passwd* userInfos, bool currentUserCron, CTInitializationError& ctInitializationError) :
d(new CTCronPrivate()) {
Q_ASSERT(userInfos != NULL);
d->multiUserCron = false;
d->systemCron = false;
d->currentUserCron = currentUserCron;
d->crontabBinary = crontabBinary;
KTemporaryFile tmp;
tmp.open();
d->tmpFileName = tmp.fileName();
CommandLine readCommandLine;
// regular user, so provide user's own crontab
if (currentUserCron == true) {
readCommandLine.commandLine = d->crontabBinary;
readCommandLine.parameters << QLatin1String( "-l" );
readCommandLine.standardOutputFile = d->tmpFileName;
d->writeCommandLine.commandLine = d->crontabBinary;
d->writeCommandLine.parameters << d->tmpFileName;
}
else {
readCommandLine.commandLine = d->crontabBinary;
readCommandLine.parameters << QLatin1String( "-u" ) << QLatin1String(userInfos->pw_name) << QLatin1String( "-l" );
readCommandLine.standardOutputFile = d->tmpFileName;
d->writeCommandLine.commandLine = d->crontabBinary;
d->writeCommandLine.parameters << QLatin1String( "-u" ) << QLatin1String(userInfos->pw_name) << d->tmpFileName;
}
d->initialTaskCount = 0;
d->initialVariableCount = 0;
if (initializeFromUserInfos(userInfos) == false) {
ctInitializationError.setErrorMessage(i18n("No password entry found for uid '%1'", getuid()));
logDebug() << "Error in crontab creation of" << userInfos->pw_name;
return;
}
// Don't set error if it can't be read, it means the user doesn't have a crontab.
CommandLineStatus commandLineStatus = readCommandLine.execute();
if (commandLineStatus.exitCode == 0) {
this->parseFile(d->tmpFileName);
}
else {
logDebug() << "Error when executing command" << commandLineStatus.commandLine;
logDebug() << "Standard output :" << commandLineStatus.standardOutput;
logDebug() << "Standard error :" << commandLineStatus.standardError;
}
d->initialTaskCount = d->task.size();
d->initialVariableCount = d->variable.size();
}
CTCron::CTCron() :
d(new CTCronPrivate()) {
}
bool CTCron::initializeFromUserInfos(const struct passwd* userInfos) {
if (userInfos == 0) {
return false;
} else {
d->userLogin = QLatin1String( userInfos->pw_name );
d->userRealName = QLatin1String( userInfos->pw_gecos );
return true;
}
}
CTCron& CTCron::operator = (const CTCron& source) {
if (this == &source)
return *this;
if (source.isSystemCron() == true) {
logDebug() << "Affect the system cron";
}
d->variable.clear();
foreach(CTVariable* ctVariable, source.variables()) {
CTVariable* tmp = new CTVariable(*ctVariable);
d->variable.append(tmp);
}
d->task.clear();
foreach(CTTask* ctTask, source.tasks()) {
CTTask* tmp = new CTTask(*ctTask);
d->task.append(tmp);
}
return *this;
}
void CTCron::parseFile(const QString& fileName) {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString comment;
bool leadingComment = true;
QTextStream in(&file);
while (in.atEnd() == false) {
QString line = in.readLine();
// search for comments "#" but not disabled tasks "#\"
if ( line.indexOf(QLatin1String( "#" )) == 0 && line.indexOf(QLatin1String( "\\" )) != 1 ) {
// Skip leading comments with leading spaces, those are not written by KCron
if ( leadingComment && line.startsWith(QLatin1String( "# " ))) {
continue;
}
leadingComment = false;
// If the first 10 characters don't contain a character, it's probably a disabled entry.
int firstText = line.indexOf(QRegExp(QLatin1String( "\\w" )));
if (firstText < 0)
continue;
if (firstText < 10) {
// remove leading pound sign
line = line.mid(1, line.length()-1);
if (comment.isEmpty())
comment = line.trimmed();
else
comment += QLatin1String( "\n" ) + line.trimmed();
continue;
}
}
// either a task or a variable
int firstWhiteSpace(line.indexOf(QRegExp(QLatin1String( "[ \t]" ))));
int firstEquals(line.indexOf(QLatin1String( "=" )));
// if there is an equals sign and either there is no
// whitespace or the first whitespace is after the equals
// sign, it must be a variable
if ((firstEquals > 0) && ((firstWhiteSpace == -1) || firstWhiteSpace > firstEquals)) {
// create variable
CTVariable* tmp = new CTVariable(line, comment, d->userLogin);
d->variable.append(tmp);
comment.clear();
}
// must be a task, either enabled or disabled
else {
if (firstWhiteSpace > 0) {
CTTask* tmp = new CTTask(line, comment, d->userLogin, d->multiUserCron);
d->task.append(tmp);
comment.clear();
}
}
}
}
QString CTCron::exportCron() const {
QString exportCron;
foreach(CTVariable* ctVariable, d->variable) {
exportCron += ctVariable->exportVariable();
exportCron += QLatin1String( "\n" );
}
foreach(CTTask* ctTask, d->task) {
exportCron += ctTask->exportTask();
exportCron += QLatin1String( "\n" );
}
exportCron += QLatin1String( "\n" );
QString exportInfo = i18nc("Generation Message + current date", "File generated by KCron the %1.", KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), KLocale::LongDate));
exportCron += QLatin1String( "# " ) + exportInfo + QLatin1String( "\n" );
return exportCron;
}
CTCron::~CTCron() {
foreach(CTTask* ctTask, d->task) {
delete ctTask;
}
foreach(CTVariable* ctVariable, d->variable) {
delete ctVariable;
}
delete d;
}
bool CTCron::saveToFile(const QString& fileName) {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return false;
}
//logDebug() << exportCron();
QTextStream out(&file);
out << exportCron();
out.flush();
file.close();
return true;
}
CTSaveStatus CTCron::prepareSaveStatusError(const CommandLineStatus& commandLineStatus) {
QString standardOutput;
if (commandLineStatus.standardOutput.isEmpty())
standardOutput = i18n("<em>No output.</em>");
else
standardOutput = commandLineStatus.standardOutput;
QString standardError;
if (commandLineStatus.standardError.isEmpty())
standardError = i18n("<em>No error.</em>");
else
standardError = commandLineStatus.standardError;
QString detailError;
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);
return CTSaveStatus(i18n("An error occurred while updating crontab."), detailError);
}
CTSaveStatus CTCron::save() {
// write to temp file
bool saveStatus = saveToFile(d->tmpFileName);
if (saveStatus == false) {
return CTSaveStatus(i18n("Unable to open crontab file for writing"), i18n("The file %1 could not be opened.", d->tmpFileName));
}
CommandLineStatus commandLineStatus = d->writeCommandLine.execute();
// install temp file into crontab
if (commandLineStatus.exitCode != 0) {
QFile::remove(d->tmpFileName);
return prepareSaveStatusError(commandLineStatus);
}
else {
//Remove the temp file
QFile::remove(d->tmpFileName);
}
//Mark as applied
foreach(CTTask* ctTask, d->task) {
ctTask->apply();
}
foreach(CTVariable* ctVariable, d->variable) {
ctVariable->apply();
}
d->initialTaskCount = d->task.size();
d->initialVariableCount = d->variable.size();
return CTSaveStatus();
}
void CTCron::cancel() {
foreach(CTTask* ctTask, d->task) {
ctTask->cancel();
}
foreach(CTVariable* ctVariable, d->variable) {
ctVariable->cancel();
}
}
bool CTCron::isDirty() const {
if (d->initialTaskCount != d->task.count())
return true;
if (d->initialVariableCount != d->variable.count())
return true;
foreach(CTTask* ctTask, d->task) {
if (ctTask->dirty())
return true;
}
foreach(CTVariable* ctVariable, d->variable) {
if (ctVariable->dirty())
return true;
}
return false;
}
QString CTCron::path() const {
QString path;
foreach(CTVariable* ctVariable, d->variable) {
if (ctVariable->variable == QLatin1String( "PATH" )) {
path = ctVariable->value;
}
}
return path;
}
QList<CTTask*> CTCron::tasks() const {
return d->task;
}
QList<CTVariable*> CTCron::variables() const {
return d->variable;
}
void CTCron::addTask(CTTask* task) {
if (isSystemCron()) {
task->setSystemCrontab(true);
}
else {
task->userLogin = d->userLogin;
task->setSystemCrontab(false);
}
logDebug() << "Adding task" << task->comment << " user : "<< task->userLogin;
d->task.append(task);
}
void CTCron::addVariable(CTVariable* variable) {
if (isSystemCron())
variable->userLogin = QLatin1String( "root" );
else
variable->userLogin = d->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
}
void CTCron::modifyVariable(CTVariable* /*variable*/) {
//Nothing to do specifically when modifying a variable
}
void CTCron::removeTask(CTTask* task) {
d->task.removeAll(task);
}
void CTCron::removeVariable(CTVariable* variable) {
d->variable.removeAll(variable);
}
bool CTCron::isMultiUserCron() const {
return d->multiUserCron;
}
bool CTCron::isCurrentUserCron() const {
return d->currentUserCron;
}
bool CTCron::isSystemCron() const {
return d->systemCron;
}
QString CTCron::userLogin() const {
return d->userLogin;
}
QString CTCron::userRealName() const {
return d->userRealName;
}

View file

@ -1,219 +0,0 @@
/***************************************************************************
* CT Cron Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTCRON_H
#define CTCRON_H
#include <QString>
#include <QList>
#include <QStringList>
#include <QProcess>
class CTTask;
class CTVariable;
class CTInitializationError;
struct passwd;
#include "ctSaveStatus.h"
class CommandLineStatus {
public:
int exitCode;
QString commandLine;
QString standardOutput;
QString standardError;
};
class CommandLine {
public:
QString commandLine;
QStringList parameters;
QString standardOutputFile;
CommandLineStatus execute();
};
class CTCronPrivate {
public:
/**
* Indicates whether or not the crontab belongs to the system.
*/
bool systemCron;
/**
* Indicates if this cron could have tasks and variables from different user
*/
bool multiUserCron;
/**
* Indicates whether or not the crontab belongs to the current user.
*/
bool currentUserCron;
/**
* User login.
*/
QString userLogin;
/**
* User real name.
*/
QString userRealName;
/**
* User's scheduled tasks.
*/
QList<CTTask *> task;
/**
* User's environment variables. Note: These are only environment variables
* found in the user's crontab file and does not include any set in a
* login or shell script such as ".bash_profile".
*/
QList<CTVariable *> variable;
int initialTaskCount;
int initialVariableCount;
CommandLine writeCommandLine;
QString tmpFileName;
/**
* Contains path to the crontab binary file
*/
QString crontabBinary;
};
/**
* A user (encapsulation of a single crontab file). Encapsulates
* file i/o, parsing, tokenization, and natural language description.
*/
class CTCron {
public:
/**
* If you already have a struct passwd, use it instead. This
* is never used for the system crontab.
*/
explicit CTCron(const QString& cronBinary, const struct passwd* userInfos, bool currentUserCron, CTInitializationError& ctInitializationError);
/**
* Destructor.
*/
virtual ~CTCron();
/**
* Copy one user's tasks and environement variables to another user.
*/
CTCron& operator =(const CTCron& source);
virtual QList<CTTask*> tasks() const;
virtual QList<CTVariable*> variables() const;
virtual void addTask(CTTask* task);
virtual void addVariable(CTVariable* variable);
virtual void modifyTask(CTTask* task);
virtual void modifyVariable(CTVariable* variable);
virtual void removeVariable(CTVariable* variable);
virtual void removeTask(CTTask* task);
/**
* Tokenizes to crontab file format.
*/
QString exportCron() const;
/**
* Apply changes.
*/
CTSaveStatus save();
/**
* Cancel changes.
*/
void cancel();
/**
* Indicates whether or not dirty.
*/
bool isDirty() const;
/**
* Returns the PATH environment variable value. A short cut to iterating
* the tasks vector.
*/
QString path() const;
/**
* Returns true if this cron could have tasks and variables from different user
*/
bool isMultiUserCron() const;
/**
* Returns true if this cron is the system cron
*/
bool isSystemCron() const;
/**
* Returns true if this cron is the cron of the user who launches this app
*/
bool isCurrentUserCron() const;
QString userLogin() const;
/**
* Bugged method for the moment (need to parse x,x,x,x data from /etc/passwd)
*/
QString userRealName() const;
protected:
/**
* Help constructor for subclasses
*/
explicit CTCron();
// Initialize member variables from the struct passwd.
bool initializeFromUserInfos(const struct passwd* userInfos);
private:
/**
* Can't copy a user!
*/
CTCron(const CTCron& source);
CTSaveStatus prepareSaveStatusError(const CommandLineStatus& commandLineStatus);
protected:
/**
* Parses crontab file format.
*/
void parseFile(const QString& fileName);
bool saveToFile(const QString& fileName);
CTCronPrivate* const d;
};
#endif // CTCRON_H

View file

@ -1,36 +0,0 @@
/***************************************************************************
* CT Day of Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctdom.h"
#include <klocale.h>
QList<QString> CTDayOfMonth::shortName;
CTDayOfMonth::CTDayOfMonth(const QString& tokStr) :
CTUnit(CTDayOfMonth::MINIMUM, CTDayOfMonth::MAXIMUM, tokStr) {
}
QString CTDayOfMonth::describe() const {
initializeNames();
return (enabledCount() == CTDayOfMonth::MAXIMUM) ? i18n("every day ") : CTUnit::genericDescribe(shortName);
}
QString CTDayOfMonth::getName(const int ndx) {
initializeNames();
return shortName[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");
}
}

View file

@ -1,47 +0,0 @@
/***************************************************************************
* CT Day of Month Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTDOM_H
#define CTDOM_H
#include <QString>
#include <QList>
#include "ctunit.h"
/**
* Scheduled task days of month.
*/
class CTDayOfMonth : public CTUnit {
public:
/**
* Constructs from a tokenized string.
*/
CTDayOfMonth(const QString& tokStr = QLatin1String(""));
/**
* Get natural language description.
*/
virtual QString describe() const;
/**
* Get day of month name.
*/
static QString getName(const int ndx);
static const int MINIMUM = 1;
static const int MAXIMUM = 31;
private:
static void initializeNames();
static QList<QString> shortName;
};
#endif // CTDOM_H

View file

@ -1,61 +0,0 @@
/***************************************************************************
* CT Day Of Week Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctdow.h"
#include <klocale.h>
QList<QString> CTDayOfWeek::shortName;
QList<QString> CTDayOfWeek::longName;
CTDayOfWeek::CTDayOfWeek(const QString& tokStr) :
CTUnit(CTDayOfWeek::MINIMUM, CTDayOfWeek::MAXIMUM, tokStr) {
// Compensate for cron supporting Sunday as both 0 and 7.
if (isEnabled(0)) {
setEnabled(0, false);
setEnabled(7, true);
}
}
void CTDayOfWeek::initialize(const QString &tokStr) {
CTUnit::initialize(tokStr);
// Compensate for cron supporting Sunday as both 0 and 7.
if (isEnabled(0)) {
setEnabled(0, false);
setEnabled(7, true);
apply();
}
}
QString CTDayOfWeek::describe() const {
initializeNames();
if (enabledCount() == CTDayOfWeek::MAXIMUM)
return i18n("every day ");
else
return CTUnit::genericDescribe(shortName);
}
QString CTDayOfWeek::getName(const int ndx, const bool format) {
initializeNames();
return (format == shortFormat) ? shortName[ndx] : longName[ndx];
}
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");
}
}

View file

@ -1,55 +0,0 @@
/***************************************************************************
* CT Day of Week Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTDOW_H
#define CTDOW_H
#include <QString>
#include <QList>
#include "ctunit.h"
/**
* Scheduled task days of week.
*/
class CTDayOfWeek : public CTUnit {
public:
/**
* Constructs from a tokenized string.
*/
CTDayOfWeek(const QString& tokStr = QLatin1String(""));
/**
* Override initialize to support crontab using both 0 and 7 for
* Sunday.
*/
void initialize(const QString& tokStr = QLatin1String(""));
/**
* Get natural language description.
*/
virtual QString describe() const;
/**
* Get day of week name.
*/
static QString getName(const int ndx, const bool format = CTDayOfWeek::longFormat);
static const int MINIMUM = 1;
static const int MAXIMUM = 7;
private:
static void initializeNames();
static QList<QString> shortName;
static QList<QString> longName;
};
#endif // CTDOW_H

View file

@ -1,249 +0,0 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* CT Host Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "cthost.h"
#include <unistd.h> // getuid()
#include <sys/types.h>
#include <pwd.h>
#include <QFile>
#include <QTextStream>
#include <klocale.h>
#include "ctcron.h"
#include "ctSystemCron.h"
#include "ctInitializationError.h"
#include "logging.h"
CTHost::CTHost(const QString& cronBinary, CTInitializationError& ctInitializationError) {
struct passwd* userInfos = NULL;
this->crontabBinary = cronBinary;
// If it is the root user
if (getuid() == 0) {
// Read /etc/passwd
setpwent(); // restart
while ((userInfos=getpwent())) {
if (allowDeny(userInfos->pw_name)) {
QString errorMessage = createCTCron(userInfos);
if (errorMessage.isEmpty()==false) {
ctInitializationError.setErrorMessage(errorMessage);
return;
}
}
//delete userInfos;
}
setpwent(); // restart again for others
}
// Non-root user, so just create user's cron table.
else {
// Get name from UID, check it against AllowDeny()
unsigned int uid = getuid();
setpwent(); // restart
while ((userInfos=getpwent())) {
if ((userInfos->pw_uid == uid) && (!allowDeny(userInfos->pw_name))) {
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.")
);
return;
}
//delete userInfos;
}
setpwent(); // restart again for others
passwd* currentUserPassword = getpwuid(uid);
QString errorMessage = createCTCron(currentUserPassword);
if (errorMessage.isEmpty()==false) {
ctInitializationError.setErrorMessage(errorMessage);
return;
}
//delete currentUserPassword;
}
// Create the system cron table.
createSystemCron();
}
CTHost::~CTHost() {
foreach(CTCron* ctCron, crons) {
delete ctCron;
}
}
bool CTHost::allowDeny(char *name) {
QFile allow(QLatin1String( "/etc/cron.allow" ));
// if cron.allow exists make sure user is listed
if (allow.open(QFile::ReadOnly)) {
QTextStream stream(&allow);
while (!stream.atEnd()) {
if (stream.readLine() == QLatin1String( name )) {
allow.close();
return true;
}
}
allow.close();
return false;
} else {
allow.close();
QFile deny(QLatin1String( "/etc/cron.deny" ));
// else if cron.deny exists make sure user is not listed
if (deny.open(QFile::ReadOnly)) {
QTextStream stream(&deny);
while (!stream.atEnd()) {
if (stream.readLine() == QLatin1String( name )) {
deny.close();
return false;
}
}
deny.close();
return true;
} else {
deny.close();
return true;
}
}
}
CTSaveStatus CTHost::save() {
if (isRootUser() == false) {
logDebug() << "Save current user cron";
CTCron* ctCron = findCurrentUserCron();
return ctCron->save();
}
foreach(CTCron* ctCron, crons) {
CTSaveStatus ctSaveStatus = ctCron->save();
if (ctSaveStatus.isError() == true) {
return CTSaveStatus(i18nc("User login: errorMessage", "User %1: %2", ctCron->userLogin(), ctSaveStatus.errorMessage()), ctSaveStatus.detailErrorMessage());
}
}
return CTSaveStatus();
}
void CTHost::cancel() {
foreach(CTCron* ctCron, crons) {
ctCron->cancel();
}
}
bool CTHost::isDirty() {
bool isDirty = false;
foreach(CTCron* ctCron, crons) {
if (ctCron->isDirty()) {
isDirty = true;
}
}
return isDirty;
}
CTCron* CTHost::createSystemCron() {
CTCron* p = new CTSystemCron(crontabBinary);
crons.append(p);
return p;
}
QString CTHost::createCTCron(const struct passwd* userInfos) {
bool currentUserCron = false;
if (userInfos->pw_uid == getuid())
currentUserCron = true;
CTInitializationError ctInitializationError;
CTCron* p = new CTCron(crontabBinary, userInfos, currentUserCron, ctInitializationError);
if (ctInitializationError.hasErrorMessage()) {
delete p;
return ctInitializationError.errorMessage();
}
crons.append(p);
return QString();
}
CTCron* CTHost::findCurrentUserCron() const {
foreach(CTCron* ctCron, crons) {
if (ctCron->isCurrentUserCron())
return ctCron;
}
logDebug() << "Unable to find the current user Cron. Please report this bug and your crontab config to the developers";
return NULL;
}
CTCron* CTHost::findSystemCron() const {
foreach(CTCron* ctCron, crons) {
if (ctCron->isMultiUserCron())
return ctCron;
}
logDebug() << "Unable to find the system Cron. Please report this bug and your crontab config to the developers";
return NULL;
}
CTCron* CTHost::findUserCron(const QString& userLogin) const {
foreach(CTCron* ctCron, crons) {
if (ctCron->userLogin() == userLogin)
return ctCron;
}
logDebug() << "Unable to find the user Cron " << userLogin << ". Please report this bug and your crontab config to the developers";
return NULL;
}
CTCron* CTHost::findCronContaining(CTTask* ctTask) const {
foreach(CTCron* ctCron, crons) {
if (ctCron->tasks().contains(ctTask) == true) {
return ctCron;
}
}
logDebug() << "Unable to find the cron of this task. Please report this bug and your crontab config to the developers";
return NULL;
}
CTCron* CTHost::findCronContaining(CTVariable* ctVariable) const {
foreach(CTCron* ctCron, crons) {
if (ctCron->variables().contains(ctVariable) == true) {
return ctCron;
}
}
logDebug() << "Unable to find the cron of this variable. Please report this bug and your crontab config to the developers";
return NULL;
}
bool CTHost::isRootUser() const {
return (getuid() == 0);
}

View file

@ -1,119 +0,0 @@
/***************************************************************************
* CT Host Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTHOST_H
#define CTHOST_H
#include <QString>
#include <QList>
#include "ctSaveStatus.h"
class CTTask;
class CTVariable;
class CTCron;
class CTInitializationError;
struct passwd;
/**
* The host machine, or computer (encapsulation of crontab files on the
* host).
*
* If the user is the root user, the cron vector will have a member for
* each user of the host plus one for the system crontab.
*
* If the user is a non-root user, there will be only one member in the
* cron vector.
*/
class CTHost {
public:
/**
* Constructs the user(s), scheduled tasks, and environment variables
* from crontab files.
*/
CTHost(const QString& cronBinary, CTInitializationError& ctInitializationError);
/**
* Destroys the user(s), scheduled tasks, and environment variable
* objects. Does not make any changes to the crontab files. Any unapplied
* changes are consequently "cancelled."
*/
~CTHost();
/**
* Apply changes.
* return an empty string if no problem
*/
CTSaveStatus save();
/**
* Cancel changes.
*/
void cancel();
/**
* Indicates whether or not dirty.
*/
bool isDirty();
/**
* Indicates whether or not the user is the root user.
*/
bool isRootUser() const;
CTCron* findCurrentUserCron() const;
CTCron* findSystemCron() const;
CTCron* findUserCron(const QString& userLogin) const;
CTCron* findCronContaining(CTTask* ctTask) const;
CTCron* findCronContaining(CTVariable* ctVariable) const;
/**
* User(s).
*
* If the user is the root user, the cron vector will have a member for
* each user of the host plus one for the system crontab.
*
* If the user is a non-root user, there will be only one member in the
* cron vector.
*/
QList<CTCron*> crons;
private:
/**
* Copy construction not allowed.
*/
CTHost(const CTHost& source);
/**
* Assignment not allowed
*/
CTHost& operator =(const CTHost& source);
/**
* Factory create a cron table. Appends to the end of cron.
*/
CTCron* createSystemCron();
CTCron* createCurrentUserCron();
QString createCTCron(const struct passwd* password);
/**
* Check /etc/cron.allow, /etc/cron.deny
*/
bool allowDeny(char *name);
QString crontabBinary;
};
#endif // CTHOST_H

View file

@ -1,37 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "cthour.h"
#include <klocale.h>
/**
* Constructs from a tokenized string.
*/
CTHour::CTHour(const QString& tokStr) :
CTUnit(0, 23, tokStr) {
}
int CTHour::findPeriod() const {
QList<int> periods;
periods << 2 << 3 << 4 << 6 << 8;
return CTUnit::findPeriod(periods);
}
QString CTHour::exportUnit() const {
int period = findPeriod();
if (period!=0 && period!=1)
return QString(QLatin1String( "*/%1" )).arg(QString::number(period));
return CTUnit::exportUnit();
}

View file

@ -1,33 +0,0 @@
/***************************************************************************
* CT Hour Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTHOUR_H
#define CTHOUR_H
#include "ctunit.h"
/**
* Scheduled task hours.
*/
class CTHour : public CTUnit {
public:
/**
* Constructs from a tokenized string.
*/
CTHour(const QString& tokStr = QLatin1String(""));
int findPeriod() const;
QString exportUnit() const;
};
#endif // CTHOUR_H

View file

@ -1,41 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctminute.h"
#include <klocale.h>
/**
* Constructs from a tokenized string.
*/
CTMinute::CTMinute(const QString& tokStr) :
CTUnit(0, 59, tokStr) {
}
CTMinute::CTMinute() :
CTUnit(0, 59, QLatin1String( "" )) {
}
int CTMinute::findPeriod() const {
QList<int> periods;
periods << 1 << 2 << 5 << 10 << 15 << 20 << 30;
return CTUnit::findPeriod(periods);
}
QString CTMinute::exportUnit() const {
int period = findPeriod();
if (period!=0 && period!=1)
return QString(QLatin1String( "*/%1" )).arg(QString::number(period));
return CTUnit::exportUnit();
}

View file

@ -1,36 +0,0 @@
/***************************************************************************
* CT Minute Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTMINUTE_H
#define CTMINUTE_H
#include "ctunit.h"
/**
* Scheduled task minutes.
*/
class CTMinute : public CTUnit {
public:
/**
* Constructs from a tokenized string.
*/
CTMinute(const QString& tokStr);
CTMinute();
int findPeriod() const;
QString exportUnit() const;
};
#endif // CTMINUTE_H

View file

@ -1,35 +0,0 @@
/***************************************************************************
* CT Month Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctmonth.h"
#include <klocale.h>
QList<QString> CTMonth::shortName;
CTMonth::CTMonth(const QString& tokStr) :
CTUnit(CTMonth::MINIMUM, CTMonth::MAXIMUM, tokStr) {
}
QString CTMonth::describe() const {
initializeNames();
return (enabledCount() == CTMonth::MAXIMUM) ? i18n("every month") : CTUnit::genericDescribe(shortName);
}
QString CTMonth::getName(const int ndx) {
initializeNames();
return shortName[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");
}
}

View file

@ -1,48 +0,0 @@
/***************************************************************************
* CT Month Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTMONTH_H
#define CTMONTH_H
#include <QString>
#include <QList>
#include "ctunit.h"
/**
* Scheduled task months.
*/
class CTMonth : public CTUnit {
public:
/**
* Constructs from a tokenized string.
*/
CTMonth(const QString& tokStr = QLatin1String(""));
/**
* Get natural language description.
*/
virtual QString describe() const;
/**
* Get month name.
*/
static QString getName(const int ndx);
static const int MINIMUM = 1;
static const int MAXIMUM = 12;
private:
static void initializeNames();
static QList<QString> shortName;
};
#endif // CTMONTH_H

View file

@ -1,462 +0,0 @@
/***************************************************************************
* CT Task Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "cttask.h"
#include <klocale.h>
#include <kiconloader.h>
#include <kmimetype.h>
#include "ctHelper.h"
#include "kcronIcons.h"
#include "logging.h"
CTTask::CTTask(const QString& tokenString, const QString& _comment, const QString& _userLogin, bool _systemCrontab) :
systemCrontab(_systemCrontab) {
QString tokStr = tokenString;
if (tokStr.mid(0, 2) == QLatin1String( "#\\" )) {
tokStr = tokStr.mid(2, tokStr.length() - 2);
enabled = false;
} else if (tokStr.mid(0, 1) == QLatin1String( "#" )) {
tokStr = tokStr.mid(1, tokStr.length() - 1);
enabled = false;
} else
enabled = true;
// Skip over 'silence' if found... old option in vixie cron
if (tokStr.mid(0, 1) == QLatin1String( "-" ))
tokStr = tokStr.mid(1, tokStr.length() - 1);
reboot = false;
if (tokStr.mid(0, 1) == QLatin1String( "@" )) {
if (tokStr.mid(1, 6) == QLatin1String( "yearly" )) {
tokStr = QLatin1String( "0 0 1 1 *" )+tokStr.mid(7, tokStr.length()-1);
} else if (tokStr.mid(1, 8) == QLatin1String( "annually" )) {
tokStr = QLatin1String( "0 0 1 1 *" )+tokStr.mid(9, tokStr.length()-1);
} else if (tokStr.mid(1, 7) == QLatin1String( "monthly" )) {
tokStr = QLatin1String( "0 0 1 * *" )+tokStr.mid(8, tokStr.length()-1);
} else if (tokStr.mid(1, 6) == QLatin1String( "weekly" )) {
tokStr = QLatin1String( "0 0 * * 0" )+tokStr.mid(7, tokStr.length()-1);
} else if (tokStr.mid(1, 5) == QLatin1String( "daily" )) {
tokStr = QLatin1String( "0 0 * * *" )+tokStr.mid(6, tokStr.length()-1);
} else if (tokStr.mid(1, 6) == QLatin1String( "hourly" )) {
tokStr = QLatin1String( "0 * * * *" )+tokStr.mid(7, tokStr.length()-1);
} else if (tokStr.mid(1, 6) == QLatin1String( "reboot" )) {
tokStr = tokStr.mid(7, tokStr.length()-1);
reboot = true;
}
}
int spacePos(tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" ))));
// If reboot bypass initialize functions so no keys selected in modify task
if (reboot == false) {
//logDebug() << "Line : " << tokStr;
minute.initialize(tokStr.mid(0, spacePos));
while (isSpace(tokStr, spacePos+1))
spacePos++;
tokStr = tokStr.mid(spacePos+1, tokStr.length()-1);
spacePos = tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" )));
hour.initialize(tokStr.mid(0, spacePos));
while (isSpace(tokStr, spacePos+1))
spacePos++;
tokStr = tokStr.mid(spacePos+1, tokStr.length()-1);
spacePos = tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" )));
dayOfMonth.initialize(tokStr.mid(0, spacePos));
while (isSpace(tokStr, spacePos+1))
spacePos++;
tokStr = tokStr.mid(spacePos+1, tokStr.length()-1);
spacePos = tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" )));
month.initialize(tokStr.mid(0, spacePos));
while (isSpace(tokStr, spacePos+1))
spacePos++;
tokStr = tokStr.mid(spacePos+1, tokStr.length()-1);
spacePos = tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" )));
dayOfWeek.initialize(tokStr.mid(0, spacePos));
}
if (systemCrontab) {
while (isSpace(tokStr, spacePos+1))
spacePos++;
tokStr = tokStr.mid(spacePos+1, tokStr.length()-1);
spacePos = tokStr.indexOf(QRegExp(QLatin1String( "[ \t]" )));
userLogin = tokStr.mid(0, spacePos);
}
else {
userLogin = _userLogin;
}
command = tokStr.mid(spacePos+1, tokStr.length()-1);
// remove leading whitespace
while (command.indexOf(QRegExp(QLatin1String( "[ \t]" ))) == 0)
command = command.mid(1, command.length()-1);
comment = _comment;
initialUserLogin = userLogin;
initialCommand = command;
initialComment = comment;
initialEnabled = enabled;
initialReboot = reboot;
}
CTTask::CTTask(const CTTask &source) :
month(source.month), dayOfMonth(source.dayOfMonth), dayOfWeek(source.dayOfWeek), hour(source.hour), minute(source.minute), userLogin(source.userLogin), command(source.command), comment(source.comment), enabled(source.enabled), reboot(source.reboot), initialUserLogin(QLatin1String( "" )), initialCommand(QLatin1String( "" )),
initialComment(QLatin1String( "" )), initialEnabled(true), initialReboot(false) {
}
CTTask& CTTask::operator = (const CTTask& source) {
if (this == &source)
return *this;
month = source.month;
dayOfMonth = source.dayOfMonth;
dayOfWeek = source.dayOfWeek;
hour = source.hour;
minute = source.minute;
userLogin = source.userLogin;
command = source.command;
comment = source.comment;
enabled = source.enabled;
reboot = source.reboot;
initialUserLogin = QLatin1String( "" );
initialCommand = QLatin1String( "" );
initialComment = QLatin1String( "" );
initialEnabled = true;
initialReboot = false;
return *this;
}
QString CTTask::exportTask() {
QString exportTask;
exportTask += CTHelper::exportComment(comment);
if (enabled == false)
exportTask += QLatin1String( "#\\" );
exportTask += schedulingCronFormat();
exportTask += QLatin1String( "\t" );
if (isSystemCrontab() == true)
exportTask += userLogin + QLatin1String( "\t" );
exportTask += command + QLatin1String( "\n" );
return exportTask;
}
void CTTask::apply() {
month.apply();
dayOfMonth.apply();
dayOfWeek.apply();
hour.apply();
minute.apply();
initialUserLogin = userLogin;
initialCommand = command;
initialComment = comment;
initialEnabled = enabled;
initialReboot = reboot;
}
void CTTask::cancel() {
month.cancel();
dayOfMonth.cancel();
dayOfWeek.cancel();
hour.cancel();
minute.cancel();
userLogin = initialUserLogin;
command = initialCommand;
comment = initialComment;
enabled = initialEnabled;
reboot = initialReboot;
}
bool CTTask::dirty() const {
return (month.isDirty() || dayOfMonth.isDirty() || dayOfWeek.isDirty() || hour.isDirty() || minute.isDirty() || (userLogin != initialUserLogin) || (command != initialCommand) || (comment != initialComment) || (enabled != initialEnabled) || (reboot != initialReboot));
}
QString CTTask::schedulingCronFormat() const {
if (reboot) {
return QLatin1String( "@reboot" );
}
QString scheduling;
scheduling += minute.exportUnit() + QLatin1String( " " );
scheduling += hour.exportUnit() + QLatin1String( " " );
scheduling += dayOfMonth.exportUnit() + QLatin1String( " " );
scheduling += month.exportUnit() + QLatin1String( " " );
scheduling += dayOfWeek.exportUnit();
return scheduling;
}
/**
* Of the whole program, this method is probably the trickiest.
*
* This method creates the natural language description, such as
* "At 1:00am, every Sun".
*
* First, I declare some strings for holding what can be internationalized.
* Note the tokens such as "MONTHS". Translators should reuse these
* tokens in their translations. See README.translators for more
* information.
*
* Second, I get the descriptions from the component parts such as
* days of the month.
*
* Third, I get hour/minute time combinations. Although a little bit
* awkward, I use the tm struct and strftime from <time.h>. This
* way this code is portable across all Unixes.
*
* Fourth, I know that "every day of the week" and "every day of the
* month" simply makes "every day".
*
* Fifth and finally I do tag substitution to create the natural language
* description.
*
*/
QString CTTask::describe() const {
if (reboot) {
return i18n("At system startup");
}
QString dateFormat = createDateFormat();
QString timeFormat = createTimeFormat();
return i18nc("1:Time Description, 2:Date Description", "%1, %2", timeFormat, dateFormat);
}
QString CTTask::describeDayOfWeek() const {
return i18nc("Every 'days of week'", "every %1", dayOfWeek.describe());
}
QString CTTask::describeDayOfMonth() const {
return i18nc("'Days of month' of 'Months'", "%1 of %2", dayOfMonth.describe(), month.describe());
}
QString CTTask::createDateFormat() const {
/*
* "* * *" means truly every day.
* Note: Languages may use different phrases to indicate
* every day of month versus every day of week.
*/
QString dateFormat;
if ((dayOfMonth.enabledCount() == CTDayOfMonth::MAXIMUM) && (dayOfWeek.enabledCount() == CTDayOfWeek::MAXIMUM)) {
dateFormat = i18n("every day ");
}
// Day of month not specified, so use day of week.
else if (dayOfMonth.enabledCount() == CTDayOfMonth::MAXIMUM) {
dateFormat = describeDayOfWeek();
}
// Day of week not specified, so use day of month.
else if (dayOfWeek.enabledCount() == CTDayOfWeek::MAXIMUM) {
dateFormat = describeDayOfMonth();
}
else {
dateFormat = i18nc("1:Day of month, 2:Day of week", "%1 as well as %2", describeDayOfMonth(), describeDayOfWeek());
}
return dateFormat;
}
QString CTTask::describeDateAndHours() const {
// Create time description.
int total = minute.enabledCount() * hour.enabledCount();
QString timeDesc;
int count = 0;
for (int h = 0; h <= 23; h++) {
if (hour.isEnabled(h)) {
for (int m = 0; m <= 59; m++) {
if (minute.isEnabled(m) == true) {
QString hourString;
if (h<10)
hourString = QLatin1String( "0" ) + QString::number(h);
else
hourString = QString::number(h);
QString minuteString;
if (m<10)
minuteString = QLatin1String( "0" ) + QString::number(m);
else
minuteString = QString::number(m);
QString tmpStr = i18nc("1:Hour, 2:Minute", "%1:%2", hourString, minuteString);
timeDesc += tmpStr;
count++;
switch (total - count) {
case 0:
break;
case 1:
if (total > 2)
timeDesc += i18n(", and ");
else
timeDesc += i18n(" and ");
break;
default:
timeDesc += i18n(", ");
}
}
}
}
}
return i18nc("Hour::Minute list", "At %1", timeDesc);
}
QString CTTask::createTimeFormat() const {
if (hour.isAllEnabled()) {
int minutePeriod = minute.findPeriod();
if (minutePeriod != 0)
return i18np("Every minute", "Every %1 minutes", minutePeriod);
}
return describeDateAndHours();
}
bool CTTask::isSystemCrontab() const {
return systemCrontab;
}
void CTTask::setSystemCrontab(bool _systemCrontab) {
systemCrontab = _systemCrontab;
}
QPixmap CTTask::commandIcon() const {
KUrl commandPath(completeCommandPath());
KMimeType::Ptr mimeType = KMimeType::findByUrl(commandPath);
//logDebug() << mimeType->name();
if (mimeType->name() == QLatin1String( "application/x-executable" ) || mimeType->name() == QLatin1String( "application/octet-stream" )) {
//The next line is identical as SmallIcon(commandPath.fileName()), but is able to return a isNull() QPixmap
QPixmap icon = KIconLoader::global()->loadIcon(commandPath.fileName(), KIconLoader::Small, 0, KIconLoader::DefaultState, QStringList(), 0L, true);
if (icon.isNull()) {
return KCronIcons::task(KCronIcons::Small);
}
return icon;
}
QPixmap icon = SmallIcon(KMimeType::iconNameForUrl(commandPath));
return icon;
}
QPair<QString, bool> CTTask::unQuoteCommand() const {
QString fullCommand = command;
fullCommand = fullCommand.trimmed();
QStringList quotes;
quotes << QLatin1String( "\"" ) << QLatin1String( "'" );
foreach(const QString &quote, quotes) {
if (fullCommand.indexOf(quote) == 0) {
int nextQuote = fullCommand.indexOf(quote, 1);
if (nextQuote == -1)
return QPair<QString, bool>(QLatin1String( "" ), false);
return QPair<QString, bool>(fullCommand.mid(1, nextQuote-1), true);
}
}
return QPair<QString, bool>(fullCommand, false);
}
QString CTTask::decryptBinaryCommand(const QString& command) const {
QString fullCommand;
bool found = false;
for (int i=0; i<command.length(); ++i) {
if (command.at(i) == QLatin1Char( ' ' ) && command.at(i-1) != QLatin1Char( '\\' )) {
fullCommand = command.left(i);
found = true;
break;
}
}
if (found == false)
fullCommand = command;
fullCommand = fullCommand.remove(QLatin1Char( '\\' ));
return fullCommand;
}
QStringList CTTask::separatePathCommand(const QString& command, bool quoted) const {
QStringList pathCommand;
if (command.at(0) == QLatin1Char( '/' )) {
QString fullCommand;
if (quoted == true)
fullCommand = command;
else
fullCommand = decryptBinaryCommand(command);
if (fullCommand.isEmpty()) {
return QStringList();
}
QString path = fullCommand.section(QLatin1Char( '/' ), 0, -2);
QString commandBinary = fullCommand.section(QLatin1Char( '/' ), -1);
pathCommand << path << commandBinary;
}
else {
QString fullCommand;
if (quoted == true)
fullCommand = command;
else
fullCommand = decryptBinaryCommand(command);
// relying on $PATH
pathCommand << QString() << fullCommand;
}
return pathCommand;
}
QString CTTask::completeCommandPath() const {
QPair<QString, bool> commandQuoted = unQuoteCommand();
if (commandQuoted.first.isEmpty())
return QLatin1String( "" );
QStringList pathCommand = separatePathCommand(commandQuoted.first, commandQuoted.second);
if (pathCommand.isEmpty()) {
return QLatin1String( "" );
}
return pathCommand.join(QLatin1String( "/" ));
}

View file

@ -1,137 +0,0 @@
/***************************************************************************
* CT Task Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTTASK_H
#define CTTASK_H
#include <QString>
#include <QPair>
#include <QStringList>
#include <QPixmap>
#include "ctmonth.h"
#include "ctdom.h"
#include "ctdow.h"
#include "cthour.h"
#include "ctminute.h"
/**
* A scheduled task (encapsulation of crontab entry). Encapsulates
* parsing, tokenization, and natural language description.
*/
class CTTask {
public:
/**
* Constructs scheduled task from crontab format string.
*/
explicit CTTask(const QString& tokenString, const QString& _comment, const QString& _userLogin, bool syscron = false);
/**
* Copy constructor.
*/
CTTask(const CTTask& source);
/**
* Assignment operator.
*/
CTTask& operator =(const CTTask& source);
/**
* Tokenizes scheduled task to crontab format.
*/
QString exportTask();
/**
* Scheduling using the cron format
*/
QString schedulingCronFormat() const;
/**
* Mark changes as applied.
*/
void apply();
/**
* Cancel changes.
*/
void cancel();
/**
* Indicates whether or not the task has been modified.
*/
bool dirty() const;
/**
* Returns natural language description of the task's schedule.
*/
QString describe() const;
/**
* Indicates whether or not the task belongs to the system crontab.
*/
bool isSystemCrontab() const;
void setSystemCrontab(bool systemCrontab);
QPixmap commandIcon() const;
/**
* Internal methods
*/
QPair<QString, bool> unQuoteCommand() const;
QStringList separatePathCommand(const QString& command, bool quoted) const;
QString decryptBinaryCommand(const QString& command) const;
QString completeCommandPath() const;
CTMonth month;
CTDayOfMonth dayOfMonth;
CTDayOfWeek dayOfWeek;
CTHour hour;
CTMinute minute;
QString userLogin;
QString command;
QString comment;
bool enabled;
bool reboot;
private:
inline bool isSpace(const QString& token, int pos) {
if (pos >= token.length())
return false;
if (token.at(pos) == QLatin1Char( ' ' ) )
return true;
return false;
}
QString describeDayOfMonth() const;
QString describeDayOfWeek() const;
QString describeDateAndHours() const;
QString createTimeFormat() const;
QString createDateFormat() const;
bool systemCrontab;
QString initialUserLogin;
QString initialCommand;
QString initialComment;
bool initialEnabled;
bool initialReboot;
};
#endif // CTTASK_H

View file

@ -1,290 +0,0 @@
/***************************************************************************
* CT Unit of Time Interval Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctunit.h"
#include <klocale.h>
#include "logging.h"
CTUnit::CTUnit(int _min, int _max, const QString& tokStr) {
min = _min;
max = _max;
initialize(tokStr);
}
CTUnit::CTUnit(const CTUnit& source) {
min = source.min;
max = source.max;
initialEnabled.clear();
enabled.clear();
for (int i = 0; i <= max; i++) {
initialEnabled.append(false);
enabled.append(source.enabled.at(i));
}
initialTokStr = QLatin1String( "" );
dirty = true;
}
CTUnit::~CTUnit() {
}
CTUnit& CTUnit::operator = (const CTUnit& unit) {
if (this == &unit)
return *this;
min = unit.min;
max = unit.max;
enabled.clear();
for (int i = 0; i <= max; i++) {
enabled.append(unit.enabled[i]);
}
dirty = true;
return *this;
}
void CTUnit::initialize(const QString& tokStr) {
enabled.clear();
for (int i = 0; i <= max; i++) {
enabled.append(false);
initialEnabled.append(false);
}
for (int i = min; i <= max; i++) {
initialEnabled[i] = enabled[i];
}
parse(tokStr);
initialTokStr = tokStr;
dirty = false;
}
void CTUnit::parse(const QString& tokenString) {
QString tokStr = tokenString;
// subelement is that which is between commas
QString subelement;
int commapos, slashpos, dashpos;
int beginat, endat, step;
// loop through each subelement
tokStr += QLatin1Char( ',' );
while ((commapos = tokStr.indexOf(QLatin1String( "," ))) > 0) {
subelement = tokStr.mid(0, commapos);
// find "/" to determine step
slashpos = subelement.indexOf(QLatin1String( "/" ));
if (slashpos == -1) {
step = 1;
slashpos = subelement.length();
} else {
step = fieldToValue(subelement.mid(slashpos+1, subelement.length()-slashpos-1));
if (step < 1)
step = 1;
}
// find "=" to determine range
dashpos = subelement.indexOf(QLatin1String( "-" ));
if (dashpos == -1) {
// deal with "*"
if (subelement.mid(0, slashpos) == QLatin1String( "*" )) {
beginat = min;
endat = max;
} else {
beginat = fieldToValue(subelement.mid(0, slashpos));
endat = beginat;
}
} else {
beginat = fieldToValue(subelement.mid(0, dashpos));
endat = fieldToValue(subelement.mid(dashpos+1, slashpos-dashpos-1));
}
// ignore out of range
if (beginat < 0)
beginat = 0;
if (endat > max)
endat = max;
// setup enabled
for (int i = beginat; i <= endat; i+=step) {
initialEnabled[i] = enabled[i] = true;
}
tokStr = tokStr.mid(commapos+1, tokStr.length()-commapos-1);
}
return;
}
QString CTUnit::exportUnit() const {
if (!dirty) {
return initialTokStr;
}
if (isAllEnabled())
return QLatin1String( "*" );
int total = enabledCount();
int count = 0;
QString tokenizeUnit;
for (int num=min; num<=max; num++) {
if (enabled[num]) {
tokenizeUnit += QString::number(num);
count++;
if (count < total)
tokenizeUnit += QLatin1Char( ',' );
}
}
return tokenizeUnit;
}
QString CTUnit::genericDescribe(const QList<QString>& label) const {
int total(enabledCount());
int count(0);
QString tmpStr;
for (int i = min; i <= max; i++) {
if (enabled[i]) {
tmpStr += label.at(i);
count++;
switch (total - count) {
case 0:
break;
case 1:
if (total > 2)
tmpStr += i18n(",");
tmpStr += i18n(" and ");
break;
default:
tmpStr += i18n(", ");
break;
}
}
}
return tmpStr;
}
int CTUnit::minimum() const {
return min;
}
int CTUnit::maximum() const {
return max;
}
bool CTUnit::isEnabled(int pos) const {
return enabled.at(pos);
}
bool CTUnit::isAllEnabled() const {
for (int i = min; i <= max; i++) {
if (enabled.at(i) == false) {
return false;
}
}
return true;
}
void CTUnit::setEnabled(int pos, bool value) {
enabled[pos] = value;
dirty = true;
return;
}
bool CTUnit::isDirty() const {
return dirty;
}
int CTUnit::enabledCount() const {
int total(0);
for (int i = min; i <= max; i++)
total += (enabled[i] == true);
return total;
}
void CTUnit::apply() {
initialTokStr = exportUnit();
for (int i = min; i <= max; i++)
initialEnabled[i] = enabled[i];
dirty = false;
return;
}
void CTUnit::cancel() {
for (int i = min; i <= max; i++)
enabled[i] = initialEnabled[i];
dirty = false;
return;
}
int CTUnit::fieldToValue(const QString& entry) const {
QString lower = entry.toLower();
// check for days
QList<QString> days;
days << QLatin1String( "sun" ) << QLatin1String( "mon" ) << QLatin1String( "tue" ) << QLatin1String( "wed" ) << QLatin1String( "thu" ) << QLatin1String( "fri" ) << QLatin1String( "sat" );
int day = days.indexOf(lower);
if (day != -1) {
return day;
}
// check for months
QList<QString> months;
months << QLatin1String( "" ) << QLatin1String( "jan" ) << QLatin1String( "feb" ) << QLatin1String( "mar" ) << QLatin1String( "apr" ) << QLatin1String( "may" ) << QLatin1String( "jun" ) << QLatin1String( "jul" ) << QLatin1String( "aug" ) << QLatin1String( "sep" ) << QLatin1String( "oct" ) << QLatin1String( "nov" ) << QLatin1String( "dec" );
int month = months.indexOf(lower);
if (month != -1) {
return month;
}
//If the string does not match a day ora month, then it's a simple number (minute, hour or day of month)
return entry.toInt();
}
/**
* Find a period in enabled values
* If no period has been found, return 0
*/
int CTUnit::findPeriod(const QList<int>& periods) const {
foreach(int period, periods) {
bool validPeriod = true;
for (int i = minimum(); i <= maximum(); i++) {
bool periodTesting;
if ( (double)i/(double)period == i/period)
periodTesting = true;
else
periodTesting = false;
if (isEnabled(i) != periodTesting) {
validPeriod = false;
break;
}
}
if (validPeriod) {
return period;
}
}
return 0;
}

View file

@ -1,142 +0,0 @@
/***************************************************************************
* CT Unit of Time Interval Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTUNIT_H
#define CTUNIT_H
#include <QString>
#include <QList>
/**
* A cron table unit parser and tokenizer.
* Parses/tokenizes unit such as "0-3,5,6,10-30/5"
* Also provides default natural language description.
*/
class CTUnit {
protected:
CTUnit(int min, int max, const QString& tokStr = QLatin1String(""));
/**
* Get default natural language description.
*/
virtual QString genericDescribe(const QList<QString>& label) const;
public:
/**
* Base initial image as empty and copy enabled intervals.
*/
CTUnit(const CTUnit& source);
/**
* Destructor.
*/
virtual ~CTUnit();
/**
* Copy enabled intervals.
*/
CTUnit& operator =(const CTUnit& unit);
/**
* Tokenizes unit into string such as
* "0,1,2,3,5,6,10,15,20,25,30".
*/
virtual QString exportUnit() const;
/**
* Parses unit such as "0-3,5,6,10-30/5".
* And initialize array of enabled intervals.
*/
void initialize(const QString& tokStr = QLatin1String(""));
/**
* Lower bound.
*/
int minimum() const;
/**
* Upper bound.
*/
int maximum() const;
/**
* Accessor.
*/
bool isEnabled(int pos) const;
bool isAllEnabled() const;
void setEnabled(int pos, bool value);
/**
* Indicates whether enabled intervals have been modified.
*/
bool isDirty() const;
/**
* Total count of enabled intervals.
*/
int enabledCount() const;
/**
* Mark changes as applied.
*/
void apply();
/**
* Mark cancel changes and revert to initial or last applied
* image.
*/
void cancel();
/**
* Find a period in enabled values
* If no period has been found, return 0
*/
int findPeriod(const QList<int>& periods) const;
protected:
/**
* Parses unit such as "0-3,5,6,10-30/5".
* Does not initialize array of enabled intervals.
*/
void parse(const QString& tokenString = QLatin1String(""));
private:
int min;
int max;
int fieldToValue(const QString& entry) const;
bool dirty;
QList<bool> enabled;
QList<bool> initialEnabled;
QString initialTokStr;
public:
/**
* Constant indicating short format.
*/
static const bool shortFormat = 0;
/**
* Constant indicating long format.
*/
static const bool longFormat = 1;
};
#endif // CTUNIT_H

View file

@ -1,143 +0,0 @@
/***************************************************************************
* CT Environment Variable Implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "ctvariable.h"
#include <QRegExp>
#include <klocale.h>
#include <kiconloader.h>
#include "kcronIcons.h"
#include "ctHelper.h"
CTVariable::CTVariable(const QString& tokenString, const QString& _comment, const QString& _userLogin) {
QString tokStr = tokenString;
if (tokStr.mid(0, 2) == QLatin1String( "#\\" )) {
tokStr = tokStr.mid(2, tokStr.length() - 2);
enabled = false;
} else
enabled = true;
int spacepos(0);
spacepos = tokStr.indexOf(QRegExp(QLatin1String( "[ =]" )));
variable = tokStr.mid(0, spacepos);
value = tokStr.mid(spacepos+1, tokStr.length()-spacepos-1);
comment = _comment;
userLogin = _userLogin;
initialVariable = variable;
initialValue = value;
initialComment = comment;
initialUserLogin = userLogin;
initialEnabled = enabled;
}
CTVariable::CTVariable(const CTVariable &source) :
variable(source.variable), value(source.value), comment(source.comment), userLogin(source.userLogin), enabled(source.enabled), initialVariable(QLatin1String( "" )), initialValue(QLatin1String( "" )), initialComment(QLatin1String( "" )), initialUserLogin(QLatin1String( "" )), initialEnabled(true) {
}
CTVariable& CTVariable::operator = (const CTVariable& source) {
if (this == &source)
return *this;
variable = source.variable;
value = source.value;
comment = source.comment;
userLogin = source.userLogin;
enabled = source.enabled;
initialVariable = QLatin1String( "" );
initialValue = QLatin1String( "" );
initialComment = QLatin1String( "" );
initialUserLogin = QLatin1String( "" );
initialEnabled = true;
return *this;
}
QString CTVariable::exportVariable() {
QString exportVariable;
exportVariable += CTHelper::exportComment(comment);
if (enabled == false)
exportVariable += QLatin1String( "#\\" );
exportVariable += variable + QLatin1String( "=" ) + value + QLatin1String( "\n" );
return exportVariable;
}
void CTVariable::apply() {
initialVariable = variable;
initialValue = value;
initialComment = comment;
initialUserLogin = userLogin;
initialEnabled = enabled;
}
void CTVariable::cancel() {
variable = initialVariable;
value = initialValue;
comment = initialComment;
userLogin = initialUserLogin;
enabled = initialEnabled;
}
bool CTVariable::dirty() const {
return ((variable != initialVariable) || (value != initialValue) || (comment != initialComment) || (userLogin != initialUserLogin) || (enabled != initialEnabled));
}
QPixmap CTVariable::variableIcon() const {
if (variable == QLatin1String( "MAILTO" ))
return SmallIcon(QLatin1String( "mail-message" ));
else if (variable == QLatin1String( "SHELL" ))
return SmallIcon(QLatin1String( "utilities-terminal" ));
else if (variable == QLatin1String( "HOME" ))
return SmallIcon(QLatin1String( "go-home" ));
else if (variable == QLatin1String( "PATH" ))
return SmallIcon(QLatin1String( "folder" ));
else if (variable == QLatin1String( "LD_CONFIG_PATH" ))
return SmallIcon(QLatin1String( "application-x-sharedlib" ));
return KCronIcons::variable(KCronIcons::Small);
}
QString CTVariable::information() const {
if (variable == QLatin1String( "HOME" )) {
return i18n("Override default home folder.");
}
else if (variable == QLatin1String( "MAILTO" )) {
return i18n("Email output to specified account.");
}
else if (variable == QLatin1String( "SHELL" )) {
return i18n("Override default shell.");
}
else if (variable == QLatin1String( "PATH" )) {
return i18n("Folders to search for program files.");
}
else if (variable == QLatin1String( "LD_CONFIG_PATH" )) {
return i18n("Dynamic libraries location.");
}
return i18n("Local Variable");
}

View file

@ -1,80 +0,0 @@
/***************************************************************************
* CT Environment Variable Header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CTVARIABLE_H
#define CTVARIABLE_H
#include <QString>
#include <QPixmap>
/**
* An environment variable (encapsulation of crontab environment variable
* entry). Encapsulates parsing and tokenization.
*/
class CTVariable {
public:
/**
* Constructs environment variable from crontab format string.
*/
explicit CTVariable(const QString& tokenString, const QString& _comment, const QString& _userLogin);
/**
* Copy constructor.
*/
CTVariable(const CTVariable& source);
/**
* Assignment operator.
*/
CTVariable& operator =(const CTVariable& source);
/**
* Tokenizes environment variable to crontab format.
*/
QString exportVariable();
/**
* Mark changes as applied.
*/
void apply();
/**
* Cancel changes.
*/
void cancel();
/**
* Indicates whether or not the environment variable has been modified.
*/
bool dirty() const;
QPixmap variableIcon() const;
QString information() const;
QString variable;
QString value;
QString comment;
QString userLogin;
bool enabled;
private:
QString initialVariable;
QString initialValue;
QString initialComment;
QString initialUserLogin;
bool initialEnabled;
};
#endif // CTVARIABLE_H

View file

@ -1,32 +0,0 @@
/***************************************************************************
* KSystemLog, a system log viewer tool *
* Copyright (C) 2007 by Nicolas Ternisien *
* nicolas.ternisien@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _KCRON_LOGGING_H_
#define _KCRON_LOGGING_H_
#include <kdebug.h>
#define KCRON_KDEBUG_ID 87400
#define logDebug() kDebug(KCRON_KDEBUG_ID)
#endif // _KCRON_LOGGING_H_

View file

@ -1,192 +0,0 @@
/***************************************************************************
* KT list view item tasks implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "genericListWidget.h"
#include <QHeaderView>
#include <QTreeWidgetItemIterator>
#include <QVBoxLayout>
#include <QPixmap>
#include <QtGui/qevent.h>
#include <QAction>
#include <klocale.h>
#include <kglobalsettings.h>
#include "ctcron.h"
#include "cttask.h"
#include "crontabWidget.h"
#include "taskWidget.h"
#include "taskEditorDialog.h"
#include "kcronIcons.h"
#include "logging.h"
class GenericListWidgetPrivate {
public:
QTreeWidget* treeWidget;
CrontabWidget* crontabWidget;
QVBoxLayout* actionsLayout;
};
/**
* Construct tasks folder from branch.
*/
GenericListWidget::GenericListWidget(CrontabWidget* crontabWidget, const QString& label, const QPixmap& icon) :
QWidget(crontabWidget), d(new GenericListWidgetPrivate()) {
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
d->crontabWidget = crontabWidget;
// Label layout
QHBoxLayout* labelLayout = new QHBoxLayout();
QLabel* tasksIcon = new QLabel(this);
tasksIcon->setPixmap(icon);
labelLayout->addWidget(tasksIcon);
QLabel* tasksLabel = new QLabel(label, this);
labelLayout->addWidget(tasksLabel, 1, Qt::AlignLeft);
mainLayout->addLayout(labelLayout);
// Tree layout
QHBoxLayout* treeLayout = new QHBoxLayout();
d->treeWidget = new QTreeWidget(this);
d->treeWidget->setRootIsDecorated(true);
d->treeWidget->setAllColumnsShowFocus(true);
d->treeWidget->header()->setSortIndicatorShown(true);
d->treeWidget->header()->setStretchLastSection(true);
d->treeWidget->header()->setMovable(true);
d->treeWidget->setSortingEnabled(true);
d->treeWidget->setAnimated(true);
d->treeWidget->setRootIsDecorated(false);
d->treeWidget->setAllColumnsShowFocus(true);
d->treeWidget->setAlternatingRowColors(true);
d->treeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
d->treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
treeLayout->addWidget(d->treeWidget);
d->actionsLayout = new QVBoxLayout();
treeLayout->addLayout(d->actionsLayout);
mainLayout->addLayout(treeLayout);
logDebug() << "Generic list created";
connect(treeWidget(), SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(modifySelection(QTreeWidgetItem*,int)));
}
GenericListWidget::~GenericListWidget() {
delete d;
}
QTreeWidget* GenericListWidget::treeWidget() const {
return d->treeWidget;
}
CrontabWidget* GenericListWidget::crontabWidget() const {
return d->crontabWidget;
}
CTHost* GenericListWidget::ctHost() const {
return d->crontabWidget->ctHost();
}
void GenericListWidget::resizeColumnContents() {
//Resize all columns except the last one (which always take the last available space)
for (int i=0; i<d->treeWidget->columnCount()-1; ++i) {
d->treeWidget->resizeColumnToContents(i);
}
}
QTreeWidgetItem* GenericListWidget::firstSelected() const {
QList<QTreeWidgetItem*> tasksItems = treeWidget()->selectedItems();
if (tasksItems.isEmpty()) {
return NULL;
}
return tasksItems.first();
}
void GenericListWidget::keyPressEvent(QKeyEvent *e) {
if ( e->key() == Qt::Key_Delete ) {
deleteSelection();
}
}
void GenericListWidget::removeAll() {
//Remove previous items
for(int i= treeWidget()->topLevelItemCount()-1; i>=0; --i) {
delete treeWidget()->takeTopLevelItem(i);
}
}
QAction* GenericListWidget::createSeparator() {
QAction* action = new QAction(this);
action->setSeparator(true);
return action;
}
void GenericListWidget::addRightAction(QAction* action, const QObject* receiver, const char* member) {
QPushButton* button = new QPushButton(action->text(), this);
button->setIcon(action->icon());
button->setWhatsThis(action->whatsThis());
button->setToolTip(action->toolTip());
d->actionsLayout->addWidget(button);
button->addAction(action);
connect(button, SIGNAL(clicked(bool)), receiver, member);
connect(action, SIGNAL(triggered(bool)), receiver, member);
}
void GenericListWidget::addRightStretch() {
d->actionsLayout->addStretch(1);
}
void GenericListWidget::setActionEnabled(QAction* action, bool enabled) {
foreach(QWidget* widget, action->associatedWidgets()) {
//Only change status of associated Buttons
QPushButton* button = qobject_cast<QPushButton*>(widget);
if (button!=NULL) {
button->setEnabled(enabled);
}
}
action->setEnabled(enabled);
}

View file

@ -1,69 +0,0 @@
/***************************************************************************
* KT list view item cron tasks folder. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef GENERIC_LIST_WIDGET_H
#define GENERIC_LIST_WIDGET_H
#include <QTreeWidget>
#include <QList>
#include "cthost.h"
class GenericListWidgetPrivate;
#include <QKeyEvent>
#include <QAction>
class CrontabWidget;
/**
* GenericListWidget
*/
class GenericListWidget : public QWidget {
Q_OBJECT
public:
GenericListWidget(CrontabWidget* crontabWidget, const QString& label, const QPixmap& icon);
~GenericListWidget();
QTreeWidget* treeWidget() const;
CTHost* ctHost() const;
CrontabWidget* crontabWidget() const;
void resizeColumnContents();
virtual void keyPressEvent(QKeyEvent *e);
protected slots:
virtual void modifySelection(QTreeWidgetItem* item, int position) = 0;
virtual void deleteSelection() = 0;
protected:
void removeAll();
QTreeWidgetItem* firstSelected() const;
QAction* createSeparator();
void addRightAction(QAction* action, const QObject* receiver, const char* member);
void addRightStretch();
void setActionEnabled(QAction* action, bool enabled);
private:
GenericListWidgetPrivate* const d;
};
#endif // GENERIC_LIST_WIDGET_H

View file

@ -1,166 +0,0 @@
/***************************************************************************
* KT icons implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "kcmCron.h"
#include <QImage>
#include <QPixmap>
#include <QLayout>
#include <QComboBox>
#include <QLabel>
#include <kglobal.h>
#include <kpluginfactory.h>
#include <kaboutdata.h>
#include <kstandardshortcut.h>
#include <kmessagebox.h>
#include <kconfig.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kmenu.h>
#include <kstatusbar.h>
#include <ktoggleaction.h>
#include <kxmlguifactory.h>
#include <kglobal.h>
#include <ktoolbar.h>
#include <kicon.h>
#include <kconfiggroup.h>
#include <kdeversion.h>
#include "kcronIcons.h"
#include "crontabWidget.h"
#include "cttask.h"
#include "ctcron.h"
#include "cthost.h"
#include "ctInitializationError.h"
#include "logging.h"
K_PLUGIN_FACTORY(KCMCronFactory, registerPlugin<KCMCron>();)
K_EXPORT_PLUGIN(KCMCronFactory("kcron"))
class KCMCronPrivate {
public:
/**
* Main GUI view/working area.
*/
CrontabWidget* crontabWidget;
/**
* Document object, here crotab enries.
*/
CTHost* ctHost;
};
KCMCron::KCMCron(QWidget* parent, const QVariantList& /*args*/) :
KCModule(KCMCronFactory::componentData(), parent),
d(new KCMCronPrivate()) {
KAboutData* aboutData = new KAboutData("kcm_cron", 0, ki18n("Task Scheduler"),
KDE_VERSION_STRING, ki18n("KDE Task Scheduler"), KAboutData::License_GPL, ki18n("(c) 2008, Nicolas Ternisien\n(c) 1999-2000, Gary Meyer"));
aboutData->addAuthor(ki18n("Nicolas Ternisien"), KLocalizedString(), "nicolas.ternisien@gmail.com");
aboutData->addAuthor(ki18n("Gary Meyer"), KLocalizedString(), "gary@meyer.net");
aboutData->addAuthor(ki18n("Robert Berry"), KLocalizedString(), "rjmber@ntlworld.com");
aboutData->addAuthor(ki18n("James Ots"), KLocalizedString(), "code@jamesots.com");
aboutData->addAuthor(ki18n("Alberto G. Hierro"), KLocalizedString(), "alberto.hierro@kdemail.net");
setAboutData(aboutData);
// Initialize document.
CTInitializationError ctInitializationError;
d->ctHost = new CTHost(findCrontabBinary(), ctInitializationError);
if (ctInitializationError.hasErrorMessage()) {
KMessageBox::error(this, i18n("The following error occurred while initializing KCron:"
"\n\n%1\n\nKCron will now exit.\n", ctInitializationError.errorMessage()));
}
d->crontabWidget = new CrontabWidget(this, d->ctHost);
logDebug() << "Crontab Widget initialized";
connect(d->crontabWidget->tasksWidget(), SIGNAL(taskModified(bool)), this, SIGNAL(changed(bool)));
connect(d->crontabWidget->variablesWidget(), SIGNAL(variableModified(bool)), this, SIGNAL(changed(bool)));
// Initialize view.
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(d->crontabWidget);
init();
}
QString KCMCron::findCrontabBinary() {
return QLatin1String( CRONTAB_BINARY );
}
KCMCron::~KCMCron() {
delete d->crontabWidget;
delete d->ctHost;
delete d;
}
void KCMCron::load() {
logDebug() << "Calling load";
d->ctHost->cancel();
}
void KCMCron::save() {
logDebug() << "Saving crontab...";
CTSaveStatus saveStatus = d->ctHost->save();
if (saveStatus.isError() == true) {
KMessageBox::detailedError(this, saveStatus.errorMessage(), saveStatus.detailErrorMessage());
}
}
void KCMCron::defaults() {
logDebug() << "Loading defaults";
d->ctHost->cancel();
}
bool KCMCron::init() {
// Display greeting screen.
// if there currently are no scheduled tasks...
if (!d->ctHost->isRootUser()) {
int taskCount = 0;
foreach(CTCron* ctCron, d->ctHost->crons) {
taskCount += ctCron->tasks().count();
}
if (taskCount == 0) {
show();
//TODO Add this as a passive popup/message/something else
KMessageBox::information(this, i18n("You can use this application to schedule programs to run in the background.\nTo schedule a new task now, click on the Tasks folder and select Edit/New from the menu."), i18n("Welcome to the Task Scheduler"), QLatin1String( "welcome" ));
}
}
return true;
}
CTHost* KCMCron::ctHost() const {
return d->ctHost;
}
#include "moc_kcmCron.cpp"

View file

@ -1,64 +0,0 @@
/***************************************************************************
* KT icons. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KCM_CRON_H
#define KCM_CRON_H
/**
* Crontab binary executable location
* The $PATH variable could be used
*/
#define CRONTAB_BINARY "crontab"
#include <QPixmap>
#include <QString>
#include <QWidget>
#include <QtCore/qvariant.h>
#include <QStringList>
#include <kcmodule.h>
#include <ksharedconfig.h>
class CTHost;
class KCMCronPrivate;
class KCMCron : public KCModule {
Q_OBJECT
public:
//, const QVariantList& arguments
KCMCron(QWidget* parent, const QVariantList& args);
~KCMCron();
virtual void load();
virtual void save();
virtual void defaults();
/**
* Additional init
*/
bool init();
/**
* Returns a reference to the CTHost.
*/
CTHost* ctHost() const;
QString findCrontabBinary();
private:
KCMCronPrivate* const d;
};
#endif // KCM_CRON_H

View file

@ -1,172 +0,0 @@
[Desktop Entry]
Exec=kcmshell4 kcm_cron
Icon=preferences-system-cron
X-DocPath=kcron/index.html
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_cron
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=system-administration
Name=Task Scheduler
Name[ast]=Organizador de xeres
Name[bg]=Диспечер на задачи
Name[bs]=Raspored Zadataka
Name[ca]=Planificador de tasques
Name[ca@valencia]=Planificador de tasques
Name[cs]=Plánovač úloh
Name[da]=Opgaveskemalægger
Name[de]=Aufgabenplaner
Name[el]=Task Scheduler
Name[en_GB]=Task Scheduler
Name[es]=Planificador de tareas
Name[et]=Tegumihaldur
Name[eu]=Atazen antolatzailea
Name[fi]=Tehtävien ajastus
Name[fr]=Planificateur de tâches
Name[ga]=Sceidealóir na dTascanna
Name[gl]=Programador de tarefas
Name[hne]=
Name[hr]=Raspoređivač zadataka
Name[hu]=Feladatütemező
Name[ia]=Planificator de Cargas
Name[id]=Penjadwal Tugas
Name[is]=Verkefnastjóri
Name[it]=Pianificatore di operazioni
Name[ja]=
Name[kk]=Тапсырма жоспарлағышы
Name[ko]=
Name[lt]=Užduočių planuoklis
Name[lv]=Uzdevumu plānotājs
Name[ml]=
Name[mr]= ि
Name[nb]=Oppgavebehandler
Name[nds]=Opgavenpleger
Name[nl]=Takenplanner
Name[nn]=Oppgåveplanleggjar
Name[pa]= ਿ
Name[pl]=Harmonogram zadań
Name[pt]=Escalonador de Tarefas
Name[pt_BR]=Agendador de tarefas
Name[ro]=Planificator de procese
Name[ru]=Планировщик заданий
Name[se]=Bargoplánejeaddji
Name[sk]=Plánovač úloh
Name[sl]=Razporejevalnik opravil
Name[sq]=Skeduesi i Detyrave
Name[sr]=Распоређивач задатака
Name[sr@ijekavian]=Распоређивач задатака
Name[sr@ijekavianlatin]=Raspoređivač zadataka
Name[sr@latin]=Raspoređivač zadataka
Name[sv]=Jobbschemaläggare
Name[th]=
Name[tr]=Görev Zamanlayıcı
Name[ug]=ۋەزىپە پىلانلاش پروگراممىسى
Name[uk]=Планувальник завдань
Name[x-test]=xxTask Schedulerxx
Name[zh_CN]=
Name[zh_TW]=
Comment=Configure and schedule tasks
Comment[ast]=Configuración y xeres planificaes
Comment[bg]=Задаване и настройване на задачи
Comment[bs]=Konfiguriraj i rasporedi zadatke
Comment[ca]=Configura i planifica les tasques
Comment[ca@valencia]=Configura i planifica les tasques
Comment[cs]=Nastavení a plánování úloh
Comment[da]=Indstil og skemalæg opgaver
Comment[de]=Aufgaben einrichten und planen
Comment[el]=Διαμορφώνει και χρονοπρογραμματίζει εργασίες
Comment[en_GB]=Configure and schedule tasks
Comment[es]=Configurar y planificar tareas
Comment[et]=Tegumite seadistamine ja ajastamine
Comment[eu]=Atazak konfiguratu eta antolatu
Comment[fi]=Tehtävien ajastuksen asetukset
Comment[fr]=Configurer et planifier les tâches
Comment[ga]=Cumraigh agus sceideal tascanna
Comment[gl]=Configura e planifica tarefas
Comment[hne]= ि
Comment[hr]=Podesi i rasporedi zadatke
Comment[hu]=Időzített feladatok beállítása
Comment[ia]=Configura e planifica cargas
Comment[id]=Atur dan jadwal tugas
Comment[is]=Stilla og tímasetja verk
Comment[it]=Configura e pianifica le operazioni
Comment[ja]=
Comment[kk]=Баптау және тапсырмаларды жоспарлау
Comment[ko]=
Comment[lt]=Konfigūruoti ir planuoti užduotis
Comment[lv]=Konfigurēt un plānot uzdevumus
Comment[ml]= ി
Comment[mr]= ि
Comment[nb]=Sett opp og planlegg oppgaver
Comment[nds]=Opgaven planen un plegen
Comment[nl]=Taken instellen en plannen
Comment[nn]=Planlegg og set opp oppgåver
Comment[pa]= ਿ
Comment[pl]=Konfiguracja i harmonogramowanie zadań
Comment[pt]=Configurar e agendar tarefas
Comment[pt_BR]=Configura e agenda tarefas
Comment[ro]=Configurează și planifică sarcinile
Comment[ru]=Настройка и планирование заданий
Comment[sk]=Nastavenie a plánovanie úloh
Comment[sl]=Nastavite in razporedite opravila
Comment[sq]=Konfiguro dhe skedo detyrat
Comment[sr]=Подешавање и заказивање задатака
Comment[sr@ijekavian]=Подешавање и заказивање задатака
Comment[sr@ijekavianlatin]=Podešavanje i zakazivanje zadataka
Comment[sr@latin]=Podešavanje i zakazivanje zadataka
Comment[sv]=Anpassa och schemalägg jobb
Comment[th]=
Comment[tr]=Görevleri zamanla ve yapılandır
Comment[ug]=ۋەزىپىنى سەپلەش ۋە پىلانلاش
Comment[uk]=Налаштування і планування завдання
Comment[x-test]=xxConfigure and schedule tasksxx
Comment[zh_CN]=
Comment[zh_TW]=
X-KDE-Keywords=cron,crontab,scheduled,tasks,task,schedule,vixie
X-KDE-Keywords[bs]=cron,crontab,scheduled,tasks,raspoređeni,zadaci,zadato, redoslijed,task,schedule,vixie
X-KDE-Keywords[ca]=cron,crontab,planificat,tasques,tasca,planificació,vixie
X-KDE-Keywords[ca@valencia]=cron,crontab,planificat,tasques,tasca,planificació,vixie
X-KDE-Keywords[cs]=cron,crontab,naplánováno,úlohy,úloha,naplánovat,vixie
X-KDE-Keywords[da]=cron,crontab,skemalagt,opgaver,opgaveskema,skema,vixie
X-KDE-Keywords[de]=cron,crontab,scheduled,tasks,task,schedule,vixie,aufgaben,planung
X-KDE-Keywords[el]=cron,crontab,προγραμματισμένες,εργασίες,εργασία,προγραμματισμός,vixie
X-KDE-Keywords[en_GB]=cron,crontab,scheduled,tasks,task,schedule,vixie
X-KDE-Keywords[es]=cron,crontab,programado,tareas,tarea,programar,vixie
X-KDE-Keywords[et]=cron,crontab,ajastamine,ülesanded,ülesanne,ajastaja,vixie
X-KDE-Keywords[eu]=cron,crontab,scheduled,antolatuta,tasks,task,atazak,ataza,schedule,antolatu,vixie
X-KDE-Keywords[fi]=cron,crontab,ajastus,ajasta,tehtävät,työt,ajastin,vixie
X-KDE-Keywords[fr]=cron, crontab, planification, tâche, tâches, planifiée, vixie
X-KDE-Keywords[ga]=cron,crontab,sceidealta,tascanna,tasc,sceideal,vixie
X-KDE-Keywords[gl]=cron,crontab,planificada,tarefa,planificar,vixie
X-KDE-Keywords[hu]=cron,crontab,ütemezett,feladatok,feladat,ütemezés,vixie
X-KDE-Keywords[ia]=cron,crontab,planificate,cargas,carga,planifica,vixie
X-KDE-Keywords[it]=cron,crontab,piano,compiti,compito,pianificare,vixie
X-KDE-Keywords[kk]=cron,crontab,scheduled,tasks,task,schedule,vixie
X-KDE-Keywords[ko]=cron,crontab,scheduled,tasks,task,schedule,vixie,,,
X-KDE-Keywords[lt]=cron,crontab,nustatyta,užduotys,užduotis,tvarkaraštis,vixie
X-KDE-Keywords[mr]=,,ि,,,ि,ि
X-KDE-Keywords[nb]=cron,crontab,planlagt,oppgaver,oppgave,plan,vixie
X-KDE-Keywords[nds]=cron,Opgaav,Opgaven,Opgaventabell,plaant,Plaan,vixie
X-KDE-Keywords[nl]=cron,crontab,gepland,taken,taak,planning,vixie
X-KDE-Keywords[pl]=cron,crontab,program_planujący,zadania,zadanie,planuj,vixie
X-KDE-Keywords[pt]=cron,crontab,agendadas,tarefas,tarefa,agendar,vixie
X-KDE-Keywords[pt_BR]=cron,crontab,agendadas,tarefas,tarefa,agendar,vixie
X-KDE-Keywords[ro]=cron,crontab,sarcini,sarcină,planifica,planifica,vixie,plan
X-KDE-Keywords[ru]=cron,crontab,scheduled,tasks,task,schedule,vixie,планирование,задания,задание,задачи,задача,планировщик,запуск,автозапуск
X-KDE-Keywords[sk]=cron,crontab,plánované,úlohy,úloha,plánovanie,vixie
X-KDE-Keywords[sl]=cron,crontab,razporejeno,opravila,opravilo,razpored,vixie
X-KDE-Keywords[sr]=cron,crontab,scheduled,tasks,task,schedule,vixie,крон,кронтаб,распоред,задаци,распоређен
X-KDE-Keywords[sr@ijekavian]=cron,crontab,scheduled,tasks,task,schedule,vixie,крон,кронтаб,распоред,задаци,распоређен
X-KDE-Keywords[sr@ijekavianlatin]=cron,crontab,scheduled,tasks,task,schedule,vixie,cron,crontab,raspored,zadaci,raspoređen
X-KDE-Keywords[sr@latin]=cron,crontab,scheduled,tasks,task,schedule,vixie,cron,crontab,raspored,zadaci,raspoređen
X-KDE-Keywords[sv]=cron,crontab,schemalagd,uppgifter,uppgift,schema,vixie
X-KDE-Keywords[tr]=cron,crontab,scheduled,tasks,task,schedule,vixie
X-KDE-Keywords[uk]=cron;crontab;scheduled;tasks;task;schedule;vixie;таблиця планування;список планування;завдання;план;запуск
X-KDE-Keywords[x-test]=xxcron,crontab,scheduled,tasks,task,schedule,vixiexx
X-KDE-Keywords[zh_CN]=cron,crontab,scheduled,tasks,task,schedule,vixie,,,
X-KDE-Keywords[zh_TW]=cron,crontab,scheduled,tasks,task,schedule,vixie
Categories=Qt;KDE;X-KDE-settings-system;

View file

@ -1,64 +0,0 @@
/***************************************************************************
* KT icons implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "kcronHelper.h"
#include <QFontMetrics>
#include <QImage>
#include <QPixmap>
#include <QTextEdit>
#include <QComboBox>
#include <kglobal.h>
#include "cttask.h"
#include "ctcron.h"
#include "cthost.h"
#include "crontabWidget.h"
void KCronHelper::initUserCombo(QComboBox* userCombo, CrontabWidget* crontabWidget, const QString& selectedUserLogin) {
int userComboIndex = 0;
QStringList users;
int selectedIndex = 0;
foreach(CTCron* ctCron, crontabWidget->ctHost()->crons) {
if (ctCron->isSystemCron())
continue;
users.append(ctCron->userLogin());
//Select the actual user
if (ctCron->userLogin() == selectedUserLogin) {
selectedIndex = userComboIndex;
}
userComboIndex++;
}
users.sort();
userCombo->addItems(users);
userCombo->setCurrentIndex(selectedIndex);
}
QTextEdit* KCronHelper::createCommentEdit(QWidget* parent) {
QTextEdit* edit = new QTextEdit(parent);
edit->setAcceptRichText(false);
edit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
edit->setTabChangesFocus(true);
QFontMetrics fontMetrics(edit->currentFont());
edit->setMaximumHeight(fontMetrics.lineSpacing() * 3); //TODO Choose a smarter value
return edit;
}

View file

@ -1,32 +0,0 @@
/***************************************************************************
* KT icons. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KCRON_HELPER_H
#define KCRON_HELPER_H
#include <QPixmap>
#include <QString>
#include <QComboBox>
#include <QTextEdit>
class CrontabWidget;
class KCronHelper {
public:
static void initUserCombo(QComboBox* userCombo, CrontabWidget* crontabWidget, const QString& selectedUserLogin);
static QTextEdit* createCommentEdit(QWidget* parent);
};
#endif // KCRON_HELPER_H

View file

@ -1,47 +0,0 @@
/***************************************************************************
* KT icons implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "kcronIcons.h"
#include <QImage>
#include <QPixmap>
#include <kglobal.h>
#include <kiconloader.h>
QPixmap KCronIcons::getIcon(const QString&name, KCronIcons::IconSize size) {
if (size == KCronIcons::Small)
return SmallIcon(name);
else if (size == KCronIcons::Normal)
return BarIcon(name);
return DesktopIcon(name);
}
QPixmap KCronIcons::application(KCronIcons::IconSize size) {
return getIcon(QLatin1String( "kcron" ), size);
}
QPixmap KCronIcons::variable(KCronIcons::IconSize size) {
return getIcon(QLatin1String( "text" ), size);
}
QPixmap KCronIcons::task(KCronIcons::IconSize size) {
return getIcon(QLatin1String( "system-run" ), size);
}
QPixmap KCronIcons::information(KCronIcons::IconSize size) {
return getIcon(QLatin1String( "dialog-information" ), size);
}
QPixmap KCronIcons::error(KCronIcons::IconSize size) {
return getIcon(QLatin1String( "dialog-error" ), size);
}

View file

@ -1,40 +0,0 @@
/***************************************************************************
* KT icons. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KCRON_ICONS_H
#define KCRON_ICONS_H
#include <QPixmap>
/**
* Wraps all icons used by the application.
*/
class KCronIcons {
public:
enum IconSize {Small,Normal,Large};
static QPixmap application(KCronIcons::IconSize size);
static QPixmap variable(KCronIcons::IconSize size);
static QPixmap task(KCronIcons::IconSize size);
static QPixmap information(KCronIcons::IconSize size);
static QPixmap error(KCronIcons::IconSize size);
private:
static QPixmap getIcon(const QString&name, KCronIcons::IconSize size);
};
#endif // KCRON_ICONS_H

File diff suppressed because it is too large Load diff

View file

@ -1,268 +0,0 @@
/***************************************************************************
* KT task editor window header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TASK_EDITOR_DIALOG_H
#define TASK_EDITOR_DIALOG_H
#include <QLabel>
#include <QPushButton>
#include <QGroupBox>
#include <QComboBox>
#include <QStringList>
#include <QTextEdit>
#include <QPair>
#include <kdialog.h>
#include <kicon.h>
#include <ktitlewidget.h>
#include <kmimetype.h>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QGridLayout>
#include <QHBoxLayout>
class KUrlRequester;
class CTTask;
class CrontabWidget;
class SetOrClearAllButton : public QPushButton {
public:
enum Status {
SET_ALL,
CLEAR_ALL
};
SetOrClearAllButton(QWidget * parent, SetOrClearAllButton::Status status);
void setStatus(SetOrClearAllButton::Status status);
bool isSetAll();
bool isClearAll();
private:
SetOrClearAllButton::Status currentStatus;
};
class NumberPushButton : public QPushButton {
public:
NumberPushButton(QWidget * parent);
NumberPushButton(bool digitMode, QWidget * parent);
void updatePalette();
bool event(QEvent *e);
void paintEvent(QPaintEvent*);
bool isDirty;
QPalette palSelected;
QPalette palNormal;
};
/**
* Task editor window.
*/
class TaskEditorDialog : public KDialog {
Q_OBJECT
public:
/**
* Initialize from CTTask.
*/
explicit TaskEditorDialog(CTTask* ctTask, const QString& caption, CrontabWidget* crontabWidget);
/**
* Destroy.
*/
~TaskEditorDialog();
private slots:
/**
* Control the task title bar.
*/
void setupTitleWidget(const QString& comment=QLatin1String(""), KTitleWidget::MessageType = KTitleWidget::PlainMessage);
/**
* Enable checkbox has changed
*/
void slotEnabledChanged();
/**
* Reboot checkbox has changed
*/
void slotRebootChanged();
/**
* Daily checkbox has been changed.
*/
void slotDailyChanged();
/**
* Apply changes and close.
*/
void slotOK();
/**
* Run the wizard.
*/
void slotWizard();
/**
* Cancel and close.
*/
void slotCancel();
/**
* Set or clear all month checkboxes
*/
void slotAllMonths();
/**
* A month checkbox has changed
*/
void slotMonthChanged();
/**
* Set or clear all day of month checkboxes
*/
void slotAllDaysOfMonth();
/**
* A day of month checkbox has changed
*/
void slotDayOfMonthChanged();
/**
* Set or clear all day of week checkboxes
*/
void slotAllDaysOfWeek();
/**
* A day of week checkbox has changed
*/
void slotDayOfWeekChanged();
/**
* Set or clear all hour checkboxes
*/
void slotAllHours();
/**
* An hour checkbox has changed
*/
void slotHourChanged();
void slotMinutesPreselection(int index);
/**
* A minute checkbox has changed
*/
void slotMinuteChanged();
private:
NumberPushButton* createHourButton(QGroupBox* hoursGroup, int hour);
QGroupBox* createHoursGroup(QWidget* mainWidget);
NumberPushButton* createMinuteButton(int minuteIndex);
void createMinutesGroup(QWidget* mainWidget);
/**
* Returns true if there is no checked minute in the hidden minuteButton
*/
bool canReduceMinutesGroup();
void emptyMinutesGroup();
void reduceMinutesGroup();
void increaseMinutesGroup();
QGroupBox* createMonthsGroup(QWidget* mainWidget);
QGroupBox* createDaysOfMonthGroup(QWidget* mainWidget);
QGroupBox* createDaysOfWeekGroup(QWidget* mainWidget);
bool checkCommand();
void defineCommandIcon();
bool isEveryDay();
/**
* Task.
*/
CTTask* ctTask;
CrontabWidget* crontabWidget;
// Widgets.
KTitleWidget* titleWidget;
QComboBox* userCombo;
QTextEdit* leComment;
QLabel* commandIcon;
KUrlRequester* command;
QCheckBox* chkEnabled;
QCheckBox* chkReboot;
QCheckBox* cbEveryDay;
QGroupBox* bgMonth;
NumberPushButton* monthButtons[13]; // The index 0 is not used
SetOrClearAllButton* allMonths;
QGroupBox* bgDayOfMonth;
NumberPushButton* dayOfMonthButtons[32]; // The index 0 is not used
SetOrClearAllButton* allDaysOfMonth;
QGroupBox* bgDayOfWeek;
NumberPushButton* dayOfWeekButtons[8]; // The index 0 is not used
SetOrClearAllButton* allDaysOfWeek;
QGroupBox* hoursGroup;
QLabel* morningLabel;
QLabel* afternoonLabel;
QPushButton* hourButtons[24];
SetOrClearAllButton* allHours;
QGroupBox* minutesGroup;
QGridLayout* minutesLayout;
QPushButton* minuteButtons[60];
QHBoxLayout* minutesPreselectionLayout;
QComboBox* minutesPreselection;
static const int minuteTotal = 59; // or 55 or 59
static const int minutePerColumn = 12; // or 30 or 12
static const int reducedMinuteStep = 5;
QStringList specialValidCommands;
};
#endif // TASK_EDITOR_DIALOG_H

View file

@ -1,68 +0,0 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "taskWidget.h"
#include <klocale.h>
#include <kiconloader.h>
#include "cttask.h"
#include "ctcron.h"
#include "tasksWidget.h"
#include "crontabWidget.h"
#include "kcronIcons.h"
#include "taskEditorDialog.h"
#include "logging.h"
TaskWidget::TaskWidget(TasksWidget* _tasksWidget, CTTask* _cttask) :
QTreeWidgetItem(_tasksWidget->treeWidget()) {
ctTask = _cttask;
tasksWidget = _tasksWidget;
refresh();
}
void TaskWidget::refresh() {
int column = 0;
if (tasksWidget->needUserColumn()) {
setText(column++, ctTask->userLogin);
}
setText(column++, ctTask->schedulingCronFormat());
setText(column, ctTask->command);
setIcon(column++, ctTask->commandIcon());
if (ctTask->enabled) {
setText(column, i18n("Enabled"));
setIcon(column++, SmallIcon(QLatin1String( "dialog-ok-apply" )));
} else {
setText(column, i18n("Disabled"));
setIcon(column++, SmallIcon(QLatin1String( "dialog-cancel" )));
}
setText(column++, ctTask->comment);
setText(column++, ctTask->describe());
}
void TaskWidget::toggleEnable() {
ctTask->enabled = !ctTask->enabled;
refresh();
}
CTTask* TaskWidget::getCTTask() const {
return ctTask;
}

View file

@ -1,56 +0,0 @@
/***************************************************************************
* KT list view item task header. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TASK_WIDGET_H
#define TASK_WIDGET_H
#include <QtGui/qtreewidget.h>
class CTTask;
class TasksWidget;
/**
* QTreeWidgetItem with a CTTask.
*/
class TaskWidget : public QTreeWidgetItem {
public:
/**
* Initialize the list view item and task.
*/
TaskWidget(TasksWidget* tasksWidget, CTTask* _cttask);
/*
* Change the status of this task
*/
void toggleEnable();
/**
* Get the task.
*/
CTTask* getCTTask() const;
/**
* Refresh from underlying task.
*/
void refresh();
private:
/**
* Task.
*/
CTTask* ctTask;
TasksWidget* tasksWidget;
};
#endif // TASK_WIDGET_H

View file

@ -1,357 +0,0 @@
/***************************************************************************
* KT list view item tasks implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "tasksWidget.h"
#include <QHeaderView>
#include <QTreeWidgetItemIterator>
#include <QVBoxLayout>
#include <QProcess>
#include <QAction>
#include <QList>
#include <kaction.h>
#include <kstandardaction.h>
#include <klocale.h>
#include <kglobalsettings.h>
#include "ctcron.h"
#include "cthost.h"
#include "cttask.h"
#include "ctvariable.h"
#include "kcronIcons.h"
#include "crontabWidget.h"
#include "taskWidget.h"
#include "taskEditorDialog.h"
#include "logging.h"
class TasksWidgetPrivate {
public:
QAction* newTaskAction;
QAction* modifyAction;
QAction* deleteAction;
QAction* runNowAction;
KAction* printAction;
};
/**
* Construct tasks folder from branch.
*/
TasksWidget::TasksWidget(CrontabWidget* crontabWidget) :
GenericListWidget(crontabWidget, i18n("<b>Scheduled Tasks</b>"), KCronIcons::task(KCronIcons::Small)),
d(new TasksWidgetPrivate()) {
refreshHeaders();
treeWidget()->sortItems(1, Qt::AscendingOrder);
setupActions(crontabWidget);
prepareContextualMenu();
connect(treeWidget(), SIGNAL(itemSelectionChanged()), this, SLOT(changeCurrentSelection()));
logDebug() << "Tasks list created";
}
TasksWidget::~TasksWidget() {
delete d;
}
QList<TaskWidget*> TasksWidget::selectedTasksWidget() const {
QList<TaskWidget*> tasksWidget;
QList<QTreeWidgetItem*> tasksItems = treeWidget()->selectedItems();
foreach(QTreeWidgetItem* item, tasksItems) {
TaskWidget* taskWidget = static_cast<TaskWidget*>(item);
tasksWidget.append(taskWidget);
}
return tasksWidget;
}
TaskWidget* TasksWidget::firstSelectedTaskWidget() const {
QTreeWidgetItem* item = firstSelected();
if (item==NULL)
return NULL;
return static_cast<TaskWidget*>(item);
}
int TasksWidget::statusColumnIndex() {
if (needUserColumn()) {
return 3;
}
return 2;
}
void TasksWidget::runTaskNow() const {
TaskWidget* taskWidget = firstSelectedTaskWidget();
if (taskWidget == NULL)
return;
QString taskCommand = taskWidget->getCTTask()->command;
QString echoMessage = i18nc("Do not use any quote characters (') in this string", "End of script execution. Type Enter or Ctrl+C to exit.");
CTCron* ctCron = crontabWidget()->currentCron();
if (ctCron == NULL) {
logDebug() << "Unable to find the related CtCron, please report this bug to KCron developer";
return;
}
QStringList commandList;
foreach(CTVariable* variable, ctCron->variables()) {
commandList << QString::fromLatin1("export %1=\"%2\"").arg(variable->variable, variable->value);
}
commandList << taskCommand;
commandList << QLatin1String( "echo '-------------------------------------------------------------------------'" );
commandList << QLatin1String( "echo " ) + echoMessage;
commandList << QLatin1String( "echo '-------------------------------------------------------------------------'" );
commandList << QLatin1String( "read" );
QStringList parameters;
parameters << QLatin1String( "-e" ) << QLatin1String( "bash" ) << QLatin1String( "-c" );
parameters << commandList.join(QLatin1String( ";" ));
QProcess::startDetached(QLatin1String( "konsole" ), parameters);
}
void TasksWidget::createTask() {
CTTask* task = new CTTask(QLatin1String( "" ), QLatin1String( "" ), crontabWidget()->currentCron()->userLogin(), crontabWidget()->currentCron()->isMultiUserCron());
TaskEditorDialog taskEditorDialog(task, i18n("New Task"), crontabWidget());
int result = taskEditorDialog.exec();
if (result == QDialog::Accepted) {
addTask(task);
emit taskModified(true);
changeCurrentSelection();
}
else {
delete task;
}
}
void TasksWidget::addTask(CTTask* task) {
CTCron* cron = crontabWidget()->currentCron();
cron->addTask(task);
new TaskWidget(this, task);
}
void TasksWidget::modifySelection() {
modifySelection(firstSelectedTaskWidget(), -1);
}
void TasksWidget::modifySelection(QTreeWidgetItem* item, int position) {
TaskWidget* taskWidget = static_cast<TaskWidget*>(item);
if (taskWidget!=NULL) {
if (position == statusColumnIndex()) {
taskWidget->toggleEnable();
emit taskModified(true);
}
else {
CTTask* task = taskWidget->getCTTask();
TaskEditorDialog taskEditorDialog(task, i18n("Modify Task"), crontabWidget());
int result = taskEditorDialog.exec();
if (result == QDialog::Accepted) {
crontabWidget()->currentCron()->modifyTask(task);
taskWidget->refresh();
emit taskModified(true);
}
}
}
logDebug() << "End of modification";
}
void TasksWidget::deleteSelection() {
logDebug() << "Selection deleting...";
QList<QTreeWidgetItem*> tasksItems = treeWidget()->selectedItems();
bool deleteSomething = ! (tasksItems.isEmpty());
foreach(QTreeWidgetItem* item, tasksItems) {
TaskWidget* taskWidget = static_cast<TaskWidget*>(item);
crontabWidget()->currentCron()->removeTask(taskWidget->getCTTask());
delete taskWidget->getCTTask();
treeWidget()->takeTopLevelItem( treeWidget()->indexOfTopLevelItem(taskWidget) );
delete taskWidget;
}
if (deleteSomething) {
emit taskModified(true);
changeCurrentSelection();
}
logDebug() << "End of deletion";
}
void TasksWidget::refreshTasks(CTCron* cron) {
//Remove previous items
removeAll();
refreshHeaders();
//Add new items
foreach(CTTask* ctTask, cron->tasks()) {
new TaskWidget(this, ctTask);
}
resizeColumnContents();
}
void TasksWidget::refreshHeaders() {
QStringList headerLabels;
if (needUserColumn()) {
headerLabels << i18n("User");
}
headerLabels << i18n("Scheduling");
headerLabels << i18n("Command");
headerLabels << i18n("Status");
headerLabels << i18n("Description");
headerLabels << i18n("Scheduling Details");
treeWidget()->setHeaderLabels(headerLabels);
if (needUserColumn())
treeWidget()->setColumnCount(6);
else
treeWidget()->setColumnCount(5);
}
bool TasksWidget::needUserColumn() const {
CTCron* ctCron = crontabWidget()->currentCron();
if (ctCron && ctCron->isMultiUserCron()) {
return true;
}
return false;
}
void TasksWidget::setupActions(CrontabWidget* crontabWidget) {
d->newTaskAction = new QAction(this);
d->newTaskAction->setIcon(KIcon( QLatin1String( "document-new" )));
d->newTaskAction->setText(i18nc("Adds a new task", "New &Task...") );
d->newTaskAction->setToolTip(i18n("Create a new task."));
addRightAction(d->newTaskAction, this, SLOT(createTask()));
d->modifyAction = new QAction(this);
d->modifyAction->setText(i18n("M&odify...") );
d->modifyAction->setIcon(KIcon( QLatin1String( "document-open" )) );
d->modifyAction->setToolTip(i18n("Modify the selected task."));
addRightAction(d->modifyAction, this, SLOT(modifySelection()));
d->deleteAction = new QAction(this);
d->deleteAction->setText(i18n("&Delete") );
d->deleteAction->setIcon(KIcon( QLatin1String( "edit-delete" )) );
d->deleteAction->setToolTip(i18n("Delete the selected task."));
addRightAction(d->deleteAction, this, SLOT(deleteSelection()));
d->runNowAction = new QAction(this);
d->runNowAction->setText(i18n("&Run Now") );
d->runNowAction->setIcon(KIcon( QLatin1String( "system-run" )));
d->runNowAction->setToolTip(i18n("Run the selected task now."));
addRightAction(d->runNowAction, this, SLOT(runTaskNow()));
d->printAction = KStandardAction::print(crontabWidget, SLOT(print()), this);
addRightAction(d->printAction, crontabWidget, SLOT(print()));
addRightStretch();
}
void TasksWidget::prepareContextualMenu() {
treeWidget()->addAction(d->newTaskAction);
treeWidget()->addAction(createSeparator());
treeWidget()->addAction(d->modifyAction);
treeWidget()->addAction(d->deleteAction);
treeWidget()->addAction(createSeparator());
foreach(QAction* action, crontabWidget()->cutCopyPasteActions()) {
treeWidget()->addAction(action);
}
treeWidget()->addAction(createSeparator());
treeWidget()->addAction(d->runNowAction);
}
void TasksWidget::toggleRunNowAction(bool state) {
setActionEnabled(d->runNowAction, state);
}
void TasksWidget::togglePrintAction(bool state) {
setActionEnabled(d->printAction, state);
}
void TasksWidget::toggleModificationActions(bool state) {
setActionEnabled(d->modifyAction, state);
setActionEnabled(d->deleteAction, state);
}
void TasksWidget::toggleNewEntryAction(bool state) {
setActionEnabled(d->newTaskAction, state);
}
void TasksWidget::changeCurrentSelection() {
//logDebug() << "Change selection...";
if (treeWidget()->topLevelItemCount()==0) {
togglePrintAction(false);
}
else {
togglePrintAction(true);
}
bool enabled;
if (treeWidget()->selectedItems().isEmpty())
enabled = false;
else
enabled = true;
toggleModificationActions(enabled);
toggleRunNowAction(enabled);
}

View file

@ -1,104 +0,0 @@
/***************************************************************************
* KT list view item cron tasks folder. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TASKS_WIDGET_H
#define TASKS_WIDGET_H
#include <QTreeWidget>
#include "genericListWidget.h"
#include "cthost.h"
class TaskWidget;
class TasksWidgetPrivate;
/**
* QTreeWidget of a "tasks" folder.
*/
class TasksWidget : public GenericListWidget {
Q_OBJECT
public:
/**
* Construct tasks folder from branch.
*/
TasksWidget(CrontabWidget* crontabWidget);
~TasksWidget();
TaskWidget* firstSelectedTaskWidget() const;
QList<TaskWidget*> selectedTasksWidget() const;
void refreshTasks(CTCron* cron);
bool needUserColumn() const;
/**
* Enables/disables modification buttons
*/
void toggleModificationActions(bool enabled);
/**
* Enables/disables new entry actions
*/
void toggleNewEntryAction(bool enabled);
/**
* Enables/disables "Run now"
*/
void toggleRunNowAction(bool enabled);
/**
* Enables/disables Print Action
*/
void togglePrintAction(bool enabled);
signals:
void taskModified(bool);
public slots:
void modifySelection();
void deleteSelection();
/**
* Run task now.
*/
void runTaskNow() const;
/**
* Create a new task. Default is which type is most recently selected.
*/
void createTask();
void addTask(CTTask* task);
void changeCurrentSelection();
protected slots:
void modifySelection(QTreeWidgetItem* item, int position);
private:
void refreshHeaders();
int statusColumnIndex();
void setupActions(CrontabWidget* crontabWidget);
void prepareContextualMenu();
TasksWidgetPrivate* const d;
};
#endif // TASKS_WIDGET_H

View file

@ -1,225 +0,0 @@
/***************************************************************************
* KT environment variable editor window implementation *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "variableEditorDialog.h"
#include <QLabel>
#include <QComboBox>
#include <QGridLayout>
#include <QLineEdit>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <ktitlewidget.h>
#include "ctvariable.h"
#include "cthost.h"
#include "ctcron.h"
#include "crontabWidget.h"
#include "kcronIcons.h"
#include "kcronHelper.h"
#include <KDebug>
VariableEditorDialog::VariableEditorDialog(CTVariable* _ctVariable, const QString &_caption, CrontabWidget* _crontabWidget) :
KDialog(_crontabWidget) {
ctVariable = _ctVariable;
crontabWidget = _crontabWidget;
setModal(true);
setCaption(_caption);
setButtons(Ok|Cancel);
setDefaultButton(Ok);
QWidget* page = new QWidget;
QGridLayout* layout = new QGridLayout;
page->setLayout(layout);
layout->setMargin(0);
layout->setColumnMinimumWidth(1, 270);
layout->setRowStretch(3, 1);
layout->setColumnStretch(1, 1);
setMainWidget(page);
setWindowIcon(KCronIcons::application(KCronIcons::Small));
int layoutPosition = 0;
// top title widget
titleWidget = new KTitleWidget(this);
titleWidget->setText(i18n("Add or modify a variable"));
layout->addWidget(titleWidget, layoutPosition, 0, 1, 2);
// variable
QLabel* labVariable = new QLabel(i18nc("The environmental variable name ie HOME, MAILTO etc", "&Variable:"), this);
layout->addWidget(labVariable, ++layoutPosition, 0, Qt::AlignLeft);
cmbVariable = new QComboBox(this);
cmbVariable->setEditable(true);
layout->addWidget(cmbVariable, layoutPosition, 1);
cmbVariable->addItem(QLatin1String( "HOME" ));
cmbVariable->addItem(QLatin1String( "MAILTO" ));
cmbVariable->addItem(QLatin1String( "PATH" ));
cmbVariable->addItem(QLatin1String( "SHELL" ));
cmbVariable->addItem(QLatin1String( "LD_CONFIG_PATH" ));
labVariable->setBuddy(cmbVariable);
// details
QLabel* labDetails = new QLabel(QLatin1String( "" ), this);
layout->addWidget(labDetails, ++layoutPosition, 0, Qt::AlignLeft);
QHBoxLayout* detailsLayout = new QHBoxLayout;
detailsIcon = new QLabel(this);
detailsLayout->addWidget(detailsIcon);
details = new QLabel(this);
detailsLayout->addWidget(details);
layout->addLayout(detailsLayout, layoutPosition, 1, Qt::AlignLeft);
// value
QLabel* labValue = new QLabel(i18n("Va&lue:"), this);
layout->addWidget(labValue, ++layoutPosition, 0, Qt::AlignLeft);
leValue = new QLineEdit(this);
layout->addWidget(leValue, layoutPosition, 1);
leValue->setMaxLength(255);
labValue->setBuddy(leValue);
// User Combo
QLabel* userLabel = new QLabel( i18n("&Run as:"), this);
layout->addWidget(userLabel, ++layoutPosition, 0);
userCombo = new QComboBox(this);
userLabel->setBuddy(userCombo);
layout->addWidget(userCombo, layoutPosition, 1);
if (crontabWidget->variablesWidget()->needUserColumn()) {
KCronHelper::initUserCombo(userCombo, crontabWidget, ctVariable->userLogin);
}
else {
userLabel->hide();
userCombo->hide();
}
// comment
QLabel* labComment = new QLabel(i18n("Co&mment:"), this);
layout->addWidget(labComment, ++layoutPosition, 0, Qt::AlignLeft);
teComment = KCronHelper::createCommentEdit(this);
layout->addWidget(teComment, layoutPosition, 1);
labComment->setBuddy(teComment);
// enabled
chkEnabled = new QCheckBox(i18n("&Enable this variable"), this);
layout->addWidget(chkEnabled, ++layoutPosition, 0, 1, 2);
// set starting field values
cmbVariable->setEditText(ctVariable->variable);
leValue->setText(ctVariable->value);
teComment->setText(ctVariable->comment);
chkEnabled->setChecked(ctVariable->enabled);
cmbVariable->setFocus();
slotEnabled();
slotWizard();
show();
// connect them up
connect(cmbVariable, SIGNAL(editTextChanged(QString)), SLOT(slotWizard()));
connect(leValue, SIGNAL(textEdited(QString)), SLOT(slotWizard()));
connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
connect(chkEnabled, SIGNAL(clicked()), SLOT(slotEnabled()));
}
VariableEditorDialog::~VariableEditorDialog() {
}
void VariableEditorDialog::setupTitleWidget(const QString& comment, KTitleWidget::MessageType messageType) {
//krazy:exclude=doublequote_chars
if (comment.isEmpty()) {
titleWidget->setComment(i18n("<i>This variable will be used by scheduled tasks.</i>"));
titleWidget->setPixmap(KCronIcons::variable(KCronIcons::Large), KTitleWidget::ImageRight);
}
else {
titleWidget->setComment(comment, messageType);
if (messageType == KTitleWidget::ErrorMessage)
titleWidget->setPixmap(KIcon(KCronIcons::error(KCronIcons::Large)), KTitleWidget::ImageRight);
else
titleWidget->setPixmap(KIcon(KCronIcons::information(KCronIcons::Large)), KTitleWidget::ImageRight);
}
}
void VariableEditorDialog::slotEnabled() {
bool enabled = chkEnabled->isChecked();
cmbVariable->setEnabled(enabled);
leValue->setEnabled(enabled);
teComment->setEnabled(enabled);
userCombo->setEnabled(enabled);
}
void VariableEditorDialog::slotOk() {
ctVariable->variable = cmbVariable->currentText();
ctVariable->value = leValue->text();
ctVariable->comment = teComment->toPlainText();
ctVariable->enabled = chkEnabled->isChecked();
// save work in process
if (crontabWidget->variablesWidget()->needUserColumn()) {
ctVariable->userLogin = userCombo->currentText();
}
close();
}
void VariableEditorDialog::slotWizard() {
CTVariable tempVariable(*ctVariable);
tempVariable.variable = cmbVariable->currentText();
detailsIcon->setPixmap(tempVariable.variableIcon());
details->setText(tempVariable.information());
bool error = false;
if (!chkEnabled->isChecked()) {
setupTitleWidget(i18n("<i>This variable is disabled.</i>"));
chkEnabled->setFocus();
KDialog::enableButtonOk(true);
error = true;
}
if (cmbVariable->currentText().isEmpty() && !error) {
setupTitleWidget(i18n("<i>Please enter the variable name...</i>"), KTitleWidget::ErrorMessage);
cmbVariable->setFocus();
KDialog::enableButtonOk(false);
error = true;
}
if (leValue->text().isEmpty() && !error) {
setupTitleWidget(i18n("<i>Please enter the variable value ...</i>"), KTitleWidget::ErrorMessage);
KDialog::enableButtonOk(false);
error = true;
}
if (!error) {
setupTitleWidget();
KDialog::enableButtonOk(true);
}
}
#include "moc_variableEditorDialog.cpp"

View file

@ -1,94 +0,0 @@
/***************************************************************************
* KT environment variable editor window header *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef VARIABLE_EDITOR_DIALOG_H
#define VARIABLE_EDITOR_DIALOG_H
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
#include <QTextEdit>
#include <klineedit.h>
#include <kdialog.h>
#include <ktitlewidget.h>
class CTVariable;
class CrontabWidget;
/**
* Environment variable editor window.
*/
class VariableEditorDialog : public KDialog {
Q_OBJECT
public:
/**
* Initialize from CTVariable.
*/
explicit VariableEditorDialog(CTVariable* _ctVariable, const QString &_caption, CrontabWidget* crontabWidget);
/**
* Destroy.
*/
~VariableEditorDialog();
private slots:
/**
* Setup title widget
*/
void setupTitleWidget(const QString& comment = QLatin1String(""), KTitleWidget::MessageType = KTitleWidget::PlainMessage);
/**
* Enable / disable variable
*/
void slotEnabled();
/**
* Apply changes and close.
*/
void slotOk();
/**
* Run the wizard.
*/
void slotWizard();
private:
/**
* Environment variable.
*/
CTVariable* ctVariable;
CrontabWidget* crontabWidget;
// Widgets.
KTitleWidget* titleWidget;
QComboBox* cmbVariable;
QLabel* detailsIcon;
QLabel* details;
QLineEdit* leValue;
QTextEdit* teComment;
QCheckBox* chkEnabled;
QComboBox* userCombo;
};
#endif // VARIABLE_EDITOR_DIALOG_H

View file

@ -1,65 +0,0 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "variableWidget.h"
#include <klocale.h>
#include "ctvariable.h"
#include "variableEditorDialog.h"
#include "kcronIcons.h"
#include "taskEditorDialog.h"
VariableWidget::VariableWidget(VariablesWidget* _variablesWidget, CTVariable* _ctVariable) :
QTreeWidgetItem(_variablesWidget->treeWidget()) {
ctVariable = _ctVariable;
variablesWidget = _variablesWidget;
refresh();
}
void VariableWidget::refresh() {
int column = 0;
if (variablesWidget->needUserColumn()) {
setText(column++, ctVariable->userLogin);
}
setText(column, ctVariable->variable);
setIcon(column++, ctVariable->variableIcon());
setText(column++, ctVariable->value);
if (ctVariable->enabled) {
setText(column, i18n("Enabled"));
setIcon(column++, SmallIcon(QLatin1String( "dialog-ok-apply" )));
}
else {
setText(column, i18n("Disabled"));
setIcon(column++, SmallIcon(QLatin1String( "dialog-cancel" )));
}
setText(column++, ctVariable->comment);
}
void VariableWidget::toggleEnable() {
ctVariable->enabled = ! ctVariable->enabled;
refresh();
}
CTVariable* VariableWidget::getCTVariable() const {
return ctVariable;
}

View file

@ -1,60 +0,0 @@
/***************************************************************************
* KT list view item task header. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef VARIABLE_WIDGET_H
#define VARIABLE_WIDGET_H
#include <QIcon>
#include "variablesWidget.h"
class CTVariable;
/**
* QTreeWidgetItem with a CTTask.
*/
class VariableWidget : public QTreeWidgetItem {
public:
/**
* Initialize the list view item and task.
*/
VariableWidget(VariablesWidget* variablesWidget, CTVariable* _ctVariable);
/**
* Refresh from underlying task.
*/
void refresh();
/*
* Change the status of this variable
*/
void toggleEnable();
/**
* Get the task.
*/
CTVariable* getCTVariable() const;
private:
QIcon findIcon() const;
/**
* Variable
*/
CTVariable* ctVariable;
VariablesWidget* variablesWidget;
};
#endif // VARIABLE_WIDGET_H

View file

@ -1,274 +0,0 @@
/***************************************************************************
* KT list view item tasks implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "variablesWidget.h"
#include <QHeaderView>
#include <QVBoxLayout>
#include <QTreeWidgetItemIterator>
#include <QAction>
#include <QList>
#include <klocale.h>
#include <kglobalsettings.h>
#include "ctcron.h"
#include "cttask.h"
#include "ctvariable.h"
#include "kcronIcons.h"
#include "crontabWidget.h"
#include "variableWidget.h"
#include "variableEditorDialog.h"
#include "logging.h"
class VariablesWidgetPrivate {
public:
QAction* newVariableAction;
QAction* modifyAction;
QAction* deleteAction;
};
/**
* Construct tasks folder from branch.
*/
VariablesWidget::VariablesWidget(CrontabWidget* crontabWidget) :
GenericListWidget(crontabWidget, i18n("<b>Environment Variables</b>"), KCronIcons::variable(KCronIcons::Small)),
d(new VariablesWidgetPrivate()) {
refreshHeaders();
treeWidget()->sortItems(0, Qt::AscendingOrder);
setupActions();
prepareContextualMenu();
connect(treeWidget(), SIGNAL(itemSelectionChanged()), this, SLOT(changeCurrentSelection()));
logDebug() << "Variables list created";
}
VariablesWidget::~VariablesWidget() {
delete d;
}
void VariablesWidget::modifySelection() {
modifySelection(firstSelectedVariableWidget(), -1);
}
void VariablesWidget::modifySelection(QTreeWidgetItem* item, int position) {
VariableWidget* variableWidget = static_cast<VariableWidget*>(item);
if (variableWidget!=NULL) {
if (position == statusColumnIndex()) {
variableWidget->toggleEnable();
emit variableModified(true);
}
else {
CTVariable* variable = variableWidget->getCTVariable();
VariableEditorDialog variableEditorDialog(variable, i18n("Modify Variable"), crontabWidget());
int result = variableEditorDialog.exec();
if (result == QDialog::Accepted) {
crontabWidget()->currentCron()->modifyVariable(variable);
variableWidget->refresh();
emit variableModified(true);
}
}
}
}
QList<VariableWidget*> VariablesWidget::selectedVariablesWidget() const {
QList<VariableWidget*> variablesWidget;
QList<QTreeWidgetItem*> variablesItems = treeWidget()->selectedItems();
foreach(QTreeWidgetItem* item, variablesItems) {
VariableWidget* variableWidget = static_cast<VariableWidget*>(item);
variablesWidget.append(variableWidget);
}
return variablesWidget;
}
VariableWidget* VariablesWidget::firstSelectedVariableWidget() const {
QTreeWidgetItem* item = firstSelected();
if (item==NULL)
return NULL;
return static_cast<VariableWidget*>(item);
}
void VariablesWidget::deleteSelection() {
QList<QTreeWidgetItem*> variablesItems = treeWidget()->selectedItems();
bool deleteSomething = ! (variablesItems.isEmpty());
foreach(QTreeWidgetItem* item, variablesItems) {
VariableWidget* variableWidget = static_cast<VariableWidget*>(item);
crontabWidget()->currentCron()->removeVariable(variableWidget->getCTVariable());
delete variableWidget->getCTVariable();
treeWidget()->takeTopLevelItem( treeWidget()->indexOfTopLevelItem(variableWidget) );
delete variableWidget;
}
if (deleteSomething) {
emit variableModified(true);
changeCurrentSelection();
}
}
bool VariablesWidget::needUserColumn() {
CTCron* currentCron = crontabWidget()->currentCron();
if (currentCron->isMultiUserCron()==true && currentCron->isSystemCron()==false)
return true;
return false;
}
int VariablesWidget::statusColumnIndex() {
if (needUserColumn() == true)
return 3;
return 2;
}
void VariablesWidget::createVariable() {
CTVariable* variable = new CTVariable(QLatin1String( "" ), QLatin1String( "" ), crontabWidget()->currentCron()->userLogin());
VariableEditorDialog variableEditorDialog(variable, i18n("New Variable"), crontabWidget());
int result = variableEditorDialog.exec();
if (result == QDialog::Accepted) {
addVariable(variable);
emit variableModified(true);
changeCurrentSelection();
}
else {
delete variable;
}
}
void VariablesWidget::addVariable(CTVariable* variable) {
logDebug() << "Add a new variable";
crontabWidget()->currentCron()->addVariable(variable);
new VariableWidget(this, variable);
changeCurrentSelection();
}
void VariablesWidget::refreshVariables(CTCron* cron) {
//Remove previous items
removeAll();
refreshHeaders();
foreach(CTVariable* ctVariable, cron->variables()) {
new VariableWidget(this, ctVariable);
}
resizeColumnContents();
}
void VariablesWidget::refreshHeaders() {
QStringList headerLabels;
if (needUserColumn()) {
headerLabels << i18n("User");
}
headerLabels << i18n("Variable");
headerLabels << i18n("Value");
headerLabels << i18n("Status");
headerLabels << i18n("Comment");
treeWidget()->setHeaderLabels(headerLabels);
if (needUserColumn())
treeWidget()->setColumnCount(5);
else
treeWidget()->setColumnCount(4);
}
void VariablesWidget::setupActions() {
d->newVariableAction = new QAction(this);
d->newVariableAction->setIcon(KIcon( QLatin1String( "document-new" )));
d->newVariableAction->setText(i18nc("Adds a new variable", "New &Variable...") );
d->newVariableAction->setToolTip(i18n("Create a new variable."));
addRightAction(d->newVariableAction, this, SLOT(createVariable()));
d->modifyAction = new QAction(this);
d->modifyAction->setText(i18n("M&odify...") );
d->modifyAction->setIcon(KIcon( QLatin1String( "document-open" )) );
d->modifyAction->setToolTip(i18n("Modify the selected variable."));
addRightAction(d->modifyAction, this, SLOT(modifySelection()));
d->deleteAction = new QAction(this);
d->deleteAction->setText(i18n("&Delete") );
d->deleteAction->setIcon(KIcon( QLatin1String( "edit-delete" )) );
d->deleteAction->setToolTip(i18n("Delete the selected variable."));
addRightAction(d->deleteAction, this, SLOT(deleteSelection()));
addRightStretch();
}
void VariablesWidget::prepareContextualMenu() {
treeWidget()->addAction(d->newVariableAction);
treeWidget()->addAction(createSeparator());
treeWidget()->addAction(d->modifyAction);
treeWidget()->addAction(d->deleteAction);
treeWidget()->addAction(createSeparator());
foreach(QAction* action, crontabWidget()->cutCopyPasteActions()) {
treeWidget()->addAction(action);
}
}
void VariablesWidget::toggleModificationActions(bool state) {
setActionEnabled(d->modifyAction, state);
setActionEnabled(d->deleteAction, state);
}
void VariablesWidget::toggleNewEntryAction(bool state) {
setActionEnabled(d->newVariableAction, state);
}
void VariablesWidget::changeCurrentSelection() {
logDebug() << "Change selection...";
bool enabled;
if (treeWidget()->selectedItems().isEmpty())
enabled = false;
else
enabled = true;
toggleModificationActions(enabled);
}

View file

@ -1,90 +0,0 @@
/***************************************************************************
* KT list view item cron tasks folder. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef VARIABLES_WIDGET_H
#define VARIABLES_WIDGET_H
#include <QTreeWidget>
#include "genericListWidget.h"
#include "cthost.h"
class VariableWidget;
class CTVariable;
class VariablesWidgetPrivate;
/**
* QListViewItem of a "tasks" folder.
*/
class VariablesWidget : public GenericListWidget {
Q_OBJECT
public:
/**
* Construct tasks folder from branch.
*/
VariablesWidget(CrontabWidget* crontabWidget);
virtual ~VariablesWidget();
QList<VariableWidget*> selectedVariablesWidget() const;
VariableWidget* firstSelectedVariableWidget() const;
void refreshVariables(CTCron* cron);
bool needUserColumn();
/**
* Enables/disables modification buttons
*/
void toggleModificationActions(bool enabled);
/**
* Enables/disables new entry actions
*/
void toggleNewEntryAction(bool enabled);
signals:
void variableModified(bool);
public slots:
void modifySelection();
void deleteSelection();
/**
* Create a new variable. Default is which type is most recently selected.
*/
void createVariable();
void addVariable(CTVariable* variable);
void changeCurrentSelection();
protected slots:
void modifySelection(QTreeWidgetItem* item, int position);
private:
void refreshHeaders();
int statusColumnIndex();
void setupActions();
void prepareContextualMenu();
VariablesWidgetPrivate* const d;
};
#endif // VARIABLES_WIDGET_H