2017-01-02 21:27:08 -05:00
|
|
|
// Copyright (c) Charles J. Cliffe
|
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2016-09-14 19:46:57 -04:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-02 01:29:27 -05:00
|
|
|
#include <wx/arrstr.h>
|
|
|
|
|
2016-09-14 19:46:57 -04:00
|
|
|
#include <vector>
|
2016-09-14 22:10:27 -04:00
|
|
|
#include <set>
|
2017-02-28 12:58:54 -05:00
|
|
|
#include <memory>
|
2016-09-14 19:46:57 -04:00
|
|
|
|
|
|
|
#include "DemodulatorInstance.h"
|
|
|
|
|
2016-09-14 22:10:27 -04:00
|
|
|
|
2017-03-20 20:20:17 -04:00
|
|
|
class DataNode;
|
|
|
|
|
2016-09-14 19:46:57 -04:00
|
|
|
class BookmarkEntry {
|
|
|
|
public:
|
|
|
|
std::mutex busy_lock;
|
|
|
|
|
|
|
|
std::string type;
|
2017-04-01 13:38:08 -04:00
|
|
|
//maps on the Demod user label.
|
|
|
|
std::wstring label;
|
2016-09-14 19:46:57 -04:00
|
|
|
|
|
|
|
long long frequency;
|
|
|
|
int bandwidth;
|
|
|
|
|
|
|
|
DataNode *node;
|
2017-03-07 12:30:33 -05:00
|
|
|
|
2017-03-20 20:20:17 -04:00
|
|
|
virtual ~BookmarkEntry();
|
2016-09-14 19:46:57 -04:00
|
|
|
};
|
|
|
|
|
2016-12-27 00:06:25 -05:00
|
|
|
|
|
|
|
class BookmarkRangeEntry {
|
|
|
|
public:
|
2016-12-27 13:01:19 -05:00
|
|
|
BookmarkRangeEntry() : label(L""), freq(0), startFreq(0), endFreq(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
BookmarkRangeEntry(std::wstring label, long long freq, long long startFreq, long long endFreq) : label(label), freq(freq), startFreq(startFreq), endFreq(endFreq) {
|
|
|
|
}
|
|
|
|
|
2016-12-27 00:06:25 -05:00
|
|
|
std::mutex busy_lock;
|
|
|
|
|
|
|
|
std::wstring label;
|
|
|
|
|
2016-12-27 00:46:12 -05:00
|
|
|
long long freq;
|
2016-12-27 00:06:25 -05:00
|
|
|
long long startFreq;
|
|
|
|
long long endFreq;
|
|
|
|
};
|
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
typedef std::shared_ptr<BookmarkEntry> BookmarkEntryPtr;
|
|
|
|
typedef std::shared_ptr<BookmarkRangeEntry> BookmarkRangeEntryPtr;
|
2016-12-27 00:06:25 -05:00
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
struct BookmarkEntryCompare : public std::binary_function<BookmarkEntryPtr,BookmarkEntryPtr,bool>
|
2016-09-14 22:10:27 -04:00
|
|
|
{
|
2017-02-28 12:58:54 -05:00
|
|
|
bool operator()(const BookmarkEntryPtr a, BookmarkEntryPtr b) const
|
2016-09-14 22:10:27 -04:00
|
|
|
{
|
|
|
|
return a->frequency < b->frequency;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntryPtr ,BookmarkRangeEntryPtr ,bool>
|
2016-12-27 00:06:25 -05:00
|
|
|
{
|
2017-02-28 12:58:54 -05:00
|
|
|
bool operator()(const BookmarkRangeEntryPtr a, BookmarkRangeEntryPtr b) const
|
2016-12-27 00:06:25 -05:00
|
|
|
{
|
2016-12-27 00:46:12 -05:00
|
|
|
return a->freq < b->freq;
|
2016-12-27 00:06:25 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
typedef std::vector<BookmarkEntryPtr> BookmarkList;
|
|
|
|
typedef std::vector<BookmarkRangeEntryPtr> BookmarkRangeList;
|
2016-11-21 20:12:10 -05:00
|
|
|
typedef std::map<std::string, BookmarkList > BookmarkMap;
|
|
|
|
typedef std::map<std::string, bool > BookmarkMapSorted;
|
2016-09-29 20:47:38 -04:00
|
|
|
typedef std::vector<std::string> BookmarkNames;
|
2016-12-26 21:56:19 -05:00
|
|
|
typedef std::map<std::string, bool> BookmarkExpandState;
|
2016-09-14 19:46:57 -04:00
|
|
|
|
|
|
|
class BookmarkMgr {
|
|
|
|
public:
|
2016-12-27 00:06:25 -05:00
|
|
|
BookmarkMgr();
|
2018-01-06 04:22:14 -05:00
|
|
|
//if useFullpath = false, use the application config dir.
|
|
|
|
//else assume bookmarkFn is a full path and use it for location.
|
|
|
|
void saveToFile(std::string bookmarkFn, bool backup = true, bool useFullpath = false);
|
|
|
|
bool loadFromFile(std::string bookmarkFn, bool backup = true, bool useFullpath = false);
|
2016-12-27 13:01:19 -05:00
|
|
|
|
|
|
|
bool hasLastLoad(std::string bookmarkFn);
|
|
|
|
bool hasBackup(std::string bookmarkFn);
|
2016-12-13 21:09:44 -05:00
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
void addBookmark(std::string group, DemodulatorInstancePtr demod);
|
2017-02-28 12:58:54 -05:00
|
|
|
void addBookmark(std::string group, BookmarkEntryPtr be);
|
|
|
|
void removeBookmark(std::string group, BookmarkEntryPtr be);
|
|
|
|
void removeBookmark(BookmarkEntryPtr be);
|
|
|
|
void moveBookmark(BookmarkEntryPtr be, std::string group);
|
2016-10-05 19:10:01 -04:00
|
|
|
|
2016-11-21 20:47:16 -05:00
|
|
|
void addGroup(std::string group);
|
2016-11-25 22:19:19 -05:00
|
|
|
void removeGroup(std::string group);
|
|
|
|
void renameGroup(std::string group, std::string ngroup);
|
2017-04-01 13:38:08 -04:00
|
|
|
const BookmarkList& getBookmarks(std::string group);
|
2016-11-21 20:12:10 -05:00
|
|
|
void getGroups(BookmarkNames &arr);
|
2016-11-20 23:26:38 -05:00
|
|
|
void getGroups(wxArrayString &arr);
|
2016-12-26 21:56:19 -05:00
|
|
|
|
|
|
|
void setExpandState(std::string groupName, bool state);
|
|
|
|
bool getExpandState(std::string groupName);
|
|
|
|
|
2016-09-22 20:40:07 -04:00
|
|
|
void updateActiveList();
|
2016-10-06 22:27:12 -04:00
|
|
|
void updateBookmarks();
|
|
|
|
void updateBookmarks(std::string group);
|
2016-10-05 19:10:01 -04:00
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
void addRecent(DemodulatorInstancePtr demod);
|
2017-02-28 12:58:54 -05:00
|
|
|
void addRecent(BookmarkEntryPtr be);
|
|
|
|
void removeRecent(BookmarkEntryPtr be);
|
2017-04-01 13:38:08 -04:00
|
|
|
const BookmarkList& getRecents();
|
2016-12-17 21:14:13 -05:00
|
|
|
void clearRecents();
|
2016-10-05 19:10:01 -04:00
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
void removeActive(DemodulatorInstancePtr demod);
|
2017-04-01 13:38:08 -04:00
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
void addRange(BookmarkRangeEntryPtr re);
|
|
|
|
void removeRange(BookmarkRangeEntryPtr re);
|
2017-04-01 13:38:08 -04:00
|
|
|
const BookmarkRangeList& getRanges();
|
2016-12-27 00:06:25 -05:00
|
|
|
void clearRanges();
|
2017-04-01 13:38:08 -04:00
|
|
|
|
2017-02-28 12:58:54 -05:00
|
|
|
static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt);
|
2017-08-27 05:11:30 -04:00
|
|
|
static std::wstring getActiveDisplayName(DemodulatorInstancePtr demod);
|
2016-12-23 18:45:25 -05:00
|
|
|
|
2016-09-14 19:46:57 -04:00
|
|
|
protected:
|
2016-12-13 21:09:44 -05:00
|
|
|
|
|
|
|
void trimRecents();
|
2016-09-14 19:46:57 -04:00
|
|
|
|
2017-08-27 05:11:30 -04:00
|
|
|
BookmarkEntryPtr demodToBookmarkEntry(DemodulatorInstancePtr demod);
|
2017-05-29 14:08:45 -04:00
|
|
|
BookmarkEntryPtr nodeToBookmark(DataNode *node);
|
2016-10-05 19:10:01 -04:00
|
|
|
|
2016-09-14 19:46:57 -04:00
|
|
|
BookmarkMap bmData;
|
2016-11-21 20:12:10 -05:00
|
|
|
BookmarkMapSorted bmDataSorted;
|
2016-10-05 19:10:01 -04:00
|
|
|
BookmarkList recents;
|
2016-12-27 00:06:25 -05:00
|
|
|
BookmarkRangeList ranges;
|
|
|
|
bool rangesSorted;
|
2017-04-01 13:38:08 -04:00
|
|
|
std::recursive_mutex busy_lock;
|
2016-12-26 21:56:19 -05:00
|
|
|
|
|
|
|
BookmarkExpandState expandState;
|
2017-04-01 13:38:08 -04:00
|
|
|
|
|
|
|
//represents an empty BookMarkList that is returned by reference by some functions.
|
|
|
|
static const BookmarkList emptyResults;
|
2016-09-14 19:46:57 -04:00
|
|
|
};
|