author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui> |
|
43 |
||
44 |
#include "locationdialog.h" |
|
45 |
||
46 |
LocationDialog::LocationDialog(QWidget *parent) |
|
47 |
: QDialog(parent) |
|
48 |
{ |
|
49 |
formatComboBox = new QComboBox; |
|
50 |
formatComboBox->addItem(tr("Native")); |
|
51 |
formatComboBox->addItem(tr("INI")); |
|
52 |
||
53 |
scopeComboBox = new QComboBox; |
|
54 |
scopeComboBox->addItem(tr("User")); |
|
55 |
scopeComboBox->addItem(tr("System")); |
|
56 |
||
57 |
organizationComboBox = new QComboBox; |
|
58 |
organizationComboBox->addItem(tr("Trolltech")); |
|
59 |
organizationComboBox->setEditable(true); |
|
60 |
||
61 |
applicationComboBox = new QComboBox; |
|
62 |
applicationComboBox->addItem(tr("Any")); |
|
63 |
applicationComboBox->addItem(tr("Application Example")); |
|
64 |
applicationComboBox->addItem(tr("Assistant")); |
|
65 |
applicationComboBox->addItem(tr("Designer")); |
|
66 |
applicationComboBox->addItem(tr("Linguist")); |
|
67 |
applicationComboBox->setEditable(true); |
|
68 |
applicationComboBox->setCurrentIndex(3); |
|
69 |
||
70 |
formatLabel = new QLabel(tr("&Format:")); |
|
71 |
formatLabel->setBuddy(formatComboBox); |
|
72 |
||
73 |
scopeLabel = new QLabel(tr("&Scope:")); |
|
74 |
scopeLabel->setBuddy(scopeComboBox); |
|
75 |
||
76 |
organizationLabel = new QLabel(tr("&Organization:")); |
|
77 |
organizationLabel->setBuddy(organizationComboBox); |
|
78 |
||
79 |
applicationLabel = new QLabel(tr("&Application:")); |
|
80 |
applicationLabel->setBuddy(applicationComboBox); |
|
81 |
||
82 |
locationsGroupBox = new QGroupBox(tr("Setting Locations")); |
|
83 |
||
84 |
QStringList labels; |
|
85 |
labels << tr("Location") << tr("Access"); |
|
86 |
||
87 |
locationsTable = new QTableWidget; |
|
88 |
locationsTable->setSelectionMode(QAbstractItemView::SingleSelection); |
|
89 |
locationsTable->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
90 |
locationsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
91 |
locationsTable->setColumnCount(2); |
|
92 |
locationsTable->setHorizontalHeaderLabels(labels); |
|
93 |
locationsTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); |
|
94 |
locationsTable->horizontalHeader()->resizeSection(1, 180); |
|
95 |
||
96 |
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
97 |
| QDialogButtonBox::Cancel); |
|
98 |
||
99 |
connect(formatComboBox, SIGNAL(activated(int)), |
|
100 |
this, SLOT(updateLocationsTable())); |
|
101 |
connect(scopeComboBox, SIGNAL(activated(int)), |
|
102 |
this, SLOT(updateLocationsTable())); |
|
103 |
connect(organizationComboBox->lineEdit(), |
|
104 |
SIGNAL(editingFinished()), |
|
105 |
this, SLOT(updateLocationsTable())); |
|
106 |
connect(applicationComboBox->lineEdit(), |
|
107 |
SIGNAL(editingFinished()), |
|
108 |
this, SLOT(updateLocationsTable())); |
|
109 |
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
|
110 |
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
|
111 |
||
112 |
QVBoxLayout *locationsLayout = new QVBoxLayout; |
|
113 |
locationsLayout->addWidget(locationsTable); |
|
114 |
locationsGroupBox->setLayout(locationsLayout); |
|
115 |
||
116 |
QGridLayout *mainLayout = new QGridLayout; |
|
117 |
mainLayout->addWidget(formatLabel, 0, 0); |
|
118 |
mainLayout->addWidget(formatComboBox, 0, 1); |
|
119 |
mainLayout->addWidget(scopeLabel, 1, 0); |
|
120 |
mainLayout->addWidget(scopeComboBox, 1, 1); |
|
121 |
mainLayout->addWidget(organizationLabel, 2, 0); |
|
122 |
mainLayout->addWidget(organizationComboBox, 2, 1); |
|
123 |
mainLayout->addWidget(applicationLabel, 3, 0); |
|
124 |
mainLayout->addWidget(applicationComboBox, 3, 1); |
|
125 |
mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2); |
|
126 |
mainLayout->addWidget(buttonBox, 5, 0, 1, 2); |
|
127 |
setLayout(mainLayout); |
|
128 |
||
129 |
updateLocationsTable(); |
|
130 |
||
131 |
setWindowTitle(tr("Open Application Settings")); |
|
132 |
resize(650, 400); |
|
133 |
} |
|
134 |
||
135 |
QSettings::Format LocationDialog::format() const |
|
136 |
{ |
|
137 |
if (formatComboBox->currentIndex() == 0) |
|
138 |
return QSettings::NativeFormat; |
|
139 |
else |
|
140 |
return QSettings::IniFormat; |
|
141 |
} |
|
142 |
||
143 |
QSettings::Scope LocationDialog::scope() const |
|
144 |
{ |
|
145 |
if (scopeComboBox->currentIndex() == 0) |
|
146 |
return QSettings::UserScope; |
|
147 |
else |
|
148 |
return QSettings::SystemScope; |
|
149 |
} |
|
150 |
||
151 |
QString LocationDialog::organization() const |
|
152 |
{ |
|
153 |
return organizationComboBox->currentText(); |
|
154 |
} |
|
155 |
||
156 |
QString LocationDialog::application() const |
|
157 |
{ |
|
158 |
if (applicationComboBox->currentText() == tr("Any")) |
|
159 |
return ""; |
|
160 |
else |
|
161 |
return applicationComboBox->currentText(); |
|
162 |
} |
|
163 |
||
164 |
void LocationDialog::updateLocationsTable() |
|
165 |
{ |
|
166 |
locationsTable->setUpdatesEnabled(false); |
|
167 |
locationsTable->setRowCount(0); |
|
168 |
||
169 |
for (int i = 0; i < 2; ++i) { |
|
170 |
if (i == 0 && scope() == QSettings::SystemScope) |
|
171 |
continue; |
|
172 |
||
173 |
QSettings::Scope actualScope = (i == 0) ? QSettings::UserScope |
|
174 |
: QSettings::SystemScope; |
|
175 |
for (int j = 0; j < 2; ++j) { |
|
176 |
if (j == 0 && application().isEmpty()) |
|
177 |
continue; |
|
178 |
||
179 |
QString actualApplication; |
|
180 |
if (j == 0) |
|
181 |
actualApplication = application(); |
|
182 |
QSettings settings(format(), actualScope, organization(), |
|
183 |
actualApplication); |
|
184 |
||
185 |
int row = locationsTable->rowCount(); |
|
186 |
locationsTable->setRowCount(row + 1); |
|
187 |
||
188 |
QTableWidgetItem *item0 = new QTableWidgetItem; |
|
189 |
item0->setText(settings.fileName()); |
|
190 |
||
191 |
QTableWidgetItem *item1 = new QTableWidgetItem; |
|
192 |
bool disable = (settings.childKeys().isEmpty() |
|
193 |
&& settings.childGroups().isEmpty()); |
|
194 |
||
195 |
if (row == 0) { |
|
196 |
if (settings.isWritable()) { |
|
197 |
item1->setText(tr("Read-write")); |
|
198 |
disable = false; |
|
199 |
} else { |
|
200 |
item1->setText(tr("Read-only")); |
|
201 |
} |
|
202 |
buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable); |
|
203 |
} else { |
|
204 |
item1->setText(tr("Read-only fallback")); |
|
205 |
} |
|
206 |
||
207 |
if (disable) { |
|
208 |
item0->setFlags(item0->flags() & ~Qt::ItemIsEnabled); |
|
209 |
item1->setFlags(item1->flags() & ~Qt::ItemIsEnabled); |
|
210 |
} |
|
211 |
||
212 |
locationsTable->setItem(row, 0, item0); |
|
213 |
locationsTable->setItem(row, 1, item1); |
|
214 |
} |
|
215 |
} |
|
216 |
locationsTable->setUpdatesEnabled(true); |
|
217 |
} |