Commit b32005ef authored by Simon Persson's avatar Simon Persson

Clean up planexecutor and prepare for handling repair and corruption check jobs

parent 8f8cfb20
......@@ -39,17 +39,23 @@ void BupJob::start() {
}
void BupJob::startJob() {
KProcess lVersionProcess;
lVersionProcess.setOutputChannelMode(KProcess::SeparateChannels);
lVersionProcess << QLatin1String("bup") << QLatin1String("version");
if(lVersionProcess.execute() < 0) {
KProcess lPar2Process;
lPar2Process.setOutputChannelMode(KProcess::SeparateChannels);
lPar2Process << QLatin1String("bup") << QLatin1String("fsck") << QLatin1String("--par2-ok");
int lExitCode = lPar2Process.execute();
if(lExitCode < 0) {
setError(ErrorWithoutLog);
setErrorText(i18nc("notification", "The \"bup\" program is needed but could not be found, "
"maybe it is not installed?"));
emitResult();
return;
} else if(mBackupPlan.mGenerateRecoveryInfo && lExitCode != 0) {
setError(ErrorWithoutLog);
setErrorText(i18nc("notification", "The \"par2\" program is needed but could not be found, "
"maybe it is not installed?"));
emitResult();
return;
}
mBupVersion = QString::fromUtf8(lVersionProcess.readAllStandardOutput());
mLogStream << QLatin1String("Kup is starting bup backup job at ")
<< KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(),
......
......@@ -49,7 +49,6 @@ protected:
KProcess mIndexProcess;
KProcess mSaveProcess;
KProcess mPar2Process;
QString mBupVersion;
};
#endif /*BUPJOB_H*/
......@@ -79,7 +79,7 @@ void KupDaemon::setupGuiStuff() {
void KupDaemon::reloadConfig() {
foreach(PlanExecutor *lExecutor, mExecutors) {
if(lExecutor->running()) {
if(lExecutor->busy()) {
mWaitingToReloadConfig = true;
return;
}
......@@ -114,21 +114,21 @@ void KupDaemon::updateTrayIcon() {
QString lToolTipIconName = BackupPlan::iconName(BackupPlan::GOOD);
foreach(PlanExecutor *lExec, mExecutors) {
if(lExec->destinationAvailable()) {
if(lExec->mState != PlanExecutor::NOT_AVAILABLE) {
lStatus = KStatusNotifierItem::Active;
lToolTipTitle = i18nc("@info:tooltip", "Backup destination available");
}
}
foreach(PlanExecutor *lExec, mExecutors) {
if(lExec->planStatus() == BackupPlan::MEDIUM) {
if(lExec->mPlan->backupStatus() == BackupPlan::MEDIUM) {
lToolTipIconName = BackupPlan::iconName(BackupPlan::MEDIUM);
lToolTipSubTitle = i18nc("@info:tooltip", "New backup suggested");
}
}
foreach(PlanExecutor *lExec, mExecutors) {
if(lExec->planStatus() == BackupPlan::BAD) {
if(lExec->mPlan->backupStatus() == BackupPlan::BAD) {
if(lExec->scheduleType() != BackupPlan::MANUAL) {
lStatus = KStatusNotifierItem::Active;
}
......@@ -137,12 +137,12 @@ void KupDaemon::updateTrayIcon() {
lToolTipSubTitle = i18nc("@info:tooltip", "New backup neeeded");
}
}
foreach(PlanExecutor *lExec, mExecutors) {
if(lExec->running()) {
foreach(PlanExecutor *lExecutor, mExecutors) {
if(lExecutor->busy()) {
lStatus = KStatusNotifierItem::NeedsAttention;
lToolTipIconName = QLatin1String("kup");
lToolTipTitle = i18nc("@info:tooltip", "Taking new backup");
lToolTipSubTitle = lExec->description(); // TODO: show percentage etc.
lToolTipTitle = lExecutor->currentActivityTitle();
lToolTipSubTitle = lExecutor->mPlan->mDescription; // TODO: show percentage etc.
}
}
mStatusNotifier->setStatus(lStatus);
......@@ -192,7 +192,7 @@ void KupDaemon::setupContextMenu() {
mContextMenu = new KMenu(i18nc("@title:menu", "Backups"));
mContextMenu->addAction(i18nc("@action:inmenu", "Configure Backups"), this, SLOT(showConfig()));
foreach(PlanExecutor *lExec, mExecutors) {
mContextMenu->addMenu(lExec->planActions());
mContextMenu->addMenu(lExec->mActionMenu);
}
mStatusNotifier->setContextMenu(mContextMenu);
mStatusNotifier->setAssociatedWidget(mContextMenu);
......
......@@ -23,7 +23,7 @@
#include <KSharedConfig>
#define KUP_DBUS_SERVICE_NAME QLatin1String("org.kde.kupdaemon")
#define KUP_DBUS_SERVICE_NAME QLatin1String("org.kde.kup-daemon")
#define KUP_DBUS_OBJECT_PATH QLatin1String("/DaemonControl")
......@@ -38,6 +38,9 @@ class QTimer;
class KupDaemon : public QObject
{
Q_OBJECT
// interface names are not allowed to have hyphens. set name here without hyphen, otherwise the
// name gets taken from KAboutData combined with the QMetaData of this class.
Q_CLASSINFO("D-Bus Interface", "org.kde.kupdaemon")
public:
KupDaemon();
......
......@@ -55,7 +55,7 @@ extern "C" int KDE_EXPORT kdemain(int argc, char **argv) {
KUniqueApplication lApp;
// Use for debugging...
//KApplication lApp;
// KApplication lApp;
lApp.setQuitOnLastWindowClosed(false);
lApp.disableSessionManagement();
......
......@@ -77,6 +77,19 @@ PlanExecutor::PlanExecutor(BackupPlan *pPlan, QObject *pParent)
PlanExecutor::~PlanExecutor() {
}
QString PlanExecutor::currentActivityTitle() {
switch(mState) {
case BACKUP_RUNNING:
return i18nc("@info:tooltip", "Taking new backup");
case INTEGRITY_TESTING:
return i18nc("@info:tooltip", "Checking backup integrity");
case REPAIRING:
return i18nc("@info:tooltip", "Repairing backups");
default:
return QString();
}
}
// dispatcher code for entering one of the available states
void PlanExecutor::enterAvailableState() {
if(mState == NOT_AVAILABLE) {
......@@ -195,13 +208,12 @@ void PlanExecutor::discardFailNotification() {
}
void PlanExecutor::showLog() {
discardFailNotification();
KRun::runUrl(mLogFilePath, QLatin1String("text/x-log"), NULL);
}
void PlanExecutor::enterBackupRunningState() {
discardUserQuestion();
mState = RUNNING;
mState = BACKUP_RUNNING;
emit stateChanged();
mRunBackupAction->setEnabled(false);
startBackup();
......@@ -231,7 +243,7 @@ void PlanExecutor::exitBackupRunningState(bool pWasSuccessful) {
}
void PlanExecutor::updateAccumulatedUsageTime() {
if(mState == RUNNING) { //usage time during backup doesn't count...
if(mState == BACKUP_RUNNING) { //usage time during backup doesn't count...
return;
}
......
......@@ -46,29 +46,24 @@ public:
PlanExecutor(BackupPlan *pPlan, QObject *pParent);
virtual ~PlanExecutor();
bool destinationAvailable() {
return mState != NOT_AVAILABLE;
}
bool running() {
return mState == RUNNING;
BackupPlan::ScheduleType scheduleType() {
return (BackupPlan::ScheduleType)mPlan->mScheduleType;
}
virtual QMenu *planActions() {
return mActionMenu;
bool busy() {
return mState == BACKUP_RUNNING || mState == INTEGRITY_TESTING || mState == REPAIRING;
}
QString description() {
return mPlan->mDescription;
}
QString currentActivityTitle();
BackupPlan::Status planStatus() {
return mPlan->backupStatus();
}
BackupPlan::ScheduleType scheduleType() {
return (BackupPlan::ScheduleType)mPlan->mScheduleType;
}
enum ExecutorState {NOT_AVAILABLE, WAITING_FOR_FIRST_BACKUP,
WAITING_FOR_BACKUP_AGAIN, BACKUP_RUNNING, WAITING_FOR_MANUAL_BACKUP,
INTEGRITY_TESTING, REPAIRING};
ExecutorState mState;
QString mDestinationPath;
QString mLogFilePath;
BackupPlan *mPlan;
QMenu *mActionMenu;
public slots:
virtual void checkStatus() = 0;
......@@ -96,15 +91,8 @@ protected slots:
void showLog();
protected:
enum ExecutorState {NOT_AVAILABLE, WAITING_FOR_FIRST_BACKUP,
WAITING_FOR_BACKUP_AGAIN, RUNNING, WAITING_FOR_MANUAL_BACKUP};
ExecutorState mState;
BackupJob *createBackupJob();
QString mDestinationPath;
QString mLogFilePath;
BackupPlan *mPlan;
QMenu *mActionMenu;
QAction *mShowFilesAction;
QAction *mRunBackupAction;
QAction *mShowLogFileAction;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment