-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support multiple machine-specific configurations ("profiles")
This makes Candle2 usable for driving multiple machines from the same computer, by making separate copies of the entire config file per machine. By default, nothing will change; the file format is unchanged, and the current configuration is treated as a default profile. If multiple profiles are present at startup, the user is prompted to select one. If the environment variable $CANDLE_PROFILE is present and non-empty, that profile is used without prompting. Profiles are stored in the app config directory, as urlencode(profilename) + ".ini". (URL-encoding the names allows profiles to be named without regard for the platform's file naming rules.) There is currently no UI for managing profiles; they may be created by manually copying `settings.ini` to a new file in the same directory, or by setting $CANDLE_PROFILE to a profile that does not yet exist (it will be created with default settings).
- Loading branch information
Showing
6 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "profiles.h" | ||
#include <QUrl> | ||
|
||
// chosen for backward compatibility with pre-profiles versions, which always stored settings in `settings.ini` | ||
const QString default_profile_name = "settings"; | ||
|
||
QStringList getProfileNames() { | ||
const QDir configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); | ||
const QStringList configFiles = configDir.entryList({"*.ini"}, QDir::Files); | ||
QStringList rv; | ||
for (QString configFile : configFiles) { | ||
rv << QUrl::fromPercentEncoding(configFile.replace(QRegExp("\\.ini$"), "").toUtf8()); | ||
} | ||
return rv; | ||
} | ||
|
||
QString configPathForProfile(QString profile_name) { | ||
const QDir configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); | ||
return configDir.filePath(QUrl::toPercentEncoding(profile_name) + ".ini"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef PROFILES_H | ||
#define PROFILES_H | ||
#include <QStringList> | ||
#include <QStandardPaths> | ||
#include <QDir> | ||
|
||
extern const QString default_profile_name; | ||
QStringList getProfileNames(); | ||
QString configPathForProfile(QString profile_name); | ||
|
||
#endif // PROFILES_H |