annotate main/PreferencesDialog.cpp @ 1086:744f1bbc6222 plugin-startup-test

Check for plugin loadability before trying to load in the main process (POSIX only so far)
author Chris Cannam
date Mon, 11 Jan 2016 14:18:56 +0000
parents 1f4e40be5aa2
children 52570633e6ff
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@950 229 #ifdef Q_OS_MAC
Chris@950 230 m_retina = settings.value("scaledHiDpi", true).toBool();
Chris@950 231 QCheckBox *retina = new QCheckBox;
Chris@950 232 retina->setCheckState(m_retina ? Qt::Checked : Qt::Unchecked);
Chris@950 233 connect(retina, SIGNAL(stateChanged(int)), this, SLOT(retinaChanged(int)));
Chris@950 234 #else
Chris@950 235 m_retina = false;
Chris@950 236 #endif
Chris@950 237
Chris@658 238 QString userLocale = settings.value("locale", "").toString();
Chris@658 239 m_currentLocale = userLocale;
Chris@686 240
Chris@686 241 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 242 m_networkPermission = settings.value(permishTag, false).toBool();
Chris@686 243
Chris@658 244 settings.endGroup();
Chris@658 245
Chris@658 246 QComboBox *locale = new QComboBox;
Chris@658 247 QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
Chris@658 248 locale->addItem(tr("Follow system locale"));
Chris@658 249 m_locales.push_back("");
Chris@658 250 if (userLocale == "") {
Chris@658 251 locale->setCurrentIndex(0);
Chris@658 252 }
Chris@658 253 foreach (QString f, localeFiles) {
Chris@658 254 QString f0 = f;
Chris@658 255 f.replace("sonic-visualiser_", "").replace(".qm", "");
Chris@658 256 if (f == f0) { // our expectations about filename format were not met
Chris@665 257 cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << endl;
Chris@658 258 } else {
Chris@658 259 m_locales.push_back(f);
Chris@658 260 QString displayText;
Chris@658 261 // Add new translations here
Chris@658 262 if (f == "ru") displayText = tr("Russian");
Chris@658 263 else if (f == "en_GB") displayText = tr("British English");
Chris@658 264 else if (f == "en_US") displayText = tr("American English");
Chris@658 265 else if (f == "cs_CZ") displayText = tr("Czech");
Chris@658 266 else displayText = f;
Chris@658 267 locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
Chris@658 268 if (userLocale == f) {
Chris@658 269 locale->setCurrentIndex(locale->count() - 1);
Chris@658 270 }
Chris@658 271 }
Chris@658 272 }
Chris@658 273 connect(locale, SIGNAL(currentIndexChanged(int)),
Chris@658 274 this, SLOT(localeChanged(int)));
Chris@658 275
Chris@686 276 QCheckBox *networkPermish = new QCheckBox;
Chris@686 277 networkPermish->setCheckState(m_networkPermission ? Qt::Checked : Qt::Unchecked);
Chris@686 278 connect(networkPermish, SIGNAL(stateChanged(int)),
Chris@686 279 this, SLOT(networkPermissionChanged(int)));
Chris@686 280
Chris@225 281 QSpinBox *fontSize = new QSpinBox;
Chris@225 282 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 283 &deflt);
Chris@234 284 m_viewFontSize = fs;
Chris@225 285 fontSize->setMinimum(min);
Chris@225 286 fontSize->setMaximum(max);
Chris@225 287 fontSize->setSuffix(" pt");
Chris@225 288 fontSize->setSingleStep(1);
Chris@225 289 fontSize->setValue(fs);
Chris@225 290
Chris@225 291 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 292 this, SLOT(viewFontSizeChanged(int)));
Chris@225 293
Chris@337 294 QComboBox *ttMode = new QComboBox;
Chris@337 295 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 296 &deflt);
Chris@337 297 m_timeToTextMode = tt;
Chris@337 298 for (i = min; i <= max; ++i) {
Chris@337 299 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 300 }
Chris@337 301 ttMode->setCurrentIndex(tt);
Chris@337 302
Chris@337 303 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 304 this, SLOT(timeToTextModeChanged(int)));
Chris@337 305
Chris@906 306 QCheckBox *hms = new QCheckBox;
Chris@906 307 int showHMS = prefs->getPropertyRangeAndValue
Chris@906 308 ("Show Hours And Minutes", &min, &max, &deflt);
Chris@906 309 m_showHMS = (showHMS != 0);
Chris@906 310 hms->setCheckState(m_showHMS ? Qt::Checked : Qt::Unchecked);
Chris@906 311 connect(hms, SIGNAL(stateChanged(int)),
Chris@906 312 this, SLOT(showHMSChanged(int)));
Chris@906 313
Chris@180 314 // General tab
Chris@180 315
Chris@180 316 QFrame *frame = new QFrame;
Chris@180 317
Chris@180 318 QGridLayout *subgrid = new QGridLayout;
Chris@180 319 frame->setLayout(subgrid);
Chris@180 320
Chris@0 321 int row = 0;
Chris@0 322
Chris@658 323 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
Chris@658 324 row, 0);
Chris@658 325 subgrid->addWidget(locale, row++, 1, 1, 1);
Chris@658 326
Chris@686 327 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("Allow network usage"))),
Chris@686 328 row, 0);
Chris@686 329 subgrid->addWidget(networkPermish, row++, 1, 1, 1);
Chris@686 330
Chris@0 331 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 332 ("Temporary Directory Root"))),
Chris@263 333 row, 0);
Chris@263 334 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 335 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 336 row++;
Chris@263 337
Chris@263 338 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 339 ("Resample On Load"))),
Chris@263 340 row, 0);
Chris@263 341 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 342
Chris@1035 343 //!!! subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@1035 344 //!!! subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 345
Chris@263 346 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 347 ("Resample Quality"))),
Chris@263 348 row, 0);
Chris@263 349 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 350
Chris@263 351 subgrid->setRowStretch(row, 10);
Chris@263 352
Chris@436 353 m_tabOrdering[GeneralTab] = m_tabs->count();
Chris@436 354 m_tabs->addTab(frame, tr("&General"));
Chris@263 355
Chris@263 356 // Appearance tab
Chris@263 357
Chris@263 358 frame = new QFrame;
Chris@263 359 subgrid = new QGridLayout;
Chris@263 360 frame->setLayout(subgrid);
Chris@263 361 row = 0;
Chris@263 362
Chris@263 363 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 364 ("Show Splash Screen"))),
Chris@906 365 row, 0);
Chris@906 366 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@906 367
Chris@950 368 #ifdef Q_OS_MAC
Chris@950 369 if (devicePixelRatio() > 1) {
Chris@950 370 subgrid->addWidget(new QLabel(tr("Draw layers at Retina resolution:")), row, 0);
Chris@950 371 subgrid->addWidget(retina, row++, 1, 1, 1);
Chris@950 372 }
Chris@950 373 #endif
Chris@950 374
Chris@906 375 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 376 ("Property Box Layout"))),
Chris@0 377 row, 0);
Chris@0 378 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 379
Chris@661 380 #ifndef Q_OS_MAC
Chris@0 381 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 382 ("Background Mode"))),
Chris@0 383 row, 0);
Chris@180 384 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 385 #endif
Chris@180 386
Chris@180 387 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 388 ("View Font Size"))),
Chris@225 389 row, 0);
Chris@225 390 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 391
Chris@225 392 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 393 ("Time To Text Mode"))),
Chris@337 394 row, 0);
Chris@337 395 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 396
Chris@337 397 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 398 ("Show Hours And Minutes"))),
Chris@237 399 row, 0);
Chris@906 400 subgrid->addWidget(hms, row++, 1, 1, 1);
Chris@237 401
Chris@180 402 subgrid->setRowStretch(row, 10);
Chris@180 403
Chris@436 404 m_tabOrdering[AppearanceTab] = m_tabs->count();
Chris@436 405 m_tabs->addTab(frame, tr("&Appearance"));
Chris@180 406
Chris@180 407 // Analysis tab
Chris@180 408
Chris@180 409 frame = new QFrame;
Chris@180 410 subgrid = new QGridLayout;
Chris@180 411 frame->setLayout(subgrid);
Chris@180 412 row = 0;
Chris@180 413
Chris@180 414 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 415 ("Tuning Frequency"))),
Chris@180 416 row, 0);
Chris@180 417 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 418
Chris@702 419 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@702 420 ("Octave Numbering System"))),
Chris@702 421 row, 0);
Chris@702 422 subgrid->addWidget(octaveSystem, row++, 1, 1, 2);
Chris@702 423
Chris@0 424 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 425 ("Spectrogram Y Smoothing")),
Chris@115 426 row, 0);
Chris@115 427 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 428
Chris@299 429 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 430 ("Spectrogram X Smoothing")),
Chris@299 431 row, 0);
Chris@299 432 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 433
Chris@0 434 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 435 ("Window Type"))),
Chris@0 436 row, 0);
Chris@9 437 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 438 subgrid->setRowStretch(row, 10);
Chris@9 439 row++;
Chris@0 440
Chris@180 441 subgrid->setRowStretch(row, 10);
Chris@180 442
Chris@436 443 m_tabOrdering[AnalysisTab] = m_tabs->count();
Chris@436 444 m_tabs->addTab(frame, tr("Anal&ysis"));
Chris@436 445
Chris@436 446 // Template tab
Chris@436 447
Chris@436 448 frame = new QFrame;
Chris@436 449 subgrid = new QGridLayout;
Chris@436 450 frame->setLayout(subgrid);
Chris@436 451 row = 0;
Chris@436 452
Chris@436 453 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
Chris@436 454
Chris@436 455 QListWidget *lw = new QListWidget();
Chris@436 456 subgrid->addWidget(lw, row, 0);
Chris@436 457 subgrid->setRowStretch(row, 10);
Chris@436 458 row++;
Chris@436 459
Chris@436 460 settings.beginGroup("MainWindow");
Chris@436 461 m_currentTemplate = settings.value("sessiontemplate", "").toString();
Chris@436 462 settings.endGroup();
Chris@436 463
Chris@455 464 lw->addItem(tr("Standard Waveform"));
Chris@436 465 if (m_currentTemplate == "" || m_currentTemplate == "default") {
Chris@436 466 lw->setCurrentRow(lw->count()-1);
Chris@436 467 }
Chris@436 468 m_templates.push_back("");
Chris@436 469
Chris@436 470 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@436 471
Chris@436 472 std::set<QString> byName;
Chris@436 473 foreach (QString t, templates) {
Chris@436 474 byName.insert(QFileInfo(t).baseName());
Chris@436 475 }
Chris@436 476
Chris@436 477 foreach (QString t, byName) {
Chris@436 478 if (t.toLower() == "default") continue;
Chris@436 479 m_templates.push_back(t);
Chris@436 480 lw->addItem(t);
Chris@436 481 if (m_currentTemplate == t) {
Chris@436 482 lw->setCurrentRow(lw->count()-1);
Chris@436 483 }
Chris@436 484 }
Chris@436 485
Chris@436 486 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
Chris@436 487
Chris@436 488 m_tabOrdering[TemplateTab] = m_tabs->count();
Chris@436 489 m_tabs->addTab(frame, tr("Session &Template"));
Chris@180 490
Chris@163 491 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 492 grid->addWidget(bb, 1, 0);
Chris@0 493
Chris@0 494 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 495 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 496 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 497 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 498 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 499 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 500 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 501 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 502
Chris@0 503 m_applyButton->setEnabled(false);
Chris@0 504 }
Chris@0 505
Chris@0 506 PreferencesDialog::~PreferencesDialog()
Chris@0 507 {
Chris@438 508 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 509 }
Chris@0 510
Chris@0 511 void
Chris@436 512 PreferencesDialog::switchToTab(Tab t)
Chris@436 513 {
Chris@436 514 if (m_tabOrdering.contains(t)) {
Chris@436 515 m_tabs->setCurrentIndex(m_tabOrdering[t]);
Chris@436 516 }
Chris@436 517 }
Chris@436 518
Chris@436 519 void
Chris@9 520 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 521 {
Chris@0 522 m_windowType = type;
Chris@0 523 m_applyButton->setEnabled(true);
Chris@0 524 }
Chris@0 525
Chris@0 526 void
Chris@115 527 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 528 {
Chris@115 529 m_spectrogramSmoothing = smoothing;
Chris@0 530 m_applyButton->setEnabled(true);
Chris@0 531 }
Chris@0 532
Chris@0 533 void
Chris@299 534 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 535 {
Chris@299 536 m_spectrogramXSmoothing = smoothing;
Chris@299 537 m_applyButton->setEnabled(true);
Chris@299 538 }
Chris@299 539
Chris@299 540 void
Chris@0 541 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 542 {
Chris@0 543 m_propertyLayout = layout;
Chris@0 544 m_applyButton->setEnabled(true);
Chris@0 545 }
Chris@0 546
Chris@0 547 void
Chris@0 548 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 549 {
Chris@0 550 m_tuningFrequency = freq;
Chris@0 551 m_applyButton->setEnabled(true);
Chris@0 552 }
Chris@0 553
Chris@0 554 void
Chris@263 555 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 556 {
Chris@263 557 m_audioDevice = s;
Chris@263 558 m_applyButton->setEnabled(true);
Chris@263 559 m_changesOnRestart = true;
Chris@263 560 }
Chris@263 561
Chris@263 562 void
Chris@32 563 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 564 {
Chris@32 565 m_resampleQuality = q;
Chris@32 566 m_applyButton->setEnabled(true);
Chris@32 567 }
Chris@32 568
Chris@32 569 void
Chris@180 570 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 571 {
Chris@180 572 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 573 m_applyButton->setEnabled(true);
Chris@180 574 m_changesOnRestart = true;
Chris@180 575 }
Chris@180 576
Chris@180 577 void
Chris@686 578 PreferencesDialog::networkPermissionChanged(int state)
Chris@686 579 {
Chris@686 580 m_networkPermission = (state == Qt::Checked);
Chris@686 581 m_applyButton->setEnabled(true);
Chris@686 582 m_changesOnRestart = true;
Chris@686 583 }
Chris@686 584
Chris@686 585 void
Chris@950 586 PreferencesDialog::retinaChanged(int state)
Chris@950 587 {
Chris@950 588 m_retina = (state == Qt::Checked);
Chris@950 589 m_applyButton->setEnabled(true);
Chris@950 590 // Does not require a restart
Chris@950 591 }
Chris@950 592
Chris@950 593 void
Chris@237 594 PreferencesDialog::showSplashChanged(int state)
Chris@237 595 {
Chris@237 596 m_showSplash = (state == Qt::Checked);
Chris@237 597 m_applyButton->setEnabled(true);
Chris@237 598 m_changesOnRestart = true;
Chris@237 599 }
Chris@237 600
Chris@237 601 void
Chris@436 602 PreferencesDialog::defaultTemplateChanged(int i)
Chris@436 603 {
Chris@436 604 m_currentTemplate = m_templates[i];
Chris@436 605 m_applyButton->setEnabled(true);
Chris@436 606 }
Chris@436 607
Chris@436 608 void
Chris@658 609 PreferencesDialog::localeChanged(int i)
Chris@658 610 {
Chris@658 611 m_currentLocale = m_locales[i];
Chris@658 612 m_applyButton->setEnabled(true);
Chris@658 613 m_changesOnRestart = true;
Chris@658 614 }
Chris@658 615
Chris@658 616 void
Chris@180 617 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 618 {
Chris@180 619 m_tempDirRoot = r;
Chris@180 620 m_applyButton->setEnabled(true);
Chris@180 621 }
Chris@180 622
Chris@180 623 void
Chris@180 624 PreferencesDialog::tempDirButtonClicked()
Chris@180 625 {
Chris@180 626 QString dir = QFileDialog::getExistingDirectory
Chris@180 627 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 628 m_tempDirRoot);
Chris@180 629 if (dir == "") return;
Chris@180 630 m_tempDirRootEdit->setText(dir);
Chris@180 631 tempDirRootChanged(dir);
Chris@180 632 m_changesOnRestart = true;
Chris@180 633 }
Chris@180 634
Chris@180 635 void
Chris@180 636 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 637 {
Chris@180 638 m_backgroundMode = mode;
Chris@180 639 m_applyButton->setEnabled(true);
Chris@180 640 m_changesOnRestart = true;
Chris@180 641 }
Chris@180 642
Chris@180 643 void
Chris@337 644 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 645 {
Chris@337 646 m_timeToTextMode = mode;
Chris@337 647 m_applyButton->setEnabled(true);
Chris@337 648 }
Chris@337 649
Chris@337 650 void
Chris@906 651 PreferencesDialog::showHMSChanged(int state)
Chris@906 652 {
Chris@906 653 m_showHMS = (state == Qt::Checked);
Chris@906 654 m_applyButton->setEnabled(true);
Chris@906 655 }
Chris@906 656
Chris@906 657 void
Chris@702 658 PreferencesDialog::octaveSystemChanged(int system)
Chris@702 659 {
Chris@702 660 m_octaveSystem = system;
Chris@702 661 m_applyButton->setEnabled(true);
Chris@702 662 }
Chris@702 663
Chris@702 664 void
Chris@225 665 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 666 {
Chris@225 667 m_viewFontSize = sz;
Chris@225 668 m_applyButton->setEnabled(true);
Chris@225 669 }
Chris@225 670
Chris@225 671 void
Chris@0 672 PreferencesDialog::okClicked()
Chris@0 673 {
Chris@0 674 applyClicked();
Chris@0 675 accept();
Chris@0 676 }
Chris@0 677
Chris@0 678 void
Chris@0 679 PreferencesDialog::applyClicked()
Chris@0 680 {
Chris@0 681 Preferences *prefs = Preferences::getInstance();
Chris@0 682 prefs->setWindowType(WindowType(m_windowType));
Chris@115 683 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 684 (m_spectrogramSmoothing));
Chris@299 685 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 686 (m_spectrogramXSmoothing));
Chris@0 687 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 688 (m_propertyLayout));
Chris@0 689 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 690 prefs->setResampleQuality(m_resampleQuality);
Chris@180 691 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 692 prefs->setShowSplash(m_showSplash);
Chris@180 693 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 694 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 695 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@906 696 prefs->setShowHMS(m_showHMS);
Chris@225 697 prefs->setViewFontSize(m_viewFontSize);
Chris@263 698
Chris@702 699 prefs->setProperty("Octave Numbering System", m_octaveSystem);
Chris@702 700
Chris@1035 701 //!!! std::vector<QString> devices =
Chris@1035 702 //!!! AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 703
Chris@263 704 QSettings settings;
Chris@263 705 settings.beginGroup("Preferences");
Chris@686 706 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 707 settings.setValue(permishTag, m_networkPermission);
Chris@1035 708 //!!! settings.setValue("audio-target", devices[m_audioDevice]);
Chris@686 709 settings.setValue("locale", m_currentLocale);
Chris@950 710 #ifdef Q_OS_MAC
Chris@950 711 settings.setValue("scaledHiDpi", m_retina);
Chris@950 712 #endif
Chris@263 713 settings.endGroup();
Chris@180 714
Chris@436 715 settings.beginGroup("MainWindow");
Chris@436 716 settings.setValue("sessiontemplate", m_currentTemplate);
Chris@436 717 settings.endGroup();
Chris@436 718
Chris@0 719 m_applyButton->setEnabled(false);
Chris@180 720
Chris@180 721 if (m_changesOnRestart) {
Chris@180 722 QMessageBox::information(this, tr("Preferences"),
Chris@255 723 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 724 m_changesOnRestart = false;
Chris@180 725 }
Chris@0 726 }
Chris@0 727
Chris@0 728 void
Chris@0 729 PreferencesDialog::cancelClicked()
Chris@0 730 {
Chris@0 731 reject();
Chris@0 732 }
Chris@0 733
Chris@163 734 void
Chris@163 735 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 736 {
Chris@163 737 if (quickly) {
Chris@163 738 reject();
Chris@163 739 return;
Chris@163 740 }
Chris@163 741
Chris@163 742 if (m_applyButton->isEnabled()) {
Chris@163 743 int rv = QMessageBox::warning
Chris@163 744 (this, tr("Preferences Changed"),
Chris@163 745 tr("Some preferences have been changed but not applied.\n"
Chris@163 746 "Apply them before closing?"),
Chris@163 747 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 748 QMessageBox::Discard);
Chris@163 749 if (rv == QMessageBox::Apply) {
Chris@163 750 applyClicked();
Chris@163 751 accept();
Chris@163 752 } else {
Chris@163 753 reject();
Chris@163 754 }
Chris@163 755 } else {
Chris@163 756 accept();
Chris@163 757 }
Chris@163 758 }
Chris@163 759