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
21
#include <sys/types.h>
25
#include <qdatetime.h>
30
#include <QVBoxLayout>
31
#include <QHBoxLayout>
36
#include "FileInfoWidget.h"
39
#include "FileInfoWidget.moc"
41
FileInfoWidget::FileInfoWidget( QWidget* parent, const char* name )
42
: QWidget( parent, name )
44
QLabel* lbl1 = new QLabel( i18n( "File name:" ), this );
45
QLabel* lbl2 = new QLabel( i18n( "Created on:" ), this );
46
QLabel* lbl3 = new QLabel( i18n( "Last modified:" ), this );
47
QLabel* lbl4 = new QLabel( i18n( "Last accessed:" ), this );
48
QLabel* lbl5 = new QLabel( i18n( "Size:" ), this );
49
QLabel* lbl6 = new QLabel( i18n( "Owner:" ), this );
50
QLabel* lbl7 = new QLabel( i18n( "Group:" ), this );
52
int max = lbl1->sizeHint().width();
53
if ( lbl2->sizeHint().width() > max ) max = lbl2->sizeHint().width();
54
if ( lbl3->sizeHint().width() > max ) max = lbl3->sizeHint().width();
55
if ( lbl4->sizeHint().width() > max ) max = lbl4->sizeHint().width();
56
if ( lbl5->sizeHint().width() > max ) max = lbl5->sizeHint().width();
57
if ( lbl6->sizeHint().width() > max ) max = lbl6->sizeHint().width();
58
if ( lbl7->sizeHint().width() > max ) max = lbl7->sizeHint().width();
60
lbl1->setFixedSize( max, lbl1->sizeHint().height() );
61
lbl2->setFixedSize( max, lbl2->sizeHint().height() );
62
lbl3->setFixedSize( max, lbl3->sizeHint().height() );
63
lbl4->setFixedSize( max, lbl4->sizeHint().height() );
64
lbl5->setFixedSize( max, lbl5->sizeHint().height() );
65
lbl6->setFixedSize( max, lbl6->sizeHint().height() );
66
lbl7->setFixedSize( max, lbl7->sizeHint().height() );
68
_fileName = new QLabel( "???", this );
69
_fileName->setFixedHeight( _fileName->sizeHint().height() );
71
_ctime = new QLabel( "???", this );
72
_ctime->setFixedHeight( _ctime->sizeHint().height() );
74
_mtime = new QLabel( "???", this );
75
_mtime->setFixedHeight( _mtime->sizeHint().height() );
77
_atime = new QLabel( "???", this );
78
_atime->setFixedHeight( _atime->sizeHint().height() );
80
_size = new QLabel( "???", this );
81
_size->setFixedHeight( _size->sizeHint().height() );
83
_owner = new QLabel( "???", this );
84
_owner->setFixedHeight( _owner->sizeHint().height() );
86
_group = new QLabel( "???", this );
87
_group->setFixedHeight( _group->sizeHint().height() );
89
QVBoxLayout* l1 = new QVBoxLayout( this, 4, 4 );
91
QHBoxLayout* l1_1 = new QHBoxLayout();
92
l1->addLayout( l1_1 );
93
l1_1->addWidget( lbl1 );
94
l1_1->addWidget( _fileName, 1 );
96
QHBoxLayout* l1_2 = new QHBoxLayout();
97
l1->addLayout( l1_2 );
98
l1_2->addWidget( lbl2 );
99
l1_2->addWidget( _ctime, 1 );
101
QHBoxLayout* l1_3 = new QHBoxLayout();
102
l1->addLayout( l1_3 );
103
l1_3->addWidget( lbl3 );
104
l1_3->addWidget( _mtime, 1 );
106
QHBoxLayout* l1_4 = new QHBoxLayout();
107
l1->addLayout( l1_4 );
108
l1_4->addWidget( lbl4 );
109
l1_4->addWidget( _atime, 1 );
111
QHBoxLayout* l1_5 = new QHBoxLayout();
112
l1->addLayout( l1_5 );
113
l1_5->addWidget( lbl5 );
114
l1_5->addWidget( _size, 1 );
116
QHBoxLayout* l1_6 = new QHBoxLayout();
117
l1->addLayout( l1_6 );
118
l1_6->addWidget( lbl6 );
119
l1_6->addWidget( _owner, 1 );
121
QHBoxLayout* l1_7 = new QHBoxLayout();
122
l1->addLayout( l1_7 );
123
l1_7->addWidget( lbl7 );
124
l1_7->addWidget( _group, 1 );
129
FileInfoWidget::~FileInfoWidget()
133
void FileInfoWidget::setFile( const QString & name )
135
if ( name.isNull() ) {
139
_fileName->setText( name );
142
lstat( QFile::encodeName(name), &info );
147
datetime.setTime_t(info.st_ctime);
148
_ctime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
150
datetime.setTime_t(info.st_mtime);
151
_mtime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
153
datetime.setTime_t(info.st_atime);
154
_atime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
156
_size->setText( Util::bytesToString( info.st_size ) );
159
p = getpwuid( info.st_uid );
163
tmp.setNum( info.st_uid );
165
_owner->setText( tmp );
168
g = getgrgid( info.st_gid );
172
tmp.setNum( info.st_gid );
174
_group->setText( tmp );