1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //
5 //  plugin_list.cpp
6 //  (C) Copyright 2018 Tim E. Real (terminator356 on users dot sourceforge dot net)
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; version 2 of
11 //  the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 //=========================================================
23 
24 #include "plugin_list.h"
25 
26 // For debugging output: Uncomment the fprintf section.
27 #define DEBUG_PLUGIN_LIST(dev, format, args...) // std::fprintf(dev, format, ##args);
28 
29 namespace MusEPlugin {
30 
31 //---------------------------------------------------------
32 //   find
33 //---------------------------------------------------------
34 
find(const PluginInfoString_t & file,const PluginInfoString_t & uri,const PluginInfoString_t & label,PluginScanInfoStruct::PluginType_t types) const35 PluginScanInfoRef PluginScanList::find(const PluginInfoString_t& file,
36                                        const PluginInfoString_t& uri,
37                                        const PluginInfoString_t& label,
38                                        PluginScanInfoStruct::PluginType_t types) const
39 {
40   const bool f_empty = file.isEmpty();
41   const bool u_empty = uri.isEmpty();
42   const bool l_empty = label.isEmpty();
43   for(ciPluginScanList i = begin(); i != end(); ++i)
44   {
45     const PluginScanInfoRef& ref = *i;
46     if((ref->info()._type & types) &&
47        //(!u_empty || f_empty || file == ref->info()._completeBaseName) &&
48        (!u_empty || f_empty || file == ref->info().filePath()) &&
49        (u_empty  || uri   == ref->info()._uri) &&
50        (!u_empty || l_empty || label == ref->info()._label))
51       return ref;
52   }
53   //fprintf(stderr, "Plugin <%s> not found\n", name.toLatin1().constData());
54   return PluginScanInfoRef();
55 }
56 
find(const PluginScanInfoStruct & info) const57 PluginScanInfoRef PluginScanList::find(const PluginScanInfoStruct& info) const
58 {
59   //const bool f_empty = info._completeBaseName.isEmpty();
60   const bool f_empty = info.filePath().isEmpty();
61   const bool u_empty = info._uri.isEmpty();
62   const bool l_empty = info._label.isEmpty();
63   for(ciPluginScanList i = begin(); i != end(); ++i)
64   {
65     const PluginScanInfoRef& ref = *i;
66     if((info._type == ref->info()._type) &&
67        //(!u_empty || f_empty || info._completeBaseName == ref->info()._completeBaseName) &&
68        (!u_empty || f_empty || info.filePath() == ref->info().filePath()) &&
69        (u_empty  || info._uri == ref->info()._uri) &&
70        (!u_empty || l_empty || info._label == ref->info()._label))
71           return ref;
72   }
73   //fprintf(stderr, "Plugin <%s> not found\n", name.toLatin1().constData());
74   return PluginScanInfoRef();
75 }
76 
77 //---------------------------------------------------------
78 //   add
79 //---------------------------------------------------------
80 
add(PluginScanInfo * info)81 bool PluginScanList::add(PluginScanInfo* info)
82 {
83 // Ignore duplicates.
84 // NOTE: For now we don't ignore anything down at this low-level. Ignoring is done more at higher levels.
85 //   PluginScanInfoRef psi = find(info->info()._completeBaseName, info->info()._label);
86 //   if(!psi)
87 //   {
88 //     fprintf(stderr, "PluginScanList::add: Ignoring %s: path:%s duplicate path of %s\n",
89 //             info->info()._label.c_str(),
90 //             info->info().fileName().c_str(),
91 //             psi->info().fileName().c_str());
92 //     return false;
93 //   }
94 
95   // Takes ownership of the object.
96   push_back(PluginScanInfoRef(info));
97   return true;
98 }
99 
100 } // namespace MusEPlugin
101