SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / TapeInfoWidget.cpp
blob52e43955e246862dae35c837c72126b4f8650f6d
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
4 //
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.
9 //
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
19 #include <stdlib.h>
20 #include <time.h>
22 #include <QComboBox>
23 #include <QLabel>
24 #include <QLayout>
25 #include <QLineEdit>
26 //Added by qt3to4:
27 #include <QVBoxLayout>
28 #include <QHBoxLayout>
30 #include <kglobal.h>
31 #include <klocale.h>
32 #include <kpushbutton.h>
33 #include <KStandardGuiItem>
35 #include "Options.h"
36 #include "Tape.h"
37 #include "TapeInfoWidget.h"
38 #include "Util.h"
40 #include "TapeInfoWidget.moc"
42 TapeInfoWidget::TapeInfoWidget( QWidget* parent, const char* name )
43 : QWidget( parent, name ),
44 _tape( 0 )
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 );
139 l1->addStretch( 1 );
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 )
158 _tape = tape;
160 if ( !_tape ) {
161 return;
164 _tapeName->setText( _tape->getName() );
166 int size = _tape->getSize();
167 if ( ( size >= 1024*1024 ) && ( size % ( 1024*1024 ) == 0 ) ) {
168 // GB
169 size /= 1024*1024;
170 _tapeSizeUnits->setCurrentItem( 1 );
171 } else {
172 // MB
173 size /= 1024;
174 _tapeSizeUnits->setCurrentItem( 0 );
176 QString tmp;
177 tmp.setNum( size );
178 _tapeSize->setText( tmp );
180 _tapeID->setText( _tape->getID() );
182 time_t tm = _tape->getCTime();
183 tmp = ctime( &tm );
184 tmp = tmp.trimmed();
185 _ctime->setText( tmp );
187 tm = _tape->getMTime();
188 tmp = ctime( &tm );
189 tmp = tmp.trimmed();
190 _mtime->setText( tmp );
192 tmp.setNum( _tape->getChildren().count() );
193 _archiveCount->setText( tmp );
195 Q3PtrListIterator<Archive> i( _tape->getChildren() );
196 int used = 1;
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() );
211 } else {
212 tmp = Util::kbytesToString( used );
214 _spaceUsed->setText( tmp );
217 bool TapeInfoWidget::isModified()
219 if ( _tape->getName() != _tapeName->text() ) {
220 return TRUE;
223 int size = (int)KGlobal::locale()->readNumber( _tapeSize->text() );
224 if ( _tapeSizeUnits->currentItem() == 0 ) {
225 // MB
226 size *= 1024;
227 } else {
228 // GB
229 size *= 1024*1024;
232 return _tape->getSize() != size;
235 void TapeInfoWidget::slotTextChanged( const QString & )
237 if ( !_tape ) {
238 return;
241 _apply->setEnabled( isModified() );
244 void TapeInfoWidget::slotActivated( int )
246 if ( !_tape ) {
247 return;
250 _apply->setEnabled( isModified() );
253 void TapeInfoWidget::slotApply()
255 if ( !_tape ) {
256 return;
259 int size = (int)KGlobal::locale()->readNumber( _tapeSize->text() );
260 if ( _tapeSizeUnits->currentItem() == 0 ) {
261 // MB
262 size *= 1024;
263 } else {
264 // GB
265 size *= 1024*1024;
268 if ( _tape->getName() != _tapeName->text() ) {
269 _tape->setName( _tapeName->text() );
272 if ( size != _tape->getSize() ) {
273 _tape->setSize( size );
276 _apply->setEnabled( FALSE );