From 2df7dc38f93b9016a606aad3bf07e3dff2ab27e2 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Sun, 25 Mar 2001 00:07:23 +0000 Subject: Implemented auto-backup --- kde2/kpsion/kpsion.cpp | 104 ++++++++++++++++++++++++++--------- kde2/kpsion/kpsion.h | 1 + kde2/kpsion/kpsionbackuplistview.cpp | 25 +++++++++ kde2/kpsion/kpsionbackuplistview.h | 2 + kde2/kpsion/kpsionconfig.cpp | 15 +++++ kde2/kpsion/kpsionconfig.h | 3 + kde2/kpsion/setupdialog.cpp | 15 +++++ 7 files changed, 139 insertions(+), 26 deletions(-) (limited to 'kde2/kpsion') diff --git a/kde2/kpsion/kpsion.cpp b/kde2/kpsion/kpsion.cpp index e0c81a4..9189548 100644 --- a/kde2/kpsion/kpsion.cpp +++ b/kde2/kpsion/kpsion.cpp @@ -51,11 +51,6 @@ #include #include -// internal use for developing offline without -// having a Psion connected. -// !!!!! set to 0 for production code !!!!! -#define OFFLINE 0 - #define STID_CONNECTION 1 KPsionMainWindow::KPsionMainWindow() @@ -203,11 +198,7 @@ setupActions() { actionCollection()->action("fullbackup")->setEnabled(false); actionCollection()->action("incbackup")->setEnabled(false); -#if OFFLINE - actionCollection()->action("restore")->setEnabled(true); -#else actionCollection()->action("restore")->setEnabled(false); -#endif actionCollection()->action("format")->setEnabled(false); actionCollection()->action("fullbackup")-> @@ -245,11 +236,7 @@ switchActions() { } view->setEnabled(true); } -#if OFFLINE - actionCollection()->action("restore")->setEnabled(true); -#else actionCollection()->action("restore")->setEnabled(rwSelected); -#endif actionCollection()->action("format")->setEnabled(rwSelected); actionCollection()->action("fullbackup")->setEnabled(anySelected); actionCollection()->action("incbackup")->setEnabled(anySelected); @@ -290,13 +277,6 @@ queryPsion() { statusBar()->changeItem(i18n("Retrieving machine info ..."), STID_CONNECTION); -#if OFFLINE - machineUID = 0x1000118a0c428fa3ULL; - S5mx = true; - insertDrive('C', "Intern"); - insertDrive('D', "Flash"); - insertDrive('Z', "RomDrive"); -#else rpcs::machineInfo mi; if ((res = plpRpcs->getMachineInfo(mi)) != rfsv::E_PSI_GEN_NONE) { QString msg = i18n("Could not get Psion machine info"); @@ -306,7 +286,6 @@ queryPsion() { } machineUID = mi.machineUID; S5mx = (strcmp(mi.machineName, "SERIES5mx") == 0); -#endif QString uid = getMachineUID(); bool machineFound = false; @@ -324,7 +303,7 @@ queryPsion() { machineFound = true; } } -#if (!(OFFLINE)) + drives.clear(); statusBar()->changeItem(i18n("Retrieving drive list ..."), STID_CONNECTION); @@ -342,7 +321,7 @@ queryPsion() { } devbits >>= 1; } -#endif + if (!machineFound) { if (args->isSet("autobackup")) { connected = false; @@ -361,6 +340,78 @@ queryPsion() { } statusBar()->changeItem(i18n("Connected to %1").arg(machineName), STID_CONNECTION); + + if (args->isSet("autobackup") || args->isSet("backup") || + args->isSet("restore") || args->isSet("format")) { + view->setEnabled(false); + actionCollection()->action("restore")->setEnabled(false); + actionCollection()->action("format")->setEnabled(false); + actionCollection()->action("fullbackup")->setEnabled(false); + actionCollection()->action("incbackup")->setEnabled(false); + QTimer::singleShot(1000, this, SLOT(slotAutoAction())); + } +} + +void KPsionMainWindow:: +slotAutoAction() { + QString uid = getMachineUID(); + KConfig *config = kapp->config(); + KPsionConfig pcfg; + + if (args->isSet("autobackup")) { + bool any = false; + QStringList::Iterator it; + QDateTime d; + int fi = pcfg.getIntervalDays(config, KPsionConfig::OPT_FULLINTERVAL); + int ii = pcfg.getIntervalDays(config, KPsionConfig::OPT_INCINTERVAL); + + KPsionBackupListView *bl = new KPsionBackupListView(0, "backups"); + bl->readBackups(uid); + + // Full Backups + for (it = backupDrives.begin(); it != backupDrives.end(); ++it) { + d = bl->getLastBackup(KPsionBackupListView::FULL, *it); + if (fi && d.daysTo(QDateTime::currentDateTime()) >= fi) { + fullBackup = true; + for (QIconViewItem *i = view->firstItem(); i; i = i->nextItem()) { + if (i->key() == *it) { + i->setSelected(true); + any = true; + } + } + } + } + if (any) { + delete bl; + doBackup(); + // If just made a backup, re-read backups + bl = new KPsionBackupListView(0, "backups"); + bl->readBackups(uid); + } + + // Incremental Backups + any = false; + fullBackup = false; + view->clearSelection(); + for (it = backupDrives.begin(); it != backupDrives.end(); ++it) { + d = bl->getLastBackup(KPsionBackupListView::INCREMENTAL, *it); + if (ii && d.daysTo(QDateTime::currentDateTime()) >= ii) { + for (QIconViewItem *i = view->firstItem(); i; i = i->nextItem()) { + if (i->key() == *it) { + i->setSelected(true); + any = true; + } + } + } + } + delete bl; + + if (any) + doBackup(); + + return; + } + if (args->isSet("backup")) { bool any = false; @@ -383,6 +434,7 @@ queryPsion() { } return; } + if (args->isSet("restore")) { bool any = false; @@ -408,6 +460,7 @@ queryPsion() { slotStartRestore(); return; } + if (args->isSet("format")) { bool any = false; QCStringList argl = args->getOptionList("format"); @@ -422,7 +475,8 @@ queryPsion() { } } } - KMessageBox::sorry(this, "Formatting is not yet implemented"); + if (any) + slotStartFormat(); return; } } @@ -454,7 +508,6 @@ queryClose() { void KPsionMainWindow:: tryConnect() { -#if (!(OFFLINE)) if (shuttingDown || connected) return; bool showMB = firstTry; @@ -558,7 +611,6 @@ tryConnect() { } return; } -#endif connected = true; queryPsion(); } diff --git a/kde2/kpsion/kpsion.h b/kde2/kpsion/kpsion.h index faae85a..748450e 100644 --- a/kde2/kpsion/kpsion.h +++ b/kde2/kpsion/kpsion.h @@ -87,6 +87,7 @@ private slots: void iconClicked(QIconViewItem *i); void iconOver(QIconViewItem *i); void slotUpdateTimer(); + void slotAutoAction(); private: void doBackup(); diff --git a/kde2/kpsion/kpsionbackuplistview.cpp b/kde2/kpsion/kpsionbackuplistview.cpp index c51c62d..ed4808a 100644 --- a/kde2/kpsion/kpsionbackuplistview.cpp +++ b/kde2/kpsion/kpsionbackuplistview.cpp @@ -391,6 +391,31 @@ getFormatDrives() { return l; } +QDateTime KPsionBackupListView:: +getLastBackup(int backupType, QString drive) { + time_t stamp = 0; + + drive += ":"; + // Find latest backup for given drive + KPsionCheckListItem *i = firstChild(); + while (i != 0L) { + if ((backupType >= i->backupType()) && (i->when() > stamp)) { + KPsionCheckListItem *c = i->firstChild(); + while (c != 0L) { + if (c->text() == drive) { + stamp = i->when(); + break; + } + c = c->nextSibling(); + } + } + i = i->nextSibling(); + } + QDateTime d; + d.setTime_t(stamp); + return d; +} + bool KPsionBackupListView:: autoSelect(QString drive) { KPsionCheckListItem *latest = NULL; diff --git a/kde2/kpsion/kpsionbackuplistview.h b/kde2/kpsion/kpsionbackuplistview.h index f4c3fed..7119eb6 100644 --- a/kde2/kpsion/kpsionbackuplistview.h +++ b/kde2/kpsion/kpsionbackuplistview.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -102,6 +103,7 @@ public: QStringList getSelectedTars(); QStringList getFormatDrives(); bool autoSelect(QString drive); + QDateTime getLastBackup(int backupType, QString drive); signals: void itemsEnabled(bool); diff --git a/kde2/kpsion/kpsionconfig.cpp b/kde2/kpsion/kpsionconfig.cpp index 7a0f6f4..976ae69 100644 --- a/kde2/kpsion/kpsionconfig.cpp +++ b/kde2/kpsion/kpsionconfig.cpp @@ -131,6 +131,21 @@ getConfigBackupInterval() { return l; } +int KPsionConfig:: +getIntervalDays(KConfig *config, int optIdx) { + config->setGroup(getSectionName(optIdx)); + int i = config->readNumEntry(getOptionName(optIdx)); + switch (i) { + case 8: + return 14; + case 9: + return 21; + case 10: + return 28; + } + return i; +} + /* * Local variables: * c-basic-offset: 4 diff --git a/kde2/kpsion/kpsionconfig.h b/kde2/kpsion/kpsionconfig.h index 5dd2bfa..f0ae075 100644 --- a/kde2/kpsion/kpsionconfig.h +++ b/kde2/kpsion/kpsionconfig.h @@ -23,6 +23,8 @@ #ifndef _KPSIONCONFIG_H_ #define _KPSIONCONFIG_H_ +#include + #include #include @@ -64,6 +66,7 @@ public: const QString getSectionName(int); const QString getStrDefault(int); int getIntDefault(int); + int getIntervalDays(KConfig *config, int optIdx); private: cfgMap optionNames; diff --git a/kde2/kpsion/setupdialog.cpp b/kde2/kpsion/setupdialog.cpp index e049ec2..b62640e 100644 --- a/kde2/kpsion/setupdialog.cpp +++ b/kde2/kpsion/setupdialog.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include #include #include @@ -415,6 +417,19 @@ slotSaveSettings() { config->setGroup(pcfg.getSectionName(KPsionConfig::OPT_SERIALSPEED)); config->writeEntry(pcfg.getOptionName(KPsionConfig::OPT_SERIALSPEED), speedCombo->currentText()); + + QString asFile = KGlobalSettings::autostartPath() + "/PsionBackup.desktop"; + // Create or remove autostart entry + if (iIntCombo->currentItem() || fIntCombo->currentItem()) { + KDesktopFile f(asFile); + f.setGroup("Desktop Entry"); + f.writeEntry("Type", "Application"); + f.writeEntry("Exec", "kpsion --autobackup"); + f.writeEntry("Icon", "kpsion"); + f.writeEntry("Terminal", false); + f.writeEntry("Comment", "Scheduled backup of your Psion"); + } else + unlink(asFile.latin1()); } bool SetupDialog:: -- cgit v1.2.3