mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-26 09:34:44 +01:00
Added persistant config for file source
This commit is contained in:
parent
bed0712be1
commit
ce8b4ceb44
@ -45,10 +45,11 @@ bool FileSelect::render(std::string id) {
|
||||
return _pathChanged;
|
||||
}
|
||||
|
||||
void FileSelect::setPath(std::string path) {
|
||||
void FileSelect::setPath(std::string path, bool markChanged) {
|
||||
this->path = path;
|
||||
std::string expandedPath = expandString(path);
|
||||
pathValid = std::filesystem::is_regular_file(expandedPath);
|
||||
if (markChanged) { pathChanged = true; }
|
||||
strcpy(strPath, path.c_str());
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ class FileSelect {
|
||||
public:
|
||||
FileSelect(std::string defaultPath, std::vector<std::string> filter = {"All Files", "*"});
|
||||
bool render(std::string id);
|
||||
void setPath(std::string path);
|
||||
void setPath(std::string path, bool markChanged = false);
|
||||
bool pathIsValid();
|
||||
|
||||
std::string expandString(std::string input);
|
||||
|
@ -44,10 +44,11 @@ bool FolderSelect::render(std::string id) {
|
||||
return _pathChanged;
|
||||
}
|
||||
|
||||
void FolderSelect::setPath(std::string path) {
|
||||
void FolderSelect::setPath(std::string path, bool markChanged) {
|
||||
this->path = path;
|
||||
std::string expandedPath = expandString(path);
|
||||
pathValid = std::filesystem::is_directory(expandedPath);
|
||||
if (markChanged) { pathChanged = true; }
|
||||
strcpy(strPath, path.c_str());
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ class FolderSelect {
|
||||
public:
|
||||
FolderSelect(std::string defaultPath);
|
||||
bool render(std::string id);
|
||||
void setPath(std::string path);
|
||||
void setPath(std::string path, bool markChanged = false);
|
||||
bool pathIsValid();
|
||||
|
||||
std::string expandString(std::string input);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <signal_path/signal_path.h>
|
||||
#include <wavreader.h>
|
||||
#include <core.h>
|
||||
#include <options.h>
|
||||
#include <gui/widgets/file_select.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
@ -17,12 +18,17 @@ SDRPP_MOD_INFO {
|
||||
/* Max instances */ 1
|
||||
};
|
||||
|
||||
ConfigManager config;
|
||||
|
||||
class FileSourceModule : public ModuleManager::Instance {
|
||||
public:
|
||||
FileSourceModule(std::string name) : fileSelect("", {"Wav IQ Files (*.wav)", "*.wav", "All Files", "*"}) {
|
||||
this->name = name;
|
||||
|
||||
config.aquire();
|
||||
fileSelect.setPath(config.conf["path"], true);
|
||||
config.release();
|
||||
|
||||
handler.ctx = this;
|
||||
handler.selectHandler = menuSelected;
|
||||
handler.deselectHandler = menuDeselected;
|
||||
@ -105,6 +111,9 @@ private:
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
}
|
||||
catch (std::exception e) {}
|
||||
config.aquire();
|
||||
config.conf["path"] = _this->fileSelect.path;
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +166,11 @@ private:
|
||||
};
|
||||
|
||||
MOD_EXPORT void _INIT_() {
|
||||
// Do your one time init here
|
||||
json def = json({});
|
||||
def["path"] = "";
|
||||
config.setPath(options::opts.root + "/file_source_config.json");
|
||||
config.load(def);
|
||||
config.enableAutoSave();
|
||||
}
|
||||
|
||||
MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) {
|
||||
@ -169,5 +182,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
|
||||
}
|
||||
|
||||
MOD_EXPORT void _END_() {
|
||||
// Do your one shutdown here
|
||||
config.disableAutoSave();
|
||||
config.save();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user