annotate main/PreferencesDialog.cpp @ 686:7f7fba33b7de

Add network permission to prefs; make OSC support one of the things that depends on it
author Chris Cannam
date Thu, 12 Dec 2013 15:20:42 +0000
parents 17fe7e0c23a1
children c7945dad2f49
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PreferencesDialog.h"
Chris@0 17
Chris@0 18 #include <QGridLayout>
Chris@0 19 #include <QComboBox>
Chris@0 20 #include <QCheckBox>
Chris@0 21 #include <QGroupBox>
Chris@0 22 #include <QDoubleSpinBox>
Chris@0 23 #include <QLabel>
Chris@0 24 #include <QPushButton>
Chris@0 25 #include <QHBoxLayout>
Chris@0 26 #include <QString>
Chris@163 27 #include <QDialogButtonBox>
Chris@163 28 #include <QMessageBox>
Chris@180 29 #include <QTabWidget>
Chris@180 30 #include <QLineEdit>
Chris@180 31 #include <QFileDialog>
Chris@180 32 #include <QMessageBox>
Chris@225 33 #include <QSpinBox>
Chris@436 34 #include <QListWidget>
Chris@263 35 #include <QSettings>
Chris@0 36
Chris@436 37 #include <set>
Chris@436 38
Chris@9 39 #include "widgets/WindowTypeSelector.h"
Chris@180 40 #include "widgets/IconLoader.h"
Chris@0 41 #include "base/Preferences.h"
Chris@263 42 #include "audioio/AudioTargetFactory.h"
Chris@436 43 #include "base/ResourceFinder.h"
Chris@0 44
Chris@686 45 #include "version.h"
Chris@686 46
Chris@528 47 PreferencesDialog::PreferencesDialog(QWidget *parent) :
Chris@528 48 QDialog(parent),
Chris@263 49 m_audioDevice(0),
Chris@180 50 m_changesOnRestart(false)
Chris@0 51 {
Chris@163 52 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
Chris@0 53
Chris@0 54 Preferences *prefs = Preferences::getInstance();
Chris@0 55
Chris@0 56 QGridLayout *grid = new QGridLayout;
Chris@0 57 setLayout(grid);
Chris@180 58
Chris@436 59 m_tabs = new QTabWidget;
Chris@436 60 grid->addWidget(m_tabs, 0, 0);
Chris@0 61
Chris@436 62 m_tabs->setTabPosition(QTabWidget::North);
Chris@0 63
Chris@0 64 // Create this first, as slots that get called from the ctor will
Chris@0 65 // refer to it
Chris@0 66 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 67
Chris@180 68 // Create all the preference widgets first, then create the
Chris@180 69 // individual tab widgets and place the preferences in their
Chris@180 70 // appropriate places in one go afterwards
Chris@180 71
Chris@114 72 int min, max, deflt, i;
Chris@0 73
Chris@9 74 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@114 75 ("Window Type", &min, &max, &deflt));
Chris@9 76 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 77
Chris@9 78 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 79 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 80
Chris@115 81 QComboBox *smoothing = new QComboBox;
Chris@115 82
Chris@299 83 int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
Chris@115 84 &deflt);
Chris@115 85 m_spectrogramSmoothing = sm;
Chris@0 86
Chris@115 87 for (i = min; i <= max; ++i) {
Chris@299 88 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
Chris@115 89 }
Chris@115 90
Chris@115 91 smoothing->setCurrentIndex(sm);
Chris@115 92
Chris@115 93 connect(smoothing, SIGNAL(currentIndexChanged(int)),
Chris@115 94 this, SLOT(spectrogramSmoothingChanged(int)));
Chris@0 95
Chris@299 96 QComboBox *xsmoothing = new QComboBox;
Chris@299 97
Chris@299 98 int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
Chris@299 99 &deflt);
Chris@299 100 m_spectrogramXSmoothing = xsm;
Chris@299 101
Chris@299 102 for (i = min; i <= max; ++i) {
Chris@299 103 xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
Chris@299 104 }
Chris@299 105
Chris@299 106 xsmoothing->setCurrentIndex(xsm);
Chris@299 107
Chris@299 108 connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
Chris@299 109 this, SLOT(spectrogramXSmoothingChanged(int)));
Chris@299 110
Chris@0 111 QComboBox *propertyLayout = new QComboBox;
Chris@114 112 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
Chris@115 113 &deflt);
Chris@0 114 m_propertyLayout = pl;
Chris@0 115
Chris@0 116 for (i = min; i <= max; ++i) {
Chris@0 117 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 118 }
Chris@0 119
Chris@0 120 propertyLayout->setCurrentIndex(pl);
Chris@0 121
Chris@0 122 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 123 this, SLOT(propertyLayoutChanged(int)));
Chris@0 124
Chris@0 125 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 126
Chris@0 127 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 128 frequency->setMinimum(100.0);
Chris@0 129 frequency->setMaximum(5000.0);
Chris@0 130 frequency->setSuffix(" Hz");
Chris@0 131 frequency->setSingleStep(1);
Chris@0 132 frequency->setValue(m_tuningFrequency);
Chris@0 133 frequency->setDecimals(2);
Chris@0 134
Chris@0 135 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 136 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 137
Chris@263 138 QComboBox *audioDevice = new QComboBox;
Chris@263 139 std::vector<QString> devices =
Chris@263 140 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 141
Chris@263 142 QSettings settings;
Chris@263 143 settings.beginGroup("Preferences");
Chris@263 144 QString targetName = settings.value("audio-target", "").toString();
Chris@263 145 settings.endGroup();
Chris@263 146
Chris@658 147 for (int i = 0; i < (int)devices.size(); ++i) {
Chris@263 148 audioDevice->addItem(AudioTargetFactory::getInstance()
Chris@263 149 ->getCallbackTargetDescription(devices[i]));
Chris@263 150 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
Chris@263 151 }
Chris@263 152
Chris@263 153 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
Chris@263 154 this, SLOT(audioDeviceChanged(int)));
Chris@263 155
Chris@32 156 QComboBox *resampleQuality = new QComboBox;
Chris@32 157
Chris@114 158 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
Chris@114 159 &deflt);
Chris@32 160 m_resampleQuality = rsq;
Chris@32 161
Chris@32 162 for (i = min; i <= max; ++i) {
Chris@32 163 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 164 }
Chris@32 165
Chris@32 166 resampleQuality->setCurrentIndex(rsq);
Chris@32 167
Chris@32 168 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 169 this, SLOT(resampleQualityChanged(int)));
Chris@32 170
Chris@180 171 QCheckBox *resampleOnLoad = new QCheckBox;
Chris@180 172 m_resampleOnLoad = prefs->getResampleOnLoad();
Chris@180 173 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
Chris@180 174 Qt::Unchecked);
Chris@180 175 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
Chris@180 176 this, SLOT(resampleOnLoadChanged(int)));
Chris@180 177
Chris@180 178 m_tempDirRootEdit = new QLineEdit;
Chris@180 179 QString dir = prefs->getTemporaryDirectoryRoot();
Chris@180 180 m_tempDirRoot = dir;
Chris@180 181 dir.replace("$HOME", tr("<home directory>"));
Chris@180 182 m_tempDirRootEdit->setText(dir);
Chris@180 183 m_tempDirRootEdit->setReadOnly(true);
Chris@180 184 QPushButton *tempDirButton = new QPushButton;
Chris@180 185 tempDirButton->setIcon(IconLoader().load("fileopen"));
Chris@180 186 connect(tempDirButton, SIGNAL(clicked()),
Chris@180 187 this, SLOT(tempDirButtonClicked()));
Chris@180 188 tempDirButton->setFixedSize(QSize(24, 24));
Chris@180 189
Chris@237 190 QCheckBox *showSplash = new QCheckBox;
Chris@237 191 m_showSplash = prefs->getShowSplash();
Chris@237 192 showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
Chris@237 193 connect(showSplash, SIGNAL(stateChanged(int)),
Chris@237 194 this, SLOT(showSplashChanged(int)));
Chris@237 195
Chris@661 196 #ifndef Q_OS_MAC
Chris@180 197 QComboBox *bgMode = new QComboBox;
Chris@180 198 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
Chris@180 199 &deflt);
Chris@180 200 m_backgroundMode = bg;
Chris@180 201 for (i = min; i <= max; ++i) {
Chris@180 202 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
Chris@180 203 }
Chris@180 204 bgMode->setCurrentIndex(bg);
Chris@180 205
Chris@180 206 connect(bgMode, SIGNAL(currentIndexChanged(int)),
Chris@180 207 this, SLOT(backgroundModeChanged(int)));
Chris@237 208 #endif
Chris@180 209
Chris@658 210 settings.beginGroup("Preferences");
Chris@686 211
Chris@658 212 QString userLocale = settings.value("locale", "").toString();
Chris@658 213 m_currentLocale = userLocale;
Chris@686 214
Chris@686 215 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 216 m_networkPermission = settings.value(permishTag, false).toBool();
Chris@686 217
Chris@658 218 settings.endGroup();
Chris@658 219
Chris@658 220 QComboBox *locale = new QComboBox;
Chris@658 221 QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
Chris@658 222 locale->addItem(tr("Follow system locale"));
Chris@658 223 m_locales.push_back("");
Chris@658 224 if (userLocale == "") {
Chris@658 225 locale->setCurrentIndex(0);
Chris@658 226 }
Chris@658 227 foreach (QString f, localeFiles) {
Chris@658 228 QString f0 = f;
Chris@658 229 f.replace("sonic-visualiser_", "").replace(".qm", "");
Chris@658 230 if (f == f0) { // our expectations about filename format were not met
Chris@665 231 cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << endl;
Chris@658 232 } else {
Chris@658 233 m_locales.push_back(f);
Chris@658 234 QString displayText;
Chris@658 235 // Add new translations here
Chris@658 236 if (f == "ru") displayText = tr("Russian");
Chris@658 237 else if (f == "en_GB") displayText = tr("British English");
Chris@658 238 else if (f == "en_US") displayText = tr("American English");
Chris@658 239 else if (f == "cs_CZ") displayText = tr("Czech");
Chris@658 240 else displayText = f;
Chris@658 241 locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
Chris@658 242 if (userLocale == f) {
Chris@658 243 locale->setCurrentIndex(locale->count() - 1);
Chris@658 244 }
Chris@658 245 }
Chris@658 246 }
Chris@658 247 connect(locale, SIGNAL(currentIndexChanged(int)),
Chris@658 248 this, SLOT(localeChanged(int)));
Chris@658 249
Chris@686 250 QCheckBox *networkPermish = new QCheckBox;
Chris@686 251 networkPermish->setCheckState(m_networkPermission ? Qt::Checked : Qt::Unchecked);
Chris@686 252 connect(networkPermish, SIGNAL(stateChanged(int)),
Chris@686 253 this, SLOT(networkPermissionChanged(int)));
Chris@686 254
Chris@225 255 QSpinBox *fontSize = new QSpinBox;
Chris@225 256 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 257 &deflt);
Chris@234 258 m_viewFontSize = fs;
Chris@225 259 fontSize->setMinimum(min);
Chris@225 260 fontSize->setMaximum(max);
Chris@225 261 fontSize->setSuffix(" pt");
Chris@225 262 fontSize->setSingleStep(1);
Chris@225 263 fontSize->setValue(fs);
Chris@225 264
Chris@225 265 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 266 this, SLOT(viewFontSizeChanged(int)));
Chris@225 267
Chris@337 268 QComboBox *ttMode = new QComboBox;
Chris@337 269 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 270 &deflt);
Chris@337 271 m_timeToTextMode = tt;
Chris@337 272 for (i = min; i <= max; ++i) {
Chris@337 273 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 274 }
Chris@337 275 ttMode->setCurrentIndex(tt);
Chris@337 276
Chris@337 277 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 278 this, SLOT(timeToTextModeChanged(int)));
Chris@337 279
Chris@180 280 // General tab
Chris@180 281
Chris@180 282 QFrame *frame = new QFrame;
Chris@180 283
Chris@180 284 QGridLayout *subgrid = new QGridLayout;
Chris@180 285 frame->setLayout(subgrid);
Chris@180 286
Chris@0 287 int row = 0;
Chris@0 288
Chris@658 289 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
Chris@658 290 row, 0);
Chris@658 291 subgrid->addWidget(locale, row++, 1, 1, 1);
Chris@658 292
Chris@686 293 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("Allow network usage"))),
Chris@686 294 row, 0);
Chris@686 295 subgrid->addWidget(networkPermish, row++, 1, 1, 1);
Chris@686 296
Chris@0 297 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 298 ("Temporary Directory Root"))),
Chris@263 299 row, 0);
Chris@263 300 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 301 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 302 row++;
Chris@263 303
Chris@263 304 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 305 ("Resample On Load"))),
Chris@263 306 row, 0);
Chris@263 307 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 308
Chris@263 309 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@263 310 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 311
Chris@263 312 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 313 ("Resample Quality"))),
Chris@263 314 row, 0);
Chris@263 315 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 316
Chris@263 317 subgrid->setRowStretch(row, 10);
Chris@263 318
Chris@436 319 m_tabOrdering[GeneralTab] = m_tabs->count();
Chris@436 320 m_tabs->addTab(frame, tr("&General"));
Chris@263 321
Chris@263 322 // Appearance tab
Chris@263 323
Chris@263 324 frame = new QFrame;
Chris@263 325 subgrid = new QGridLayout;
Chris@263 326 frame->setLayout(subgrid);
Chris@263 327 row = 0;
Chris@263 328
Chris@263 329 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 330 ("Property Box Layout"))),
Chris@0 331 row, 0);
Chris@0 332 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 333
Chris@661 334 #ifndef Q_OS_MAC
Chris@0 335 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 336 ("Background Mode"))),
Chris@0 337 row, 0);
Chris@180 338 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 339 #endif
Chris@180 340
Chris@180 341 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 342 ("View Font Size"))),
Chris@225 343 row, 0);
Chris@225 344 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 345
Chris@225 346 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 347 ("Time To Text Mode"))),
Chris@337 348 row, 0);
Chris@337 349 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 350
Chris@337 351 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@237 352 ("Show Splash Screen"))),
Chris@237 353 row, 0);
Chris@237 354 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@237 355
Chris@180 356 subgrid->setRowStretch(row, 10);
Chris@180 357
Chris@436 358 m_tabOrdering[AppearanceTab] = m_tabs->count();
Chris@436 359 m_tabs->addTab(frame, tr("&Appearance"));
Chris@180 360
Chris@180 361 // Analysis tab
Chris@180 362
Chris@180 363 frame = new QFrame;
Chris@180 364 subgrid = new QGridLayout;
Chris@180 365 frame->setLayout(subgrid);
Chris@180 366 row = 0;
Chris@180 367
Chris@180 368 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 369 ("Tuning Frequency"))),
Chris@180 370 row, 0);
Chris@180 371 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 372
Chris@0 373 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 374 ("Spectrogram Y Smoothing")),
Chris@115 375 row, 0);
Chris@115 376 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 377
Chris@299 378 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 379 ("Spectrogram X Smoothing")),
Chris@299 380 row, 0);
Chris@299 381 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 382
Chris@0 383 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 384 ("Window Type"))),
Chris@0 385 row, 0);
Chris@9 386 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 387 subgrid->setRowStretch(row, 10);
Chris@9 388 row++;
Chris@0 389
Chris@180 390 subgrid->setRowStretch(row, 10);
Chris@180 391
Chris@436 392 m_tabOrdering[AnalysisTab] = m_tabs->count();
Chris@436 393 m_tabs->addTab(frame, tr("Anal&ysis"));
Chris@436 394
Chris@436 395 // Template tab
Chris@436 396
Chris@436 397 frame = new QFrame;
Chris@436 398 subgrid = new QGridLayout;
Chris@436 399 frame->setLayout(subgrid);
Chris@436 400 row = 0;
Chris@436 401
Chris@436 402 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
Chris@436 403
Chris@436 404 QListWidget *lw = new QListWidget();
Chris@436 405 subgrid->addWidget(lw, row, 0);
Chris@436 406 subgrid->setRowStretch(row, 10);
Chris@436 407 row++;
Chris@436 408
Chris@436 409 settings.beginGroup("MainWindow");
Chris@436 410 m_currentTemplate = settings.value("sessiontemplate", "").toString();
Chris@436 411 settings.endGroup();
Chris@436 412
Chris@455 413 lw->addItem(tr("Standard Waveform"));
Chris@436 414 if (m_currentTemplate == "" || m_currentTemplate == "default") {
Chris@436 415 lw->setCurrentRow(lw->count()-1);
Chris@436 416 }
Chris@436 417 m_templates.push_back("");
Chris@436 418
Chris@436 419 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@436 420
Chris@436 421 std::set<QString> byName;
Chris@436 422 foreach (QString t, templates) {
Chris@436 423 byName.insert(QFileInfo(t).baseName());
Chris@436 424 }
Chris@436 425
Chris@436 426 foreach (QString t, byName) {
Chris@436 427 if (t.toLower() == "default") continue;
Chris@436 428 m_templates.push_back(t);
Chris@436 429 lw->addItem(t);
Chris@436 430 if (m_currentTemplate == t) {
Chris@436 431 lw->setCurrentRow(lw->count()-1);
Chris@436 432 }
Chris@436 433 }
Chris@436 434
Chris@436 435 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
Chris@436 436
Chris@436 437 m_tabOrdering[TemplateTab] = m_tabs->count();
Chris@436 438 m_tabs->addTab(frame, tr("Session &Template"));
Chris@180 439
Chris@163 440 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 441 grid->addWidget(bb, 1, 0);
Chris@0 442
Chris@0 443 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 444 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 445 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 446 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 447 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 448 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 449 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 450 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 451
Chris@0 452 m_applyButton->setEnabled(false);
Chris@0 453 }
Chris@0 454
Chris@0 455 PreferencesDialog::~PreferencesDialog()
Chris@0 456 {
Chris@438 457 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 458 }
Chris@0 459
Chris@0 460 void
Chris@436 461 PreferencesDialog::switchToTab(Tab t)
Chris@436 462 {
Chris@436 463 if (m_tabOrdering.contains(t)) {
Chris@436 464 m_tabs->setCurrentIndex(m_tabOrdering[t]);
Chris@436 465 }
Chris@436 466 }
Chris@436 467
Chris@436 468 void
Chris@9 469 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 470 {
Chris@0 471 m_windowType = type;
Chris@0 472 m_applyButton->setEnabled(true);
Chris@0 473 }
Chris@0 474
Chris@0 475 void
Chris@115 476 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 477 {
Chris@115 478 m_spectrogramSmoothing = smoothing;
Chris@0 479 m_applyButton->setEnabled(true);
Chris@0 480 }
Chris@0 481
Chris@0 482 void
Chris@299 483 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 484 {
Chris@299 485 m_spectrogramXSmoothing = smoothing;
Chris@299 486 m_applyButton->setEnabled(true);
Chris@299 487 }
Chris@299 488
Chris@299 489 void
Chris@0 490 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 491 {
Chris@0 492 m_propertyLayout = layout;
Chris@0 493 m_applyButton->setEnabled(true);
Chris@0 494 }
Chris@0 495
Chris@0 496 void
Chris@0 497 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 498 {
Chris@0 499 m_tuningFrequency = freq;
Chris@0 500 m_applyButton->setEnabled(true);
Chris@0 501 }
Chris@0 502
Chris@0 503 void
Chris@263 504 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 505 {
Chris@263 506 m_audioDevice = s;
Chris@263 507 m_applyButton->setEnabled(true);
Chris@263 508 m_changesOnRestart = true;
Chris@263 509 }
Chris@263 510
Chris@263 511 void
Chris@32 512 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 513 {
Chris@32 514 m_resampleQuality = q;
Chris@32 515 m_applyButton->setEnabled(true);
Chris@32 516 }
Chris@32 517
Chris@32 518 void
Chris@180 519 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 520 {
Chris@180 521 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 522 m_applyButton->setEnabled(true);
Chris@180 523 m_changesOnRestart = true;
Chris@180 524 }
Chris@180 525
Chris@180 526 void
Chris@686 527 PreferencesDialog::networkPermissionChanged(int state)
Chris@686 528 {
Chris@686 529 m_networkPermission = (state == Qt::Checked);
Chris@686 530 m_applyButton->setEnabled(true);
Chris@686 531 m_changesOnRestart = true;
Chris@686 532 }
Chris@686 533
Chris@686 534 void
Chris@237 535 PreferencesDialog::showSplashChanged(int state)
Chris@237 536 {
Chris@237 537 m_showSplash = (state == Qt::Checked);
Chris@237 538 m_applyButton->setEnabled(true);
Chris@237 539 m_changesOnRestart = true;
Chris@237 540 }
Chris@237 541
Chris@237 542 void
Chris@436 543 PreferencesDialog::defaultTemplateChanged(int i)
Chris@436 544 {
Chris@436 545 m_currentTemplate = m_templates[i];
Chris@436 546 m_applyButton->setEnabled(true);
Chris@436 547 }
Chris@436 548
Chris@436 549 void
Chris@658 550 PreferencesDialog::localeChanged(int i)
Chris@658 551 {
Chris@658 552 m_currentLocale = m_locales[i];
Chris@658 553 m_applyButton->setEnabled(true);
Chris@658 554 m_changesOnRestart = true;
Chris@658 555 }
Chris@658 556
Chris@658 557 void
Chris@180 558 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 559 {
Chris@180 560 m_tempDirRoot = r;
Chris@180 561 m_applyButton->setEnabled(true);
Chris@180 562 }
Chris@180 563
Chris@180 564 void
Chris@180 565 PreferencesDialog::tempDirButtonClicked()
Chris@180 566 {
Chris@180 567 QString dir = QFileDialog::getExistingDirectory
Chris@180 568 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 569 m_tempDirRoot);
Chris@180 570 if (dir == "") return;
Chris@180 571 m_tempDirRootEdit->setText(dir);
Chris@180 572 tempDirRootChanged(dir);
Chris@180 573 m_changesOnRestart = true;
Chris@180 574 }
Chris@180 575
Chris@180 576 void
Chris@180 577 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 578 {
Chris@180 579 m_backgroundMode = mode;
Chris@180 580 m_applyButton->setEnabled(true);
Chris@180 581 m_changesOnRestart = true;
Chris@180 582 }
Chris@180 583
Chris@180 584 void
Chris@337 585 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 586 {
Chris@337 587 m_timeToTextMode = mode;
Chris@337 588 m_applyButton->setEnabled(true);
Chris@337 589 }
Chris@337 590
Chris@337 591 void
Chris@225 592 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 593 {
Chris@225 594 m_viewFontSize = sz;
Chris@225 595 m_applyButton->setEnabled(true);
Chris@225 596 }
Chris@225 597
Chris@225 598 void
Chris@0 599 PreferencesDialog::okClicked()
Chris@0 600 {
Chris@0 601 applyClicked();
Chris@0 602 accept();
Chris@0 603 }
Chris@0 604
Chris@0 605 void
Chris@0 606 PreferencesDialog::applyClicked()
Chris@0 607 {
Chris@0 608 Preferences *prefs = Preferences::getInstance();
Chris@0 609 prefs->setWindowType(WindowType(m_windowType));
Chris@115 610 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 611 (m_spectrogramSmoothing));
Chris@299 612 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 613 (m_spectrogramXSmoothing));
Chris@0 614 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 615 (m_propertyLayout));
Chris@0 616 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 617 prefs->setResampleQuality(m_resampleQuality);
Chris@180 618 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 619 prefs->setShowSplash(m_showSplash);
Chris@180 620 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 621 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 622 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@225 623 prefs->setViewFontSize(m_viewFontSize);
Chris@263 624
Chris@263 625 std::vector<QString> devices =
Chris@263 626 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 627
Chris@263 628 QSettings settings;
Chris@263 629 settings.beginGroup("Preferences");
Chris@686 630 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 631 settings.setValue(permishTag, m_networkPermission);
Chris@263 632 settings.setValue("audio-target", devices[m_audioDevice]);
Chris@686 633 settings.setValue("locale", m_currentLocale);
Chris@263 634 settings.endGroup();
Chris@180 635
Chris@436 636 settings.beginGroup("MainWindow");
Chris@436 637 settings.setValue("sessiontemplate", m_currentTemplate);
Chris@436 638 settings.endGroup();
Chris@436 639
Chris@0 640 m_applyButton->setEnabled(false);
Chris@180 641
Chris@180 642 if (m_changesOnRestart) {
Chris@180 643 QMessageBox::information(this, tr("Preferences"),
Chris@255 644 tr("<b>Restart required</b><p>One or more of the application preferences you have changed may not take full effect until Sonic Visualiser is restarted.</p><p>Please exit and restart the application now if you want these changes to take effect immediately.</p>"));
Chris@180 645 m_changesOnRestart = false;
Chris@180 646 }
Chris@0 647 }
Chris@0 648
Chris@0 649 void
Chris@0 650 PreferencesDialog::cancelClicked()
Chris@0 651 {
Chris@0 652 reject();
Chris@0 653 }
Chris@0 654
Chris@163 655 void
Chris@163 656 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 657 {
Chris@163 658 if (quickly) {
Chris@163 659 reject();
Chris@163 660 return;
Chris@163 661 }
Chris@163 662
Chris@163 663 if (m_applyButton->isEnabled()) {
Chris@163 664 int rv = QMessageBox::warning
Chris@163 665 (this, tr("Preferences Changed"),
Chris@163 666 tr("Some preferences have been changed but not applied.\n"
Chris@163 667 "Apply them before closing?"),
Chris@163 668 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 669 QMessageBox::Discard);
Chris@163 670 if (rv == QMessageBox::Apply) {
Chris@163 671 applyClicked();
Chris@163 672 accept();
Chris@163 673 } else {
Chris@163 674 reject();
Chris@163 675 }
Chris@163 676 } else {
Chris@163 677 accept();
Chris@163 678 }
Chris@163 679 }
Chris@163 680