-rw-r--r-- | bin/kdepim/korganizer/germantranslation.txt | 13 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 30 | ||||
-rw-r--r-- | libkdepim/kcmconfigs/kdepimconfigwidget.cpp | 26 | ||||
-rw-r--r-- | libkdepim/kpimglobalprefs.cpp | 6 | ||||
-rw-r--r-- | libkdepim/kpimprefs.cpp | 3 | ||||
-rw-r--r-- | libkdepim/kpimprefs.h | 1 | ||||
-rw-r--r-- | microkde/kapplication.cpp | 120 | ||||
-rw-r--r-- | microkde/kapplication.h | 1 |
8 files changed, 195 insertions, 5 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 @@ -1344,17 +1344,30 @@ { "The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?","Das Todo\n%1\nwird geklont!\nEs hat Untertodos!\nMöchten Sie alle\nUntertodos auch klonen?" }, { "Todo has subtodos","Todo hat Untertodos" }, { "Block popup until mouse button release","Sperre Popup bis Mausknopf losgelassen" }, { "Colors","Farben" }, { "Click on new parent item","Klicke auf neues Übertodo" }, { "Reparenting aborted!","Übertodo setzen abgebrochen" }, { "Cannot move Todo to itself\nor a child of itself","Kann nicht Todo auf\nsich selbst oder\nein Untertodo verschieben" }, { "Recursive reparenting not possible!","Rekursives Verschieben nicht möglich" }, { "Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)","Entferne alle erledigten Todos?\n(Erledigte wiederholende Todos\nwerden nicht gelöscht!)" }, { "Alternating background of list views","Abwechselnder Hintergrund für Listen" }, { "times","Zeiten" }, { "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?" }, +{ "Backup enabled","Backup angeschaltet" }, +{ "Use standard backup dir","Standard Backupverzeichnis" }, +{ "Number of Backups:","Anzahl der Backups" }, +{ "Make backup every ","Mache ein Backup alle " }, +{ " days"," Tage" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, { "","" }, { "","" }, { "","" }, { "","" }, { "","" }, diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 68e5e5a..9ad0694 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -52,24 +52,25 @@ #include "kdialogbase.h" #include "kapplication.h" #include "kofilterview.h" #include "kstandarddirs.h" #include "koprefs.h" #include "kfiledialog.h" #include "koglobals.h" #include "kglobal.h" #include "ktoolbar.h" #include "klocale.h" #include "kconfig.h" #include "externalapphandler.h" +#include <kglobalsettings.h> using namespace KCal; #ifndef _WIN32_ #include <unistd.h> #else #ifdef _OL_IMPORT_ #include "koimportoldialog.h" #endif #endif #include "mainwindow.h" @@ -1792,24 +1793,53 @@ void MainWindow::saveStopTimer() mSaveTimer.stop(); } void MainWindow::save() { if ( !mCalendarModifiedFlag ) { qDebug("KO: Calendar not modified. Nothing saved."); return; } if ( mSyncManager->blockSave() ) return; mSyncManager->setBlockSave(true); if ( mView->checkFileVersion( defaultFileName()) ) { + if ( KPimGlobalPrefs::instance()->mBackupEnabled ){ + QDate reference ( 2000,1,1); + int daysTo = reference.daysTo ( QDate::currentDate() ); + if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) { + setCaption(i18n("KO/Pi:Creating backup ... please wait ..." )); + qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate); + // we need the file path, the backup dir and the number of bups as param + QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir; + if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir) + bupDir = KGlobalSettings::backupDataDir(); + int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );//55;//call backup + if ( retval == 0 ) { + qDebug("KO: Backup cancelled. Will try again tomorrow "); + // retval == 0 : backup skipped for today, try again tomorrow + KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1; + } else if ( retval == 1 ){ + qDebug("KO: Backup created."); + // backup ok + KOPrefs::instance()->mLastBackupDate = daysTo; + + } else if ( retval == 2 ){ + qDebug("KO: Backup globally cancelled."); + // backup globally cancelled + KPimGlobalPrefs::instance()->mBackupEnabled = false; + } + // retval == 3: do nothing, try again later + } + ; // KPimGlobalPrefs::instance()->mLastBackupDate + } QTime neededSaveTime = QDateTime::currentDateTime().time(); setCaption(i18n("KO/Pi:Saving Data to File ..." )); qDebug("KO: Start saving data to file!"); mView->saveCalendar( defaultFileName() ); mCalendarModifiedFlag = false; int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); qDebug("KO: Needed %d ms for saving.",msNeeded ); QString savemes; savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); setCaption(savemes); } else setCaption(i18n("Saving cancelled!")); 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 @@ -123,44 +123,53 @@ void KDEPIMConfigWidget::setupBackupTab() QVBox *colorPage = new QVBox( this ); tabWidget->addTab( colorPage, i18n( "Backup" ) ); QWidget* topFrame = new QWidget( colorPage ); QVBoxLayout *topLayout = new QVBoxLayout(topFrame); KPrefsWidBool *sb = addWidBool(i18n("Backup enabled"), &(KPimGlobalPrefs::instance()->mBackupEnabled),topFrame); topLayout->addWidget((QWidget*)sb->checkBox()); QWidget* bupFrame = new QWidget( topFrame ); topLayout->addWidget((bupFrame)); QObject::connect ( sb->checkBox(), SIGNAL (toggled ( bool ) ), bupFrame, SLOT ( setEnabled( bool ) ) ); QVBoxLayout *bupLayout = new QVBoxLayout(bupFrame); sb = addWidBool(i18n("Use standard backup dir"), - &(KPimGlobalPrefs::instance()->mBackupEnabled),bupFrame); + &(KPimGlobalPrefs::instance()->mBackupUseDefaultDir),bupFrame); bupLayout->addWidget((QWidget*)sb->checkBox()); mBackupUrl = new KURLRequester( bupFrame ); mBackupUrl->setURL( KGlobalSettings::backupDataDir() ); QObject::connect ( sb->checkBox(), SIGNAL (toggled ( bool ) ), mBackupUrl ,SLOT ( setDisabled( bool ) ) ); bupLayout->addWidget( mBackupUrl ); - + mBackupUrl->setEnabled( !KPimGlobalPrefs::instance()->mBackupUseDefaultDir ); + bupFrame->setEnabled( KPimGlobalPrefs::instance()->mBackupEnabled ); QHBox *dummy = new QHBox(bupFrame); new QLabel(i18n("Number of Backups:"),dummy); mBackupNumbersSpin = new QSpinBox(1,21,1,dummy); new QLabel(i18n(" "),dummy); bupLayout->addWidget( dummy ); dummy = new QHBox(bupFrame); new QLabel(i18n("Make backup every "),dummy); mBackupDayCountSpin = new QSpinBox(1,28,1,dummy); new QLabel(i18n(" days"),dummy); new QLabel(i18n(" "),dummy); bupLayout->addWidget( dummy ); + QString localKdeDir; + localKdeDir = readEnvPath("LOCALMICROKDEHOME"); + if ( ! localKdeDir.isEmpty() ) { + sb->checkBox()->setEnabled( false ); + sb->checkBox()->setChecked( true ); + mBackupUrl->setEnabled( false ); + KPimGlobalPrefs::instance()->mBackupUseDefaultDir = true; + } } void KDEPIMConfigWidget::setupStoreTab() { QVBox *colorPage = new QVBox( this ); tabWidget->addTab( colorPage, i18n( "Colors" ) ); QWidget* cw = new QWidget( colorPage ); KPrefsWidColor *holidayColor = addWidColor(i18n("Alternating background of list views"), &(KPimGlobalPrefs::instance()->mAlternateColor),cw); QHBoxLayout *topLayout = new QHBoxLayout(cw); topLayout->addWidget(holidayColor->label()); @@ -797,37 +806,41 @@ void KDEPIMConfigWidget::updateClientWidgets() blockSignals( blocked ); } void KDEPIMConfigWidget::usrReadConfig() { KPimGlobalPrefs* prefs = KPimGlobalPrefs::instance(); bool blocked = signalsBlocked(); blockSignals( true ); + if (KPimGlobalPrefs::instance()->mBackupUseDefaultDir ) + mBackupUrl->setURL( KGlobalSettings::backupDataDir() ); + else + mBackupUrl->setURL(prefs->mBackupDatadir); + mBackupNumbersSpin->setValue( prefs->mBackupNumbers ); + mBackupDayCountSpin->setValue( prefs->mBackupDayCount); + QString dummy = prefs->mUserDateFormatLong; mUserDateFormatLong->setText(dummy.replace( QRegExp("K"), QString(",") )); dummy = prefs->mUserDateFormatShort; mUserDateFormatShort->setText(dummy.replace( QRegExp("K"), QString(",") )); QDate current ( 2001, 1,1); mStartDateSavingEdit->setDate(current.addDays(prefs->mDaylightsavingStart-1)); mEndDateSavingEdit->setDate(current.addDays(prefs->mDaylightsavingEnd-1)); setCombo(mTimeZoneCombo,i18n(prefs->mTimeZoneId)); - - - mEmailClient = prefs->mEmailClient; mEmailOtherChannel = prefs->mEmailOtherChannel; mEmailOtherMessage = prefs->mEmailOtherMessage; mEmailOtherMessageParameters = prefs->mEmailOtherMessageParameters; mEmailOtherMessage2 = prefs->mEmailOtherMessage2; mEmailOtherMessageParameters2 = prefs->mEmailOtherMessageParameters2; mPhoneClient = prefs->mPhoneClient; mPhoneOtherChannel = prefs->mPhoneOtherChannel; mPhoneOtherMessage = prefs->mPhoneOtherMessage; mPhoneOtherMessageParameters = prefs->mPhoneOtherMessageParameters; @@ -857,24 +870,27 @@ void KDEPIMConfigWidget::usrReadConfig() updateClientWidgets(); blockSignals( blocked ); } void KDEPIMConfigWidget::usrWriteConfig() { KPimGlobalPrefs* prefs = KPimGlobalPrefs::instance(); saveEditFieldSettings(); + prefs->mBackupNumbers = mBackupNumbersSpin->value(); + prefs->mBackupDayCount = mBackupDayCountSpin->value(); + prefs->mBackupDatadir = mBackupUrl->url(); prefs->mUserDateFormatShort = mUserDateFormatShort->text().replace( QRegExp(","), QString("K") ); prefs->mUserDateFormatLong = mUserDateFormatLong->text().replace( QRegExp(","), QString("K") ); prefs->mTimeZoneId = mTimeZoneCombo->currentText(); QDate date; date = mStartDateSavingEdit->date(); int sub = 0; if ( QDate::leapYear( date.year() ) && date.dayOfYear() > 59 ) sub = 1; prefs->mDaylightsavingStart = date.dayOfYear()-sub; date = mEndDateSavingEdit->date(); diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp index 90321b2..9c28425 100644 --- a/libkdepim/kpimglobalprefs.cpp +++ b/libkdepim/kpimglobalprefs.cpp @@ -191,24 +191,30 @@ void KPimGlobalPrefs::setGlobalConfig() KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate ); KGlobal::locale()->setLanguage( mPreferredLanguage ); QString dummy = mUserDateFormatLong; KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); dummy = mUserDateFormatShort; KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); KGlobal::locale()->setDaylightSaving( mUseDaylightsaving, mDaylightsavingStart, mDaylightsavingEnd ); KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min ); KGlobalSettings::setAlternateBackgroundColor(mAlternateColor); + QString localKdeDir; + localKdeDir = readEnvPath("LOCALMICROKDEHOME"); + if ( ! localKdeDir.isEmpty() ) { + mBackupUseDefaultDir = true; + mBackupDatadir = KGlobalSettings::backupDataDir(); + } } KPimGlobalPrefs::~KPimGlobalPrefs() { if (sInstance == this) sInstance = staticDeleterGP.setObject(0); else qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); if ( mLocaleDict ) delete mLocaleDict; } diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp index d68ccb6..714d1b7 100644 --- a/libkdepim/kpimprefs.cpp +++ b/libkdepim/kpimprefs.cpp @@ -41,24 +41,27 @@ KPimPrefs::KPimPrefs( const QString &name ) : #ifdef _WIN32_ QString hdp= locateLocal("data","korganizer")+"\\\\"; #else QString hdp= locateLocal("data","korganizer")+"/"; #endif setCurrentGroup("SyncOptions"); addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" ); addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" ); addItemString("LastSyncedLocalFile", &mLastSyncedLocalFile ,hdp +"lastsync.ics" ); addItemBool("PassiveSyncWithDesktop",&mPassiveSyncWithDesktop,false ); addItemBool("PassiveSyncAutoStart",&mPassiveSyncAutoStart,false ); addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3); + + setCurrentGroup("BackupDate"); + addItemInt("LastBackupDate",&mLastBackupDate,0); } KPimPrefs::~KPimPrefs() { } void KPimPrefs::usrSetDefaults() { setCategoryDefaults(); } void KPimPrefs::usrReadConfig() diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h index c177bd6..bf80042 100644 --- a/libkdepim/kpimprefs.h +++ b/libkdepim/kpimprefs.h @@ -52,22 +52,23 @@ class KPimPrefs : public KPrefs /** Write preferences to config file */ void usrWriteConfig(); public: QStringList mCustomCategories; QString mPassiveSyncPort; QString mPassiveSyncPw; bool mPassiveSyncWithDesktop; bool mPassiveSyncAutoStart; int mRingSyncAlgoPrefs; QString mLastSyncedLocalFile; + int mLastBackupDate; protected: virtual void setCategoryDefaults(); }; #endif diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp index 80a83e0..539397b 100644 --- a/microkde/kapplication.cpp +++ b/microkde/kapplication.cpp @@ -115,12 +115,132 @@ void KApplication::showText(QString caption, QString text) KTextEdit tb ( &dia ); tb.setWordWrap( QMultiLineEdit::WidgetWidth ); lay->addWidget( &tb ); tb.setText( text ); #ifdef DESKTOP_VERSION dia.resize( 640, 480); #else dia.showMaximized(); #endif dia.exec(); } + +#include <qlabel.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qdir.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include "kglobal.h" +#include "klocale.h" + +class KBackupPrefs : public QDialog +{ + public: + KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) : + QDialog( parent, name, true ) + { + setCaption( i18n("Backup Failed!") ); + QVBoxLayout* lay = new QVBoxLayout( this ); + lay->setSpacing( 3 ); + lay->setMargin( 3 ); + QLabel * lab = new QLabel( message, this ); + lay->addWidget( lab ); + QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this ); + lay->addWidget( format ); + format->setExclusive ( true ) ; + vcal = new QRadioButton(i18n("Try again now"), format ); + tcal = new QRadioButton(i18n("Try again later"), format ); + ical = new QRadioButton(i18n("Try again tomorrow"), format ); + ocal = new QRadioButton(i18n("Disable backup"), format ); + vcal->setChecked( true ); + QPushButton * ok = new QPushButton( i18n("OK"), this ); + lay->addWidget(ok ); + connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); + } + + bool again() { return vcal->isChecked(); } + bool later() { return tcal->isChecked(); } + bool againTomorrow() { return ical->isChecked(); } +private: + QRadioButton* vcal, *ical, *ocal, *tcal; +}; +int KApplication::createBackup( QString fn, QString dp, int numBup ) +{ + if ( numBup < 1) return 3; + int ret = 3; + qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup); + QDir bupDir ( dp ); + bool tryAgain = true; + while ( tryAgain ) { + if ( !bupDir.exists() ) { + KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + dp.right(30)); + if ( !noDir.exec() ) return 3; + if ( noDir.againTomorrow() ) { + return 0; + } else if ( noDir.later() ) { + return 3; + } else if ( !noDir.again() ) { + return 2; + } + } else { + tryAgain = false; + } + } + // we have a valid dir! + QStringList allFileList = bupDir.entryList(QDir::Files); + QFileInfo fileInfo ( fn ); + QString fName = fileInfo.fileName (); + QStringList fileList; + + int i; + for ( i = 0; i < allFileList.count(); ++i ) { + QString fi = allFileList[i]; + if ( fi. find( fName ) > -1 ) + fileList.append( fi ); + } + qDebug("%d backup files exist ", fileList.count()); + int count = fileList.count(); + fileList.sort(); + int remCount = 0; + while ( count >= numBup ) { + QString fnr = dp + "/"+fileList[remCount]; + QFile::remove( fnr ); + --count; + ++remCount; + } + QDateTime mRunStart = QDateTime::currentDateTime(); + QString file = "%1%2%3-%4%5%6-"; + 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 ); + file.replace ( QRegExp (" "), "0" ); + file += fName ; + file = dp + "/"+file; + QString command; + int res = 0; +#ifdef _WIN32_ + command = "xcopy "+ fn+ " "+file; + command = QDir::convertSeparators( command ); +#else + command = "cp "+ fn+ " "+file; +#endif + qDebug("command %s ",command.latin1() ); + tryAgain = true; + while ( tryAgain ) { + res = system ( command.latin1() ); + qDebug("copy result %d ", res); + if ( res != 0 ) { + KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>")); + if ( !noDir.exec() ) return 3; + if ( noDir.againTomorrow() ) { + return 0; + } else if ( noDir.later() ) { + return 3; + } else if ( !noDir.again() ) { + return 2; + } + } else { + tryAgain = false; + } + } + return 1; +} diff --git a/microkde/kapplication.h b/microkde/kapplication.h index f7eb1ef..de5a084 100644 --- a/microkde/kapplication.h +++ b/microkde/kapplication.h @@ -16,16 +16,17 @@ class KApplication /** * Generates a random string. It operates in the range [A-Za-z0-9] * @param length Generate a string of this length. * @return the random string */ static QString randomString(int length); static int execDialog( QDialog* ); static void showLicence(); static void testCoords( int* x, int* y, int* wid, int * hei ); static void showFile(QString caption, QString file); static void showText(QString caption, QString text); static bool convert2latin1(QString file); + static int createBackup( QString fn, QString dp, int numBup ); }; #endif |