annotate main/PreferencesDialog.cpp @ 1060:d1d4f627d24e recording

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