mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-02-03 05:14:44 +01:00
change indentation and brackets style
This commit is contained in:
parent
bbff0036dc
commit
51ef8b1891
@ -1,27 +1,25 @@
|
|||||||
#include <imgui.h>
|
#include <core.h>
|
||||||
#include <module.h>
|
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <core.h>
|
#include <imgui.h>
|
||||||
#include <radio_interface.h>
|
|
||||||
#include <options.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
#include <signal_path/signal_path.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <module.h>
|
||||||
|
#include <options.h>
|
||||||
|
#include <radio_interface.h>
|
||||||
|
#include <signal_path/signal_path.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define strcpy strcpy_s
|
#define strcpy strcpy_s
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
SDRPP_MOD_INFO{
|
SDRPP_MOD_INFO{
|
||||||
/* Name: */ "frequency_manager",
|
/* Name: */ "frequency_manager",
|
||||||
/* Description: */ "Basic frequency manager module for SDR++",
|
/* Description: */ "Basic frequency manager module for SDR++",
|
||||||
/* Author: */ "zimm",
|
/* Author: */ "zimm",
|
||||||
/* Version: */ 0, 0, 1,
|
/* Version: */ 0, 0, 1,
|
||||||
/* Max instances */ 1
|
/* Max instances */ 1};
|
||||||
};
|
|
||||||
|
|
||||||
static ConfigManager config;
|
static ConfigManager config;
|
||||||
|
|
||||||
@ -32,10 +30,8 @@ public:
|
|||||||
|
|
||||||
CheckConfigFileIntegrity();
|
CheckConfigFileIntegrity();
|
||||||
config.aquire();
|
config.aquire();
|
||||||
if (config.conf.size() > 0)
|
if (config.conf.size() > 0) {
|
||||||
{
|
for (const auto &item : config.conf.items()) {
|
||||||
for (const auto& item : config.conf.items())
|
|
||||||
{
|
|
||||||
bookmarks.push_back((std::string)item.key());
|
bookmarks.push_back((std::string)item.key());
|
||||||
if (config.conf[item.key()].contains("category"))
|
if (config.conf[item.key()].contains("category"))
|
||||||
if (!VectorArrayContainsString(categories, (std::string)config.conf[item.key()]["category"]))
|
if (!VectorArrayContainsString(categories, (std::string)config.conf[item.key()]["category"]))
|
||||||
@ -45,8 +41,7 @@ public:
|
|||||||
std::sort(categories.begin(), categories.end());
|
std::sort(categories.begin(), categories.end());
|
||||||
selected_category = categories[0];
|
selected_category = categories[0];
|
||||||
|
|
||||||
for (const auto& i : bookmarks)
|
for (const auto &i : bookmarks) {
|
||||||
{
|
|
||||||
if (config.conf[i].contains("category") && ((std::string)config.conf[i]["category"] == selected_category))
|
if (config.conf[i].contains("category") && ((std::string)config.conf[i]["category"] == selected_category))
|
||||||
displayed_bookmarks.push_back(i);
|
displayed_bookmarks.push_back(i);
|
||||||
}
|
}
|
||||||
@ -59,7 +54,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~FreqManModule() {
|
~FreqManModule() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable() {
|
void enable() {
|
||||||
@ -75,21 +69,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void CheckConfigFileIntegrity() {
|
||||||
static void CheckConfigFileIntegrity()
|
|
||||||
{
|
|
||||||
config.aquire();
|
config.aquire();
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
if (config.conf.size() > 0)
|
if (config.conf.size() > 0) {
|
||||||
{
|
for (const auto &item : config.conf.items()) {
|
||||||
for (const auto& item : config.conf.items())
|
|
||||||
{
|
|
||||||
if ((!config.conf[item.key()].contains("category") || !config.conf[item.key()]["category"].is_string()) ||
|
if ((!config.conf[item.key()].contains("category") || !config.conf[item.key()]["category"].is_string()) ||
|
||||||
(!config.conf[item.key()].contains("frequency") || !config.conf[item.key()]["frequency"].is_number()) ||
|
(!config.conf[item.key()].contains("frequency") || !config.conf[item.key()]["frequency"].is_number()) ||
|
||||||
(!config.conf[item.key()].contains("mode") || !config.conf[item.key()]["mode"].is_string()) ||
|
(!config.conf[item.key()].contains("mode") || !config.conf[item.key()]["mode"].is_string()) ||
|
||||||
(!config.conf[item.key()].contains("bandwidth") || !config.conf[item.key()]["bandwidth"].is_number())
|
(!config.conf[item.key()].contains("bandwidth") || !config.conf[item.key()]["bandwidth"].is_number())) {
|
||||||
)
|
|
||||||
{
|
|
||||||
spdlog::warn("Frequency Manager: Invalid entry found in config file, removing '{0}'.", (std::string)item.key());
|
spdlog::warn("Frequency Manager: Invalid entry found in config file, removing '{0}'.", (std::string)item.key());
|
||||||
config.conf.erase(item.key());
|
config.conf.erase(item.key());
|
||||||
modified = true;
|
modified = true;
|
||||||
@ -99,35 +87,27 @@ private:
|
|||||||
config.release(modified);
|
config.release(modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetActiveVFOName()
|
static std::string GetActiveVFOName() {
|
||||||
{
|
|
||||||
return gui::waterfall.selectedVFO;
|
return gui::waterfall.selectedVFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetActiveVFOFrequency(double *frequency)
|
static void GetActiveVFOFrequency(double *frequency) {
|
||||||
{
|
|
||||||
*frequency = (double)gui::freqSelect.frequency;
|
*frequency = (double)gui::freqSelect.frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetActiveVFOFrequencyShort(double freq)
|
static std::string GetActiveVFOFrequencyShort(double freq) {
|
||||||
{
|
|
||||||
std::string ret_val = "";
|
std::string ret_val = "";
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
if (freq < 1000000)
|
if (freq < 1000000) {
|
||||||
{
|
|
||||||
stream << std::fixed << std::setprecision(3) << freq / 1000.0;
|
stream << std::fixed << std::setprecision(3) << freq / 1000.0;
|
||||||
ret_val = stream.str();
|
ret_val = stream.str();
|
||||||
ret_val += " kHz";
|
ret_val += " kHz";
|
||||||
}
|
} else if (freq >= 1000000000) {
|
||||||
else if (freq >= 1000000000)
|
|
||||||
{
|
|
||||||
stream << std::fixed << std::setprecision(3) << freq / 1000000000.0;
|
stream << std::fixed << std::setprecision(3) << freq / 1000000000.0;
|
||||||
ret_val = stream.str();
|
ret_val = stream.str();
|
||||||
ret_val += " GHz";
|
ret_val += " GHz";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
stream << std::fixed << std::setprecision(3) << freq / 1000000.0;
|
stream << std::fixed << std::setprecision(3) << freq / 1000000.0;
|
||||||
ret_val = stream.str();
|
ret_val = stream.str();
|
||||||
ret_val += " MHz";
|
ret_val += " MHz";
|
||||||
@ -136,24 +116,20 @@ private:
|
|||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetActiveVFOBandwidth(int *bw)
|
static void GetActiveVFOBandwidth(int *bw) {
|
||||||
{
|
|
||||||
if (GetActiveVFOName() != "")
|
if (GetActiveVFOName() != "")
|
||||||
*bw = (int)sigpath::vfoManager.getBandwidth(GetActiveVFOName());
|
*bw = (int)sigpath::vfoManager.getBandwidth(GetActiveVFOName());
|
||||||
else
|
else
|
||||||
*bw = 0;
|
*bw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetActiveVFODemod()
|
static std::string GetActiveVFODemod() {
|
||||||
{
|
|
||||||
std::string demod;
|
std::string demod;
|
||||||
std::string vfo = GetActiveVFOName();
|
std::string vfo = GetActiveVFOName();
|
||||||
if (core::modComManager.interfaceExists(vfo))
|
if (core::modComManager.interfaceExists(vfo)) {
|
||||||
{
|
|
||||||
int modeNum;
|
int modeNum;
|
||||||
core::modComManager.callInterface(vfo, RADIO_IFACE_CMD_GET_MODE, NULL, &modeNum);
|
core::modComManager.callInterface(vfo, RADIO_IFACE_CMD_GET_MODE, NULL, &modeNum);
|
||||||
switch (modeNum)
|
switch (modeNum) {
|
||||||
{
|
|
||||||
case RADIO_IFACE_MODE_NFM:
|
case RADIO_IFACE_MODE_NFM:
|
||||||
demod = "NFM";
|
demod = "NFM";
|
||||||
break;
|
break;
|
||||||
@ -186,8 +162,7 @@ private:
|
|||||||
return demod;
|
return demod;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveBookmark(std::string description, std::string category, double frequency, int bandwidth, std::string demod)
|
static void SaveBookmark(std::string description, std::string category, double frequency, int bandwidth, std::string demod) {
|
||||||
{
|
|
||||||
config.aquire();
|
config.aquire();
|
||||||
config.conf[description] = json({});
|
config.conf[description] = json({});
|
||||||
config.conf[description]["category"] = category;
|
config.conf[description]["category"] = category;
|
||||||
@ -197,8 +172,7 @@ private:
|
|||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EditBookmark(std::string description, std::string category, double frequency, int bandwidth)
|
static void EditBookmark(std::string description, std::string category, double frequency, int bandwidth) {
|
||||||
{
|
|
||||||
config.aquire();
|
config.aquire();
|
||||||
config.conf[description]["category"] = category;
|
config.conf[description]["category"] = category;
|
||||||
config.conf[description]["frequency"] = frequency;
|
config.conf[description]["frequency"] = frequency;
|
||||||
@ -206,16 +180,14 @@ private:
|
|||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DeleteBookmark(std::string description)
|
static void DeleteBookmark(std::string description) {
|
||||||
{
|
|
||||||
config.aquire();
|
config.aquire();
|
||||||
if (config.conf.contains(description))
|
if (config.conf.contains(description))
|
||||||
config.conf.erase(description);
|
config.conf.erase(description);
|
||||||
config.release(true);
|
config.release(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool VectorArrayContainsString(std::vector<std::string>& v, std::string item)
|
static bool VectorArrayContainsString(std::vector<std::string> &v, std::string item) {
|
||||||
{
|
|
||||||
auto it = std::find(v.begin(), v.end(), item);
|
auto it = std::find(v.begin(), v.end(), item);
|
||||||
if (it != v.end())
|
if (it != v.end())
|
||||||
return true;
|
return true;
|
||||||
@ -223,14 +195,13 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VectorArrayDeleteElement(std::vector<std::string>& v, std::string item)
|
static void VectorArrayDeleteElement(std::vector<std::string> &v, std::string item) {
|
||||||
{
|
|
||||||
auto itr = std::find(v.begin(), v.end(), item);
|
auto itr = std::find(v.begin(), v.end(), item);
|
||||||
if (itr != v.end()) v.erase(itr);
|
if (itr != v.end())
|
||||||
|
v.erase(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menuHandler(void* ctx)
|
static void menuHandler(void *ctx) {
|
||||||
{
|
|
||||||
FreqManModule *_this = (FreqManModule *)ctx;
|
FreqManModule *_this = (FreqManModule *)ctx;
|
||||||
|
|
||||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||||
@ -249,8 +220,7 @@ private:
|
|||||||
// categories dropdown
|
// categories dropdown
|
||||||
static int current_category_index;
|
static int current_category_index;
|
||||||
std::string categories_dropdown_list = "";
|
std::string categories_dropdown_list = "";
|
||||||
for (int i = 0; i < _this->categories.size(); i++)
|
for (int i = 0; i < _this->categories.size(); i++) {
|
||||||
{
|
|
||||||
categories_dropdown_list += _this->categories[i];
|
categories_dropdown_list += _this->categories[i];
|
||||||
categories_dropdown_list += '\0';
|
categories_dropdown_list += '\0';
|
||||||
}
|
}
|
||||||
@ -260,24 +230,20 @@ private:
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||||
bool disable_ctl = false;
|
bool disable_ctl = false;
|
||||||
if (_this->selected_category.size() == 0)
|
if (_this->selected_category.size() == 0) {
|
||||||
{
|
|
||||||
style::beginDisabled();
|
style::beginDisabled();
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
if (ImGui::Combo("##_sdrpp_freq_mgr_category", ¤t_category_index, categories_dropdown_list.c_str()))
|
if (ImGui::Combo("##_sdrpp_freq_mgr_category", ¤t_category_index, categories_dropdown_list.c_str())) {
|
||||||
{
|
|
||||||
_this->selected_category = _this->categories[current_category_index];
|
_this->selected_category = _this->categories[current_category_index];
|
||||||
_this->displayed_bookmarks.clear();
|
_this->displayed_bookmarks.clear();
|
||||||
_this->selected_bookmarks.clear();
|
_this->selected_bookmarks.clear();
|
||||||
for (const auto& i : _this->bookmarks)
|
for (const auto &i : _this->bookmarks) {
|
||||||
{
|
|
||||||
if (config.conf[i].contains("category") && ((std::string)config.conf[i]["category"] == _this->selected_category))
|
if (config.conf[i].contains("category") && ((std::string)config.conf[i]["category"] == _this->selected_category))
|
||||||
_this->displayed_bookmarks.push_back(i);
|
_this->displayed_bookmarks.push_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (disable_ctl)
|
if (disable_ctl) {
|
||||||
{
|
|
||||||
style::endDisabled();
|
style::endDisabled();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
@ -301,88 +267,95 @@ private:
|
|||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
|
|
||||||
// add new bookmark button
|
// add new bookmark button
|
||||||
if (vfoName.size() == 0)
|
if (vfoName.size() == 0) {
|
||||||
{
|
|
||||||
style::beginDisabled();
|
style::beginDisabled();
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Add", button_sz))
|
if (ImGui::Button("Add", button_sz)) {
|
||||||
{
|
|
||||||
ImGui::OpenPopup("Add new bookmark");
|
ImGui::OpenPopup("Add new bookmark");
|
||||||
GetActiveVFOBandwidth(&vfoBW);
|
GetActiveVFOBandwidth(&vfoBW);
|
||||||
GetActiveVFOFrequency(&vfoFreq);
|
GetActiveVFOFrequency(&vfoFreq);
|
||||||
strcpy(description, (GetActiveVFOFrequencyShort(vfoFreq) + " " + vfoDemod).c_str());
|
strcpy(description, (GetActiveVFOFrequencyShort(vfoFreq) + " " + vfoDemod).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disable_ctl)
|
if (disable_ctl) {
|
||||||
{
|
|
||||||
style::endDisabled();
|
style::endDisabled();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(2, 300));
|
ImGui::SetNextWindowPos(ImVec2(2, 300));
|
||||||
if (ImGui::BeginPopupModal("Add new bookmark", &unused_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings))
|
if (ImGui::BeginPopupModal("Add new bookmark", &unused_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings)) {
|
||||||
{
|
|
||||||
ImGui::SetWindowSize("Add new bookmark", ImVec2(330, 210));
|
ImGui::SetWindowSize("Add new bookmark", ImVec2(330, 210));
|
||||||
|
|
||||||
ImGui::Text("Category: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Category: ");
|
||||||
if (ImGui::InputTextWithHint("##_sdrpp_freq_mgr_add_history", "General", category, IM_ARRAYSIZE(category), ImGuiInputTextFlags_CallbackHistory, HistoryHandling::CategoryHistoryCallback))
|
ImGui::SameLine();
|
||||||
{
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
|
if (ImGui::InputTextWithHint("##_sdrpp_freq_mgr_add_history", "General", category, IM_ARRAYSIZE(category), ImGuiInputTextFlags_CallbackHistory, HistoryHandling::CategoryHistoryCallback)) {
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextDisabled(" ?"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("If a category is not provided, \"General\" will be used.\nStart typing and use UP/DOWN keys to cycle through history.");
|
ImGui::TextDisabled(" ?");
|
||||||
if (strlen(description) == 0 || VectorArrayContainsString(_this->bookmarks, (std::string)description))
|
if (ImGui::IsItemHovered())
|
||||||
{
|
ImGui::SetTooltip("If a category is not provided, \"General\" will be used.\nStart typing and use UP/DOWN keys to cycle through history.");
|
||||||
|
if (strlen(description) == 0 || VectorArrayContainsString(_this->bookmarks, (std::string)description)) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)ImColor::HSV(254.0f, 255.0f, 210.0f));
|
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)ImColor::HSV(254.0f, 255.0f, 210.0f));
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
ImGui::Text("Description: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Description: ");
|
||||||
if (disable_ctl)
|
ImGui::SameLine();
|
||||||
{
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
|
if (disable_ctl) {
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
if (ImGui::InputText("##_sdrpp_freq_mgr_add_descr", description, IM_ARRAYSIZE(description), ImGuiInputTextFlags_AutoSelectAll))
|
if (ImGui::InputText("##_sdrpp_freq_mgr_add_descr", description, IM_ARRAYSIZE(description), ImGuiInputTextFlags_AutoSelectAll)) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(description) == 0)
|
if (strlen(description) == 0) {
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextDisabled(" ?"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Description cannot be empty.");
|
ImGui::TextDisabled(" ?");
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("Description cannot be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VectorArrayContainsString(_this->bookmarks, (std::string)description))
|
if (VectorArrayContainsString(_this->bookmarks, (std::string)description)) {
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextDisabled(" ?"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("A bookmark by that name already exists.\nDescription must be unique.");
|
ImGui::TextDisabled(" ?");
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("A bookmark by that name already exists.\nDescription must be unique.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Text("Frequency: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Frequency: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
ImGui::InputDouble("##_sdrpp_freq_mgr_add_freq", &vfoFreq, 1.0, 100.0, "%.0f");
|
ImGui::InputDouble("##_sdrpp_freq_mgr_add_freq", &vfoFreq, 1.0, 100.0, "%.0f");
|
||||||
ImGui::Text("Bandwidth: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Bandwidth: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
ImGui::InputInt("##_sdrpp_freq_mgr_add_bw", &vfoBW);
|
ImGui::InputInt("##_sdrpp_freq_mgr_add_bw", &vfoBW);
|
||||||
ImGui::Text("Demodulator: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0);
|
ImGui::Text("Demodulator: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
ImGui::Text(vfoDemod.c_str());
|
ImGui::Text(vfoDemod.c_str());
|
||||||
|
|
||||||
//ImGui::NewLine();
|
//ImGui::NewLine();
|
||||||
ImGui::TextDisabled("Active VFO: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::TextDisabled(vfoName.c_str());
|
ImGui::TextDisabled("Active VFO: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::TextDisabled(vfoName.c_str());
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() / 2 - 94);
|
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() / 2 - 94);
|
||||||
if (ImGui::Button("Add", ImVec2(90, 24)))
|
if (ImGui::Button("Add", ImVec2(90, 24))) {
|
||||||
{
|
if (strlen(description) == 0) {
|
||||||
if (strlen(description) == 0)
|
|
||||||
{
|
|
||||||
spdlog::error("Frequency Manager: Description cannot be empty.");
|
spdlog::error("Frequency Manager: Description cannot be empty.");
|
||||||
}
|
} else if (VectorArrayContainsString(_this->bookmarks, (std::string)description)) {
|
||||||
else if (VectorArrayContainsString(_this->bookmarks, (std::string)description))
|
|
||||||
{
|
|
||||||
spdlog::error("Frequency Manager: A bookmark by that name already exists. Description must be unique.");
|
spdlog::error("Frequency Manager: A bookmark by that name already exists. Description must be unique.");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (strlen(category) == 0)
|
if (strlen(category) == 0)
|
||||||
strcpy(category, "General");
|
strcpy(category, "General");
|
||||||
|
|
||||||
@ -422,15 +395,13 @@ private:
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// edit bookmark button
|
// edit bookmark button
|
||||||
if (_this->selected_bookmarks.size() != 1)
|
if (_this->selected_bookmarks.size() != 1) {
|
||||||
{
|
|
||||||
style::beginDisabled();
|
style::beginDisabled();
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char mode[4] = "";
|
static char mode[4] = "";
|
||||||
if (ImGui::Button("Edit", button_sz))
|
if (ImGui::Button("Edit", button_sz)) {
|
||||||
{
|
|
||||||
ImGui::OpenPopup("Edit bookmark");
|
ImGui::OpenPopup("Edit bookmark");
|
||||||
config.aquire();
|
config.aquire();
|
||||||
vfoFreq = config.conf[_this->selected_bookmarks[0]]["frequency"];
|
vfoFreq = config.conf[_this->selected_bookmarks[0]]["frequency"];
|
||||||
@ -442,66 +413,72 @@ private:
|
|||||||
original_description = description;
|
original_description = description;
|
||||||
original_category = category;
|
original_category = category;
|
||||||
}
|
}
|
||||||
if (disable_ctl)
|
if (disable_ctl) {
|
||||||
{
|
|
||||||
style::endDisabled();
|
style::endDisabled();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
ImGui::SetNextWindowPos(ImVec2(2, 300));
|
ImGui::SetNextWindowPos(ImVec2(2, 300));
|
||||||
|
|
||||||
if (ImGui::BeginPopupModal("Edit bookmark", &unused_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings))
|
if (ImGui::BeginPopupModal("Edit bookmark", &unused_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings)) {
|
||||||
{
|
|
||||||
ImGui::SetWindowSize("Edit bookmark", ImVec2(330, 210));
|
ImGui::SetWindowSize("Edit bookmark", ImVec2(330, 210));
|
||||||
|
|
||||||
ImGui::Text("Category: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Category: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
ImGui::InputTextWithHint("##_sdrpp_freq_mgr_edit_category", "General", category, IM_ARRAYSIZE(category), ImGuiInputTextFlags_CallbackHistory, HistoryHandling::CategoryHistoryCallback);
|
ImGui::InputTextWithHint("##_sdrpp_freq_mgr_edit_category", "General", category, IM_ARRAYSIZE(category), ImGuiInputTextFlags_CallbackHistory, HistoryHandling::CategoryHistoryCallback);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextDisabled(" ?"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("If a category is not provided, \"General\" will be used.\nStart typing and use UP/DOWN keys to cycle through history.");
|
ImGui::TextDisabled(" ?");
|
||||||
if (strlen(description) == 0)
|
if (ImGui::IsItemHovered())
|
||||||
{
|
ImGui::SetTooltip("If a category is not provided, \"General\" will be used.\nStart typing and use UP/DOWN keys to cycle through history.");
|
||||||
|
if (strlen(description) == 0) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)ImColor::HSV(254.0f, 255.0f, 210.0f));
|
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)ImColor::HSV(254.0f, 255.0f, 210.0f));
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
ImGui::Text("Description: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Description: ");
|
||||||
if (disable_ctl)
|
ImGui::SameLine();
|
||||||
{
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
|
if (disable_ctl) {
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
ImGui::InputText("##_sdrpp_freq_mgr_edit_descr", description, IM_ARRAYSIZE(description));
|
ImGui::InputText("##_sdrpp_freq_mgr_edit_descr", description, IM_ARRAYSIZE(description));
|
||||||
if (strlen(description) == 0)
|
if (strlen(description) == 0) {
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextDisabled(" ?"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Description cannot be empty.");
|
ImGui::TextDisabled(" ?");
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("Description cannot be empty.");
|
||||||
}
|
}
|
||||||
ImGui::Text("Frequency: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Frequency: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
ImGui::InputDouble("##_sdrpp_freq_mgr_edit_freq", &vfoFreq, 1.0, 100.0, "%.0f");
|
ImGui::InputDouble("##_sdrpp_freq_mgr_edit_freq", &vfoFreq, 1.0, 100.0, "%.0f");
|
||||||
ImGui::Text("Bandwidth: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0); ImGui::SetNextItemWidth(200.0);
|
ImGui::Text("Bandwidth: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
|
ImGui::SetNextItemWidth(200.0);
|
||||||
ImGui::InputInt("##_sdrpp_freq_mgr_edit_bw", &vfoBW);
|
ImGui::InputInt("##_sdrpp_freq_mgr_edit_bw", &vfoBW);
|
||||||
ImGui::Text("Demodulator: "); ImGui::SameLine(); ImGui::SetCursorPosX(100.0);
|
ImGui::Text("Demodulator: ");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SetCursorPosX(100.0);
|
||||||
ImGui::Text(mode);
|
ImGui::Text(mode);
|
||||||
|
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() / 2 - 94);
|
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() / 2 - 94);
|
||||||
if (ImGui::Button("Edit", ImVec2(90, 24)))
|
if (ImGui::Button("Edit", ImVec2(90, 24))) {
|
||||||
{
|
if (strlen(description) == 0) {
|
||||||
if (strlen(description) == 0)
|
|
||||||
{
|
|
||||||
spdlog::error("Frequency Manager: Description cannot be empty.");
|
spdlog::error("Frequency Manager: Description cannot be empty.");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (strlen(category) == 0)
|
if (strlen(category) == 0)
|
||||||
strcpy(category, "General");
|
strcpy(category, "General");
|
||||||
|
|
||||||
if (strcmp(original_description.c_str(), description) == 0)
|
if (strcmp(original_description.c_str(), description) == 0) {
|
||||||
{
|
|
||||||
EditBookmark(original_description, category, vfoFreq, vfoBW);
|
EditBookmark(original_description, category, vfoFreq, vfoBW);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DeleteBookmark(original_description);
|
DeleteBookmark(original_description);
|
||||||
SaveBookmark(description, category, vfoFreq, vfoBW, mode);
|
SaveBookmark(description, category, vfoFreq, vfoBW, mode);
|
||||||
VectorArrayDeleteElement(_this->displayed_bookmarks, original_description);
|
VectorArrayDeleteElement(_this->displayed_bookmarks, original_description);
|
||||||
@ -511,10 +488,8 @@ private:
|
|||||||
_this->bookmarks.push_back(description);
|
_this->bookmarks.push_back(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(original_category.c_str(), category) != 0)
|
if (strcmp(original_category.c_str(), category) != 0) {
|
||||||
{
|
if (!VectorArrayContainsString(_this->categories, std::string(category))) {
|
||||||
if (!VectorArrayContainsString(_this->categories, std::string(category)))
|
|
||||||
{
|
|
||||||
_this->categories.push_back(category);
|
_this->categories.push_back(category);
|
||||||
std::sort(_this->categories.begin(), _this->categories.end());
|
std::sort(_this->categories.begin(), _this->categories.end());
|
||||||
if (strncmp(_this->selected_category.c_str(), category, 1) > 0)
|
if (strncmp(_this->selected_category.c_str(), category, 1) > 0)
|
||||||
@ -539,31 +514,29 @@ private:
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// delete bookmark button
|
// delete bookmark button
|
||||||
if (_this->selected_bookmarks.size() == 0)
|
if (_this->selected_bookmarks.size() == 0) {
|
||||||
{
|
|
||||||
style::beginDisabled();
|
style::beginDisabled();
|
||||||
disable_ctl = true;
|
disable_ctl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Delete", button_sz))
|
if (ImGui::Button("Delete", button_sz)) {
|
||||||
{
|
|
||||||
if (_this->selected_bookmarks.size() > 0)
|
if (_this->selected_bookmarks.size() > 0)
|
||||||
for (const auto& i : _this->selected_bookmarks)
|
for (const auto &i : _this->selected_bookmarks) {
|
||||||
{
|
|
||||||
spdlog::info("Frequency Manager: Deleting saved bookmark '{0}'.", i);
|
spdlog::info("Frequency Manager: Deleting saved bookmark '{0}'.", i);
|
||||||
|
|
||||||
auto itr = std::find(_this->bookmarks.begin(), _this->bookmarks.end(), i);
|
auto itr = std::find(_this->bookmarks.begin(), _this->bookmarks.end(), i);
|
||||||
if (itr != _this->bookmarks.end()) _this->bookmarks.erase(itr);
|
if (itr != _this->bookmarks.end())
|
||||||
|
_this->bookmarks.erase(itr);
|
||||||
itr = std::find(_this->displayed_bookmarks.begin(), _this->displayed_bookmarks.end(), i);
|
itr = std::find(_this->displayed_bookmarks.begin(), _this->displayed_bookmarks.end(), i);
|
||||||
if (itr != _this->displayed_bookmarks.end()) _this->displayed_bookmarks.erase(itr);
|
if (itr != _this->displayed_bookmarks.end())
|
||||||
|
_this->displayed_bookmarks.erase(itr);
|
||||||
|
|
||||||
DeleteBookmark(i);
|
DeleteBookmark(i);
|
||||||
}
|
}
|
||||||
_this->selected_bookmarks.clear();
|
_this->selected_bookmarks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disable_ctl)
|
if (disable_ctl) {
|
||||||
{
|
|
||||||
style::endDisabled();
|
style::endDisabled();
|
||||||
disable_ctl = false;
|
disable_ctl = false;
|
||||||
}
|
}
|
||||||
@ -571,35 +544,28 @@ private:
|
|||||||
// saved frequencies table
|
// saved frequencies table
|
||||||
static ImGuiTableFlags table_flags = ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg;
|
static ImGuiTableFlags table_flags = ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg;
|
||||||
ImGui::BeginTable("bookmarks_table", 2, table_flags, ImVec2(0.0f, 300));
|
ImGui::BeginTable("bookmarks_table", 2, table_flags, ImVec2(0.0f, 300));
|
||||||
|
ImGui::TableSetupScrollFreeze(0, 1);
|
||||||
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 67);
|
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 67);
|
||||||
ImGui::TableSetupColumn("Frequency", ImGuiTableColumnFlags_WidthStretch, 33);
|
ImGui::TableSetupColumn("Frequency", ImGuiTableColumnFlags_WidthStretch, 33);
|
||||||
ImGui::TableSetupScrollFreeze(0, 1);
|
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
static bool tmpzzz;
|
static bool tmpzzz;
|
||||||
if (_this->displayed_bookmarks.size() > 0)
|
if (_this->displayed_bookmarks.size() > 0) {
|
||||||
{
|
for (int i = 0; i < _this->displayed_bookmarks.size(); i++) {
|
||||||
for (int i = 0; i < _this->displayed_bookmarks.size(); i++)
|
|
||||||
{
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
const bool selected = VectorArrayContainsString(_this->selected_bookmarks, _this->displayed_bookmarks[i]);
|
const bool selected = VectorArrayContainsString(_this->selected_bookmarks, _this->displayed_bookmarks[i]);
|
||||||
if (ImGui::Selectable(_this->displayed_bookmarks[i].c_str(), selected, ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap))
|
if (ImGui::Selectable(_this->displayed_bookmarks[i].c_str(), selected, ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
|
||||||
{
|
if (ImGui::GetIO().KeyCtrl) {
|
||||||
if (ImGui::GetIO().KeyCtrl)
|
|
||||||
{
|
|
||||||
if (selected)
|
if (selected)
|
||||||
_this->selected_bookmarks.erase(std::remove(_this->selected_bookmarks.begin(), _this->selected_bookmarks.end(), _this->displayed_bookmarks[i]), _this->selected_bookmarks.end());
|
_this->selected_bookmarks.erase(std::remove(_this->selected_bookmarks.begin(), _this->selected_bookmarks.end(), _this->displayed_bookmarks[i]), _this->selected_bookmarks.end());
|
||||||
else
|
else
|
||||||
_this->selected_bookmarks.push_back(_this->displayed_bookmarks[i]);
|
_this->selected_bookmarks.push_back(_this->displayed_bookmarks[i]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
_this->selected_bookmarks.clear();
|
_this->selected_bookmarks.clear();
|
||||||
_this->selected_bookmarks.push_back(_this->displayed_bookmarks[i]);
|
_this->selected_bookmarks.push_back(_this->displayed_bookmarks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||||
{
|
|
||||||
// TODO: set frequency, bw, demod, fft marker
|
// TODO: set frequency, bw, demod, fft marker
|
||||||
spdlog::info("Frequency Manager: applying bookmark {0} to VFO {1}", _this->displayed_bookmarks[i], vfoName);
|
spdlog::info("Frequency Manager: applying bookmark {0} to VFO {1}", _this->displayed_bookmarks[i], vfoName);
|
||||||
spdlog::warn("Functionality not yet implemented.");
|
spdlog::warn("Functionality not yet implemented.");
|
||||||
@ -623,7 +589,8 @@ private:
|
|||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
button_sz.x = menuWidth / 2 - style.ItemSpacing.x / 2;
|
button_sz.x = menuWidth / 2 - style.ItemSpacing.x / 2;
|
||||||
style::beginDisabled();
|
style::beginDisabled();
|
||||||
ImGui::Button("Import Bookmarks", button_sz); ImGui::SameLine();
|
ImGui::Button("Import Bookmarks", button_sz);
|
||||||
|
ImGui::SameLine();
|
||||||
ImGui::Button("Export Selected", button_sz);
|
ImGui::Button("Export Selected", button_sz);
|
||||||
style::endDisabled();
|
style::endDisabled();
|
||||||
}
|
}
|
||||||
@ -637,10 +604,8 @@ private:
|
|||||||
std::vector<std::string> displayed_bookmarks;
|
std::vector<std::string> displayed_bookmarks;
|
||||||
std::vector<std::string> selected_bookmarks;
|
std::vector<std::string> selected_bookmarks;
|
||||||
|
|
||||||
struct HistoryHandling
|
struct HistoryHandling {
|
||||||
{
|
static int CategoryHistoryCallback(ImGuiInputTextCallbackData *data) {
|
||||||
static int CategoryHistoryCallback(ImGuiInputTextCallbackData* data)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user