00001
00002
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <wx/wfstream.h>
00029 #include <wx/txtstrm.h>
00030 #include <hugin_version.h>
00031
00032
00033 #include "hugin_utils/alphanum.h"
00034 #include "PluginItems.h"
00035
00036
00037 #include <iostream>
00038
00039 bool comparePluginItem(PluginItem item1,PluginItem item2)
00040 {
00041 int res=doj::alphanum_comp(
00042 std::string(item1.GetCategory().mb_str(wxConvLocal)),
00043 std::string(item2.GetCategory().mb_str(wxConvLocal)));
00044 if(res<0)
00045 {
00046 return true;
00047 }
00048 else
00049 {
00050 if(res==0)
00051 {
00052 return (doj::alphanum_comp(
00053 std::string(item1.GetName().mb_str(wxConvLocal)),
00054 std::string(item2.GetName().mb_str(wxConvLocal)))<0);
00055 }
00056 else
00057 {
00058 return false;
00059 };
00060 };
00061 };
00062
00063 bool compareVersion(wxString v1, wxString v2)
00064 {
00065 return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
00066 };
00067
00068 PluginItem::PluginItem(wxFileName filename)
00069 {
00070
00071 m_category = _("Miscellaneous");
00072
00073 m_name=filename.GetFullName();
00074 m_filename=filename;
00075 m_description=wxT("");
00076 m_validAPI=true;
00077 ParseMetadata();
00078 };
00079
00080 void PluginItem::ParseMetadata()
00081 {
00082
00083 wxFileInputStream in(m_filename.GetFullPath());
00084 wxTextInputStream text(in);
00085
00086
00087 bool foundCategory=false;
00088 bool foundName=false;
00089 bool foundAPImin=false;
00090 bool foundAPImax=false;
00091 bool foundSYS=false;
00092 bool foundDescription=false;
00093 #if defined __WXMSW__
00094 wxString system(wxT("win"));
00095 #elif defined __WXMAC__
00096 wxString system(wxT("mac"));
00097 #else
00098 wxString system(wxT("nix"));
00099 #endif
00100 wxString tagSYS(wxT("@sys"));
00101 wxString tagAPImin(wxT("@api-min"));
00102 wxString tagAPImax(wxT("@api-max"));
00103 wxString tagCategory(wxT("@category"));
00104 wxString tagName(wxT("@name"));
00105 wxString tagDescription(wxT("@description"));
00106 int pos;
00107
00108
00109 std::cout << m_filename.GetFullPath().mb_str(wxConvLocal) << std::endl;
00110
00111
00112 while(!in.Eof() && !(foundCategory && foundName && foundAPImin && foundAPImax && foundSYS && foundDescription))
00113 {
00114 wxString line=text.ReadLine();
00115
00116 wxString lowerLine=line.Lower();
00117 pos=lowerLine.Find(tagSYS);
00118 if(pos!=wxNOT_FOUND)
00119 {
00120 foundSYS=true;
00121 pos=lowerLine.Find(system);
00122 if(pos==wxNOT_FOUND)
00123 {
00124 m_validAPI=false;
00125 std::cout << " fails @sys" << std::endl;
00126 };
00127 continue;
00128 };
00129 pos=lowerLine.Find(tagAPImin);
00130 if(pos!=wxNOT_FOUND)
00131 {
00132 foundAPImin=true;
00133 wxString APImin = line.Mid(pos+1+tagAPImin.length()).Trim().Trim(false);
00134 if(compareVersion(wxT(HUGIN_API_VERSION),APImin))
00135 {
00136 m_validAPI=false;
00137 std::cout << " fails @api-min" << std::endl;
00138 };
00139 continue;
00140 };
00141 pos=lowerLine.Find(tagAPImax);
00142 if(pos!=wxNOT_FOUND)
00143 {
00144 foundAPImax=true;
00145 wxString APImax = line.Mid(pos+1+tagAPImax.length()).Trim().Trim(false);
00146 if(compareVersion(APImax,wxT(HUGIN_API_VERSION)))
00147 {
00148 m_validAPI=false;
00149 std::cout << " fails @api-max" << std::endl;
00150 };
00151 continue;
00152 };
00153 pos=lowerLine.Find(tagCategory);
00154 if(pos!=wxNOT_FOUND)
00155 {
00156 m_category = line.Mid(pos+1+tagCategory.length()).Trim().Trim(false);
00157 foundCategory=true;
00158 std::cout << " CAT:" << m_category.mb_str(wxConvLocal) << std::endl;
00159 continue;
00160 };
00161 pos=lowerLine.Find(tagName);
00162 if(pos!=wxNOT_FOUND)
00163 {
00164 m_name = line.Mid(pos+1+tagName.length()).Trim().Trim(false);
00165 foundName=true;
00166 std::cout << " NAM:" << m_name.mb_str(wxConvLocal) << std::endl;
00167 continue;
00168 };
00169 pos=lowerLine.Find(tagDescription);
00170 if(pos!=wxNOT_FOUND)
00171 {
00172 m_description = line.Mid(pos+1+tagDescription.length()).Trim().Trim(false);
00173 foundDescription=true;
00174 continue;
00175 };
00176 };
00177 };
00178
00179 const bool PluginItem::IsAPIValid() const
00180 {
00181 return m_validAPI;
00182 };
00183
00184 const wxString PluginItem::GetCategory() const
00185 {
00186 return m_category;
00187 };
00188
00189 const wxFileName PluginItem::GetFilename() const
00190 {
00191 return m_filename;
00192 };
00193
00194 const wxString PluginItem::GetName() const
00195 {
00196 return m_name;
00197 };
00198
00199 const wxString PluginItem::GetDescription() const
00200 {
00201 return m_description;
00202 };