File indexing completed on 2024-04-28 13:41:55
0001 // SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com> 0002 // 0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 #ifndef PLANEXECUTOR_H 0006 #define PLANEXECUTOR_H 0007 0008 #include "backupplan.h" 0009 #include "backupjob.h" 0010 0011 #include <KProcess> 0012 0013 class KupDaemon; 0014 0015 class KNotification; 0016 class KProcess; 0017 0018 class QTimer; 0019 0020 // Accumulate usage time every KUP_USAGE_MONITOR_INTERVAL_S while user is active. 0021 // Consider user inactive after KUP_IDLE_TIMEOUT_S s of no keyboard or mouse activity. 0022 #define KUP_USAGE_MONITOR_INTERVAL_S 2*60 0023 #define KUP_IDLE_TIMEOUT_S 30 0024 0025 class PlanExecutor : public QObject 0026 { 0027 Q_OBJECT 0028 public: 0029 PlanExecutor(BackupPlan *pPlan, KupDaemon *pKupDaemon); 0030 ~PlanExecutor() override; 0031 0032 BackupPlan::ScheduleType scheduleType() { 0033 return static_cast<BackupPlan::ScheduleType>(mPlan->mScheduleType); 0034 } 0035 0036 bool busy() { 0037 return mState == BACKUP_RUNNING || mState == INTEGRITY_TESTING || mState == REPAIRING; 0038 } 0039 bool destinationAvailable() { 0040 return mState != NOT_AVAILABLE; 0041 } 0042 0043 QString currentActivityTitle(); 0044 0045 enum ExecutorState {NOT_AVAILABLE, WAITING_FOR_FIRST_BACKUP, 0046 WAITING_FOR_BACKUP_AGAIN, BACKUP_RUNNING, WAITING_FOR_MANUAL_BACKUP, 0047 INTEGRITY_TESTING, REPAIRING}; 0048 ExecutorState mState; 0049 QString mDestinationPath; 0050 QString mLogFilePath; 0051 BackupPlan *mPlan; 0052 0053 public slots: 0054 virtual void checkStatus() = 0; 0055 virtual void showBackupFiles(); 0056 virtual void showBackupPurger(); 0057 void updateAccumulatedUsageTime(); 0058 void startIntegrityCheck(); 0059 void startRepairJob(); 0060 void startBackupSaveJob(); 0061 void showLog(); 0062 0063 signals: 0064 void stateChanged(); 0065 void backupStatusChanged(); 0066 0067 protected slots: 0068 virtual void startBackup(); 0069 void finishBackup(KJob *pJob); 0070 void finishSizeCheck(KJob *pJob); 0071 0072 void exitBackupRunningState(bool pWasSuccessful); 0073 void enterAvailableState(); 0074 void askUserOrStart(const QString& pUserQuestion); 0075 void enterNotAvailableState(); 0076 0077 void askUser(const QString &pQuestion); 0078 void discardUserQuestion(); 0079 0080 void notifyBackupFailed(KJob *pFailedJob); 0081 void discardFailNotification(); 0082 0083 static void notifyBackupSucceeded(); 0084 0085 void integrityCheckFinished(KJob *pJob); 0086 void discardIntegrityNotification(); 0087 void repairFinished(KJob *pJob); 0088 void discardRepairNotification(); 0089 0090 void startSleepInhibit(); 0091 void endSleepInhibit(); 0092 0093 protected: 0094 BackupJob *createBackupJob(); 0095 static bool powerSaveActive(); 0096 0097 KNotification *mQuestion; 0098 QTimer *mSchedulingTimer; 0099 KNotification *mFailNotification; 0100 KNotification *mIntegrityNotification; 0101 KNotification *mRepairNotification; 0102 ExecutorState mLastState; 0103 KupDaemon *mKupDaemon; 0104 uint mSleepCookie; 0105 }; 0106 0107 #endif // PLANEXECUTOR_H