diff options
author | Fritz Elfert <felfert@to.com> | 2001-03-25 00:07:23 +0000 |
---|---|---|
committer | Fritz Elfert <felfert@to.com> | 2001-03-25 00:07:23 +0000 |
commit | 2df7dc38f93b9016a606aad3bf07e3dff2ab27e2 (patch) | |
tree | 241a41c00cb3d008f04900fa4b5f38317e0903cb /kde2 | |
parent | 0f1ffc4064c073854fa51949cb8e9c44cf8885ee (diff) | |
download | plptools-2df7dc38f93b9016a606aad3bf07e3dff2ab27e2.tar.gz plptools-2df7dc38f93b9016a606aad3bf07e3dff2ab27e2.tar.bz2 plptools-2df7dc38f93b9016a606aad3bf07e3dff2ab27e2.zip |
Implemented auto-backup
Diffstat (limited to 'kde2')
-rw-r--r-- | kde2/kioslave/kio_plp.cpp | 45 | ||||
-rw-r--r-- | kde2/kpsion/kpsion.cpp | 104 | ||||
-rw-r--r-- | kde2/kpsion/kpsion.h | 1 | ||||
-rw-r--r-- | kde2/kpsion/kpsionbackuplistview.cpp | 25 | ||||
-rw-r--r-- | kde2/kpsion/kpsionbackuplistview.h | 2 | ||||
-rw-r--r-- | kde2/kpsion/kpsionconfig.cpp | 15 | ||||
-rw-r--r-- | kde2/kpsion/kpsionconfig.h | 3 | ||||
-rw-r--r-- | kde2/kpsion/setupdialog.cpp | 15 |
8 files changed, 143 insertions, 67 deletions
diff --git a/kde2/kioslave/kio_plp.cpp b/kde2/kioslave/kio_plp.cpp index ef9fe54..bfa6d70 100644 --- a/kde2/kioslave/kio_plp.cpp +++ b/kde2/kioslave/kio_plp.cpp @@ -278,7 +278,7 @@ openConnection() { for (int i = 0; i < 26; i++) { if ((devbits & 1) != 0) { PlpDrive drive; - if (plpRfsv->devinfo(i, drive) == rfsv::E_PSI_GEN_NONE) { + if (plpRfsv->devinfo(i + 'A', drive) == rfsv::E_PSI_GEN_NONE) { string vname = drive.getName(); QString name; @@ -337,8 +337,8 @@ listDir(const KURL& _url) { return; if (isRoot(path)) { - kdDebug(PLP_DEBUGAREA) << "listing root" << endl; - totalSize(drives.count()/* + 5*/); + kdDebug(PLP_DEBUGAREA) << "listing root " << drives.count() << endl; + totalSize(drives.count()); //in this case we don't need to do a real listdir UDSEntry entry; UDSAtom atom; @@ -351,43 +351,6 @@ listDir(const KURL& _url) { createVirtualDirEntry(entry, drivechars[*it] == 'Z', PLP_FTYPE_DRIVE); listEntry(entry, false); } -#if 0 - entry.clear(); - atom.m_uds = KIO::UDS_NAME; - atom.m_str = i18n("Owner"); - entry.append(atom); - createVirtualDirEntry(entry, false, PLP_FTYPE_OWNER); - listEntry(entry, false); - - entry.clear(); - atom.m_uds = KIO::UDS_NAME; - atom.m_str = i18n("Machine"); - entry.append(atom); - createVirtualDirEntry(entry, false, PLP_FTYPE_MACHINE); - listEntry(entry, false); - - entry.clear(); - atom.m_uds = KIO::UDS_NAME; - atom.m_str = i18n("Settings"); - entry.append(atom); - createVirtualDirEntry(entry, false, PLP_FTYPE_SETUP); - listEntry(entry, false); - - entry.clear(); - atom.m_uds = KIO::UDS_NAME; - atom.m_str = i18n("Backup"); - entry.append(atom); - createVirtualDirEntry(entry, false, PLP_FTYPE_BACKUP); - listEntry(entry, false); - - entry.clear(); - atom.m_uds = KIO::UDS_NAME; - atom.m_str = i18n("Restore"); - entry.append(atom); - createVirtualDirEntry(entry, false, PLP_FTYPE_RESTORE); - listEntry(entry, false); -#endif - listEntry(entry, true); finished(); return; @@ -1088,7 +1051,7 @@ special(const QByteArray &a) { return; } param = param.mid(1); - drv = drivechars[param] - 'A'; + drv = drivechars[param]; res = plpRfsv->devinfo(drv, drive); if (res != rfsv::E_PSI_GEN_NONE) { error(ERR_COULD_NOT_STAT, param); 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 <rpcsfactory.h> #include <bufferarray.h> -// 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 <klistview.h> #include <ktar.h> +#include <qdatetime.h> #include <qcheckbox.h> #include <qstringlist.h> #include <qtextstream.h> @@ -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 <kconfig.h> + #include <qstringlist.h> #include <qmap.h> @@ -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 <kapp.h> #include <kconfig.h> +#include <kdesktopfile.h> +#include <kglobalsettings.h> #include <klocale.h> #include <kfiledialog.h> #include <kmessagebox.h> @@ -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:: |