00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "backupview.h"
00023
00024
#include <konnector.h>
00025
#include <syncee.h>
00026
00027
#include <kdialog.h>
00028
#include <kglobal.h>
00029
#include <kdebug.h>
00030
#include <kstandarddirs.h>
00031
#include <kmessagebox.h>
00032
#include <kprocess.h>
00033
00034
#include <qlistview.h>
00035
#include <qpushbutton.h>
00036
#include <qlayout.h>
00037
#include <qdatetime.h>
00038
#include <qdir.h>
00039
00040
using namespace KSync;
00041
00042
class BackupItem :
public QListViewItem
00043 {
00044
public:
00045 BackupItem(
QListView *parent,
const QString &dirName )
00046 :
QListViewItem( parent )
00047 {
00048
QDateTime dt = QDateTime::fromString( dirName, ISODate );
00049
QString txt;
00050
if ( dt.isValid() ) {
00051 txt = KGlobal::locale()->formatDateTime( dt );
00052 mDirName = dirName;
00053 }
else {
00054 txt = i18n(
"Invalid (\"%1\")").arg( dirName );
00055 }
00056 setText( 0, txt );
00057 }
00058
00059
QString dirName()
const {
return mDirName; }
00060
00061
private:
00062
QString mDirName;
00063 };
00064
00065
00066 BackupView::BackupView(
QWidget *parent,
const char *name )
00067 :
QWidget( parent, name )
00068 {
00069
QBoxLayout *topLayout =
new QVBoxLayout(
this );
00070 topLayout->
setSpacing( KDialog::spacingHint() );
00071
00072 mBackupList =
new QListView(
this );
00073 mBackupList->addColumn( i18n(
"Backup") );
00074 topLayout->
addWidget( mBackupList, 1 );
00075
00076 updateBackupList();
00077
00078
QPushButton *button =
new QPushButton( i18n(
"Delete"),
this );
00079 topLayout->
addWidget( button );
00080 connect( button, SIGNAL( clicked() ), SLOT( deleteBackup() ) );
00081 }
00082
00083
void BackupView::updateBackupList()
00084 {
00085 mBackupList->clear();
00086
00087
QString dirName = locateLocal(
"appdata", topBackupDir() );
00088
QDir dir( dirName );
00089
00090
QStringList backups = dir.entryList( QDir::Dirs );
00091
00092 QStringList::ConstIterator it;
00093
for( it = backups.begin(); it != backups.end(); ++it ) {
00094
if ( *it !=
"." && *it !=
".." ) {
00095
new BackupItem( mBackupList, *it );
00096 }
00097 }
00098 }
00099
00100
QString BackupView::selectedBackup()
00101 {
00102 BackupItem *item = static_cast<BackupItem *>( mBackupList->selectedItem() );
00103
if ( !item )
return QString::null;
00104
00105
return item->dirName();
00106 }
00107
00108
QString BackupView::topBackupDir()
const
00109
{
00110
return "backup/";
00111 }
00112
00113
void BackupView::setBackupDir(
const QString &dateStr )
00114 {
00115 mBackupDir = locateLocal(
"appdata", topBackupDir() + dateStr +
"/" );
00116 }
00117
00118
void BackupView::createBackupDir()
00119 {
00120
QString date = QDateTime::currentDateTime().toString( ISODate );
00121 mBackupDir = locateLocal(
"appdata", topBackupDir() + date +
"/",
true );
00122
00123 kdDebug() <<
"DIRNAME: " << mBackupDir << endl;
00124 }
00125
00126
QString BackupView::backupFile(
Konnector *k,
Syncee *s )
00127 {
00128
return mBackupDir +
"/" + k->identifier() +
"-" + s->
type();
00129 }
00130
00131
void BackupView::deleteBackup()
00132 {
00133 BackupItem *backupItem =
00134 static_cast<BackupItem *>( mBackupList->currentItem() );
00135
00136
if ( !backupItem ) {
00137 KMessageBox::sorry(
this, i18n(
"No backup selected.") );
00138
return;
00139 }
00140
00141
int result = KMessageBox::questionYesNo(
this,
00142 i18n(
"Permanently delete backup '%1'?").arg( backupItem->text( 0 ) ) );
00143
if ( result == KMessageBox::No )
return;
00144
00145
QString dirName = locateLocal(
"appdata", topBackupDir() );
00146 dirName += backupItem->dirName();
00147
00148 KProcess proc;
00149 proc <<
"rm" <<
"-r" << dirName;
00150 proc.start( KProcess::Block );
00151
00152
delete backupItem;
00153
00154 emit backupDeleted( dirName );
00155 }
00156
00157
#include "backupview.moc"