// Copyright (c) Charles J. Cliffe // SPDX-License-Identifier: GPL-2.0+ #pragma once #include #include #include #include #include "DemodulatorInstance.h" class DataNode; class BookmarkEntry { public: std::mutex busy_lock; std::string type; //maps on the Demod user label. std::wstring label; long long frequency; int bandwidth; DataNode *node; virtual ~BookmarkEntry(); }; 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; long long freq; long long startFreq; long long endFreq; }; typedef std::shared_ptr BookmarkEntryPtr; typedef std::shared_ptr BookmarkRangeEntryPtr; struct BookmarkEntryCompare : public std::binary_function { bool operator()(const BookmarkEntryPtr a, BookmarkEntryPtr b) const { return a->frequency < b->frequency; } }; struct BookmarkRangeEntryCompare : public std::binary_function { bool operator()(const BookmarkRangeEntryPtr a, BookmarkRangeEntryPtr b) const { return a->freq < b->freq; } }; typedef std::vector BookmarkList; typedef std::vector BookmarkRangeList; typedef std::map BookmarkMap; typedef std::map BookmarkMapSorted; typedef std::vector BookmarkNames; typedef std::map BookmarkExpandState; 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); 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); void setExpandState(std::string groupName, bool state); bool getExpandState(std::string groupName); void updateActiveList(); void updateBookmarks(); void updateBookmarks(std::string group); void addRecent(DemodulatorInstancePtr demod); void addRecent(BookmarkEntryPtr be); void removeRecent(BookmarkEntryPtr be); const BookmarkList& getRecents(); void clearRecents(); void removeActive(DemodulatorInstancePtr demod); void addRange(BookmarkRangeEntryPtr re); void removeRange(BookmarkRangeEntryPtr re); const BookmarkRangeList& getRanges(); void clearRanges(); static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt); static std::wstring getActiveDisplayName(DemodulatorInstancePtr demod); protected: void trimRecents(); BookmarkEntryPtr demodToBookmarkEntry(DemodulatorInstancePtr demod); BookmarkEntryPtr nodeToBookmark(DataNode *node); BookmarkMap bmData; BookmarkMapSorted bmDataSorted; BookmarkList recents; BookmarkRangeList ranges; bool rangesSorted; std::recursive_mutex busy_lock; BookmarkExpandState expandState; //represents an empty BookMarkList that is returned by reference by some functions. static const BookmarkList emptyResults; };