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
27 #include <QVBoxLayout>
28 #include <QHBoxLayout>
32 #include <kpushbutton.h>
33 #include <KStandardGuiItem>
37 #include "TapeInfoWidget.h"
40 #include "TapeInfoWidget.moc"
42 TapeInfoWidget::TapeInfoWidget( QWidget
* parent
, const char* name
)
43 : QWidget( parent
, name
),
46 QLabel
* lbl1
= new QLabel( i18n( "Tape name:" ), this );
47 QLabel
* lbl2
= new QLabel( i18n( "Tape size:" ), this );
48 QLabel
* lbl3
= new QLabel( i18n( "Tape ID:" ), this );
49 QLabel
* lbl4
= new QLabel( i18n( "Created on:" ), this );
50 QLabel
* lbl5
= new QLabel( i18n( "Last modified:" ), this );
51 QLabel
* lbl6
= new QLabel( i18n( "Archive count:" ), this );
52 QLabel
* lbl7
= new QLabel( i18n( "Space used:" ), this );
54 int max
= lbl1
->sizeHint().width();
55 if ( lbl2
->sizeHint().width() > max
) max
= lbl2
->sizeHint().width();
56 if ( lbl3
->sizeHint().width() > max
) max
= lbl3
->sizeHint().width();
57 if ( lbl4
->sizeHint().width() > max
) max
= lbl4
->sizeHint().width();
58 if ( lbl5
->sizeHint().width() > max
) max
= lbl5
->sizeHint().width();
59 if ( lbl6
->sizeHint().width() > max
) max
= lbl6
->sizeHint().width();
60 if ( lbl7
->sizeHint().width() > max
) max
= lbl7
->sizeHint().width();
62 lbl1
->setFixedSize( max
, lbl1
->sizeHint().height() );
63 lbl2
->setFixedSize( max
, lbl2
->sizeHint().height() );
64 lbl3
->setFixedSize( max
, lbl3
->sizeHint().height() );
65 lbl4
->setFixedSize( max
, lbl4
->sizeHint().height() );
66 lbl5
->setFixedSize( max
, lbl5
->sizeHint().height() );
67 lbl6
->setFixedSize( max
, lbl6
->sizeHint().height() );
68 lbl7
->setFixedSize( max
, lbl7
->sizeHint().height() );
70 _tapeName
= new QLineEdit( this );
71 _tapeName
->setFixedHeight( _tapeName
->sizeHint().height() );
73 _tapeSize
= new QLineEdit( this );
74 _tapeSize
->setFixedSize( 48, _tapeSize
->sizeHint().height() );
76 _tapeSizeUnits
= new QComboBox( this );
77 _tapeSizeUnits
->setFixedSize( 48, _tapeSizeUnits
->sizeHint().height() );
78 _tapeSizeUnits
->insertItem( "MB" );
79 _tapeSizeUnits
->insertItem( "GB" );
81 _tapeID
= new QLabel( "???", this );
82 _tapeID
->setFixedHeight( _tapeID
->sizeHint().height() );
84 _ctime
= new QLabel( "???", this );
85 _ctime
->setFixedHeight( _ctime
->sizeHint().height() );
87 _mtime
= new QLabel( "???", this );
88 _mtime
->setFixedHeight( _mtime
->sizeHint().height() );
90 _archiveCount
= new QLabel( "???", this );
91 _archiveCount
->setFixedHeight( _archiveCount
->sizeHint().height() );
93 _spaceUsed
= new QLabel( "???", this );
94 _spaceUsed
->setFixedHeight( _spaceUsed
->sizeHint().height() );
96 _apply
= new KPushButton( KStandardGuiItem::apply(), this );
97 _apply
->setFixedSize( 80, _apply
->sizeHint().height() );
98 _apply
->setEnabled( FALSE
);
100 QVBoxLayout
* l1
= new QVBoxLayout( this, 4, 4 );
102 QHBoxLayout
* l1_1
= new QHBoxLayout();
103 l1
->addLayout( l1_1
);
104 l1_1
->addWidget( lbl1
);
105 l1_1
->addWidget( _tapeName
, 1 );
107 QHBoxLayout
* l1_2
= new QHBoxLayout();
108 l1
->addLayout( l1_2
);
109 l1_2
->addWidget( lbl2
);
110 l1_2
->addWidget( _tapeSize
);
111 l1_2
->addWidget( _tapeSizeUnits
);
112 l1_2
->addStretch( 1 );
114 QHBoxLayout
* l1_3
= new QHBoxLayout();
115 l1
->addLayout( l1_3
);
116 l1_3
->addWidget( lbl3
);
117 l1_3
->addWidget( _tapeID
);
119 QHBoxLayout
* l1_4
= new QHBoxLayout();
120 l1
->addLayout( l1_4
);
121 l1_4
->addWidget( lbl4
);
122 l1_4
->addWidget( _ctime
);
124 QHBoxLayout
* l1_5
= new QHBoxLayout();
125 l1
->addLayout( l1_5
);
126 l1_5
->addWidget( lbl5
);
127 l1_5
->addWidget( _mtime
);
129 QHBoxLayout
* l1_6
= new QHBoxLayout();
130 l1
->addLayout( l1_6
);
131 l1_6
->addWidget( lbl6
);
132 l1_6
->addWidget( _archiveCount
);
134 QHBoxLayout
* l1_7
= new QHBoxLayout();
135 l1
->addLayout( l1_7
);
136 l1_7
->addWidget( lbl7
);
137 l1_7
->addWidget( _spaceUsed
);
141 QHBoxLayout
* l1_8
= new QHBoxLayout();
142 l1
->addLayout( l1_8
);
143 l1_8
->addStretch( 1 );
144 l1_8
->addWidget( _apply
);
146 connect( _tapeName
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotTextChanged( const QString
& ) ) );
147 connect( _tapeSize
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotTextChanged( const QString
& ) ) );
148 connect( _tapeSizeUnits
, SIGNAL( activated( int ) ) , this, SLOT( slotActivated( int ) ) );
149 connect( _apply
, SIGNAL( clicked() ) , this, SLOT( slotApply() ) );
152 TapeInfoWidget::~TapeInfoWidget()
156 void TapeInfoWidget::setTape( Tape
* tape
)
164 _tapeName
->setText( _tape
->getName() );
166 int size
= _tape
->getSize();
167 if ( ( size
>= 1024*1024 ) && ( size
% ( 1024*1024 ) == 0 ) ) {
170 _tapeSizeUnits
->setCurrentItem( 1 );
174 _tapeSizeUnits
->setCurrentItem( 0 );
178 _tapeSize
->setText( tmp
);
180 _tapeID
->setText( _tape
->getID() );
182 time_t tm
= _tape
->getCTime();
185 _ctime
->setText( tmp
);
187 tm
= _tape
->getMTime();
190 _mtime
->setText( tmp
);
192 tmp
.setNum( _tape
->getChildren().count() );
193 _archiveCount
->setText( tmp
);
195 Q3PtrListIterator
<Archive
> i( _tape
->getChildren() );
197 for ( ; i
.current(); ++i
) {
198 used
+= i
.current()->getEndBlock();
200 int blockSize
= Options::instance()->getTapeBlockSize();
201 if ( blockSize
< 1024 ) {
202 used
/= 1024 / blockSize
;
203 } else if ( blockSize
> 1024 ) {
204 used
*= blockSize
/ 1024;
206 if ( _tape
->getSize() > 0 ) {
207 tmp
= QString::fromLatin1( "%1 / %2 (%3%)")
208 .arg(Util::kbytesToString( used
))
209 .arg(Util::kbytesToString( _tape
->getSize() ))
210 .arg(used
* 100 / _tape
->getSize() );
212 tmp
= Util::kbytesToString( used
);
214 _spaceUsed
->setText( tmp
);
217 bool TapeInfoWidget::isModified()
219 if ( _tape
->getName() != _tapeName
->text() ) {
223 int size
= (int)KGlobal::locale()->readNumber( _tapeSize
->text() );
224 if ( _tapeSizeUnits
->currentItem() == 0 ) {
232 return _tape
->getSize() != size
;
235 void TapeInfoWidget::slotTextChanged( const QString
& )
241 _apply
->setEnabled( isModified() );
244 void TapeInfoWidget::slotActivated( int )
250 _apply
->setEnabled( isModified() );
253 void TapeInfoWidget::slotApply()
259 int size
= (int)KGlobal::locale()->readNumber( _tapeSize
->text() );
260 if ( _tapeSizeUnits
->currentItem() == 0 ) {
268 if ( _tape
->getName() != _tapeName
->text() ) {
269 _tape
->setName( _tapeName
->text() );
272 if ( size
!= _tape
->getSize() ) {
273 _tape
->setSize( size
);
276 _apply
->setEnabled( FALSE
);