annotate plugin/PluginPathSetter.h @ 1825:029d7d3f0a3a

Add option to avoid pulling in the WinRT dependency for this very small feature
author Chris Cannam
date Fri, 06 Mar 2020 12:12:46 +0000
parents 75fe1c1e003f
children
rev   line source
Chris@1472 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1472 2
Chris@1472 3 /*
Chris@1472 4 Sonic Visualiser
Chris@1472 5 An audio file viewer and annotation editor.
Chris@1472 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1472 7
Chris@1472 8 This program is free software; you can redistribute it and/or
Chris@1472 9 modify it under the terms of the GNU General Public License as
Chris@1472 10 published by the Free Software Foundation; either version 2 of the
Chris@1472 11 License, or (at your option) any later version. See the file
Chris@1472 12 COPYING included with this distribution for more information.
Chris@1472 13 */
Chris@1472 14
Chris@1472 15 #ifndef SV_PLUGIN_PATH_SETTER_H
Chris@1472 16 #define SV_PLUGIN_PATH_SETTER_H
Chris@1472 17
Chris@1472 18 #include <QString>
Chris@1472 19 #include <QStringList>
Chris@1472 20 #include <QMutex>
Chris@1472 21
Chris@1472 22 #include <map>
Chris@1472 23
Chris@1481 24 #include "checker/knownplugins.h"
Chris@1481 25
Chris@1472 26 class PluginPathSetter
Chris@1472 27 {
Chris@1472 28 public:
Chris@1481 29 typedef std::pair<KnownPlugins::PluginType,
Chris@1481 30 KnownPlugins::BinaryFormat> TypeKey;
Chris@1481 31
Chris@1481 32 typedef std::vector<TypeKey> TypeKeys;
Chris@1472 33
Chris@1472 34 struct PathConfig {
Chris@1473 35 QStringList directories; // Actual list of directories arising
Chris@1473 36 // from user settings, environment
Chris@1473 37 // variables, and defaults as
Chris@1473 38 // appropriate
Chris@1473 39
Chris@1473 40 QString envVariable; // Name of env var, e.g. LADSPA_PATH
Chris@1473 41
Chris@1473 42 bool useEnvVariable; // True if env variable should override
Chris@1473 43 // any user settings for this
Chris@1472 44 };
Chris@1472 45
Chris@1481 46 typedef std::map<TypeKey, PathConfig> Paths;
Chris@1472 47
Chris@1473 48 /// Update *_PATH environment variables from the settings, on
Chris@1473 49 /// application startup. Must be called exactly once, before any
Chris@1473 50 /// of the other functions in this class has been called
Chris@1473 51 static void initialiseEnvironmentVariables();
Chris@1473 52
Chris@1473 53 /// Return default values of paths only, without any environment
Chris@1473 54 /// variables or user-defined preferences
Chris@1472 55 static Paths getDefaultPaths();
Chris@1472 56
Chris@1473 57 /// Return paths arising from environment variables only, falling
Chris@1473 58 /// back to the defaults, without any user-defined preferences
Chris@1473 59 static Paths getEnvironmentPaths();
Chris@1473 60
Chris@1472 61 /// Return paths arising from user settings + environment
Chris@1473 62 /// variables + defaults as appropriate
Chris@1472 63 static Paths getPaths();
Chris@1472 64
Chris@1472 65 /// Save the given paths to the settings
Chris@1472 66 static void savePathSettings(Paths paths);
Chris@1472 67
Chris@1473 68 /// Return the original value observed on startup for the given
Chris@1473 69 /// environment variable, if it is one of the variables used by a
Chris@1473 70 /// known path config.
Chris@1473 71 static QString getOriginalEnvironmentValue(QString envVariable);
Chris@1473 72
Chris@1472 73 private:
Chris@1472 74 static Paths m_defaultPaths;
Chris@1473 75 static Paths m_environmentPaths;
Chris@1473 76 static std::map<QString, QString> m_originalEnvValues;
Chris@1481 77 static TypeKeys m_supportedKeys;
Chris@1472 78 static QMutex m_mutex;
Chris@1473 79
Chris@1481 80 static std::vector<TypeKey> getSupportedKeys();
Chris@1481 81 static Paths getEnvironmentPathsUncached(const TypeKeys &keys);
Chris@1481 82 static QString getSettingTagFor(TypeKey);
Chris@1472 83 };
Chris@1472 84
Chris@1472 85 #endif