File indexing completed on 2024-04-21 05:52:34

0001 /*
0002  * Copyright 2001 Stefan Schimanski <1Stein@gmx.de>
0003  *
0004  * This program is free software; you can redistribute it and/or modify
0005  * it under the terms of the GNU General Public License as published by
0006  * the Free Software Foundation; either version 2 of the License, or
0007  * (at your option) any later version.
0008  *
0009  * This program is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  * GNU General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU General Public License
0015  * along with this program; if not, write to the Free Software
0016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0017  */
0018 
0019 #ifndef KTIMER_H_INCLUDED
0020 #define KTIMER_H_INCLUDED
0021 
0022 #include "ui_prefwidget.h"
0023 #include <QDialog>
0024 #include <QProcess>
0025 #include <QWidget>
0026 
0027 class QTreeWidgetItem;
0028 class KConfig;
0029 
0030 class KTimerJob : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit KTimerJob(QObject *parent = nullptr);
0036     ~KTimerJob() override;
0037 
0038     enum States { Stopped, Paused, Started };
0039 
0040     unsigned delay() const;
0041     QString command() const;
0042     bool loop() const;
0043     bool oneInstance() const;
0044     bool consecutive() const;
0045     unsigned value() const;
0046     States state() const;
0047     void *user();
0048     void setUser(void *user);
0049 
0050     void load(KConfig *cfg, const QString &grp);
0051     void save(KConfig *cfg, const QString &grp);
0052     QString formatTime(int seconds) const;
0053     int timeToSeconds(int hours, int minutes, int seconds) const;
0054     void secondsToHMS(int secs, int *hours, int *minutes, int *seconds) const;
0055 
0056 public Q_SLOTS:
0057     void setDelay(unsigned int sec);
0058     void setDelay(int sec);
0059     void setCommand(const QString &cmd);
0060     void setLoop(bool loop);
0061     void setOneInstance(bool one);
0062     void setConsecutive(bool consecutive);
0063     void setValue(unsigned int value);
0064     void setValue(int value);
0065     void setState(KTimerJob::States state);
0066 
0067     void pause();
0068     void stop();
0069     void start();
0070 
0071 Q_SIGNALS:
0072     void stateChanged(KTimerJob *job, KTimerJob::States state);
0073     void delayChanged(KTimerJob *job, unsigned int sec);
0074     void commandChanged(KTimerJob *job, const QString &cmd);
0075     void loopChanged(KTimerJob *job, bool loop);
0076     void oneInstanceChanged(KTimerJob *job, bool one);
0077     void consecutiveChanged(KTimerJob *job, bool consecutive);
0078     void valueChanged(KTimerJob *job, unsigned int value);
0079 
0080     void changed(KTimerJob *job);
0081     void fired(KTimerJob *job);
0082     void finished(KTimerJob *job, bool error);
0083     void error(KTimerJob *job);
0084 
0085 protected Q_SLOTS:
0086     virtual void fire();
0087 
0088 private Q_SLOTS:
0089     void timeout();
0090     void processExited(int, QProcess::ExitStatus);
0091 
0092 private:
0093     struct KTimerJobPrivate *d;
0094 };
0095 
0096 class KTimerPref : public QDialog, public Ui::PrefWidget
0097 {
0098     Q_OBJECT
0099 public:
0100     explicit KTimerPref(QWidget *parent = nullptr);
0101     ~KTimerPref() override;
0102 
0103 public Q_SLOTS:
0104     void exit();
0105     void done(int result) Q_DECL_OVERRIDE;
0106 
0107 protected Q_SLOTS:
0108     void add();
0109     void remove();
0110     void help();
0111     void currentChanged(QTreeWidgetItem *, QTreeWidgetItem *);
0112 
0113     void saveJobs(KConfig *cfg);
0114     void loadJobs(KConfig *cfg);
0115     void saveAllJobs();
0116 
0117 private Q_SLOTS:
0118     void jobChanged(KTimerJob *job);
0119     void jobFinished(KTimerJob *job, bool error);
0120     void delayChanged();
0121 
0122 private:
0123     struct KTimerPrefPrivate *d;
0124 };
0125 
0126 #endif