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-
1410DataService::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
111122int 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}
0 commit comments