comparison plugin/PluginPathSetter.h @ 1483:7459f4c4d7c3

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