summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-21 17:43:18 (UTC)
committer zautrix <zautrix>2005-04-21 17:43:18 (UTC)
commitfd38343ef53c9b2a48208f747100579703cc1814 (patch) (unidiff)
tree2aeabdf01986d59d72044615b952a65b4d8ba292
parent0a13a3490ec3bf4735e3435f80f58fa7d50b4448 (diff)
downloadkdepimpi-fd38343ef53c9b2a48208f747100579703cc1814.zip
kdepimpi-fd38343ef53c9b2a48208f747100579703cc1814.tar.gz
kdepimpi-fd38343ef53c9b2a48208f747100579703cc1814.tar.bz2
backup impl
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--bin/kdepim/korganizer/germantranslation.txt13
-rw-r--r--korganizer/mainwindow.cpp30
-rw-r--r--libkdepim/kcmconfigs/kdepimconfigwidget.cpp28
-rw-r--r--libkdepim/kpimglobalprefs.cpp6
-rw-r--r--libkdepim/kpimprefs.cpp3
-rw-r--r--libkdepim/kpimprefs.h1
-rw-r--r--microkde/kapplication.cpp120
-rw-r--r--microkde/kapplication.h1
8 files changed, 196 insertions, 6 deletions
diff --git a/bin/kdepim/korganizer/germantranslation.txt b/bin/kdepim/korganizer/germantranslation.txt
index fa18304..9e9a1a1 100644
--- a/bin/kdepim/korganizer/germantranslation.txt
+++ b/bin/kdepim/korganizer/germantranslation.txt
@@ -1355,2 +1355,15 @@
1355{ "The todo\n%1\nhas subtodos!\nDo you want to set\nthe categories for\nall subtodos as well?","Das Todo\n%1\nhat Untertodos!\nMöchten Sie die Kategorien\nauch für alle Untertodos setzen?" }, 1355{ "The todo\n%1\nhas subtodos!\nDo you want to set\nthe categories for\nall subtodos as well?","Das Todo\n%1\nhat Untertodos!\nMöchten Sie die Kategorien\nauch für alle Untertodos setzen?" },
1356{ "Backup enabled","Backup angeschaltet" },
1357{ "Use standard backup dir","Standard Backupverzeichnis" },
1358{ "Number of Backups:","Anzahl der Backups" },
1359{ "Make backup every ","Mache ein Backup alle " },
1360{ " days"," Tage" },
1361{ "","" },
1362{ "","" },
1363{ "","" },
1364{ "","" },
1365{ "","" },
1366{ "","" },
1367{ "","" },
1368{ "","" },
1356{ "","" }, 1369{ "","" },
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 68e5e5a..9ad0694 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -63,2 +63,3 @@
63#include "externalapphandler.h" 63#include "externalapphandler.h"
64#include <kglobalsettings.h>
64 65
@@ -1803,2 +1804,31 @@ void MainWindow::save()
1803 if ( mView->checkFileVersion( defaultFileName()) ) { 1804 if ( mView->checkFileVersion( defaultFileName()) ) {
1805 if ( KPimGlobalPrefs::instance()->mBackupEnabled ){
1806 QDate reference ( 2000,1,1);
1807 int daysTo = reference.daysTo ( QDate::currentDate() );
1808 if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) {
1809 setCaption(i18n("KO/Pi:Creating backup ... please wait ..." ));
1810 qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate);
1811 // we need the file path, the backup dir and the number of bups as param
1812 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
1813 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
1814 bupDir = KGlobalSettings::backupDataDir();
1815 int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );//55;//call backup
1816 if ( retval == 0 ) {
1817 qDebug("KO: Backup cancelled. Will try again tomorrow ");
1818 // retval == 0 : backup skipped for today, try again tomorrow
1819 KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1;
1820 } else if ( retval == 1 ){
1821 qDebug("KO: Backup created.");
1822 // backup ok
1823 KOPrefs::instance()->mLastBackupDate = daysTo;
1824
1825 } else if ( retval == 2 ){
1826 qDebug("KO: Backup globally cancelled.");
1827 // backup globally cancelled
1828 KPimGlobalPrefs::instance()->mBackupEnabled = false;
1829 }
1830 // retval == 3: do nothing, try again later
1831 }
1832 ; // KPimGlobalPrefs::instance()->mLastBackupDate
1833 }
1804 QTime neededSaveTime = QDateTime::currentDateTime().time(); 1834 QTime neededSaveTime = QDateTime::currentDateTime().time();
diff --git a/libkdepim/kcmconfigs/kdepimconfigwidget.cpp b/libkdepim/kcmconfigs/kdepimconfigwidget.cpp
index fbfbc45..93538ec 100644
--- a/libkdepim/kcmconfigs/kdepimconfigwidget.cpp
+++ b/libkdepim/kcmconfigs/kdepimconfigwidget.cpp
@@ -134,3 +134,3 @@ void KDEPIMConfigWidget::setupBackupTab()
134 sb = addWidBool(i18n("Use standard backup dir"), 134 sb = addWidBool(i18n("Use standard backup dir"),
135 &(KPimGlobalPrefs::instance()->mBackupEnabled),bupFrame); 135 &(KPimGlobalPrefs::instance()->mBackupUseDefaultDir),bupFrame);
136 bupLayout->addWidget((QWidget*)sb->checkBox()); 136 bupLayout->addWidget((QWidget*)sb->checkBox());
@@ -141,3 +141,4 @@ void KDEPIMConfigWidget::setupBackupTab()
141 141
142 142 mBackupUrl->setEnabled( !KPimGlobalPrefs::instance()->mBackupUseDefaultDir );
143 bupFrame->setEnabled( KPimGlobalPrefs::instance()->mBackupEnabled );
143 QHBox *dummy = new QHBox(bupFrame); 144 QHBox *dummy = new QHBox(bupFrame);
@@ -153,3 +154,11 @@ void KDEPIMConfigWidget::setupBackupTab()
153 new QLabel(i18n(" "),dummy); 154 new QLabel(i18n(" "),dummy);
154 bupLayout->addWidget( dummy ); 155 bupLayout->addWidget( dummy );
156 QString localKdeDir;
157 localKdeDir = readEnvPath("LOCALMICROKDEHOME");
158 if ( ! localKdeDir.isEmpty() ) {
159 sb->checkBox()->setEnabled( false );
160 sb->checkBox()->setChecked( true );
161 mBackupUrl->setEnabled( false );
162 KPimGlobalPrefs::instance()->mBackupUseDefaultDir = true;
163 }
155 164
@@ -808,2 +817,9 @@ void KDEPIMConfigWidget::usrReadConfig()
808 817
818 if (KPimGlobalPrefs::instance()->mBackupUseDefaultDir )
819 mBackupUrl->setURL( KGlobalSettings::backupDataDir() );
820 else
821 mBackupUrl->setURL(prefs->mBackupDatadir);
822 mBackupNumbersSpin->setValue( prefs->mBackupNumbers );
823 mBackupDayCountSpin->setValue( prefs->mBackupDayCount);
824
809 QString dummy = prefs->mUserDateFormatLong; 825 QString dummy = prefs->mUserDateFormatLong;
@@ -818,5 +834,2 @@ void KDEPIMConfigWidget::usrReadConfig()
818 834
819
820
821
822 mEmailClient = prefs->mEmailClient; 835 mEmailClient = prefs->mEmailClient;
@@ -868,2 +881,5 @@ void KDEPIMConfigWidget::usrWriteConfig()
868 881
882 prefs->mBackupNumbers = mBackupNumbersSpin->value();
883 prefs->mBackupDayCount = mBackupDayCountSpin->value();
884 prefs->mBackupDatadir = mBackupUrl->url();
869 885
diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp
index 90321b2..9c28425 100644
--- a/libkdepim/kpimglobalprefs.cpp
+++ b/libkdepim/kpimglobalprefs.cpp
@@ -202,2 +202,8 @@ void KPimGlobalPrefs::setGlobalConfig()
202 KGlobalSettings::setAlternateBackgroundColor(mAlternateColor); 202 KGlobalSettings::setAlternateBackgroundColor(mAlternateColor);
203 QString localKdeDir;
204 localKdeDir = readEnvPath("LOCALMICROKDEHOME");
205 if ( ! localKdeDir.isEmpty() ) {
206 mBackupUseDefaultDir = true;
207 mBackupDatadir = KGlobalSettings::backupDataDir();
208 }
203 209
diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp
index d68ccb6..714d1b7 100644
--- a/libkdepim/kpimprefs.cpp
+++ b/libkdepim/kpimprefs.cpp
@@ -52,2 +52,5 @@ KPimPrefs::KPimPrefs( const QString &name ) :
52 addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3); 52 addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3);
53
54 setCurrentGroup("BackupDate");
55 addItemInt("LastBackupDate",&mLastBackupDate,0);
53} 56}
diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h
index c177bd6..bf80042 100644
--- a/libkdepim/kpimprefs.h
+++ b/libkdepim/kpimprefs.h
@@ -63,2 +63,3 @@ class KPimPrefs : public KPrefs
63 QString mLastSyncedLocalFile; 63 QString mLastSyncedLocalFile;
64 int mLastBackupDate;
64 65
diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp
index 80a83e0..539397b 100644
--- a/microkde/kapplication.cpp
+++ b/microkde/kapplication.cpp
@@ -126 +126,121 @@ void KApplication::showText(QString caption, QString text)
126} 126}
127
128#include <qlabel.h>
129#include <qpushbutton.h>
130#include <qlayout.h>
131#include <qdir.h>
132#include <qradiobutton.h>
133#include <qbuttongroup.h>
134#include "kglobal.h"
135#include "klocale.h"
136
137class KBackupPrefs : public QDialog
138{
139 public:
140 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) :
141 QDialog( parent, name, true )
142 {
143 setCaption( i18n("Backup Failed!") );
144 QVBoxLayout* lay = new QVBoxLayout( this );
145 lay->setSpacing( 3 );
146 lay->setMargin( 3 );
147 QLabel * lab = new QLabel( message, this );
148 lay->addWidget( lab );
149 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this );
150 lay->addWidget( format );
151 format->setExclusive ( true ) ;
152 vcal = new QRadioButton(i18n("Try again now"), format );
153 tcal = new QRadioButton(i18n("Try again later"), format );
154 ical = new QRadioButton(i18n("Try again tomorrow"), format );
155 ocal = new QRadioButton(i18n("Disable backup"), format );
156 vcal->setChecked( true );
157 QPushButton * ok = new QPushButton( i18n("OK"), this );
158 lay->addWidget(ok );
159 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
160 }
161
162 bool again() { return vcal->isChecked(); }
163 bool later() { return tcal->isChecked(); }
164 bool againTomorrow() { return ical->isChecked(); }
165private:
166 QRadioButton* vcal, *ical, *ocal, *tcal;
167};
168int KApplication::createBackup( QString fn, QString dp, int numBup )
169{
170 if ( numBup < 1) return 3;
171 int ret = 3;
172 qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup);
173 QDir bupDir ( dp );
174 bool tryAgain = true;
175 while ( tryAgain ) {
176 if ( !bupDir.exists() ) {
177 KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + dp.right(30));
178 if ( !noDir.exec() ) return 3;
179 if ( noDir.againTomorrow() ) {
180 return 0;
181 } else if ( noDir.later() ) {
182 return 3;
183 } else if ( !noDir.again() ) {
184 return 2;
185 }
186 } else {
187 tryAgain = false;
188 }
189 }
190 // we have a valid dir!
191 QStringList allFileList = bupDir.entryList(QDir::Files);
192 QFileInfo fileInfo ( fn );
193 QString fName = fileInfo.fileName ();
194 QStringList fileList;
195
196 int i;
197 for ( i = 0; i < allFileList.count(); ++i ) {
198 QString fi = allFileList[i];
199 if ( fi. find( fName ) > -1 )
200 fileList.append( fi );
201 }
202 qDebug("%d backup files exist ", fileList.count());
203 int count = fileList.count();
204 fileList.sort();
205 int remCount = 0;
206 while ( count >= numBup ) {
207 QString fnr = dp + "/"+fileList[remCount];
208 QFile::remove( fnr );
209 --count;
210 ++remCount;
211 }
212 QDateTime mRunStart = QDateTime::currentDateTime();
213 QString file = "%1%2%3-%4%5%6-";
214 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
215 file.replace ( QRegExp (" "), "0" );
216 file += fName ;
217 file = dp + "/"+file;
218 QString command;
219 int res = 0;
220#ifdef _WIN32_
221 command = "xcopy "+ fn+ " "+file;
222 command = QDir::convertSeparators( command );
223#else
224 command = "cp "+ fn+ " "+file;
225#endif
226 qDebug("command %s ",command.latin1() );
227 tryAgain = true;
228 while ( tryAgain ) {
229 res = system ( command.latin1() );
230 qDebug("copy result %d ", res);
231 if ( res != 0 ) {
232 KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>"));
233 if ( !noDir.exec() ) return 3;
234 if ( noDir.againTomorrow() ) {
235 return 0;
236 } else if ( noDir.later() ) {
237 return 3;
238 } else if ( !noDir.again() ) {
239 return 2;
240 }
241 } else {
242 tryAgain = false;
243 }
244 }
245 return 1;
246}
diff --git a/microkde/kapplication.h b/microkde/kapplication.h
index f7eb1ef..de5a084 100644
--- a/microkde/kapplication.h
+++ b/microkde/kapplication.h
@@ -27,2 +27,3 @@ class KApplication
27 static bool convert2latin1(QString file); 27 static bool convert2latin1(QString file);
28 static int createBackup( QString fn, QString dp, int numBup );
28}; 29};