CubicSDR/src/BookmarkMgr.h

144 lines
4.1 KiB
C
Raw Normal View History

// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+
2016-09-14 19:46:57 -04:00
#pragma once
#include <wx/arrstr.h>
2016-09-14 19:46:57 -04:00
#include <vector>
#include <set>
#include <memory>
2016-09-14 19:46:57 -04:00
#include "DemodulatorInstance.h"
class DataNode;
2016-09-14 19:46:57 -04:00
class BookmarkEntry {
public:
std::mutex busy_lock;
std::string type;
//maps on the Demod user label.
std::wstring label;
2016-09-14 19:46:57 -04:00
long long frequency;
int bandwidth;
DataNode *node;
virtual ~BookmarkEntry();
2016-09-14 19:46:57 -04:00
};
class BookmarkRangeEntry {
public:
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) {
}
std::mutex busy_lock;
std::wstring label;
2016-12-27 00:46:12 -05:00
long long freq;
long long startFreq;
long long endFreq;
};
typedef std::shared_ptr<BookmarkEntry> BookmarkEntryPtr;
typedef std::shared_ptr<BookmarkRangeEntry> BookmarkRangeEntryPtr;
struct BookmarkEntryCompare : public std::binary_function<BookmarkEntryPtr,BookmarkEntryPtr,bool>
{
bool operator()(const BookmarkEntryPtr a, BookmarkEntryPtr b) const
{
return a->frequency < b->frequency;
}
};
struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntryPtr ,BookmarkRangeEntryPtr ,bool>
{
bool operator()(const BookmarkRangeEntryPtr a, BookmarkRangeEntryPtr b) const
{
2016-12-27 00:46:12 -05:00
return a->freq < b->freq;
}
};
typedef std::vector<BookmarkEntryPtr> BookmarkList;
typedef std::vector<BookmarkRangeEntryPtr> BookmarkRangeList;
typedef std::map<std::string, BookmarkList > BookmarkMap;
typedef std::map<std::string, bool > BookmarkMapSorted;
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:
BookmarkMgr();
//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);
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);
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);
void addGroup(std::string group);
void removeGroup(std::string group);
void renameGroup(std::string group, std::string ngroup);
const BookmarkList& getBookmarks(std::string group);
void getGroups(BookmarkNames &arr);
void getGroups(wxArrayString &arr);
2016-12-26 21:56:19 -05:00
void setExpandState(std::string groupName, bool state);
bool getExpandState(std::string groupName);
void updateActiveList();
2016-10-06 22:27:12 -04:00
void updateBookmarks();
void updateBookmarks(std::string group);
2017-08-27 05:11:30 -04:00
void addRecent(DemodulatorInstancePtr demod);
void addRecent(BookmarkEntryPtr be);
void removeRecent(BookmarkEntryPtr be);
const BookmarkList& getRecents();
2016-12-17 21:14:13 -05:00
void clearRecents();
2017-08-27 05:11:30 -04:00
void removeActive(DemodulatorInstancePtr demod);
void addRange(BookmarkRangeEntryPtr re);
void removeRange(BookmarkRangeEntryPtr re);
const BookmarkRangeList& getRanges();
void clearRanges();
static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt);
2017-08-27 05:11:30 -04:00
static std::wstring getActiveDisplayName(DemodulatorInstancePtr demod);
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);
BookmarkEntryPtr nodeToBookmark(DataNode *node);
2016-09-14 19:46:57 -04:00
BookmarkMap bmData;
BookmarkMapSorted bmDataSorted;
BookmarkList recents;
BookmarkRangeList ranges;
bool rangesSorted;
std::recursive_mutex busy_lock;
2016-12-26 21:56:19 -05:00
BookmarkExpandState expandState;
//represents an empty BookMarkList that is returned by reference by some functions.
static const BookmarkList emptyResults;
2016-09-14 19:46:57 -04:00
};