kitchensync Library API Documentation

restore.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include "restore.h" 00023 00024 #include "backupview.h" 00025 00026 #include <konnector.h> 00027 #include <core.h> 00028 #include <engine.h> 00029 00030 #include <kaboutdata.h> 00031 #include <kiconloader.h> 00032 #include <kparts/genericfactory.h> 00033 #include <kmessagebox.h> 00034 #include <kdialog.h> 00035 #include <kdialogbase.h> 00036 00037 #include <qlabel.h> 00038 #include <qlistview.h> 00039 #include <qcombobox.h> 00040 #include <qpushbutton.h> 00041 #include <qtextview.h> 00042 #include <qlayout.h> 00043 00044 using namespace KCal; 00045 using namespace KSync; 00046 00047 typedef KParts::GenericFactory<Restore> RestoreFactory; 00048 K_EXPORT_COMPONENT_FACTORY( libksync_restore, RestoreFactory ) 00049 00050 Restore::Restore( QWidget *parent, const char *name, 00051 QObject *, const char *,const QStringList & ) 00052 : ActionPart( parent, name ), m_widget( 0 ) 00053 { 00054 m_pixmap = KGlobal::iconLoader()->loadIcon("kcmdrkonqi", KIcon::Desktop, 48 ); 00055 } 00056 00057 KAboutData *Restore::createAboutData() 00058 { 00059 return new KAboutData("KSyncRestore", I18N_NOOP("Sync Restore Part"), "0.0" ); 00060 } 00061 00062 Restore::~Restore() 00063 { 00064 delete m_widget; 00065 } 00066 00067 QString Restore::type() const 00068 { 00069 return QString::fromLatin1("Restore"); 00070 } 00071 00072 QString Restore::title() const 00073 { 00074 return i18n("Konnector Restore"); 00075 } 00076 00077 QString Restore::description() const 00078 { 00079 return i18n("Restore for Konnectors"); 00080 } 00081 00082 QPixmap *Restore::pixmap() 00083 { 00084 return &m_pixmap; 00085 } 00086 00087 QString Restore::iconName() const 00088 { 00089 return QString::fromLatin1("kcmsystem"); 00090 } 00091 00092 bool Restore::hasGui() const 00093 { 00094 return true; 00095 } 00096 00097 QWidget *Restore::widget() 00098 { 00099 if( !m_widget ) { 00100 m_widget = new QWidget; 00101 QBoxLayout *topLayout = new QVBoxLayout( m_widget ); 00102 topLayout->setSpacing( KDialog::spacingHint() ); 00103 00104 QBoxLayout *konnectorLayout = new QHBoxLayout( topLayout ); 00105 00106 QBoxLayout *restoreLayout = new QVBoxLayout( konnectorLayout ); 00107 00108 mBackupView = new BackupView( m_widget ); 00109 restoreLayout->addWidget( mBackupView ); 00110 00111 mBackupView->updateBackupList(); 00112 00113 mLogView = new QTextView( m_widget ); 00114 mLogView->setTextFormat( LogText ); 00115 topLayout->addWidget( mLogView ); 00116 00117 logMessage( i18n("Ready.") ); 00118 } 00119 return m_widget; 00120 } 00121 00122 void Restore::logMessage( const QString &message ) 00123 { 00124 QString text = "<b>" + QTime::currentTime().toString() + "</b>: "; 00125 text += message; 00126 00127 kdDebug() << "LOG: " << text << endl; 00128 00129 mLogView->append( text ); 00130 } 00131 00132 void Restore::executeAction() 00133 { 00134 logMessage( i18n("Starting Restore") ); 00135 00136 QString backup = mBackupView->selectedBackup(); 00137 00138 if ( backup.isNull() ) { 00139 KMessageBox::sorry( m_widget, i18n("No backup selected.") ); 00140 return; 00141 } 00142 00143 if ( backup.isEmpty() ) { 00144 KMessageBox::sorry( m_widget, i18n("Selected backup is invalid.") ); 00145 return; 00146 } 00147 00148 logMessage( i18n("Restoring backup %1").arg( backup ) ); 00149 00150 mBackupView->setBackupDir( backup ); 00151 00152 Konnector::List konnectors = core()->engine()->konnectors(); 00153 Konnector *k; 00154 for( k = konnectors.first(); k; k = konnectors.next() ) { 00155 restoreKonnector( k ); 00156 } 00157 00158 logMessage( i18n("Restore finished.") ); 00159 00160 mBackupView->updateBackupList(); 00161 } 00162 00163 void Restore::restoreKonnector( Konnector *k ) 00164 { 00165 logMessage( i18n("Restoring %1.").arg( k->resourceName() ) ); 00166 00167 SynceeList syncees = k->syncees(); 00168 00169 SynceeList::ConstIterator it; 00170 for( it = syncees.begin(); it != syncees.end(); ++it ) { 00171 if ( !(*it)->isValid() ) continue; 00172 00173 QString filename = mBackupView->backupFile( k, *it ); 00174 kdDebug() << "FILENAME: " << filename << endl; 00175 QString type = (*it)->type(); 00176 if ( (*it)->restoreBackup( filename ) ) { 00177 logMessage( i18n("Restored backup for %1.").arg( type ) ); 00178 } else { 00179 logMessage( i18n("<b>Error:</b> Can't restore backup for %1.") 00180 .arg( type ) ); 00181 } 00182 } 00183 } 00184 00185 #include "restore.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:49 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003