~ubuntu-branches/ubuntu/natty/kdeadmin/natty-proposed

« back to all changes in this revision

Viewing changes to kdat/FileInfoWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-27 21:36:45 UTC
  • mfrom: (1.2.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20100227213645-ronst6mahkgf6j9w
Tags: 4:4.4.1-0ubuntu1
* New upstream release
  - Bump build-depends
  - Update kcron.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
14
 
//
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
18
 
 
19
 
#include <pwd.h>
20
 
#include <sys/stat.h>
21
 
#include <sys/types.h>
22
 
#include <grp.h>
23
 
#include <time.h>
24
 
 
25
 
#include <qdatetime.h>
26
 
#include <QLabel>
27
 
#include <QLayout>
28
 
#include <QFile>
29
 
//Added by qt3to4:
30
 
#include <QVBoxLayout>
31
 
#include <QHBoxLayout>
32
 
 
33
 
#include <kglobal.h>
34
 
#include <klocale.h>
35
 
 
36
 
#include "FileInfoWidget.h"
37
 
#include "Util.h"
38
 
 
39
 
#include "FileInfoWidget.moc"
40
 
 
41
 
FileInfoWidget::FileInfoWidget( QWidget* parent, const char* name )
42
 
        : QWidget( parent, name )
43
 
{
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 );
51
 
 
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();
59
 
 
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() );
67
 
 
68
 
    _fileName = new QLabel( "???", this );
69
 
    _fileName->setFixedHeight( _fileName->sizeHint().height() );
70
 
    
71
 
    _ctime = new QLabel( "???", this );
72
 
    _ctime->setFixedHeight( _ctime->sizeHint().height() );
73
 
 
74
 
    _mtime = new QLabel( "???", this );
75
 
    _mtime->setFixedHeight( _mtime->sizeHint().height() );
76
 
    
77
 
    _atime = new QLabel( "???", this );
78
 
    _atime->setFixedHeight( _atime->sizeHint().height() );
79
 
 
80
 
    _size = new QLabel( "???", this );
81
 
    _size->setFixedHeight( _size->sizeHint().height() );
82
 
 
83
 
    _owner = new QLabel( "???", this );
84
 
    _owner->setFixedHeight( _owner->sizeHint().height() );
85
 
 
86
 
    _group = new QLabel( "???", this );
87
 
    _group->setFixedHeight( _group->sizeHint().height() );
88
 
 
89
 
    QVBoxLayout* l1 = new QVBoxLayout( this, 4, 4 );
90
 
 
91
 
    QHBoxLayout* l1_1 = new QHBoxLayout();
92
 
    l1->addLayout( l1_1 );
93
 
    l1_1->addWidget( lbl1 );
94
 
    l1_1->addWidget( _fileName, 1 );
95
 
 
96
 
    QHBoxLayout* l1_2 = new QHBoxLayout();
97
 
    l1->addLayout( l1_2 );
98
 
    l1_2->addWidget( lbl2 );
99
 
    l1_2->addWidget( _ctime, 1 );
100
 
 
101
 
    QHBoxLayout* l1_3 = new QHBoxLayout();
102
 
    l1->addLayout( l1_3 );
103
 
    l1_3->addWidget( lbl3 );
104
 
    l1_3->addWidget( _mtime, 1 );
105
 
 
106
 
    QHBoxLayout* l1_4 = new QHBoxLayout();
107
 
    l1->addLayout( l1_4 );
108
 
    l1_4->addWidget( lbl4 );
109
 
    l1_4->addWidget( _atime, 1 );
110
 
 
111
 
    QHBoxLayout* l1_5 = new QHBoxLayout();
112
 
    l1->addLayout( l1_5 );
113
 
    l1_5->addWidget( lbl5 );
114
 
    l1_5->addWidget( _size, 1 );
115
 
 
116
 
    QHBoxLayout* l1_6 = new QHBoxLayout();
117
 
    l1->addLayout( l1_6 );
118
 
    l1_6->addWidget( lbl6 );
119
 
    l1_6->addWidget( _owner, 1 );
120
 
 
121
 
    QHBoxLayout* l1_7 = new QHBoxLayout();
122
 
    l1->addLayout( l1_7 );
123
 
    l1_7->addWidget( lbl7 );
124
 
    l1_7->addWidget( _group, 1 );
125
 
 
126
 
    l1->addStretch( 1 );
127
 
}
128
 
 
129
 
FileInfoWidget::~FileInfoWidget()
130
 
{
131
 
}
132
 
 
133
 
void FileInfoWidget::setFile( const QString & name )
134
 
{
135
 
    if ( name.isNull() ) {
136
 
        return;
137
 
    }
138
 
 
139
 
    _fileName->setText( name );
140
 
 
141
 
    struct stat info;
142
 
    lstat( QFile::encodeName(name), &info );
143
 
 
144
 
    QString tmp;
145
 
    QDateTime datetime;
146
 
 
147
 
    datetime.setTime_t(info.st_ctime);
148
 
    _ctime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
149
 
 
150
 
    datetime.setTime_t(info.st_mtime);
151
 
    _mtime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
152
 
 
153
 
    datetime.setTime_t(info.st_atime);
154
 
    _atime->setText( KGlobal::locale()->formatDateTime(datetime, KLocale::LongDate) );
155
 
    
156
 
    _size->setText( Util::bytesToString( info.st_size ) );
157
 
 
158
 
    struct passwd* p;
159
 
    p = getpwuid( info.st_uid );
160
 
    if ( p ) {
161
 
        tmp = p->pw_name;
162
 
    } else {
163
 
        tmp.setNum( info.st_uid );
164
 
    }
165
 
    _owner->setText( tmp );
166
 
 
167
 
    struct group* g;
168
 
    g = getgrgid( info.st_gid );
169
 
    if ( g ) {
170
 
        tmp = g->gr_name;
171
 
    } else {
172
 
        tmp.setNum( info.st_gid );
173
 
    }
174
 
    _group->setText( tmp );
175
 
}