1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21
** of its contributors may be used to endorse or promote products derived
22
** from this software without specific prior written permission.
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39
****************************************************************************/
43
#include "tabdialog.h"
46
TabDialog::TabDialog(const QString &fileName, QWidget *parent)
49
QFileInfo fileInfo(fileName);
51
tabWidget = new QTabWidget;
52
tabWidget->addTab(new GeneralTab(fileInfo), tr("General"));
53
tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
54
tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
58
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
60
| QDialogButtonBox::Cancel);
62
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
63
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
67
QVBoxLayout *mainLayout = new QVBoxLayout;
68
mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
69
mainLayout->addWidget(tabWidget);
70
mainLayout->addWidget(buttonBox);
71
setLayout(mainLayout);
75
setWindowTitle(tr("Tab Dialog"));
80
GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent)
83
QLabel *fileNameLabel = new QLabel(tr("File Name:"));
84
QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName());
86
QLabel *pathLabel = new QLabel(tr("Path:"));
87
QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath());
88
pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
90
QLabel *sizeLabel = new QLabel(tr("Size:"));
91
qlonglong size = fileInfo.size()/1024;
92
QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size));
93
sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
95
QLabel *lastReadLabel = new QLabel(tr("Last Read:"));
96
QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString());
97
lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
99
QLabel *lastModLabel = new QLabel(tr("Last Modified:"));
100
QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString());
101
lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
103
QVBoxLayout *mainLayout = new QVBoxLayout;
104
mainLayout->addWidget(fileNameLabel);
105
mainLayout->addWidget(fileNameEdit);
106
mainLayout->addWidget(pathLabel);
107
mainLayout->addWidget(pathValueLabel);
108
mainLayout->addWidget(sizeLabel);
109
mainLayout->addWidget(sizeValueLabel);
110
mainLayout->addWidget(lastReadLabel);
111
mainLayout->addWidget(lastReadValueLabel);
112
mainLayout->addWidget(lastModLabel);
113
mainLayout->addWidget(lastModValueLabel);
114
mainLayout->addStretch(1);
115
setLayout(mainLayout);
120
PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent)
123
QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions"));
125
QCheckBox *readable = new QCheckBox(tr("Readable"));
126
if (fileInfo.isReadable())
127
readable->setChecked(true);
129
QCheckBox *writable = new QCheckBox(tr("Writable"));
130
if ( fileInfo.isWritable() )
131
writable->setChecked(true);
133
QCheckBox *executable = new QCheckBox(tr("Executable"));
134
if ( fileInfo.isExecutable() )
135
executable->setChecked(true);
137
QGroupBox *ownerGroup = new QGroupBox(tr("Ownership"));
139
QLabel *ownerLabel = new QLabel(tr("Owner"));
140
QLabel *ownerValueLabel = new QLabel(fileInfo.owner());
141
ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
143
QLabel *groupLabel = new QLabel(tr("Group"));
144
QLabel *groupValueLabel = new QLabel(fileInfo.group());
145
groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
147
QVBoxLayout *permissionsLayout = new QVBoxLayout;
148
permissionsLayout->addWidget(readable);
149
permissionsLayout->addWidget(writable);
150
permissionsLayout->addWidget(executable);
151
permissionsGroup->setLayout(permissionsLayout);
153
QVBoxLayout *ownerLayout = new QVBoxLayout;
154
ownerLayout->addWidget(ownerLabel);
155
ownerLayout->addWidget(ownerValueLabel);
156
ownerLayout->addWidget(groupLabel);
157
ownerLayout->addWidget(groupValueLabel);
158
ownerGroup->setLayout(ownerLayout);
160
QVBoxLayout *mainLayout = new QVBoxLayout;
161
mainLayout->addWidget(permissionsGroup);
162
mainLayout->addWidget(ownerGroup);
163
mainLayout->addStretch(1);
164
setLayout(mainLayout);
169
ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent)
172
QLabel *topLabel = new QLabel(tr("Open with:"));
174
QListWidget *applicationsListBox = new QListWidget;
175
QStringList applications;
177
for (int i = 1; i <= 30; ++i)
178
applications.append(tr("Application %1").arg(i));
179
applicationsListBox->insertItems(0, applications);
181
QCheckBox *alwaysCheckBox;
183
if (fileInfo.suffix().isEmpty())
184
alwaysCheckBox = new QCheckBox(tr("Always use this application to "
185
"open this type of file"));
187
alwaysCheckBox = new QCheckBox(tr("Always use this application to "
188
"open files with the extension '%1'").arg(fileInfo.suffix()));
190
QVBoxLayout *layout = new QVBoxLayout;
191
layout->addWidget(topLabel);
192
layout->addWidget(applicationsListBox);
193
layout->addWidget(alwaysCheckBox);