00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "backup.h"
00023
00024
#include "konnectorview.h"
00025
#include "backupview.h"
00026
00027
#include <konnector.h>
00028
#include <configwidget.h>
00029
#include <konnectormanager.h>
00030
#include <konnectorinfo.h>
00031
#include <mainwindow.h>
00032
#include <calendarsyncee.h>
00033
#include <engine.h>
00034
00035
#include <kaboutdata.h>
00036
#include <kiconloader.h>
00037
#include <kparts/genericfactory.h>
00038
#include <kmessagebox.h>
00039
#include <kdialog.h>
00040
#include <kdialogbase.h>
00041
#include <kstandarddirs.h>
00042
#include <kprocess.h>
00043
00044
#include <qlabel.h>
00045
#include <qlistview.h>
00046
#include <qcombobox.h>
00047
#include <qpushbutton.h>
00048
#include <qtextview.h>
00049
#include <qlayout.h>
00050
#include <qdatetime.h>
00051
#include <qcheckbox.h>
00052
#include <qvbox.h>
00053
#include <qdir.h>
00054
00055
using namespace KCal;
00056
using namespace KSync;
00057
00058
typedef KParts::GenericFactory< Backup> BackupFactory;
00059 K_EXPORT_COMPONENT_FACTORY( libksync_backup, BackupFactory )
00060
00061 Backup::Backup(
QWidget *parent, const
char *name,
00062
QObject *, const
char *,const
QStringList & )
00063 :
ActionPart( parent, name ), m_widget( 0 ), mActive( false )
00064 {
00065 m_pixmap = KGlobal::iconLoader()->loadIcon(
"kcmdrkonqi", KIcon::Desktop, 48 );
00066 }
00067
00068 KAboutData *Backup::createAboutData()
00069 {
00070
return new KAboutData(
"KSyncBackup", I18N_NOOP(
"Sync Backup Part"),
"0.0" );
00071 }
00072
00073 Backup::~Backup()
00074 {
00075
delete m_widget;
00076 }
00077
00078
QString Backup::type()
const
00079
{
00080
return QString::fromLatin1(
"backup");
00081 }
00082
00083
QString Backup::title()
const
00084
{
00085
return i18n(
"Konnector Backup");
00086 }
00087
00088
QString Backup::description()
const
00089
{
00090
return i18n(
"Backup for Konnectors");
00091 }
00092
00093
QPixmap *Backup::pixmap()
00094 {
00095
return &m_pixmap;
00096 }
00097
00098
QString Backup::iconName()
const
00099
{
00100
return QString::fromLatin1(
"kcmsystem");
00101 }
00102
00103
bool Backup::hasGui()
const
00104
{
00105
return true;
00106 }
00107
00108
QWidget *Backup::widget()
00109 {
00110
if( !m_widget ) {
00111 m_widget =
new QWidget;
00112
QBoxLayout *topLayout =
new QVBoxLayout( m_widget );
00113 topLayout->
setSpacing( KDialog::spacingHint() );
00114
00115
QBoxLayout *konnectorLayout =
new QHBoxLayout( topLayout );
00116
00117 mKonnectorList =
new KonnectorView( m_widget );
00118 konnectorLayout->
addWidget( mKonnectorList, 1 );
00119
00120 mKonnectorList->updateKonnectorList();
00121
00122 mBackupView =
new BackupView( m_widget );
00123 konnectorLayout->
addWidget( mBackupView );
00124 connect( mBackupView, SIGNAL( backupDeleted(
const QString & ) ),
00125 SLOT( slotBackupDeleted(
const QString & ) ) );
00126
00127 mBackupView->updateBackupList();
00128
00129 mLogView =
new QTextView( m_widget );
00130 mLogView->setTextFormat( LogText );
00131 topLayout->
addWidget( mLogView );
00132
00133 logMessage( i18n(
"Ready.") );
00134 }
00135
return m_widget;
00136 }
00137
00138
void Backup::logMessage(
const QString &message )
00139 {
00140
QString text =
"<b>" + QTime::currentTime().toString() +
"</b>: ";
00141 text += message;
00142
00143 kdDebug() <<
"LOG: " << text << endl;
00144
00145 mLogView->append( text );
00146 }
00147
00148
void Backup::executeAction()
00149 {
00150 logMessage( i18n(
"Starting backup") );
00151
00152 mBackupView->createBackupDir();
00153
00154 Konnector::List konnectors = core()->engine()->konnectors();
00155
Konnector *k;
00156
for( k = konnectors.first(); k; k = konnectors.next() ) {
00157 backupKonnector( k );
00158 }
00159
00160 logMessage( i18n(
"Backup finished.") );
00161
00162 mBackupView->updateBackupList();
00163 }
00164
00165
void Backup::backupKonnector(
Konnector *k )
00166 {
00167 logMessage( i18n(
"Syncees read from '%1'").arg( k->resourceName() ) );
00168
00169
SynceeList syncees = k->
syncees();
00170
00171
if ( syncees.count() == 0 ) {
00172 logMessage( i18n(
"Syncee list is empty.") );
00173 }
else {
00174 logMessage( i18n(
"Performing backup.") );
00175
00176 SynceeList::ConstIterator it;
00177
for( it = syncees.begin(); it != syncees.end(); ++it ) {
00178
if ( !(*it)->isValid() )
continue;
00179
QString filename = mBackupView->backupFile( k, *it );
00180 kdDebug() <<
"FILENAME: " << filename << endl;
00181
QString type = (*it)->type();
00182
if ( (*it)->writeBackup( filename ) ) {
00183 logMessage( i18n(
"Wrote backup for %1.").arg( type ) );
00184 }
else {
00185 logMessage( i18n(
"<b>Error:</b> Can't write backup for %1.")
00186 .arg( type ) );
00187 }
00188 }
00189 }
00190 }
00191
00192
void Backup::slotBackupDeleted(
const QString &name )
00193 {
00194 logMessage( i18n(
"Backup '%1' deleted").arg( name ) );
00195 }
00196
00197
#include "backup.moc"