Source Code (Use browser search to find items of interest.)
Class Index
kdat'BackupDlg (./kdeadmin/kdat/BackupDlg.h:37)
class BackupDlg : public QDialog {
Q_OBJECT
KProcess* _proc;
TarParser* _tarParser;
QString _archiveName;
QString _workingDir;
QStrList _files;
bool _oneFilesystem;
bool _incremental;
QString _snapshot;
bool _removeSnapshot;
int _archiveSize;
Tape* _tape;
float _totalKBytes;
uint _totalRecords;
QLabel* _elapsedTime;
QLabel* _timeRemaining;
QLabel* _kbytesWritten;
QLabel* _transferRate;
QLabel* _fileCount;
LoggerWidget* _log;
QPushButton* _ok;
QPushButton* _save;
QPushButton* _abort;
int _startTime;
Archive* _archive;
bool _aborted;
int _numFiles;
int _fileSize;
int _fileMTime;
int _fileStartRecord;
QString _fileName;
void updateStats();
private slots:
void slotProcessExited( KProcess* proc );
void slotStdout( KProcess* proc, char* buf, int len );
void slotOK();
void slotAbort();
void slotEntry( const char* name, int size, int mtime, int record );
protected:
void show();
void timerEvent( QTimerEvent* e );
public:
/**
* Create a backup dialog.
*
* @param archiveName The name for the new archive.
* @param workingDir The directory to backup from.
* @param files The list of files to backup.
* @param oneFilesystem TRUE means do not follow symbolic links across filesystems.
* @param incremental TRUE mean do a GNU listed incremental backup.
* @param snapshot The name of the snapshot file for an incremental backup.
* @param removeSnapshot Remove the snapshot before backing up.
* @param archiveSize The estimate size of the archive in kilobytes.
* @param tape The tape index to add the archive to.
* @param parent The parent widget for this dialog.
* @param name The name of this widget.
*/
BackupDlg( const char* archiveName, const char* workingDir, const QStrList& files, bool oneFilesystem, bool incremental,
const char* snapshot, bool removeSnapshot, int archiveSize, Tape* tape,
QWidget* parent = 0, const char* name = 0 );
/**
* Destroy the backup dialog.
*/
~BackupDlg();
};
kdat'BackupDlg::BackupDlg() (./kdeadmin/kdat/BackupDlg.cpp:45)
BackupDlg::BackupDlg( const char* archiveName, const char* workingDir, const QStrList& files, bool oneFilesystem, bool incremental,
const char* snapshot, bool removeSnapshot, int archiveSize, Tape* tape,
QWidget* parent, const char* name )
: QDialog( parent, name, TRUE ),
_proc( NULL ),
_tarParser( NULL ),
_archiveName( archiveName ),
_workingDir( workingDir ),
_oneFilesystem( oneFilesystem ),
_incremental( incremental ),
_snapshot( snapshot ),
_removeSnapshot( removeSnapshot ),
_archiveSize( archiveSize ),
_tape( tape ),
_totalKBytes( 0.0 ),
_totalRecords( 0 ),
_startTime( 0 ),
_archive( NULL ),
_aborted( FALSE ),
_numFiles( 0 ),
_fileSize( -1 ),
_fileMTime( -1 ),
_fileStartRecord( -1 )
{
// Copy the list of files to archive.
QStrListIterator i( files );
for ( ; i.current(); ++i ) {
_files.append( i.current() );
}
setCaption( i18n( "KDat: Backup" ) );
setIconText( i18n( "KDat: Backup" ) );
resize( 500, 300 );
const int labelWidth = 96;
QFrame* f1 = new QFrame( this );
f1->setFrameStyle( QFrame::Panel | QFrame::Sunken );
QFrame* f2 = new QFrame( this );
f2->setFrameStyle( QFrame::Panel | QFrame::Sunken );
QLabel* lbl1 = new QLabel( i18n( "Elapsed time:" ), f1 );
lbl1->setFixedSize( labelWidth, lbl1->sizeHint().height() );
_elapsedTime = new QLabel( i18n( "00:00:00" ), f1 );
_elapsedTime->setFixedHeight( _elapsedTime->sizeHint().height() );
QLabel* lbl2 = new QLabel( i18n( "Time remaining:" ), f2 );
lbl2->setFixedSize( labelWidth, lbl2->sizeHint().height() );
_timeRemaining = new QLabel( i18n( "00:00:00" ), f2 );
_timeRemaining->setFixedHeight( _timeRemaining->sizeHint().height() );
QLabel* lbl3 = new QLabel( i18n( "Total kbytes:" ), f1 );
lbl3->setFixedSize( labelWidth, lbl3->sizeHint().height() );
QLabel* totalKbytes = new QLabel( Util::kbytesToString( archiveSize ), f1 );
totalKbytes->setFixedHeight( totalKbytes->sizeHint().height() );
QLabel* lbl4 = new QLabel( i18n( "Kbytes written:" ), f2 );
lbl4->setFixedSize( labelWidth, lbl4->sizeHint().height() );
_kbytesWritten = new QLabel( i18n( "0k" ), f2 );
_kbytesWritten->setFixedHeight( _kbytesWritten->sizeHint().height() );
QLabel* lbl5 = new QLabel( i18n( "Transfer rate:" ), f1 );
lbl5->setFixedSize( labelWidth, lbl5->sizeHint().height() );
_transferRate = new QLabel( i18n( "0k/min" ), f1 );
_transferRate->setFixedHeight( _transferRate->sizeHint().height() );
QLabel* lbl6 = new QLabel( i18n( "Files:" ), f2 );
lbl6->setFixedSize( labelWidth, lbl6->sizeHint().height() );
_fileCount = new QLabel( i18n( "0" ), f2 );
_fileCount->setFixedHeight( _fileCount->sizeHint().height() );
_log = new LoggerWidget( i18n( "Backup log:" ), this );
_ok = new QPushButton( i18n( "OK" ), this );
_ok->setFixedSize( 80, _ok->sizeHint().height() );
connect( _ok, SIGNAL( clicked() ), this, SLOT( slotOK() ) );
_ok->setEnabled( FALSE );
_save = new QPushButton( i18n( "Save Log..." ), this );
_save->setFixedSize( 80, _save->sizeHint().height() );
connect( _save, SIGNAL( clicked() ), _log, SLOT( save() ) );
_save->setEnabled( FALSE );
_abort = new QPushButton( i18n( "Abort" ), this );
_abort->setFixedSize( 80, _abort->sizeHint().height() );
connect( _abort, SIGNAL( clicked() ), this, SLOT( slotAbort() ) );
QVBoxLayout* l1 = new QVBoxLayout( this, 8, 4 );
QHBoxLayout* l1_1 = new QHBoxLayout();
l1->addLayout( l1_1 );
l1_1->addStrut( 3 * lbl1->height() + 16 );
l1_1->addWidget( f1 );
l1_1->addWidget( f2 );
QVBoxLayout* l1_1_1 = new QVBoxLayout( f1, 4, 4 );
QHBoxLayout* l1_1_1_1 = new QHBoxLayout();
l1_1_1->addLayout( l1_1_1_1 );
l1_1_1_1->addWidget( lbl1 );
l1_1_1_1->addWidget( _elapsedTime, 1 );
QHBoxLayout* l1_1_1_2 = new QHBoxLayout();
l1_1_1->addLayout( l1_1_1_2 );
l1_1_1_2->addWidget( lbl3 );
l1_1_1_2->addWidget( totalKbytes, 1 );
QHBoxLayout* l1_1_1_3 = new QHBoxLayout();
l1_1_1->addLayout( l1_1_1_3 );
l1_1_1_3->addWidget( lbl5 );
l1_1_1_3->addWidget( _transferRate, 1 );
QVBoxLayout* l1_1_2 = new QVBoxLayout( f2, 4, 4 );
QHBoxLayout* l1_1_2_1 = new QHBoxLayout();
l1_1_2->addLayout( l1_1_2_1 );
l1_1_2_1->addWidget( lbl2 );
l1_1_2_1->addWidget( _timeRemaining, 1 );
QHBoxLayout* l1_1_2_2 = new QHBoxLayout();
l1_1_2->addLayout( l1_1_2_2 );
l1_1_2_2->addWidget( lbl4 );
l1_1_2_2->addWidget( _kbytesWritten, 1 );
QHBoxLayout* l1_1_2_3 = new QHBoxLayout();
l1_1_2->addLayout( l1_1_2_3 );
l1_1_2_3->addWidget( lbl6 );
l1_1_2_3->addWidget( _fileCount, 1 );
l1->addWidget( _log, 1 );
QHBoxLayout* l1_2 = new QHBoxLayout();
l1->addLayout( l1_2 );
l1_2->addStretch( 1 );
l1_2->addWidget( _ok );
l1_2->addWidget( _save );
l1_2->addWidget( _abort );
}
kdat'BackupDlg::~BackupDlg() (./kdeadmin/kdat/BackupDlg.cpp:192)
BackupDlg::~BackupDlg()
{
delete _tarParser;
}
kdat'BackupDlg::show() (./kdeadmin/kdat/BackupDlg.cpp:197)
void BackupDlg::show()
{
_archive = new Archive( _tape, time( NULL ), _archiveName );
chdir( _workingDir );
if ( _removeSnapshot ) {
unlink( _snapshot );
}
_tarParser = new TarParser();
connect( _tarParser, SIGNAL( sigEntry( const char*, int, int, int ) ), this, SLOT( slotEntry( const char*, int, int, int ) ) );
_proc = new KProcess();
_proc->setExecutable( Options::instance()->getTarCommand() );
if ( _oneFilesystem ) {
*_proc << "-l";
}
if ( _incremental ) {
*_proc << "-g" << _snapshot;
}
*_proc << "-Spcf" << "-";
// Append the list of files to archive.
if ( ( _files.count() == 1 ) && ( !strcmp( _files.getFirst(), "." ) ) ) {
dev_t device = 0;
struct stat info;
if ( _oneFilesystem ) {
if ( lstat( ".", &info ) == 0 ) {
device = info.st_dev;
}
}
// Backup all files in current working directory.
QDir dir;
QStringList::Iterator i = dir.entryList( QDir::All, QDir::Name | QDir::DirsFirst ).begin();
for ( ; !(*i).isNull() ; ++i ) {
if ( strcmp( *i, "." ) && strcmp( *i, ".." ) ) {
if ( _oneFilesystem ) {
if ( lstat( *i, &info ) == 0 )
{
if ( info.st_dev == device ) {
*_proc << *i;
}
}
} else {
*_proc << *i;
}
}
}
} else {
// Backup listed files only.
QStrListIterator i( _files );
for ( ; i.current(); ++i ) {
*_proc << i.current();
}
}
connect( _proc, SIGNAL( processExited( KProcess* ) ), this, SLOT( slotProcessExited( KProcess* ) ) );
connect( _proc, SIGNAL( receivedStdout( KProcess*, char*, int ) ), this, SLOT( slotStdout( KProcess*, char*, int ) ) );
startTimer( 1000 );
_proc->start( KProcess::NotifyOnExit, KProcess::Stdout );
QDialog::show();
}
kdat'BackupDlg::slotProcessExited() (./kdeadmin/kdat/BackupDlg.cpp:265)
void BackupDlg::slotProcessExited( KProcess* )
{
updateStats();
_archive->setEndBlock( _totalRecords / ( Options::instance()->getTapeBlockSize() / 512 ) );
if ( _fileName.length() > 0 ) {
_archive->addFile( _fileSize, _fileMTime, _fileStartRecord, _totalRecords, _fileName );
_fileName = QString::null;
}
TapeDrive::instance()->close();
TapeDrive::instance()->open();
killTimers();
delete _proc;
_tape->addChild( _archive );
_ok->setEnabled( TRUE );
_save->setEnabled( TRUE );
_abort->setEnabled( FALSE );
}
kdat'BackupDlg::slotStdout() (./kdeadmin/kdat/BackupDlg.cpp:289)
void BackupDlg::slotStdout( KProcess*, char* buf, int len )
{
// Don't start throughput timer until the first block of data is written.
if ( _startTime == 0 ) {
_startTime = time( NULL );
}
// Pass the data through the tar parser to extract the file info.
_tarParser->slotData( buf, len );
_totalKBytes += (float)len / 1024.0;
assert( len % 512 == 0 );
_totalRecords += len / 512;
if ( TapeDrive::instance()->write( buf, len ) < len ) {
_log->append( i18n( "*** Write failed, giving up." ) );
if ( _proc ) {
_proc->kill();
}
slotProcessExited( 0 );
}
}
kdat'BackupDlg::slotEntry() (./kdeadmin/kdat/BackupDlg.cpp:313)
void BackupDlg::slotEntry( const char* name, int size, int mtime, int record )
{
if ( _fileName.length() > 0 ) {
_archive->addFile( _fileSize, _fileMTime, _fileStartRecord, record, _fileName );
}
_fileName = name;
_fileSize = size;
_fileMTime = mtime;
_fileStartRecord = record;
QString tmp;
tmp.setNum( ++_numFiles );
_fileCount->setText( tmp );
_log->append( name );
}
kdat'BackupDlg::slotOK() (./kdeadmin/kdat/BackupDlg.cpp:330)
void BackupDlg::slotOK()
{
if ( _aborted ) {
reject();
} else {
accept();
}
}
kdat'BackupDlg::slotAbort() (./kdeadmin/kdat/BackupDlg.cpp:339)
void BackupDlg::slotAbort()
{
killTimers();
if ( _proc ) {
_proc->kill();
delete _proc;
}
delete _archive;
_aborted = TRUE;
_ok->setEnabled( TRUE );
_save->setEnabled( TRUE );
_abort->setEnabled( FALSE );
}
kdat'BackupDlg::timerEvent() (./kdeadmin/kdat/BackupDlg.cpp:354)
void BackupDlg::timerEvent( QTimerEvent* )
{
updateStats();
}
kdat'BackupDlg::updateStats() (./kdeadmin/kdat/BackupDlg.cpp:359)
void BackupDlg::updateStats()
{
if ( _startTime == 0 ) {
return;
}
QString str;
int elapsed = time( NULL ) - _startTime;
str.sprintf( i18n( "%02d:%02d:%02d" ), elapsed / 3600, elapsed / 60 % 60, elapsed % 60 );
_elapsedTime->setText( str );
int remain = 0;
if ( (int)_totalKBytes > 0 ) {
remain = (int)(( (float)_archiveSize - _totalKBytes ) * (float)elapsed / _totalKBytes);
}
if ( remain < 0 ) {
remain = 0;
}
str.sprintf( i18n( "%02d:%02d:%02d" ), remain / 3600, remain / 60 % 60, remain % 60 );
_timeRemaining->setText( str );
str = Util::kbytesToString( (int)_totalKBytes );
_kbytesWritten->setText( str );
if ( elapsed > 0 ) {
str = i18n( "%1/min" ).arg(Util::kbytesToString( (int)_totalKBytes *60 / elapsed ) );
_transferRate->setText( str );
}
}