00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014
00015 #include "wx/wxprec.h"
00016
00017 #ifdef __BORLANDC__
00018 #pragma hdrstop
00019 #endif
00020
00021 #ifndef WX_PRECOMP
00022 #include "wx/wx.h"
00023 #endif
00024
00025 #include "guipkg/proppanel.h"
00026
00027 #include "wxp/package.h"
00028 #include "wxp/wxp.h"
00029 #include "wxp/packagewxp.h"
00030
00031 #include "wx/miscutils.h"
00032
00033
00034
00035
00036
00037
00038
00039 #define NUM_STANDARD_LICENSES 3
00040
00041 struct wxLicenseData
00042 {
00043 wxString strName;
00044 wxString remoteRef;
00045 wxPackageLicenseType type;
00046
00047 } g_standardLicense[3] =
00048 {
00049 { wxT("wxWidgets license"),
00050 wxT("http://www.opensource.org/licenses/wxwindows.php"), wxPLT_OPENSOURCE },
00051
00052 { wxT("GNU General Public License (GPL)"),
00053 wxT("http://www.opensource.org/licenses/gpl-license.php"), wxPLT_OPENSOURCE },
00054
00055 { wxT("GNU Lesser General Public License (LGPL)"),
00056 wxT("http://www.opensource.org/licenses/lgpl-license.php"), wxPLT_OPENSOURCE }
00057 };
00058
00059
00060
00061
00062 wxString wxGetHrefFromListbox(wxListBox *lb, unsigned int idx)
00063 { return ((wxStringClientData *)lb->GetClientObject(idx))->GetData(); }
00064
00065 void wxUpdateHrefInListbox(wxListBox *lb, unsigned int idx, const wxString &href)
00066 { ((wxStringClientData *)lb->GetClientObject(idx))->SetData(href); }
00067
00068 wxString wxGetAuthorOrMaintainerLabelFor(const wxString &name, const wxString &href)
00069 {
00070 if (!href.IsEmpty())
00071 return name + wxT(", <") + href + wxT(">");
00072 return name;
00073 }
00074
00075 wxString wxGetAuthorOrMaintainerNameFrom(const wxString &itemtext)
00076 {
00077 return itemtext.BeforeFirst(wxT(','));
00078 }
00079
00080
00081
00082
00083
00084
00085 void wxPackagePropertiesPanel::InitLicensingPage()
00086 {
00087 m_pLicenseType->Append(wxArrayString(wxPLT_MAX, wxPackageLicenseTypeName));
00088 m_pLicenseType->Select(0);
00089
00090
00091 for (size_t j=0; j<NUM_STANDARD_LICENSES; j++)
00092 m_pLicense->Append(g_standardLicense[j].strName);
00093 }
00094
00095 void wxPackagePropertiesPanel::GetLicensingPackageInfo(wxPackageInfo &ret) const
00096 {
00097
00098 ret.SetLicenseRef(m_license);
00099 ret.SetLicenseType((wxPackageLicenseType)m_pLicenseType->GetSelection());
00100 ret.SetOrganization(m_pOrganization->GetValue(), m_pOrganizationWebsite->GetValue());
00101 ret.SetCost(m_pCost->GetValue());
00102 ret.SetCopyright(m_pCopyright->GetValue());
00103 ret.SetCredits(m_pCredits->GetValue());
00104
00105 for (size_t i=0; i<m_pAuthors->GetCount(); i++)
00106 ret.AddAuthor(wxGetAuthorOrMaintainerNameFrom(m_pAuthors->GetString(i)),
00107 wxGetHrefFromListbox(m_pAuthors, i));
00108 for (size_t i=0; i<m_pMaintainers->GetCount(); i++)
00109 ret.AddMaintainer(wxGetAuthorOrMaintainerNameFrom(m_pMaintainers->GetString(i)),
00110 wxGetHrefFromListbox(m_pMaintainers, i));
00111 }
00112
00113 void wxPackagePropertiesPanel::DoSetLicensingPackageInfo(const wxPackageInfo &p)
00114 {
00115
00116 m_license = p.GetLicenseRef();
00117 m_pLicense->SetValue(m_license.GetData());
00118 m_pLicenseType->SetSelection(p.GetLicenseType());
00119 m_pOrganization->SetValue(p.GetOrganization());
00120 m_pOrganizationWebsite->SetValue(p.GetOrganizationHref());
00121 m_pCost->SetValue(p.GetCost());
00122 m_pCopyright->SetValue(p.GetCopyright());
00123 m_pCredits->SetValue(p.GetCredits());
00124
00125 m_pAuthors->Clear();
00126 for (size_t i=0; i<p.GetAuthors().GetCount(); i++)
00127 {
00128 wxString name = p.GetAuthors().Item(i), href = p.GetAuthorsHref().Item(i);
00129 m_pAuthors->Append(wxGetAuthorOrMaintainerLabelFor(name, href),
00130 new wxStringClientData(href));
00131 }
00132
00133 m_pMaintainers->Clear();
00134 for (size_t i=0; i<p.GetMaintainers().GetCount(); i++)
00135 {
00136 wxString name = p.GetMaintainers().Item(i), href = p.GetMaintainersHref().Item(i);
00137 m_pMaintainers->Append(wxGetAuthorOrMaintainerLabelFor(name, href),
00138 new wxStringClientData(href));
00139 }
00140 }
00141 bool wxPackagePropertiesPanel::IsLicensingPageOk() const
00142 {
00143 bool isok = true;
00144
00145 wxString l(m_pLicense->GetValue());
00146 if (l.IsEmpty())
00147 {
00148 wxLogError(wxT("The package license is not optional"));
00149 isok = false;
00150 }
00151
00152 return isok;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 bool wxPackagePropertiesPanel::GetAuthorOrMaintainer(bool isauthor,
00162 wxString *ret,
00163 wxString *rethref,
00164 const wxString &defname,
00165 const wxString &defhref)
00166 {
00167
00168 wxString newentry = defname + wxT(" ") + defhref;
00169 size_t i;
00170
00171 do
00172 {
00173 newentry = wxGetTextFromUser(
00174 wxString::Format(wxT("Please type the name of the new %s.\n\nNote that you can give after the name also an email address or\nmore generally an URL which allows to the users to get in touch\nwith that person (e.g. 'Isaac Newton isaac.newton@physics.net')..."), isauthor ? wxT("author") : wxT("maintainer")),
00175 wxT("Input text"),
00176 newentry,
00177 this);
00178 if (newentry.IsEmpty())
00179 return false;
00180
00181
00182 wxArrayString temp = wxStringTokenize(newentry, wxT(' '));
00183 for (i=0; i < temp.GetCount() - 1; i++)
00184 {
00185 if (!wxIsPlainWord(temp[i]))
00186 {
00187 wxLogError(wxT("Invalid name '%s'.\nYou can use only the following characters:\n%s"),
00188 temp[i].c_str(), wxGetPlainWordAllowedCharacters().c_str());
00189 break;
00190 }
00191 }
00192
00193 if (i == temp.GetCount() - 1)
00194 break;
00195
00196 } while (1);
00197
00198
00199 wxString last = newentry.AfterLast(wxT(' ')), href;
00200 if (last.Contains(wxT("www")) ||
00201 last.Contains(wxT("://")) ||
00202 last.Contains(wxT("@")))
00203 {
00204 href = last;
00205 newentry = newentry.BeforeLast(wxT(' '));
00206
00207
00208 newentry = wxGetAuthorOrMaintainerLabelFor(newentry, href);
00209 }
00210
00211 if (ret) *ret = newentry;
00212 if (rethref) *rethref = href;
00213
00214 return true;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223 void wxPackagePropertiesPanel::OnLicensingButton(wxCommandEvent &ev)
00224 {
00225 OnUserChange();
00226
00227 switch (ev.GetId())
00228 {
00229 case ID_PROP_NEW_AUTHOR:
00230 case ID_PROP_NEW_MAINTAINER:
00231 {
00232 wxString newentry, href;
00233 if (GetAuthorOrMaintainer(ev.GetId() == ID_PROP_NEW_AUTHOR, &newentry, &href))
00234 {
00235 wxListBox *p = ev.GetId() == ID_PROP_NEW_AUTHOR ? m_pAuthors : m_pMaintainers;
00236 p->Append(newentry, new wxStringClientData(href));
00237 }
00238 }
00239 break;
00240
00241 case ID_PROP_DELETE_AUTHOR:
00242 case ID_PROP_DELETE_MAINTAINER:
00243 {
00244 wxListBox *p = NULL;
00245 switch (ev.GetId())
00246 {
00247 case ID_PROP_DELETE_AUTHOR: p=m_pAuthors; break;
00248 case ID_PROP_DELETE_MAINTAINER: p=m_pMaintainers; break;
00249 case ID_PROP_DELETE_DOWNLOADLINK: p=m_pDownloadLinks; break;
00250 default: wxASSERT(0);
00251 }
00252 wxASSERT(p->GetSelection() != wxNOT_FOUND);
00253 p->Delete(p->GetSelection());
00254 }
00255 break;
00256 }
00257 }
00258
00259 void wxPackagePropertiesPanel::OnLicensingListBoxDClick(wxCommandEvent &ev)
00260 {
00261 OnUserChange();
00262
00263 switch (ev.GetId())
00264 {
00265 case ID_PROP_AUTHORS:
00266 case ID_PROP_MAINTAINERS:
00267 {
00268 wxListBox *p = ev.GetId() == ID_PROP_AUTHORS ? m_pAuthors : m_pMaintainers;
00269 int idx = p->GetSelection();
00270
00271 if (idx == wxNOT_FOUND)
00272 {
00273
00274
00275 return;
00276 }
00277
00278 wxString newentry, href,
00279 initialname = wxGetAuthorOrMaintainerNameFrom(p->GetString(idx)),
00280 initialhref = wxGetHrefFromListbox(p, idx);
00281
00282 if (GetAuthorOrMaintainer(ev.GetId() == ID_PROP_AUTHORS, &newentry, &href,
00283 initialname, initialhref))
00284 {
00285 p->SetString(idx, newentry);
00286 wxUpdateHrefInListbox(p, idx, href);
00287 }
00288 }
00289 break;
00290 }
00291 }
00292
00293 void wxPackagePropertiesPanel::OnLicenseSelected(wxCommandEvent &ev)
00294 {
00295 OnUserChange();
00296
00297
00298
00299 for (size_t i=0; i < NUM_STANDARD_LICENSES; i++)
00300 {
00301 if (ev.GetString() == g_standardLicense[i].strName)
00302 {
00303 m_pLicenseType->Select(g_standardLicense[i].type);
00304 m_license.SetHref(g_standardLicense[i].remoteRef);
00305 return;
00306 }
00307 }
00308 }
00309
00310 void wxPackagePropertiesPanel::OnLicensingPageUpdateUI(wxUpdateUIEvent &WXUNUSED(ev))
00311 {
00312 DisableIfNoSelection(ID_PROP_DELETE_AUTHOR, m_pAuthors);
00313 DisableIfNoSelection(ID_PROP_DELETE_MAINTAINER, m_pMaintainers);
00314 }
00315