source: trunk/examples/tools/settingseditor/locationdialog.cpp@ 315

Last change on this file since 315 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "locationdialog.h"
45
46LocationDialog::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
135QSettings::Format LocationDialog::format() const
136{
137 if (formatComboBox->currentIndex() == 0)
138 return QSettings::NativeFormat;
139 else
140 return QSettings::IniFormat;
141}
142
143QSettings::Scope LocationDialog::scope() const
144{
145 if (scopeComboBox->currentIndex() == 0)
146 return QSettings::UserScope;
147 else
148 return QSettings::SystemScope;
149}
150
151QString LocationDialog::organization() const
152{
153 return organizationComboBox->currentText();
154}
155
156QString LocationDialog::application() const
157{
158 if (applicationComboBox->currentText() == tr("Any"))
159 return "";
160 else
161 return applicationComboBox->currentText();
162}
163
164void 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}
Note: See TracBrowser for help on using the repository browser.