1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
package MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
openSettings => [],
openIniFile => [],
openPropertyList => [],
openRegistryPath => [],
about => [];
use LocationDialog;
use SettingsTree;
sub settingsTree() {
return this->{settingsTree};
}
sub locationDialog() {
return this->{locationDialog};
}
sub fileMenu() {
return this->{fileMenu};
}
sub optionsMenu() {
return this->{optionsMenu};
}
sub helpMenu() {
return this->{helpMenu};
}
sub openSettingsAct() {
return this->{openSettingsAct};
}
sub openIniFileAct() {
return this->{openIniFileAct};
}
sub openPropertyListAct() {
return this->{openPropertyListAct};
}
sub openRegistryPathAct() {
return this->{openRegistryPathAct};
}
sub refreshAct() {
return this->{refreshAct};
}
sub exitAct() {
return this->{exitAct};
}
sub autoRefreshAct() {
return this->{autoRefreshAct};
}
sub fallbacksAct() {
return this->{fallbacksAct};
}
sub aboutAct() {
return this->{aboutAct};
}
sub aboutQtAct() {
return this->{aboutQtAct};
}
sub NEW
{
my ($class) = @_;
$class->SUPER::NEW();
this->{settingsTree} = SettingsTree();
setCentralWidget(settingsTree);
this->{locationDialog} = undef;
createActions();
createMenus();
autoRefreshAct->setChecked(1);
fallbacksAct->setChecked(1);
setWindowTitle(this->tr('Settings Editor'));
resize(500, 600);
}
sub openSettings
{
if (!locationDialog()) {
this->{locationDialog} = LocationDialog(this);
}
if (locationDialog->exec()) {
my $settings = Qt::Settings(locationDialog->format(),
locationDialog->scope(),
locationDialog->organization(),
locationDialog->application());
setSettingsObject($settings);
fallbacksAct->setEnabled(1);
}
}
sub openIniFile
{
my $fileName = Qt::FileDialog::getOpenFileName(this, this->tr('Open INI File'),
'', this->tr('INI Files (*.ini *.conf)'));
if ($fileName) {
my $settings = Qt::Settings($fileName, Qt::Settings::IniFormat());
setSettingsObject($settings);
fallbacksAct->setEnabled(0);
}
}
sub openPropertyList
{
my $fileName = Qt::FileDialog::getOpenFileName(this,
this->tr('Open Property List'),
'', this->tr('Property List Files (*.plist)'));
if ($fileName) {
my $settings = Qt::Settings($fileName, Qt::Settings::NativeFormat());
setSettingsObject($settings);
fallbacksAct->setEnabled(0);
}
}
sub openRegistryPath
{
my $path = Qt::InputDialog::getText(this, this->tr('Open Registry Path'),
this->tr('Enter the path in the Windows registry:'),
Qt::LineEdit::Normal(), 'HKEY_CURRENT_USER\\');
if ($path) {
my $settings = Qt::Settings($path, Qt::Settings::NativeFormat());
setSettingsObject($settings);
fallbacksAct->setEnabled(0);
}
}
sub about
{
Qt::MessageBox::about(this, this->tr('About Settings Editor'),
this->tr('The <b>Settings Editor</b> example shows how to access ' .
'application settings using Qt.'));
}
sub createActions
{
this->{openSettingsAct} = Qt::Action(this->tr('&Open Application Settings...'), this);
openSettingsAct->setShortcut(Qt::KeySequence((Qt::KeySequence::Open())));
this->connect(openSettingsAct, SIGNAL 'triggered()', this, SLOT 'openSettings()');
this->{openIniFileAct} = Qt::Action(this->tr('Open I&NI File...'), this);
openIniFileAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+N')));
this->connect(openIniFileAct, SIGNAL 'triggered()', this, SLOT 'openIniFile()');
this->{openPropertyListAct} = Qt::Action(this->tr('Open Mac &Property List...'), this);
openPropertyListAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+P')));
this->connect(openPropertyListAct, SIGNAL 'triggered()',
this, SLOT 'openPropertyList()');
this->{openRegistryPathAct} = Qt::Action(this->tr('Open Windows &Registry Path...'),
this);
openRegistryPathAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+G')));
this->connect(openRegistryPathAct, SIGNAL 'triggered()',
this, SLOT 'openRegistryPath()');
this->{refreshAct} = Qt::Action(this->tr('&Refresh'), this);
refreshAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+R')));
refreshAct->setEnabled(0);
this->connect(refreshAct, SIGNAL 'triggered()', settingsTree, SLOT 'refresh()');
this->{exitAct} = Qt::Action(this->tr('E&xit'), this);
exitAct->setShortcut(Qt::KeySequence((Qt::KeySequence::Quit())));
this->connect(exitAct, SIGNAL 'triggered()', this, SLOT 'close()');
this->{autoRefreshAct} = Qt::Action(this->tr('&Auto-Refresh'), this);
autoRefreshAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+A')));
autoRefreshAct->setCheckable(1);
autoRefreshAct->setEnabled(0);
this->connect(autoRefreshAct, SIGNAL 'triggered(bool)',
settingsTree, SLOT 'setAutoRefresh(bool)');
this->connect(autoRefreshAct, SIGNAL 'triggered(bool)',
refreshAct, SLOT 'setDisabled(bool)');
this->{fallbacksAct} = Qt::Action(this->tr('&Fallbacks'), this);
fallbacksAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+F')));
fallbacksAct->setCheckable(1);
fallbacksAct->setEnabled(0);
this->connect(fallbacksAct, SIGNAL 'triggered(bool)',
settingsTree, SLOT 'setFallbacksEnabled(bool)');
this->{aboutAct} = Qt::Action(this->tr('&About'), this);
this->connect(aboutAct, SIGNAL 'triggered()', this, SLOT 'about()');
this->{aboutQtAct} = Qt::Action(this->tr('About &Qt'), this);
this->connect(aboutQtAct, SIGNAL 'triggered()', qApp, SLOT 'aboutQt()');
#ifndef Q_WS_MAC
openPropertyListAct->setEnabled(0);
#endif
#ifndef Q_WS_WIN
openRegistryPathAct->setEnabled(0);
#endif
}
sub createMenus
{
this->{fileMenu} = menuBar()->addMenu(this->tr('&File'));
fileMenu->addAction(openSettingsAct);
fileMenu->addAction(openIniFileAct);
fileMenu->addAction(openPropertyListAct);
fileMenu->addAction(openRegistryPathAct);
fileMenu->addSeparator();
fileMenu->addAction(refreshAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
this->{optionsMenu} = menuBar()->addMenu(this->tr('&Options'));
optionsMenu->addAction(autoRefreshAct);
optionsMenu->addAction(fallbacksAct);
menuBar()->addSeparator();
this->{helpMenu} = menuBar()->addMenu(this->tr('&Help'));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
sub setSettingsObject
{
my ($settings) = @_;
$settings->setFallbacksEnabled(fallbacksAct->isChecked());
settingsTree->setSettingsObject($settings);
refreshAct->setEnabled(1);
autoRefreshAct->setEnabled(1);
my $niceName = $settings->fileName();
$niceName =~ s/\\/\//g;
$niceName =~ s/.*\///g;
if (!$settings->isWritable()) {
$niceName = Qt::String(this->tr('%1 (read only)'))->arg($niceName);
}
setWindowTitle(Qt::String(this->tr('%1 - %2'))->arg($niceName)->arg(this->tr('Settings Editor')));
}
1;
|