Hugin trunk 0.1
Loading...
Searching...
No Matches
PluginItems.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
11/*
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This software is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public
23 * License along with this software. If not, see
24 * <http://www.gnu.org/licenses/>.
25 *
26 */
27
28#include <wx/wfstream.h>
29#include <wx/txtstrm.h>
30#include <hugin_version.h>
31
32//for natural sorting
34#include "PluginItems.h"
35
36//for console/debugging output
37#include <iostream>
38
40{
41 int res=doj::alphanum_comp(
42 std::string(item1.GetCategory().mb_str(wxConvLocal)),
43 std::string(item2.GetCategory().mb_str(wxConvLocal)));
44 if(res<0)
45 {
46 return true;
47 }
48 else
49 {
50 if(res==0)
51 {
52 return (doj::alphanum_comp(
53 std::string(item1.GetName().mb_str(wxConvLocal)),
54 std::string(item2.GetName().mb_str(wxConvLocal)))<0);
55 }
56 else
57 {
58 return false;
59 };
60 };
61};
62
64{
65 return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
66};
67
69{
70 // default category if nothing else found
71 m_category = _("Miscellaneous");
72 // default plugin name if nothing else found is the file name
73 m_name=filename.GetFullName();
74 m_filename=filename;
76 m_validAPI=true;
78};
79
81{
82 // use wxWidgets to read the plugin files in search for meta data
83 wxFileInputStream in(m_filename.GetFullPath());
85
86 // read the plugin file and search if it contains meta data
87 bool foundCategory=false;
88 bool foundName=false;
89 bool foundAPImin=false;
90 bool foundAPImax=false;
91 bool foundSYS=false;
92 bool foundDescription=false;
93#if defined __WXMSW__
94 wxString system(wxT("win"));
95#elif defined __WXMAC__
96 wxString system(wxT("mac"));
97#else
98 wxString system(wxT("nix"));
99#endif
100 wxString tagSYS(wxT("@sys"));
101 wxString tagAPImin(wxT("@api-min"));
102 wxString tagAPImax(wxT("@api-max"));
103 wxString tagCategory(wxT("@category"));
104 wxString tagName(wxT("@name"));
105 wxString tagDescription(wxT("@description"));
106
107 // tell me who you are processing
108 std::cout << m_filename.GetFullPath().mb_str(wxConvLocal) << std::endl;
109
110
111 while(!in.Eof() && !(foundCategory && foundName && foundAPImin && foundAPImax && foundSYS && foundDescription))
112 {
113 int pos;
114 wxString line=text.ReadLine();
115 //convert to lower case to make search for tag name case insensitive
116 wxString lowerLine=line.Lower();
117 pos=lowerLine.Find(tagSYS);
118 if(pos!=wxNOT_FOUND)
119 {
120 foundSYS=true;
121 pos=lowerLine.Find(system);
122 if(pos==wxNOT_FOUND)
123 {
124 m_validAPI=false;
125 std::cout << " fails @sys" << std::endl;
126 };
127 continue;
128 };
129 pos=lowerLine.Find(tagAPImin);
130 if(pos!=wxNOT_FOUND)
131 {
132 foundAPImin=true;
133 wxString APImin = line.Mid(pos+1+tagAPImin.length()).Trim().Trim(false);
135 {
136 m_validAPI=false;
137 std::cout << " fails @api-min" << std::endl;
138 };
139 continue;
140 };
141 pos=lowerLine.Find(tagAPImax);
142 if(pos!=wxNOT_FOUND)
143 {
144 foundAPImax=true;
145 wxString APImax = line.Mid(pos+1+tagAPImax.length()).Trim().Trim(false);
147 {
148 m_validAPI=false;
149 std::cout << " fails @api-max" << std::endl;
150 };
151 continue;
152 };
154 if(pos!=wxNOT_FOUND)
155 {
156 m_category = line.Mid(pos+1+tagCategory.length()).Trim().Trim(false);
157 foundCategory=true;
158 std::cout << " CAT:" << m_category.mb_str(wxConvLocal) << std::endl;
159 continue;
160 };
161 pos=lowerLine.Find(tagName);
162 if(pos!=wxNOT_FOUND)
163 {
164 m_name = line.Mid(pos+1+tagName.length()).Trim().Trim(false);
165 foundName=true;
166 std::cout << " NAM:" << m_name.mb_str(wxConvLocal) << std::endl;
167 continue;
168 };
170 if(pos!=wxNOT_FOUND)
171 {
172 m_description = line.Mid(pos+1+tagDescription.length()).Trim().Trim(false);
173 foundDescription=true;
174 continue;
175 };
176 };
177};
178
179const bool PluginItem::IsAPIValid() const
180{
181 return m_validAPI;
182};
183
185{
186 return m_category;
187};
188
190{
191 return m_filename;
192};
193
195{
196 return m_name;
197};
198
200{
201 return m_description;
202};
options wxIntPtr item2
bool compareVersion(wxString v1, wxString v2)
bool comparePluginItem(PluginItem item1, PluginItem item2)
compares 2 plugin with category and name
Reading python plugins metadata.
class for generating plugin menu items
Definition PluginItems.h:36
const wxFileName GetFilename() const
returns filename
bool m_validAPI
Definition PluginItems.h:58
const bool IsAPIValid() const
returns true, if plugin can run on given system and version
void ParseMetadata()
const wxString GetCategory() const
return category name
PluginItem(wxFileName filename)
constructor
wxString m_name
Definition PluginItems.h:55
const wxString GetDescription() const
return description
wxFileName m_filename
Definition PluginItems.h:56
wxString m_description
Definition PluginItems.h:57
wxString m_category
Definition PluginItems.h:54
const wxString GetName() const
return name from metadata
int alphanum_comp(const std::string &l, const std::string &r)
Compare l and r with the same semantics as strcmp(), but with the "Alphanum Algorithm" which produces...
Definition alphanum.cpp:119
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41