Skip to content

Commit b1c4433

Browse files
committed
Added more features
1 parent 3f27edc commit b1c4433

24 files changed

+1430
-773
lines changed

AnnotatorService.cpp

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,58 @@ AnnotatorService::AnnotatorService(IUnoPluginController& controller, DataService
1010

1111
void AnnotatorService::AnnotatorProcess(std::vector<IUnoAnnotatorItem>& items)
1212
{
13+
auto selected = m_dataService.getSelectedMarker();
14+
1315
int y = 0;
14-
for (const marker::marker_t& marker : m_markers)
16+
for (const marker::marker_t& current : m_markers)
1517
{
16-
IUnoAnnotatorItem* item = new IUnoAnnotatorItem();
17-
item->frequency = marker.frequency;
18-
item->text = " " + marker.name;
18+
items.push_back(*makeAnnotation(current, y++, selected.lid == current.lid));
19+
y %= 6;
20+
}
1921

20-
if (marker.type < 8) {
21-
item->style = IUnoAnnotatorStyle::AnnotatorStyleFlag;
22-
item->power = -40 - (y++ * 6);
23-
}
24-
else
25-
{
22+
if (selected.lid > 0 && !selected.show) {
23+
items.push_back(*makeAnnotation(selected, y++, true));
24+
}
25+
}
26+
27+
IUnoAnnotatorItem* AnnotatorService::makeAnnotation(marker::marker_t marker, int y, bool selected)
28+
{
29+
auto types = m_dataService.GetTypeSettings();
30+
31+
IUnoAnnotatorItem* item = new IUnoAnnotatorItem();
32+
item->frequency = marker.frequency;
33+
item->text = " " + marker.name;
34+
35+
if (marker.type < 8) {
36+
if (selected)
2637
item->style = IUnoAnnotatorStyle::AnnotatorStyleMarkerAndLine;
27-
item->lineToFreq = item->frequency;
28-
item->power = -30;
29-
item->lineToPower = -160;
30-
}
31-
32-
item->rgb = marker::type_colors[marker.type];
33-
items.push_back(*item);
34-
y %= 6;
38+
else
39+
item->style = IUnoAnnotatorStyle::AnnotatorStyleFlag;
40+
item->power = -40 - (y++ * 6);
41+
}
42+
else
43+
{
44+
item->style = IUnoAnnotatorStyle::AnnotatorStyleMarkerAndLine;
45+
item->lineToFreq = item->frequency;
46+
item->power = -30;
47+
item->lineToPower = -160;
3548
}
49+
50+
item->rgb = types[marker.type].color;
51+
52+
return item;
3653
}
3754

3855
void AnnotatorService::UpdateMarkers()
3956
{
40-
std::vector<marker::marker_t> markers;
57+
std::set<marker::marker_t> markers;
4158
long offset = 10000000;
4259

4360
do {
4461
markers.clear();
4562
for (channel_t channel = 0; channel < m_controller.GetVRXCount(); channel++) {
4663
auto channelMarkers = m_dataService.GetMarkers(m_controller.GetVfoFrequency(channel), offset, true);
47-
markers.insert(markers.end(), channelMarkers.begin(), channelMarkers.end());
64+
markers.insert(channelMarkers.begin(), channelMarkers.end());
4865
}
4966
offset -= (offset / 10);
5067
} while (markers.size() > 64);

AnnotatorService.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <vector>
3+
#include <set>
44

55
#include <iunoplugincontroller.h>
66
#include <iunoannotator.h>
@@ -17,6 +17,8 @@ class AnnotatorService : public IUnoAnnotator
1717
private:
1818
IUnoPluginController& m_controller;
1919
DataService& m_dataService;
20-
std::vector<marker::marker_t> m_markers;
20+
std::set<marker::marker_t> m_markers;
21+
22+
IUnoAnnotatorItem* makeAnnotation(marker::marker_t marker, int y, bool selected = false);
2123
};
2224

DataService.cpp

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
#include <iomanip>
88

99

10-
inline bool operator<(const marker::marker_t& a, const marker::marker_t& b) {
11-
return a.frequency != b.frequency || a.name != b.name;
12-
}
13-
1410
DataService::DataService(IUnoPluginController& controller) :
1511
m_controller(controller),
1612
m_remoteAdapter(),
13+
m_selectedMarker(),
14+
m_typeSettings(),
15+
m_vfoOffset(0),
1716
m_oid(0)
1817
{
1918
HMODULE hModule = GetModuleHandle(L"SDRunoPlugin_CloudMarkers");
@@ -106,6 +105,18 @@ void DataService::Init()
106105

107106
if (m_oid == 0)
108107
m_oid = 1000; // 1000 = Anonymous
108+
109+
m_typeSettings[0].hex_color(getConfig("ColorUnknown"), 0xd94545);
110+
m_typeSettings[1].hex_color(getConfig("ColorTimesignal"), 0xcccccc);
111+
m_typeSettings[2].hex_color(getConfig("ColorMorse"), 0xb12eb3);
112+
m_typeSettings[3].hex_color(getConfig("ColorDigimode"), 0xcfaa32);
113+
m_typeSettings[4].hex_color(getConfig("ColorVoice"), 0x247fc9);
114+
m_typeSettings[5].hex_color(getConfig("ColorBroadcast"), 0x2cb838);
115+
m_typeSettings[6].hex_color(getConfig("ColorNoise"), 0x777777);
116+
m_typeSettings[7].hex_color(getConfig("ColorNoise"), 0x777777);
117+
m_typeSettings[8].hex_color(getConfig("ColorBandmarker"), 0xf0d52b);
118+
119+
m_vfoOffset = getConfigInt("VfoOffset", 10);
109120
}
110121

111122
int DataService::GetMyOid()
@@ -434,19 +445,27 @@ int DataService::GetMarkerCount()
434445
return count;
435446
}
436447

437-
void DataService::SyncMarkers()
448+
void DataService::SyncMarkers(std::function<void(bool download, int progress) > progressHandler)
438449
{
439450
auto syncinfo = GetLastSync();
440451
int lastCommit = std::stoi(syncinfo.commit);
441452

442453
std::string commit = syncinfo.commit;
443-
std::string count = syncinfo.count;
454+
std::string count = "0";
444455
std::string time = sync::currentDateTime();
445456

446-
auto syncresult = m_remoteAdapter.Get(lastCommit, m_oid);
457+
auto syncresult = m_remoteAdapter.Get(lastCommit, m_oid, [&](uint64_t c, uint64_t t) {
458+
progressHandler(true, c * 100 / t);
459+
return true;
460+
});
461+
462+
progressHandler(true, 100);
447463

448464
if (syncresult.commit > lastCommit && syncresult.items.size() > 0)
449465
{
466+
int t = syncresult.items.size();
467+
int c = 0;
468+
450469
commit = std::to_string(syncresult.commit);
451470
count = std::to_string(syncresult.items.size());
452471

@@ -460,9 +479,13 @@ void DataService::SyncMarkers()
460479

461480
if (item.action == "UPDATE")
462481
updateSyncedMarker(item.marker);
482+
483+
progressHandler(false, ++c * 100 / t);
463484
}
464485
}
465486

487+
progressHandler(false, 100);
488+
466489
sqlite3_stmt* statement;
467490
int rc = sqlite3_prepare(m_database, "INSERT OR REPLACE INTO config (key, value1, value2, value3) VALUES ('LAST_SYNC', ?, ?, ?);", -1, &statement, 0);
468491
if (rc == SQLITE_OK)
@@ -476,4 +499,90 @@ void DataService::SyncMarkers()
476499
}
477500

478501
m_dataChangedCallback();
502+
}
503+
504+
void DataService::setSelectedMarker(marker::marker_t marker)
505+
{
506+
m_selectedMarker = marker;
507+
}
508+
marker::marker_t DataService::getSelectedMarker()
509+
{
510+
return m_selectedMarker;
511+
}
512+
513+
std::string DataService::getConfig(std::string key)
514+
{
515+
std::string value;
516+
m_controller.GetConfigurationKey("CloudMarker." + key, value);
517+
return value;
518+
}
519+
520+
void DataService::setConfig(std::string key, std::string value)
521+
{
522+
m_controller.SetConfigurationKey("CloudMarker." + key, value);
523+
}
524+
525+
int DataService::getConfigInt(std::string key, int defaultValue)
526+
{
527+
try {
528+
return std::stoi(getConfig(key));
529+
}
530+
catch(...)
531+
{
532+
return defaultValue;
533+
}
534+
}
535+
void DataService::setConfigInt(std::string key, int value)
536+
{
537+
setConfig(key, std::to_string(value));
538+
}
539+
540+
settings::types_t DataService::GetTypeSettings()
541+
{
542+
return m_typeSettings;
543+
}
544+
545+
void DataService::SetTypeSettings(settings::types_t types)
546+
{
547+
m_typeSettings = types;
548+
549+
setConfig("ColorUnknown", m_typeSettings[0].hex_color());
550+
setConfig("ColorTimesignal", m_typeSettings[1].hex_color());
551+
setConfig("ColorMorse", m_typeSettings[2].hex_color());
552+
setConfig("ColorDigimode", m_typeSettings[3].hex_color());
553+
setConfig("ColorVoice", m_typeSettings[4].hex_color());
554+
setConfig("ColorBroadcast", m_typeSettings[5].hex_color());
555+
setConfig("ColorNoise", m_typeSettings[6].hex_color());
556+
setConfig("ColorBandmarker", m_typeSettings[8].hex_color());
557+
558+
m_dataChangedCallback();
559+
}
560+
561+
void DataService::SaveWindowPos(channel_t channel, nana::point point)
562+
{
563+
setConfigInt("Window" + std::to_string(channel) + "PosX", point.x);
564+
setConfigInt("Window" + std::to_string(channel) + "PosY", point.y);
565+
}
566+
567+
nana::point DataService::LoadWindowPos(channel_t channel)
568+
{
569+
int x = getConfigInt("Window" + std::to_string(channel) + "PosX", -1);
570+
int y = getConfigInt("Window" + std::to_string(channel) + "PosY", -1);
571+
return nana::point(x, y);
572+
}
573+
574+
int DataService::GetVfoOffset() {
575+
return m_vfoOffset;
576+
}
577+
578+
void DataService::SetVfoOffset(int offset) {
579+
if (offset >= 10 && offset <= 500) {
580+
m_vfoOffset = offset;
581+
setConfigInt("VfoOffset", offset);
582+
m_dataChangedCallback();
583+
}
584+
}
585+
586+
bool DataService::UpdateAvailable() {
587+
return version::version != m_remoteAdapter.GetNewestVersion();
479588
}

DataService.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,29 @@ class DataService
2525

2626
void SaveMarker(marker::marker_t marker, const bool share);
2727
void DeleteMarker(marker::marker_t marker);
28-
void SyncMarkers();
28+
void SyncMarkers(std::function<void(bool download, int progress)> progressHandler);
2929
sync::syncinfo_t GetLastSync();
3030
int GetMarkerCount();
3131

32+
void setSelectedMarker(marker::marker_t marker);
33+
marker::marker_t getSelectedMarker();
34+
35+
settings::types_t GetTypeSettings();
36+
void SetTypeSettings(settings::types_t types);
37+
38+
void SaveWindowPos(channel_t channel, nana::point point);
39+
nana::point LoadWindowPos(channel_t channel);
40+
41+
int GetVfoOffset();
42+
void SetVfoOffset(int offset);
43+
44+
bool UpdateAvailable();
45+
3246
private:
3347
int m_oid;
48+
int m_vfoOffset;
49+
marker::marker_t m_selectedMarker;
50+
settings::types_t m_typeSettings;
3451
std::function<void()> m_dataChangedCallback;
3552
sqlite3* m_database;
3653

@@ -44,5 +61,10 @@ class DataService
4461

4562
void insertSyncedMarker(const marker::marker_t marker);
4663
void updateSyncedMarker(const marker::marker_t marker);
64+
65+
std::string getConfig(std::string key);
66+
void setConfig(std::string key, std::string value);
67+
int getConfigInt(std::string key, int defaultValue = 0);
68+
void setConfigInt(std::string key, int value);
4769
};
4870

Plugin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Plugin::Plugin(IUnoPluginController& controller) :
1212
m_dataService.Init();
1313

1414
m_annotatorService.UpdateMarkers();
15+
16+
m_windowManager.RegisterCallback(std::bind(&Plugin::CloseCallback, this));
1517
m_windowManager.UpdateVrxCount();
1618

1719
m_controller.RegisterAnnotator(&m_annotatorService);
@@ -40,6 +42,10 @@ void Plugin::HandleEvent(const UnoEvent& event)
4042
}
4143
}
4244

45+
void Plugin::CloseCallback()
46+
{
47+
m_controller.RequestUnload(this);
48+
}
4349

4450
void Plugin::DataChangedCallback()
4551
{

Plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Plugin : public IUnoPlugin
1717
const char* GetPluginName() const { return "CloudMarkers"; }
1818
void HandleEvent(const UnoEvent& event);
1919
void DataChangedCallback();
20+
void CloseCallback();
2021

2122
private:
2223
AnnotatorService m_annotatorService;

RemoteAdapter.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,28 @@ bool RemoteAdapter::Vote(const marker::marker_t marker, const int oid)
121121
}
122122
}
123123

124-
sync::syncresult_t RemoteAdapter::Get(int afterCommit, int oid)
124+
std::string RemoteAdapter::GetNewestVersion() {
125+
std::string remoteUrl = std::string("/version.txt");
126+
127+
httplib::Client remoteClient(remote::server, 80);
128+
httplib::Result result = remoteClient.Get(remoteUrl.c_str());
129+
if (result.error() == httplib::Error::Success) {
130+
if (result->status == 200 && !result->body.empty())
131+
return result->body;
132+
}
133+
134+
return "ERR";
135+
}
136+
137+
sync::syncresult_t RemoteAdapter::Get(int afterCommit, int oid, std::function<bool(uint64_t current, uint64_t total)> progress)
125138
{
126139
std::string remoteUrl = std::string("/get.php")
127140
.append("?token=").append(remote::token)
128141
.append("&oid=").append(std::to_string(oid))
129142
.append("&commit=").append(std::to_string(afterCommit));
130143

131144
httplib::Client remoteClient(remote::server, 80);
132-
httplib::Result result = remoteClient.Get(remoteUrl.c_str());
145+
httplib::Result result = remoteClient.Get(remoteUrl.c_str(), progress);
133146

134147
if (result.error() == httplib::Error::Success) {
135148
if (result->status == 200) {

RemoteAdapter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class RemoteAdapter
1111
bool Delete(marker::marker_t marker, int oid);
1212
bool Vote(const marker::marker_t marker, int oid);
1313

14-
sync::syncresult_t Get(int afterCommit, int oid);
14+
std::string GetNewestVersion();
15+
16+
sync::syncresult_t Get(int afterCommit, int oid, std::function<bool(uint64_t current, uint64_t total)> progress);
1517

1618
private:
1719
std::string markerToJson(marker::marker_t marker);

0 commit comments

Comments
 (0)