forked from Paremo/foo_bbookmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmark_playlist_callback.cpp
More file actions
126 lines (92 loc) · 3.29 KB
/
bookmark_playlist_callback.cpp
File metadata and controls
126 lines (92 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "stdafx.h"
#include "bookmark_core.h"
#include "bookmark_list_control.h"
#include "bookmark_playlist_callback.h"
using namespace glb;
unsigned bookmark_playlist_callback::get_flags() {
return flag_playlist_ops;
}
void bookmark_playlist_callback::on_playlists_removing(const bit_array& p_mask, t_size p_old_count, t_size p_new_count) {
if (!cfg_monitor.get()) {
return;
}
if (g_guiLists.empty()) {
return;
}
auto f = p_mask.find_first(true, 0, p_old_count);
for (auto n = f; n < p_old_count; n = p_mask.find_next(true, n, p_old_count))
{
bool bchanged = false;
pfc::string8 dbgstr;
playlist_manager_v5::get()->playlist_get_name(n, dbgstr);
playlist_manager_v5::get()->playlist_get_name(n - 1, dbgstr);
GUID plguid = playlist_manager_v5::get()->playlist_get_guid(n);
pfc::string8 str_plguid = pfc::print_guid(plguid);
bit_array_bittable changeMask(bit_array_false(), g_primaryGuiList->GetItemCount());
const std::vector<bookmark_t> masterList = g_store.GetMasterList();
auto& found_it = std::find_if(masterList.begin(), masterList.end(), [&](const bookmark_t& elem) {
return (pfc::guid_equal(plguid, elem.guid_playlist));
});
while (found_it != masterList.end()) {
bchanged = true;
/*found_it->guid_playlist = plguid;*/
auto pos = std::distance(masterList.begin(), found_it);
changeMask.set(pos, true);
bookmark_t rec = g_store.GetItem(pos);
rec.playlist = "";
rec.guid_playlist = pfc::guid_null;
g_store.SetItem(pos, rec);
found_it = std::find_if(found_it + 1, masterList.end(), [&](const bookmark_t& elem) {
return (pfc::guid_equal(plguid, elem.guid_playlist));
});
}
if (bchanged) {
for (auto gui : g_guiLists) {
//mask positions from master list, not get_selected()
if (gui->GetSortOrder()) {
gui->GetSortOrderedMask(changeMask);
}
gui->ReloadItems(changeMask);
}
g_store.Write();
}
}
}
void bookmark_playlist_callback::on_playlist_renamed(t_size p_index, const char* p_new_name, t_size p_new_name_len) {
if (!cfg_monitor.get()) {
return;
}
if (g_guiLists.empty()) {
return;
}
bool bchanged = false;
GUID plguid = playlist_manager_v5::get()->playlist_get_guid(p_index);
pfc::string8 str_plguid = pfc::print_guid(plguid);
bit_array_bittable changeMask(bit_array_false(), g_primaryGuiList->GetItemCount());
const std::vector<bookmark_t> masterList = g_store.GetMasterList();
auto & found_it = std::find_if(masterList.begin(), masterList.end(), [&](const bookmark_t& elem) {
return (pfc::guid_equal(plguid, elem.guid_playlist));
});
while (found_it != masterList.end()) {
bchanged = true;
auto pos = std::distance(masterList.begin(), found_it);
bookmark_t rec = g_store.GetItem(pos);
rec.playlist = pfc::string8(p_new_name).c_str();
g_store.SetItem(pos, rec);
changeMask.set(pos, true);
found_it = std::find_if(found_it+1, masterList.end(), [&](const bookmark_t& elem) {
return (pfc::guid_equal(plguid, elem.guid_playlist));
});
}
if (bchanged) {
for (auto gui : g_guiLists) {
//mask positions from master list, not get_selected()
if (gui->GetSortOrder()) {
gui->GetSortOrderedMask(changeMask);
}
gui->ReloadItems(changeMask);
}
g_store.Write();
}
}
static service_factory_single_t< bookmark_playlist_callback > bookmark_playlist_callback_service;