[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/kjots
From: Stephen Kelly <steveire () gmail ! com>
Date: 2008-11-30 12:27:28
Message-ID: 1228048048.265167.23183.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 890816 by skelly:
Create backups of KJots books on close (max 10 backup versions). Remove backups of \
deleted books 7 days later. That gives you a week to realise you shouldn't have \
deleted the book and recover it.
http://userbase.kde.org/Tutorials/Recover_Deleted_KJots_Books
BUG: 175982
M +13 -1 bookshelf.cpp
M +62 -1 kjotscomponent.cpp
M +7 -0 kjotscomponent.h
M +13 -1 kjotsentry.cpp
M +2 -1 kjotsentry.h
--- trunk/KDE/kdepim/kjots/bookshelf.cpp #890815:890816
@@ -264,6 +264,13 @@
KJotsEntry *entry = dynamic_cast<KJotsEntry*>(item);
Q_ASSERT(entry);
+
+ if ( entry->isBook() ) {
+ // Backup the book before it gets removed from the bookshelf.
+ KJotsBook *book = dynamic_cast<KJotsBook*>(entry);
+ book->saveAndBackupBook();
+ }
+
if ( entry->parentBook() ) {
entry->parentBook()->takeChild(entry->parentBook()->indexOfChild(entry));
} else {
@@ -278,7 +285,12 @@
// Stephen Kelly - 20th June 2008
jumpToEntry( entry );
- dynamic_cast<KJotsBook*>(entry)->deleteBook();
+ KJotsBook *book = dynamic_cast<KJotsBook*>(entry);
+ if (book)
+ {
+// book->
+ book->deleteBook();
+ }
}
delete entry;
--- trunk/KDE/kdepim/kjots/kjotscomponent.cpp #890815:890816
@@ -28,6 +28,7 @@
#include <q3header.h>
#include <QStackedWidget>
#include <QtDBus/QDBusConnection>
+#include <QDateTime>
#include <QPainter>
#include <QtGui/QPrinter>
#include <QtGui/QPrintDialog>
@@ -298,6 +299,53 @@
connect(m_autosaveTimer, SIGNAL(timeout()), SLOT(autoSave()));
}
+KJotsComponent::~KJotsComponent()
+{
+ cleanupOldBackups();
+}
+
+void KJotsComponent::cleanupOldBackups()
+{
+ QDir dir(KStandardDirs::locateLocal("data","kjots"));
+
+ QStringList filter;
+ filter << "*.book";
+
+ QStringList backupFilter;
+ backupFilter << "*.book.*~";
+
+ //Read in books from disk
+ QStringList files = dir.entryList(filter, QDir::Files|QDir::Readable);
+ QStringList backupFiles = dir.entryList(backupFilter, QDir::Files|QDir::Readable);
+
+ int maxBackups = 10; // The default amount of numbered backups saved by \
KSaveFile::numberedBackupFile + QSet<QString> fileSet;
+ foreach( const QString &file, files )
+ {
+ for( int bkup=1; bkup <= maxBackups; bkup++)
+ {
+ fileSet << file + "." + QString::number(bkup) + "~";
+ }
+ }
+
+ QSet<QString> backupFileSet = backupFiles.toSet();
+
+ // deletedFileBackups is a list of backup files whose original has already been \
deleted. + // If the backup file is older than AGE days, delete it.
+ QSet<QString> deletedFileBackups = backupFileSet - fileSet;
+
+ const int AGE = 7;
+
+ foreach ( const QString &backupFile, deletedFileBackups ) {
+ QString filepath = dir.absoluteFilePath(backupFile);
+ QFileInfo fi(filepath);
+ if (fi.lastModified().addDays(AGE) < QDateTime::currentDateTime() )
+ {
+ QFile::remove(filepath);
+ }
+ }
+}
+
void KJotsComponent::DelayedInitialization()
{
//TODO: Save previous searches in settings file?
@@ -1021,6 +1069,19 @@
}
}
+
+void KJotsComponent::saveAndBackupAll()
+{
+ for ( int i=0; i<bookshelf->topLevelItemCount(); i++ )
+ {
+ KJotsBook *book = dynamic_cast<KJotsBook*>(bookshelf->topLevelItem(i));
+ if (book)
+ {
+ book->saveAndBackupBook();
+ }
+ }
+}
+
void KJotsComponent::saveAscii()
{
saveToFile(Ascii);
@@ -1377,7 +1438,7 @@
*/
bool KJotsComponent::queryClose()
{
- saveAll();
+ saveAndBackupAll();
bookshelf->prepareForExit();
KJotsSettings::setSplitterSizes(splitter->sizes());
--- trunk/KDE/kdepim/kjots/kjotscomponent.h #890815:890816
@@ -69,6 +69,7 @@
public:
KJotsComponent(QWidget* parent, KActionCollection *actionCollection);
+ ~KJotsComponent();
QTextEdit* activeEditor();
QString currentCaption();
@@ -138,8 +139,14 @@
*/
void saveAll(void);
+ /**
+ Saves and backs up all books.
+ */
+ void saveAndBackupAll();
+
protected:
int search(bool);
+ void cleanupOldBackups();
private:
--- trunk/KDE/kdepim/kjots/kjotsentry.cpp #890815:890816
@@ -373,6 +373,15 @@
}
}
+void KJotsBook::saveAndBackupBook()
+{
+ if (!m_fileName.isEmpty())
+ {
+ KSaveFile::numberedBackupFile(m_fileName);
+ }
+ saveBook();
+}
+
/*!
\brief Deletes a book by removing the data file.
This does not affect the list display, and can be called for reasons other than
@@ -381,7 +390,10 @@
*/
void KJotsBook::deleteBook ( void )
{
- QFile::remove(m_fileName);
+ if (!m_fileName.isEmpty())
+ {
+ QFile::remove(m_fileName);
+ }
m_fileName.clear();
}
--- trunk/KDE/kdepim/kjots/kjotsentry.h #890815:890816
@@ -71,7 +71,7 @@
protected:
void setId(quint64);
bool m_isBook; //!< used for speed and code clarity.
-
+
private:
quint64 m_id; //!< unique ID for this entry
static QSet<quint64> all_ids;
@@ -93,6 +93,7 @@
bool openBook(const QString&);
void saveBook();
+ void saveAndBackupBook();
void deleteBook();
void rename();
KJotsPage* addPage(void);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic