You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.9 KiB
101 lines
2.9 KiB
14 years ago
|
/* This file is part of the Keep project
|
||
|
Copyright (C) 2005 Jean-Rémy Falleri <jr.falleri@laposte.net>
|
||
|
|
||
|
Keep is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
Keep is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with Keep; if not, write to the
|
||
|
Free Software Foundation, Inc.,
|
||
|
51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||
|
|
||
|
#include "keepkded.h"
|
||
|
|
||
|
#include <qdir.h>
|
||
|
#include <qfile.h>
|
||
|
#include <qfileinfo.h>
|
||
|
#include <qdatetime.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <krun.h>
|
||
|
#include <kmessagebox.h>
|
||
|
#include <kstdguiitem.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <knotifyclient.h>
|
||
|
#include <klocale.h>
|
||
|
#include <keepsettings.h>
|
||
|
|
||
|
KeepKded::KeepKded(const QCString &name): KDEDModule(name)
|
||
|
{
|
||
|
m_logFilePath = locateLocal( "data", "keep/keep.log", true );
|
||
|
|
||
|
m_manager = new RDBManager();
|
||
|
connect( m_manager, SIGNAL(backupError(Backup,QString)), this, SLOT(slotBackupError(Backup,QString)) );
|
||
|
connect( m_manager, SIGNAL(backupSuccess(Backup)), this, SLOT(slotBackupSuccess(Backup)) );
|
||
|
|
||
|
slotCheckBackup();
|
||
|
|
||
|
m_timer = new QTimer(this);
|
||
|
connect( m_timer, SIGNAL(timeout()), this, SLOT(slotCheckBackup()) );
|
||
|
m_timer->start( 1000 * 60 * 60 );
|
||
|
}
|
||
|
|
||
|
KeepKded::~KeepKded()
|
||
|
{
|
||
|
delete m_manager;
|
||
|
}
|
||
|
|
||
|
void KeepKded::slotBackupError(Backup backup,QString errorMessage)
|
||
|
{
|
||
|
if ( KeepSettings::notifyBackupError() )
|
||
|
{
|
||
|
KNotifyClient::userEvent(0,i18n("<p><b>An error occured making %1 backup:</b></p><p>%2</p>").arg(backup.source()).arg(errorMessage),16,4);
|
||
|
}
|
||
|
log("Backup Error",backup.source(),errorMessage);
|
||
|
}
|
||
|
|
||
|
void KeepKded::slotBackupSuccess(Backup backup)
|
||
|
{
|
||
|
if ( KeepSettings::notifyBackupSuccess() )
|
||
|
{
|
||
|
KNotifyClient::userEvent(0,i18n("<p><b>Backup %1 successfully backuped to %2</b></p>").arg(backup.source()).arg(backup.dest()),16,1);
|
||
|
}
|
||
|
log("Backup Success",backup.source(),"Successfully backuped to: " + backup.dest() );
|
||
|
}
|
||
|
|
||
|
void KeepKded::log(QString type,QString backup,QString message)
|
||
|
{
|
||
|
QString logMessage = QDateTime::currentDateTime().toString(Qt::ISODate) + "\t" + type + "\t" + backup + "\t" + message;
|
||
|
QFile file( m_logFilePath );
|
||
|
if ( file.open(IO_WriteOnly | IO_Append) )
|
||
|
{
|
||
|
QTextStream stream( &file );
|
||
|
stream << logMessage << "\n";
|
||
|
file.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KeepKded::slotCheckBackup()
|
||
|
{
|
||
|
kdDebug(7020) << "Launching previous backup analyse." << endl;
|
||
|
m_manager->slotCheckBackup();
|
||
|
}
|
||
|
|
||
|
extern "C"
|
||
|
{
|
||
|
KDE_EXPORT KDEDModule *create_keep(const QCString &name)
|
||
|
{
|
||
|
return new KeepKded(name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "keepkded.moc"
|