1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 1998-2000 Sean Vyain, svyain@mail.tds.net
3 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <QVBoxLayout>
26 #include <QHBoxLayout>
28 #include <kpushbutton.h>
29 #include <KStandardGuiItem>
32 #include "ArchiveInfoWidget.h"
38 #include "ArchiveInfoWidget.moc"
40 ArchiveInfoWidget::ArchiveInfoWidget( QWidget
* parent
, const char* name
)
41 : QWidget( parent
, name
),
44 QLabel
* lbl1
= new QLabel( i18n( "Archive name:" ), this );
45 QLabel
* lbl2
= new QLabel( i18n( "Created on:" ), this );
46 QLabel
* lbl3
= new QLabel( i18n( "Size:" ), this );
48 int max
= lbl1
->sizeHint().width();
49 if ( lbl2
->sizeHint().width() > max
) max
= lbl2
->sizeHint().width();
50 if ( lbl3
->sizeHint().width() > max
) max
= lbl3
->sizeHint().width();
52 lbl1
->setFixedSize( max
, lbl1
->sizeHint().height() );
53 lbl2
->setFixedSize( max
, lbl2
->sizeHint().height() );
54 lbl3
->setFixedSize( max
, lbl3
->sizeHint().height() );
56 _archiveName
= new QLineEdit( this );
57 _archiveName
->setFixedHeight( _archiveName
->sizeHint().height() );
59 _ctime
= new QLabel( "???", this );
60 _ctime
->setFixedHeight( _ctime
->sizeHint().height() );
62 _size
= new QLabel( "???", this );
63 _size
->setFixedHeight( _size
->sizeHint().height() );
65 _apply
= new KPushButton( KStandardGuiItem::apply(), this );
66 _apply
->setFixedSize( 80, _apply
->sizeHint().height() );
67 _apply
->setEnabled( FALSE
);
69 QVBoxLayout
* l1
= new QVBoxLayout( this, 4, 4 );
71 QHBoxLayout
* l1_1
= new QHBoxLayout();
72 l1
->addLayout( l1_1
);
73 l1_1
->addWidget( lbl1
);
74 l1_1
->addWidget( _archiveName
, 1 );
76 QHBoxLayout
* l1_2
= new QHBoxLayout();
77 l1
->addLayout( l1_2
);
78 l1_2
->addWidget( lbl2
);
79 l1_2
->addWidget( _ctime
);
81 QHBoxLayout
* l1_3
= new QHBoxLayout();
82 l1
->addLayout( l1_3
);
83 l1_3
->addWidget( lbl3
);
84 l1_3
->addWidget( _size
);
88 QHBoxLayout
* l1_4
= new QHBoxLayout();
89 l1
->addLayout( l1_4
);
90 l1_4
->addStretch( 1 );
91 l1_4
->addWidget( _apply
);
93 connect( _archiveName
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotTextChanged( const QString
& ) ) );
94 connect( _apply
, SIGNAL( clicked() ) , this, SLOT( slotApply() ) );
97 ArchiveInfoWidget::~ArchiveInfoWidget()
101 void ArchiveInfoWidget::setArchive( Archive
* archive
)
109 _archiveName
->setText( _archive
->getName() );
112 time_t tm
= _archive
->getCTime();
115 _ctime
->setText( tmp
);
117 int used
= _archive
->getEndBlock();
118 int blockSize
= Options::instance()->getTapeBlockSize();
119 if ( blockSize
< 1024 ) {
120 used
/= 1024 / blockSize
;
121 } else if ( blockSize
> 1024 ) {
122 used
*= blockSize
/ 1024;
124 _size
->setText( Util::kbytesToString( used
) );
127 void ArchiveInfoWidget::slotTextChanged( const QString
& text
)
133 _apply
->setEnabled( _archive
->getName() != text
);
136 void ArchiveInfoWidget::slotApply()
142 if ( _archive
->getName() != _archiveName
->text() ) {
143 _archive
->setName( _archiveName
->text() );
146 _apply
->setEnabled( FALSE
);