author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
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 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QtGui> |
|
42 |
||
43 |
#include "locationdialog.h" |
|
44 |
||
45 |
LocationDialog::LocationDialog(QWidget *parent) |
|
46 |
: QDialog(parent) |
|
47 |
{ |
|
48 |
formatComboBox = new QComboBox; |
|
49 |
formatComboBox->addItem(tr("Native")); |
|
50 |
formatComboBox->addItem(tr("INI")); |
|
51 |
||
52 |
scopeComboBox = new QComboBox; |
|
53 |
scopeComboBox->addItem(tr("User")); |
|
54 |
scopeComboBox->addItem(tr("System")); |
|
55 |
||
56 |
organizationComboBox = new QComboBox; |
|
57 |
organizationComboBox->addItem(tr("Trolltech")); |
|
58 |
organizationComboBox->setEditable(true); |
|
59 |
||
60 |
applicationComboBox = new QComboBox; |
|
61 |
applicationComboBox->addItem(tr("Any")); |
|
62 |
applicationComboBox->addItem(tr("Application Example")); |
|
63 |
applicationComboBox->addItem(tr("Assistant")); |
|
64 |
applicationComboBox->addItem(tr("Designer")); |
|
65 |
applicationComboBox->addItem(tr("Linguist")); |
|
66 |
applicationComboBox->setEditable(true); |
|
67 |
applicationComboBox->setCurrentIndex(3); |
|
68 |
||
69 |
formatLabel = new QLabel(tr("&Format:")); |
|
70 |
formatLabel->setBuddy(formatComboBox); |
|
71 |
||
72 |
scopeLabel = new QLabel(tr("&Scope:")); |
|
73 |
scopeLabel->setBuddy(scopeComboBox); |
|
74 |
||
75 |
organizationLabel = new QLabel(tr("&Organization:")); |
|
76 |
organizationLabel->setBuddy(organizationComboBox); |
|
77 |
||
78 |
applicationLabel = new QLabel(tr("&Application:")); |
|
79 |
applicationLabel->setBuddy(applicationComboBox); |
|
80 |
||
81 |
locationsGroupBox = new QGroupBox(tr("Setting Locations")); |
|
82 |
||
83 |
QStringList labels; |
|
84 |
labels << tr("Location") << tr("Access"); |
|
85 |
||
86 |
locationsTable = new QTableWidget; |
|
87 |
locationsTable->setSelectionMode(QAbstractItemView::SingleSelection); |
|
88 |
locationsTable->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
89 |
locationsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
90 |
locationsTable->setColumnCount(2); |
|
91 |
locationsTable->setHorizontalHeaderLabels(labels); |
|
92 |
locationsTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); |
|
93 |
locationsTable->horizontalHeader()->resizeSection(1, 180); |
|
94 |
||
95 |
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
96 |
| QDialogButtonBox::Cancel); |
|
97 |
||
98 |
connect(formatComboBox, SIGNAL(activated(int)), |
|
99 |
this, SLOT(updateLocationsTable())); |
|
100 |
connect(scopeComboBox, SIGNAL(activated(int)), |
|
101 |
this, SLOT(updateLocationsTable())); |
|
102 |
connect(organizationComboBox->lineEdit(), |
|
103 |
SIGNAL(editingFinished()), |
|
104 |
this, SLOT(updateLocationsTable())); |
|
105 |
connect(applicationComboBox->lineEdit(), |
|
106 |
SIGNAL(editingFinished()), |
|
107 |
this, SLOT(updateLocationsTable())); |
|
108 |
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
|
109 |
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
|
110 |
||
111 |
QVBoxLayout *locationsLayout = new QVBoxLayout; |
|
112 |
locationsLayout->addWidget(locationsTable); |
|
113 |
locationsGroupBox->setLayout(locationsLayout); |
|
114 |
||
115 |
QGridLayout *mainLayout = new QGridLayout; |
|
116 |
mainLayout->addWidget(formatLabel, 0, 0); |
|
117 |
mainLayout->addWidget(formatComboBox, 0, 1); |
|
118 |
mainLayout->addWidget(scopeLabel, 1, 0); |
|
119 |
mainLayout->addWidget(scopeComboBox, 1, 1); |
|
120 |
mainLayout->addWidget(organizationLabel, 2, 0); |
|
121 |
mainLayout->addWidget(organizationComboBox, 2, 1); |
|
122 |
mainLayout->addWidget(applicationLabel, 3, 0); |
|
123 |
mainLayout->addWidget(applicationComboBox, 3, 1); |
|
124 |
mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2); |
|
125 |
mainLayout->addWidget(buttonBox, 5, 0, 1, 2); |
|
126 |
setLayout(mainLayout); |
|
127 |
||
128 |
updateLocationsTable(); |
|
129 |
||
130 |
setWindowTitle(tr("Open Application Settings")); |
|
131 |
resize(650, 400); |
|
132 |
} |
|
133 |
||
134 |
QSettings::Format LocationDialog::format() const |
|
135 |
{ |
|
136 |
if (formatComboBox->currentIndex() == 0) |
|
137 |
return QSettings::NativeFormat; |
|
138 |
else |
|
139 |
return QSettings::IniFormat; |
|
140 |
} |
|
141 |
||
142 |
QSettings::Scope LocationDialog::scope() const |
|
143 |
{ |
|
144 |
if (scopeComboBox->currentIndex() == 0) |
|
145 |
return QSettings::UserScope; |
|
146 |
else |
|
147 |
return QSettings::SystemScope; |
|
148 |
} |
|
149 |
||
150 |
QString LocationDialog::organization() const |
|
151 |
{ |
|
152 |
return organizationComboBox->currentText(); |
|
153 |
} |
|
154 |
||
155 |
QString LocationDialog::application() const |
|
156 |
{ |
|
157 |
if (applicationComboBox->currentText() == tr("Any")) |
|
158 |
return ""; |
|
159 |
else |
|
160 |
return applicationComboBox->currentText(); |
|
161 |
} |
|
162 |
||
163 |
void LocationDialog::updateLocationsTable() |
|
164 |
{ |
|
165 |
locationsTable->setUpdatesEnabled(false); |
|
166 |
locationsTable->setRowCount(0); |
|
167 |
||
168 |
for (int i = 0; i < 2; ++i) { |
|
169 |
if (i == 0 && scope() == QSettings::SystemScope) |
|
170 |
continue; |
|
171 |
||
172 |
QSettings::Scope actualScope = (i == 0) ? QSettings::UserScope |
|
173 |
: QSettings::SystemScope; |
|
174 |
for (int j = 0; j < 2; ++j) { |
|
175 |
if (j == 0 && application().isEmpty()) |
|
176 |
continue; |
|
177 |
||
178 |
QString actualApplication; |
|
179 |
if (j == 0) |
|
180 |
actualApplication = application(); |
|
181 |
QSettings settings(format(), actualScope, organization(), |
|
182 |
actualApplication); |
|
183 |
||
184 |
int row = locationsTable->rowCount(); |
|
185 |
locationsTable->setRowCount(row + 1); |
|
186 |
||
187 |
QTableWidgetItem *item0 = new QTableWidgetItem; |
|
188 |
item0->setText(settings.fileName()); |
|
189 |
||
190 |
QTableWidgetItem *item1 = new QTableWidgetItem; |
|
191 |
bool disable = (settings.childKeys().isEmpty() |
|
192 |
&& settings.childGroups().isEmpty()); |
|
193 |
||
194 |
if (row == 0) { |
|
195 |
if (settings.isWritable()) { |
|
196 |
item1->setText(tr("Read-write")); |
|
197 |
disable = false; |
|
198 |
} else { |
|
199 |
item1->setText(tr("Read-only")); |
|
200 |
} |
|
201 |
buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable); |
|
202 |
} else { |
|
203 |
item1->setText(tr("Read-only fallback")); |
|
204 |
} |
|
205 |
||
206 |
if (disable) { |
|
207 |
item0->setFlags(item0->flags() & ~Qt::ItemIsEnabled); |
|
208 |
item1->setFlags(item1->flags() & ~Qt::ItemIsEnabled); |
|
209 |
} |
|
210 |
||
211 |
locationsTable->setItem(row, 0, item0); |
|
212 |
locationsTable->setItem(row, 1, item1); |
|
213 |
} |
|
214 |
} |
|
215 |
locationsTable->setUpdatesEnabled(true); |
|
216 |
} |