diff base/Preferences.cpp @ 297:c022976d18e8

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 3b8008d09541
children 4fc6f49436b3
line wrap: on
line diff
--- a/base/Preferences.cpp	Fri Sep 21 09:13:11 2007 +0000
+++ b/base/Preferences.cpp	Fri Sep 28 13:56:38 2007 +0000
@@ -40,7 +40,9 @@
     m_propertyBoxLayout(VerticallyStacked),
     m_windowType(HanningWindow),
     m_resampleQuality(1),
-    m_omitRecentTemps(true)
+    m_omitRecentTemps(true),
+    m_tempDirRoot(""),
+    m_resampleOnLoad(true)
 {
     QSettings settings;
     settings.beginGroup("Preferences");
@@ -52,6 +54,13 @@
     m_windowType = WindowType
         (settings.value("window-type", int(HanningWindow)).toInt());
     m_resampleQuality = settings.value("resample-quality", 1).toInt();
+    m_resampleOnLoad = settings.value("resample-on-load", true).toBool();
+    m_backgroundMode = BackgroundMode
+        (settings.value("background-mode", int(BackgroundFromTheme)).toInt());
+    settings.endGroup();
+
+    settings.beginGroup("TempDirectory");
+    m_tempDirRoot = settings.value("create-in", "$HOME").toString();
     settings.endGroup();
 }
 
@@ -69,6 +78,9 @@
     props.push_back("Window Type");
     props.push_back("Resample Quality");
     props.push_back("Omit Temporaries from Recent Files");
+    props.push_back("Resample On Load");
+    props.push_back("Temporary Directory Root");
+    props.push_back("Background Mode");
     return props;
 }
 
@@ -91,7 +103,16 @@
         return tr("Playback resampler type");
     }
     if (name == "Omit Temporaries from Recent Files") {
-        return tr("Omit Temporaries from Recent Files");
+        return tr("Omit temporaries from Recent Files menu");
+    }
+    if (name == "Resample On Load") {
+        return tr("Resample mismatching files on import");
+    }
+    if (name == "Temporary Directory Root") {
+        return tr("Location for cache file directory");
+    }
+    if (name == "Background Mode") {
+        return tr("Background colour preference");
     }
     return name;
 }
@@ -117,6 +138,16 @@
     if (name == "Omit Temporaries from Recent Files") {
         return ToggleProperty;
     }
+    if (name == "Resample On Load") {
+        return ToggleProperty;
+    }
+    if (name == "Temporary Directory Root") {
+        // It's an arbitrary string, we don't have a set of values for this
+        return InvalidProperty;
+    }
+    if (name == "Background Mode") {
+        return ValueProperty;
+    }
     return InvalidProperty;
 }
 
@@ -158,6 +189,13 @@
         if (deflt) *deflt = 1;
     }
 
+    if (name == "Background Mode") {
+        if (min) *min = 0;
+        if (max) *max = 2;
+        if (deflt) *deflt = 0;
+        return int(m_backgroundMode);
+    }        
+
     return 0;
 }
 
@@ -196,6 +234,13 @@
         case SpectrogramZeroPadded: return tr("Zero pad FFT - slow but clear");
         }
     }
+    if (name == "Background Mode") {
+        switch (value) {
+        case BackgroundFromTheme: return tr("Follow desktop theme");
+        case DarkBackground: return tr("Dark background");
+        case LightBackground: return tr("Light background");
+        }
+    }
             
     return "";
 }
@@ -227,6 +272,8 @@
         setResampleQuality(value);
     } else if (name == "Omit Temporaries from Recent Files") {
         setOmitTempsFromRecentFiles(value ? true : false);
+    } else if (name == "Background Mode") {
+        setBackgroundMode(BackgroundMode(value));
     }
 }
 
@@ -311,3 +358,49 @@
         emit propertyChanged("Omit Temporaries from Recent Files");
     }
 }
+
+void
+Preferences::setTemporaryDirectoryRoot(QString root)
+{
+    if (root == QDir::home().absolutePath()) {
+        root = "$HOME";
+    }
+    if (m_tempDirRoot != root) {
+        m_tempDirRoot = root;
+        QSettings settings;
+        settings.beginGroup("TempDirectory");
+        settings.setValue("create-in", root);
+        settings.endGroup();
+        emit propertyChanged("Temporary Directory Root");
+    }
+}
+
+void
+Preferences::setResampleOnLoad(bool resample)
+{
+    if (m_resampleOnLoad != resample) {
+        m_resampleOnLoad = resample;
+        QSettings settings;
+        settings.beginGroup("Preferences");
+        settings.setValue("resample-on-load", resample);
+        settings.endGroup();
+        emit propertyChanged("Resample On Load");
+    }
+}
+
+void
+Preferences::setBackgroundMode(BackgroundMode mode)
+{
+    if (m_backgroundMode != mode) {
+
+        m_backgroundMode = mode;
+
+        QSettings settings;
+        settings.beginGroup("Preferences");
+        settings.setValue("background-mode", int(mode));
+        settings.endGroup();
+        emit propertyChanged("Background Mode");
+    }
+}
+
+