File indexing completed on 2021-12-21 14:38:36

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 <QDialog>
0023 #include <QWidget>
0024 #include <QProcess>
0025 #include "ui_prefwidget.h"
0026 
0027 class QTreeWidgetItem;
0028 class KConfig;
0029 
0030 class KTimerJob : public QObject {
0031  Q_OBJECT
0032 
0033  public:
0034     explicit KTimerJob( QObject *parent=nullptr);
0035     ~KTimerJob() override;
0036 
0037     enum States { Stopped, Paused, Started };
0038 
0039     unsigned delay() const;
0040     QString command() const;
0041     bool loop() const;
0042     bool oneInstance() const;
0043     bool consecutive() const;
0044     unsigned value() const;
0045     States state() const;
0046     void *user();
0047     void setUser( void *user );
0048 
0049     void load( KConfig *cfg, const QString& grp );
0050     void save( KConfig *cfg, const QString& grp );
0051     QString formatTime( int seconds ) const;
0052     int timeToSeconds( int hours, int minutes, int seconds ) const;
0053     void secondsToHMS( int secs, int *hours, int *minutes, int *seconds ) const;
0054 
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 
0097 class KTimerPref : public QDialog, public Ui::PrefWidget
0098 {
0099     Q_OBJECT
0100  public:
0101     explicit KTimerPref( QWidget *parent=nullptr);
0102     ~KTimerPref() override;
0103 
0104  public Q_SLOTS:
0105     void exit();
0106     void done(int result) Q_DECL_OVERRIDE;
0107 
0108  protected Q_SLOTS:
0109     void add();
0110     void remove();
0111     void help();
0112     void currentChanged( QTreeWidgetItem * , QTreeWidgetItem *);
0113 
0114     void saveJobs( KConfig *cfg );
0115     void loadJobs( KConfig *cfg );
0116     void saveAllJobs();
0117 
0118  private Q_SLOTS:
0119     void jobChanged( KTimerJob *job );
0120     void jobFinished( KTimerJob *job, bool error );
0121     void delayChanged();
0122 
0123  private:
0124     struct KTimerPrefPrivate *d;
0125 };
0126 
0127 #endif