24 #include <klineedit.h>
25 #include <kiconloader.h>
26 #include <kapplication.h>
27 #include <kfiledialog.h>
29 #include <ktoolinvocation.h>
30 #include <kstandardguiitem.h>
32 #include <kstandardaction.h>
33 #include "kstatusnotifieritem.h"
54 virtual ~KTimerJobItem() {
60 void setStatus(
bool error ) {
66 setText( 0, m_job->formatTime(m_job->value()) );
73 setText( 1, m_job->formatTime(m_job->delay()) );
75 switch( m_job->state() ) {
93 struct KTimerPrefPrivate
101 d =
new KTimerPrefPrivate;
106 m_stop->setIcon( KIcon(
QLatin1String(
"media-playback-stop" )) );
107 m_pause->setIcon( KIcon(
QLatin1String(
"media-playback-pause" )) );
111 KStatusNotifierItem *tray =
new KStatusNotifierItem(
this);
113 tray->setCategory(KStatusNotifierItem::ApplicationStatus);
114 tray->setStatus(KStatusNotifierItem::Active);
116 m_help->setGuiItem(KStandardGuiItem::help());
119 KAction *
exit = KStandardAction::quit(
this, SLOT(
exit()),
this);
123 connect( m_add, SIGNAL(clicked()), SLOT(
add()) );
124 connect( m_remove, SIGNAL(clicked()), SLOT(
remove()) );
125 connect( m_help, SIGNAL(clicked()), SLOT(
help()) );
128 loadJobs( KGlobal::config().data() );
140 saveJobs( KGlobal::config().data() );
147 KTimerJobItem *item =
new KTimerJobItem( job, m_list );
163 if( m_list->topLevelItemCount()==1 )
166 m_list->setCurrentItem( item );
173 delete m_list->currentItem();
179 KToolInvocation::invokeHelp();
185 KTimerJobItem *item =
static_cast<KTimerJobItem*
>(i);
189 m_state->setEnabled(
true );
190 m_settings->setEnabled(
true );
191 m_remove->setEnabled(
true );
192 m_delayH->disconnect();
193 m_delayM->disconnect();
194 m_delay->disconnect();
195 m_loop->disconnect();
197 m_start->disconnect();
198 m_pause->disconnect();
199 m_stop->disconnect();
200 m_counter->disconnect();
201 m_slider->disconnect();
202 m_commandLine->disconnect();
203 m_commandLine->lineEdit()->disconnect();
208 m_delayH->setValue( h );
209 m_delayM->setValue( m );
210 m_delay->setValue( s );
213 job, SLOT(setCommand(
QString)) );
214 connect( m_delayH, SIGNAL(valueChanged(
int)),
215 SLOT(delayChanged()) );
216 connect( m_delayM, SIGNAL(valueChanged(
int)),
217 SLOT(delayChanged()) );
218 connect( m_delay, SIGNAL(valueChanged(
int)),
219 SLOT(delayChanged()) );
220 connect( m_loop, SIGNAL(toggled(
bool)),
221 job, SLOT(setLoop(
bool)) );
222 connect( m_one, SIGNAL(toggled(
bool)),
223 job, SLOT(setOneInstance(
bool)) );
224 connect( m_stop, SIGNAL(clicked()),
226 connect( m_pause, SIGNAL(clicked()),
227 job, SLOT(pause()) );
228 connect( m_start, SIGNAL(clicked()),
229 job, SLOT(start()) );
230 connect( m_slider, SIGNAL(valueChanged(
int)),
231 job, SLOT(setValue(
int)) );
233 m_commandLine->lineEdit()->setText( job->
command() );
234 m_loop->setChecked( job->
loop() );
236 m_counter->display( (
int)job->
value() );
237 m_slider->setMaximum( job->
delay() );
238 m_slider->setValue( job->
value() );
241 m_state->setEnabled(
false );
242 m_settings->setEnabled(
false );
243 m_remove->setEnabled(
false );
248 void KTimerPref::jobChanged(
KTimerJob *job )
250 KTimerJobItem *item =
static_cast<KTimerJobItem*
>(job->
user());
255 if( item==m_list->currentItem() ) {
258 m_slider->setMaximum( job->
delay() );
259 m_slider->setValue( job->
value() );
260 m_counter->display( (
int)job->
value() );
266 void KTimerPref::jobFinished(
KTimerJob *job,
bool error )
268 KTimerJobItem *item =
static_cast<KTimerJobItem*
>(job->
user());
269 item->setStatus( error );
275 void KTimerPref::delayChanged()
277 KTimerJobItem *item =
static_cast<KTimerJobItem*
>(m_list->currentItem());
280 int time_sec = job->
timeToSeconds( m_delayH->value(), m_delayM->value(), m_delay->value() );
298 const int nbList=m_list->topLevelItemCount();
299 for (
int num = 0; num < nbList; ++num)
301 KTimerJobItem *item =
static_cast<KTimerJobItem*
>(m_list->topLevelItem(num));
306 KConfigGroup jobscfg = cfg->group(
"Jobs");
307 jobscfg.writeEntry(
"Number", m_list->topLevelItemCount());
315 const int num = cfg->group(
"Jobs").readEntry(
"Number", 0 );
316 for(
int n=0; n<num; n++ ) {
318 KTimerJobItem *item =
new KTimerJobItem( job, m_list );
344 struct KTimerJobPrivate {
361 d =
new KTimerJobPrivate;
365 d->oneInstance =
true;
370 d->timer =
new QTimer(
this );
371 connect( d->timer, SIGNAL(timeout()), SLOT(timeout()) );
383 KConfigGroup groupcfg = cfg->group(grp);
384 groupcfg.writeEntry(
"Delay", d->delay );
385 groupcfg.writePathEntry(
"Command", d->command );
386 groupcfg.writeEntry(
"Loop", d->loop );
387 groupcfg.writeEntry(
"OneInstance", d->oneInstance );
388 groupcfg.writeEntry(
"State", (
int)d->state );
394 KConfigGroup groupcfg = cfg->group(grp);
395 setDelay( groupcfg.readEntry(
"Delay", 100 ) );
397 setLoop( groupcfg.readEntry(
"Loop",
false ) );
398 setOneInstance( groupcfg.readEntry(
"OneInstance", d->oneInstance ) );
415 return hours * 3600 + minutes * 60 + seconds;
474 if( d->delay!=sec ) {
494 if( d->command!=cmd ) {
510 if( d->loop!=loop ) {
520 return d->oneInstance;
526 if( d->oneInstance!=one ) {
527 d->oneInstance = one;
542 if( d->value!=value ) {
558 if( d->state!=state ) {
560 d->timer->start( 1000 );
574 void KTimerJob::timeout()
576 if( d->state==
Started && d->value!=0 ) {
589 void KTimerJob::processExited(
int, QProcess::ExitStatus status)
592 const bool ok = status==0;
593 const int i = d->processes.indexOf( proc);
595 delete d->processes.takeAt(i);
597 if( !ok ) emit
error(
this );
606 if( !d->oneInstance || d->processes.isEmpty() ) {
608 d->processes.append( proc );
610 SLOT(processExited(
int,QProcess::ExitStatus)) );
611 if (!d->command.simplified ().isEmpty()) {
612 proc->
start(d->command);
615 if(proc->
state() == QProcess::NotRunning) {
616 const int i = d->processes.indexOf( proc);
618 delete d->processes.takeAt(i);
624 #include "ktimer.moc"
KTimerPref(QWidget *parent=0)
void loopChanged(KTimerJob *job, bool loop)
void delayChanged(KTimerJob *job, unsigned int sec)
void secondsToHMS(int secs, int *hours, int *minutes, int *seconds) const
void fired(KTimerJob *job)
void setState(States state)
void stateChanged(KTimerJob *job, States state)
void finished(KTimerJob *job, bool error)
void finished(int result)
int timeToSeconds(int hours, int minutes, int seconds) const
void setValue(unsigned int value)
void setOneInstance(bool one)
KTimerJob(QObject *parent=0)
void changed(KTimerJob *job)
QString formatTime(int seconds) const
void valueChanged(KTimerJob *job, unsigned int value)
void load(KConfig *cfg, const QString &grp)
void commandChanged(KTimerJob *job, const QString &cmd)
void setDelay(unsigned int sec)
void oneInstanceChanged(KTimerJob *job, bool one)
void setText(int column, const QString &text)
void setCommand(const QString &cmd)
void saveJobs(KConfig *cfg)
void currentChanged(QTreeWidgetItem *, QTreeWidgetItem *)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void loadJobs(KConfig *cfg)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
QProcess::ProcessState state() const
void error(KTimerJob *job)
void save(KConfig *cfg, const QString &grp)