Audacity 3.2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PluginDataModel Class Referencefinal

!brief A plugins list model that can be attached to wxDataViewCtrl More...

#include <PluginDataModel.h>

Inheritance diagram for PluginDataModel:
[legend]
Collaboration diagram for PluginDataModel:
[legend]

Public Types

enum  Column {
  ColumnName , ColumnType , ColumnPath , ColumnState ,
  ColumnNum
}
 

Public Member Functions

 PluginDataModel (int filterEffectCategory=-1, int filterState=-1, const wxString &filterType={}, const wxString &filterExpr={})
 
wxDataViewItem GetItemForRow (uint32_t row) const
 
bool GetRowForItem (const wxDataViewItem &item, uint32_t &row) const
 
uint32_t GetRowCount () const
 
bool IsEnabled (const wxDataViewItem &, unsigned) const override
 
bool HasContainerColumns (const wxDataViewItem &item) const override
 
void SetFilterType (const wxString &type)
 
wxString GetFilterType () const
 
void SetFilterState (int state)
 
int GetFilterState () const
 
void SetFilterExpr (const wxString &expr)
 
wxString GetFilterExpr () const
 
void SetFilterCategory (int category)
 
int GetFilterCategory () const
 
int Compare (const wxDataViewItem &item1, const wxDataViewItem &item2, unsigned column, bool ascending) const override
 
void ApplyChanges (const std::function< bool(int, int, const wxString &)> &progressUpdateFn, const std::function< void(const TranslatableString &)> &errorFn)
 
unsigned GetColumnCount () const override
 
wxString GetColumnType (unsigned col) const override
 
void GetValue (wxVariant &variant, const wxDataViewItem &item, unsigned col) const override
 
bool SetValue (const wxVariant &variant, const wxDataViewItem &item, unsigned col) override
 
wxDataViewItem GetParent (const wxDataViewItem &item) const override
 
bool IsContainer (const wxDataViewItem &item) const override
 
unsigned GetChildren (const wxDataViewItem &item, wxDataViewItemArray &children) const override
 
PluginDescriptorGetPlugin (wxDataViewItem item)
 
bool IsListModel () const override
 

Private Member Functions

void UpdateFilter ()
 
bool IsFilterEmpty () const
 

Private Attributes

std::vector< std::pair< PluginDescriptor *, bool > > mPluginStateModel
 
std::vector< void * > mIndexFilterMap
 
wxString mFilterType
 
wxString mFilterExpr
 
int mFilterState {-1}
 
int mFilterCategory {-1}
 

Static Private Attributes

static const void * RowIdRoot {}
 

Detailed Description

!brief A plugins list model that can be attached to wxDataViewCtrl

Definition at line 19 of file PluginDataModel.h.

Member Enumeration Documentation

◆ Column

Enumerator
ColumnName 
ColumnType 
ColumnPath 
ColumnState 
ColumnNum 

Definition at line 33 of file PluginDataModel.h.

Constructor & Destructor Documentation

◆ PluginDataModel()

PluginDataModel::PluginDataModel ( int  filterEffectCategory = -1,
int  filterState = -1,
const wxString &  filterType = {},
const wxString &  filterExpr = {} 
)

Definition at line 37 of file PluginDataModel.cpp.

41 : mFilterType(filterType)
42 , mFilterExpr(filterExpr)
43 , mFilterState(filterState)
44 , mFilterCategory(filterEffectCategory)
45{
46 auto& pm = PluginManager::Get();
47 for(auto& desc : pm.AllPlugins())
48 {
49 if ((desc.GetPluginType() != PluginTypeEffect || desc.GetEffectType() == EffectTypeHidden) &&
50 desc.GetPluginType() != PluginTypeStub)
51 {
52 continue;
53 }
54 mPluginStateModel.emplace_back(&desc, desc.IsEnabled());
55 }
57}
@ EffectTypeHidden
@ PluginTypeStub
@ PluginTypeEffect
wxString mFilterExpr
wxString mFilterType
std::vector< std::pair< PluginDescriptor *, bool > > mPluginStateModel
static PluginManager & Get()
const TranslatableString desc
Definition: ExportPCM.cpp:51

References anonymous_namespace{ExportPCM.cpp}::desc, EffectTypeHidden, PluginManager::Get(), mPluginStateModel, PluginTypeEffect, PluginTypeStub, and UpdateFilter().

Here is the call graph for this function:

Member Function Documentation

◆ ApplyChanges()

void PluginDataModel::ApplyChanges ( const std::function< bool(int, int, const wxString &)> &  progressUpdateFn,
const std::function< void(const TranslatableString &)> &  errorFn 
)

Definition at line 171 of file PluginDataModel.cpp.

173{
174 auto& mm = ModuleManager::Get();
175 auto& pm = PluginManager::Get();
176
177 const auto enableCount = std::count_if(
178 mPluginStateModel.begin(),
179 mPluginStateModel.end(),
180 [](const auto& p) { return p.first->GetPluginType() == PluginTypeStub && p.second; }
181 );
182
183 auto counter = 0;
184 for(const auto& [desc, enabled] : mPluginStateModel)
185 {
186 if(desc->GetPluginType() == PluginTypeStub && enabled)
187 {
188 if(progressUpdateFn)
189 {
190 if(!progressUpdateFn(++counter, enableCount, desc->GetPath()))
191 break;
192 }
193
194 TranslatableString errMsg;
195 if (mm.RegisterEffectPlugin(desc->GetProviderID(), desc->GetPath(), errMsg))
196 pm.UnregisterPlugin(desc->GetProviderID() + wxT("_") + desc->GetPath());
197 else if (errorFn)
198 {
199 errorFn(XO("Effect or Command at %s failed to register:\n%s")
200 .Format( desc->GetPath(), !errMsg.empty() ? errMsg : XO("Unknown error") ));
201 }
202 }
203 else
204 desc->SetEnabled(enabled);
205 }
206 pm.Save();
207 pm.NotifyPluginsChanged();
208}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
Abstract base class used in importing a file.
static ModuleManager & Get()
Holds a msgid for the translation catalog; may also bind format arguments.

References anonymous_namespace{ExportPCM.cpp}::desc, TranslatableString::empty(), ModuleManager::Get(), PluginManager::Get(), mPluginStateModel, PluginTypeStub, wxT(), and XO().

Here is the call graph for this function:

◆ Compare()

int PluginDataModel::Compare ( const wxDataViewItem &  item1,
const wxDataViewItem &  item2,
unsigned  column,
bool  ascending 
) const
override

Definition at line 147 of file PluginDataModel.cpp.

149{
150 switch(column)
151 {
152 case ColumnName:
153 case ColumnPath:
154 case ColumnType:
155 {
156 wxVariant value1;
157 GetValue(value1, item1, column);
158 wxVariant value2;
159 GetValue(value2, item2, column);
160 const auto result = value1.GetString().CmpNoCase(value2.GetString());
161 //Prevent row "jumping" when strings are equal
162 if(result == 0)
163 return ascending == wxPtrToUInt(item1.GetID()) > wxPtrToUInt(item2.GetID()) ? 1 : -1;
164 return ascending ? result : -result;
165 } break;
166 default:
167 return wxDataViewModel::Compare(item1, item2, column, ascending);
168 }
169}
void GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned col) const override

References ColumnName, ColumnPath, ColumnType, and GetValue().

Here is the call graph for this function:

◆ GetChildren()

unsigned PluginDataModel::GetChildren ( const wxDataViewItem &  item,
wxDataViewItemArray &  children 
) const
override

Definition at line 292 of file PluginDataModel.cpp.

293{
294 children.clear();
295 if(item.GetID() != RowIdRoot)
296 return 0;
297
298 children.reserve(mIndexFilterMap.size());
299 for(const auto index : mIndexFilterMap)
300 children.push_back(wxDataViewItem(index));
301
302 return children.size();
303}
std::vector< void * > mIndexFilterMap
static const void * RowIdRoot

References mIndexFilterMap, and RowIdRoot.

◆ GetColumnCount()

unsigned PluginDataModel::GetColumnCount ( ) const
override

Definition at line 210 of file PluginDataModel.cpp.

211{
212 return 4;
213}

◆ GetColumnType()

wxString PluginDataModel::GetColumnType ( unsigned  col) const
override

Definition at line 215 of file PluginDataModel.cpp.

216{
217 switch(col)
218 {
219 case ColumnName:
220 case ColumnType:
221 case ColumnPath:
222 return "string";
223 case ColumnState:
224 return "bool";
225 default: break;
226 }
227 return "null";
228}

References ColumnName, ColumnPath, ColumnState, and ColumnType.

◆ GetFilterCategory()

int PluginDataModel::GetFilterCategory ( ) const

Definition at line 142 of file PluginDataModel.cpp.

143{
144 return mFilterCategory;
145}

References mFilterCategory.

◆ GetFilterExpr()

wxString PluginDataModel::GetFilterExpr ( ) const

Definition at line 128 of file PluginDataModel.cpp.

129{
130 return mFilterExpr;
131}

References mFilterExpr.

◆ GetFilterState()

int PluginDataModel::GetFilterState ( ) const

Definition at line 114 of file PluginDataModel.cpp.

115{
116 return mFilterState;
117}

References mFilterState.

◆ GetFilterType()

wxString PluginDataModel::GetFilterType ( ) const

Definition at line 100 of file PluginDataModel.cpp.

101{
102 return mFilterType;
103}

References mFilterType.

◆ GetItemForRow()

wxDataViewItem PluginDataModel::GetItemForRow ( uint32_t  row) const

Definition at line 59 of file PluginDataModel.cpp.

60{
61 if(row < mIndexFilterMap.size())
62 return wxDataViewItem { mIndexFilterMap[row] };
63 return {};
64}

References mIndexFilterMap.

◆ GetParent()

wxDataViewItem PluginDataModel::GetParent ( const wxDataViewItem &  item) const
override

Definition at line 282 of file PluginDataModel.cpp.

283{
284 return {};
285}

◆ GetPlugin()

PluginDescriptor * PluginDataModel::GetPlugin ( wxDataViewItem  item)

Definition at line 305 of file PluginDataModel.cpp.

306{
307 if(!item.IsOk())
308 return nullptr;
309 const auto index = GetRowIndex(item);
310 if(index >= mPluginStateModel.size())
311 return nullptr;
312
313 return mPluginStateModel[index].first;
314}
uint32_t GetRowIndex(const wxDataViewItem &item)

References GetRowIndex(), and mPluginStateModel.

Here is the call graph for this function:

◆ GetRowCount()

uint32_t PluginDataModel::GetRowCount ( ) const

Definition at line 76 of file PluginDataModel.cpp.

77{
78 return mIndexFilterMap.size();
79}

References mIndexFilterMap.

◆ GetRowForItem()

bool PluginDataModel::GetRowForItem ( const wxDataViewItem &  item,
uint32_t &  row 
) const

Definition at line 66 of file PluginDataModel.cpp.

67{
68 if(item.IsOk())
69 {
70 row = GetRowIndex(item);
71 return row < mIndexFilterMap.size();
72 }
73 return false;
74}

References GetRowIndex(), and mIndexFilterMap.

Here is the call graph for this function:

◆ GetValue()

void PluginDataModel::GetValue ( wxVariant &  variant,
const wxDataViewItem &  item,
unsigned  col 
) const
override

Definition at line 230 of file PluginDataModel.cpp.

231{
232 assert(item.IsOk());
233
234 const auto index = GetRowIndex(item);
235 if(index >= mPluginStateModel.size())
236 return;
237
238 const auto [descriptor, state] = mPluginStateModel[index];
239 switch(col)
240 {
241 case ColumnName:
242 {
243 if (descriptor->GetPluginType() == PluginTypeEffect)
244 variant = descriptor->GetSymbol().Translation();
245 // This is not right and will not work when other plugin types are added.
246 // But it's presumed that the plugin manager dialog will be fully developed
247 // by then.
248 else if (descriptor->GetPluginType() == PluginTypeStub)
249 {
250 wxFileName fname{ descriptor->GetPath() };
251 variant = fname.GetName().Trim(false).Trim(true);
252 }
253 } break;
254 case ColumnPath:
255 variant = descriptor->GetPath();
256 break;
257 case ColumnType:
258 variant = descriptor->GetEffectFamily();
259 break;
260 case ColumnState:
261 variant = state;
262 break;
263 default:
264 break;
265 }
266}

References ColumnName, ColumnPath, ColumnState, ColumnType, GetRowIndex(), mPluginStateModel, PluginTypeEffect, and PluginTypeStub.

Referenced by Compare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasContainerColumns()

bool PluginDataModel::HasContainerColumns ( const wxDataViewItem &  item) const
override

Definition at line 86 of file PluginDataModel.cpp.

87{
88 return item.GetID() == RowIdRoot;
89}

References RowIdRoot.

◆ IsContainer()

bool PluginDataModel::IsContainer ( const wxDataViewItem &  item) const
override

Definition at line 287 of file PluginDataModel.cpp.

288{
289 return item.GetID() == RowIdRoot;
290}

References RowIdRoot.

◆ IsEnabled()

bool PluginDataModel::IsEnabled ( const wxDataViewItem &  item,
unsigned  col 
) const
override

Definition at line 81 of file PluginDataModel.cpp.

82{
83 return true;
84}

◆ IsFilterEmpty()

bool PluginDataModel::IsFilterEmpty ( ) const
private

Definition at line 357 of file PluginDataModel.cpp.

358{
359 return mFilterState == -1 && mFilterType.empty() && mFilterExpr.empty();
360}

References mFilterExpr, mFilterState, and mFilterType.

◆ IsListModel()

bool PluginDataModel::IsListModel ( ) const
inlineoverride

Definition at line 78 of file PluginDataModel.h.

78{ return false; }

◆ SetFilterCategory()

void PluginDataModel::SetFilterCategory ( int  category)

Definition at line 133 of file PluginDataModel.cpp.

134{
135 if(mFilterCategory != category)
136 {
137 mFilterCategory = category;
138 UpdateFilter();
139 }
140}

References mFilterCategory, and UpdateFilter().

Here is the call graph for this function:

◆ SetFilterExpr()

void PluginDataModel::SetFilterExpr ( const wxString &  expr)

Definition at line 119 of file PluginDataModel.cpp.

120{
121 if(mFilterExpr != expr)
122 {
123 mFilterExpr = expr;
124 UpdateFilter();
125 }
126}

References mFilterExpr, and UpdateFilter().

Here is the call graph for this function:

◆ SetFilterState()

void PluginDataModel::SetFilterState ( int  state)

Definition at line 105 of file PluginDataModel.cpp.

106{
107 if(mFilterState != state)
108 {
109 mFilterState = state;
110 UpdateFilter();
111 }
112}

References mFilterState, and UpdateFilter().

Here is the call graph for this function:

◆ SetFilterType()

void PluginDataModel::SetFilterType ( const wxString &  type)

Definition at line 91 of file PluginDataModel.cpp.

92{
93 if(mFilterType != type)
94 {
95 mFilterType = type;
97 }
98}

References mFilterType, and UpdateFilter().

Here is the call graph for this function:

◆ SetValue()

bool PluginDataModel::SetValue ( const wxVariant &  variant,
const wxDataViewItem &  item,
unsigned  col 
)
override

Definition at line 268 of file PluginDataModel.cpp.

269{
270 if(col == ColumnState)
271 {
272 const auto index = GetRowIndex(item);
273 if(index < mPluginStateModel.size())
274 {
275 mPluginStateModel[index].second = variant.GetBool();
276 return true;
277 }
278 }
279 return false;
280}

References ColumnState, GetRowIndex(), and mPluginStateModel.

Here is the call graph for this function:

◆ UpdateFilter()

void PluginDataModel::UpdateFilter ( )
private

Definition at line 316 of file PluginDataModel.cpp.

317{
318 auto textFilters = wxSplit(mFilterExpr, ' ');
319 std::for_each(
320 textFilters.begin(),
321 textFilters.end(),
322 [](wxString& str) { str.MakeLower(); }
323 );
324 mIndexFilterMap.clear();
325
326 auto filterFn = [=](PluginDescriptor* desc, bool state)
327 {
328 if((!mFilterType.empty() && desc->GetProviderID() != mFilterType) ||
329 (mFilterState != -1 && state != static_cast<bool>(mFilterState)) ||
330 (mFilterCategory != -1 && mFilterCategory != desc->GetEffectType()))
331 {
332 return false;
333 }
334
335 for(auto& filter : textFilters)
336 {
337 if((desc->GetPluginType() != PluginTypeEffect ||
338 desc->GetSymbol().Translation().Lower().Find(filter) == wxNOT_FOUND) &&
339 (desc->GetPluginType() != PluginTypeStub ||
340 wxFileName(desc->GetPath()).GetName().Lower().Find(filter) == wxNOT_FOUND))
341 {
342 return false;
343 }
344 }
345 return true;
346 };
347
348 for(uint32_t i = 0; i < mPluginStateModel.size(); ++i)
349 {
350 const auto [desc, state] = mPluginStateModel[i];
351 if(filterFn(desc, state))
352 mIndexFilterMap.push_back(MakeRow(i));
353 }
354 Cleared();
355}
#define str(a)
void * MakeRow(uint32_t index)
wxString Translation() const

References anonymous_namespace{ExportPCM.cpp}::desc, MakeRow(), mFilterCategory, mFilterExpr, mFilterState, mFilterType, mIndexFilterMap, mPluginStateModel, PluginTypeEffect, PluginTypeStub, str, and TranslatableString::Translation().

Referenced by PluginDataModel(), SetFilterCategory(), SetFilterExpr(), SetFilterState(), and SetFilterType().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mFilterCategory

int PluginDataModel::mFilterCategory {-1}
private

Definition at line 29 of file PluginDataModel.h.

Referenced by GetFilterCategory(), SetFilterCategory(), and UpdateFilter().

◆ mFilterExpr

wxString PluginDataModel::mFilterExpr
private

Definition at line 27 of file PluginDataModel.h.

Referenced by GetFilterExpr(), IsFilterEmpty(), SetFilterExpr(), and UpdateFilter().

◆ mFilterState

int PluginDataModel::mFilterState {-1}
private

Definition at line 28 of file PluginDataModel.h.

Referenced by GetFilterState(), IsFilterEmpty(), SetFilterState(), and UpdateFilter().

◆ mFilterType

wxString PluginDataModel::mFilterType
private

Definition at line 26 of file PluginDataModel.h.

Referenced by GetFilterType(), IsFilterEmpty(), SetFilterType(), and UpdateFilter().

◆ mIndexFilterMap

std::vector<void*> PluginDataModel::mIndexFilterMap
private

◆ mPluginStateModel

std::vector<std::pair<PluginDescriptor*, bool> > PluginDataModel::mPluginStateModel
private

◆ RowIdRoot

const void * PluginDataModel::RowIdRoot {}
staticprivate

Definition at line 21 of file PluginDataModel.h.

Referenced by GetChildren(), HasContainerColumns(), and IsContainer().


The documentation for this class was generated from the following files: