proppanel_details.cpp

00001 
00002 // Name:        proppanel_details.cpp
00003 // Purpose:     wxPackagePropertiesPanel
00004 //              (stuff for handling the "details" page)
00005 // Author:      Francesco Montorsi
00006 // Modified by:
00007 // Created:     28/06/2006 19:22:47
00008 // RCS-ID:      $Id: proppanel_details.cpp,v 1.6 2007/01/01 21:36:45 frm Exp $
00009 // Copyright:   (c) 2006 Julian Smart, Francesco Montorsi
00010 // Licence:     wxWidgets license
00012 
00013 
00014 // For compilers that support precompilation, includes "wx/wx.h".
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 <wx/datectrl.h>
00026 #include <wx/spinctrl.h>
00027 #include <wx/filepicker.h>
00028 
00029 #include "guipkg/proppanel.h"
00030 #include "guipkg/refeditdlg.h"
00031 #include "guipkg/depeditdlg.h"
00032 
00033 #include "wxp/package.h"
00034 #include "wxp/wxp.h"
00035 #include "wxp/packagewxp.h"
00036 
00037 #include "wx/miscutils.h"
00038 
00039 
00040 
00041 // ----------------------------------------------------------------------------
00042 // Global helpers
00043 // ----------------------------------------------------------------------------
00044 
00045 
00046 // some globals wxPackageDataWithRef helpers
00047 
00048 wxPackageDataWithRef &wxGetPackageDataWithRefFromListbox(wxListBox *lb, unsigned int idx)
00049 { return *((wxPackageDataWithRef *)lb->GetClientData(idx)); }
00050 
00051 void wxUpdatePackageDataWithRefInListbox(wxListBox *lb, unsigned int idx,
00052                                          const wxPackageDataWithRef &ref)
00053 { wxGetPackageDataWithRefFromListbox(lb, idx) = ref; }
00054 
00055 wxString wxGetLabelFor(const wxPackageDataWithRef &ref)
00056 {
00057     // ignore data as actually we prefer to show links to in proppanel
00058 //    if (!ref.GetData().IsEmpty())
00059 //        return ref.GetData();
00060     if (!ref.GetHref().IsEmpty())
00061         return ref.GetHref();
00062     return ref.GetLocalRef();
00063 }
00064 
00065 void wxDeletePackageDataWithRefFromListbox(wxListBox *lc, int idx)
00066 {
00067     if (idx == -1)
00068     {
00069         while (lc->GetCount() > 0)
00070             wxDeletePackageDataWithRefFromListbox(lc, 0);
00071     }
00072     else
00073     {
00074         // don't leak memory!
00075         delete ((wxPackageDataWithRef*)lc->GetClientData(idx));
00076         lc->Delete(idx);
00077     }
00078 }
00079 
00080 
00081 
00082 // ----------------------------------------------------------------------------
00083 // wxPackagePropertiesPanel - details stuff - I/O
00084 // ----------------------------------------------------------------------------
00085 
00086 void wxPackagePropertiesPanel::InitDetailsPage()
00087 {
00088     m_pStatus->Append(wxArrayString(wxPDS_MAX, wxPackageDevelopmentStatusName));
00089     m_pProgLang->Append(wxArrayString(wxPPL_MAX, wxPackageProgLanguageName));
00090     m_pStatus->Select(0);
00091     m_pProgLang->Select(0);
00092 }
00093 
00094 void wxPackagePropertiesPanel::GetDetailsPackageInfo(wxPackageInfo &ret) const
00095 {
00096     // DETAILS info
00097     ret.SetDevelopmentStatus((wxPackageDevelopmentStatus)m_pStatus->GetSelection());
00098     ret.SetProgLanguage((wxPackageProgLanguage)m_pProgLang->GetSelection());
00099     ret.SetCreationDate(m_pCreationDate->GetValue().Format(wxT("%d %b %Y")));
00100     ret.SetWebsite(m_pWebsite->GetValue());
00101     ret.SetRSSHref(m_pRSS->GetValue());
00102 
00103     for (size_t i=0; i<m_pDownloadLinks->GetCount(); i++)
00104         ret.AddMirror(m_pDownloadLinks->GetString(i));
00105     for (size_t i=0; i<m_pDocs->GetCount(); i++)
00106         ret.AddDoc(wxGetPackageDataWithRefFromListbox(m_pDocs, i));
00107     for (size_t i=0; i<m_pScreenshots->GetCount(); i++)
00108         ret.AddScreenshot(wxGetPackageDataWithRefFromListbox(m_pScreenshots, i));
00109 
00110     ret.SetLogoRef(m_logo);
00111     ret.SetNumberOfSamples(m_pNumSamples->GetValue());
00112 }
00113 
00114 void wxPackagePropertiesPanel::DoSetDetailsPackageInfo(const wxPackageInfo &p)
00115 {
00116     // DETAILS info
00117     m_pStatus->SetSelection(p.GetDevelopmentStatus());
00118     m_pProgLang->SetSelection(p.GetProgLanguage());
00119 
00120     if (p.GetCreationDate().IsValid())
00121         m_pCreationDate->SetValue(p.GetCreationDate());
00122     else
00123         m_pCreationDate->SetValue(wxDateTime::Now());
00124     m_pWebsite->SetValue(p.GetWebsite());
00125     m_pRSS->SetValue(p.GetRSSHref());
00126     m_logo = p.GetLogoRef();
00127     m_pNumSamples->SetValue(p.GetNumberOfSamples());
00128 
00129     m_pDownloadLinks->Clear();
00130     for (size_t i=0; i<p.GetDownloadHref().GetCount(); i++)
00131         m_pDownloadLinks->Append(p.GetDownloadHref(i));
00132 
00133     // delete all existing wxPackageDataWithRef objects before adding the new ones
00134     wxDeletePackageDataWithRefFromListbox(m_pDocs, -1); 
00135     for (size_t i=0; i<p.GetDocumentation().GetCount(); i++)
00136         m_pDocs->Append(wxGetLabelFor(p.GetDocumentation(i)),
00137                         (void*)new wxPackageDataWithRef(p.GetDocumentation(i)));
00138 
00139     // delete all existing wxPackageDataWithRef objects before adding the new ones
00140     wxDeletePackageDataWithRefFromListbox(m_pScreenshots, -1);
00141     for (size_t i=0; i<p.GetScreenshots().GetCount(); i++)
00142         m_pScreenshots->Append(wxGetLabelFor(p.GetScreenshot(i)),
00143                                (void *)new wxPackageDataWithRef(p.GetScreenshot(i)));
00144 }
00145 
00146 bool wxPackagePropertiesPanel::IsDetailsPageOk() const
00147 {
00148     bool isok = true;
00149 
00150     if (m_pDownloadLinks->GetCount() == 0)
00151     {
00152         wxLogWarning(wxT("Please provide at least one download link for this package"));
00153         isok = false;
00154     }
00155 
00156     return isok;
00157 }
00158 
00159 
00160 
00161 // ----------------------------------------------------------------------------
00162 // wxPackagePropertiesPanel - details stuff
00163 // ----------------------------------------------------------------------------
00164 
00165 bool wxPackagePropertiesPanel::GetDownloadLink(wxString *ret, const wxString &def)
00166 {
00167     wxString newentry(def);
00168 
00169     do
00170     {
00171         newentry = wxGetTextFromUser(
00172                 wxT("Please type the URL of a *direct* download link for\nthis package (e.g. http://myproj.sourceforge.net/wxz/thispackage.wxz)..."),
00173         wxT("Input text"),
00174         newentry,
00175         this);
00176         if (newentry.IsEmpty())
00177             return false;     // user hit cancel
00178 
00179                     // is this a valid URL ?
00180         wxURL u(newentry);
00181         if (u.GetError() != wxURL_NOERR)
00182             wxLogError(wxT("The URL you entered '%s' does not seems to be a valid URL.\nPlease check its syntax."), newentry.c_str());
00183         else
00184             break;      // valid input
00185     } while (1);
00186 
00187     if (ret) *ret = newentry;
00188     return true;
00189 }
00190 
00191 bool wxPackagePropertiesPanel::GetDoc(wxPackageDataWithRef *ret,
00192                                       const wxPackageDataWithRef &initial)
00193 {
00194     wxPackageReferenceEditDlg dlg(this);
00195 
00196     // force the user to choose a path which is "under" the project directory path
00197     //dlg.SetLocalRoot(m_strRoot);
00198     dlg.SetLocalRoot(m_pProjectDir->GetPath());
00199     dlg.SetWildcard(wxPROPPANEL_DOC_WILDCARD);
00200 
00201     dlg.SetRef(initial);
00202     if (dlg.ShowModal() == wxID_OK)
00203     {
00204         wxString type = wxT("unknown");
00205 
00206 #if 0       // to enable as soon as wxTheMimeTypesManager works correctly
00207         wxString ext = dlg.GetRef().GetHref().AfterLast(wxT('.'));
00208         if (!ext.IsEmpty())
00209         {
00210             wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
00211             if (ft)
00212             {
00213                 if (!ft->GetMimeType(&type))
00214                     type = wxT("unknown");
00215             }
00216         }
00217 #endif
00218 
00219         wxPackageDataWithRef ref(dlg.GetRef());
00220         ref.SetData(type);
00221         if (ret) *ret = ref;
00222 
00223         return true;
00224     }
00225 
00226     return false;
00227 }
00228 
00229 bool wxPackagePropertiesPanel::GetScreenshot(wxPackageDataWithRef *ret,
00230                                              const wxPackageDataWithRef &initial)
00231 {
00232     wxPackageReferenceEditDlg dlg(this);
00233 
00234     // force the user to choose a path which is "under" the project directory path
00235     dlg.SetLocalRoot(m_strRoot);
00236     dlg.SetWildcard(wxPROPPANEL_IMAGE_WILDCARD);
00237 
00238     dlg.SetRef(initial);
00239     if (dlg.ShowModal() == wxID_OK)
00240     {
00241         if (ret) *ret = dlg.GetRef();
00242         return true;
00243     }
00244 
00245     return false;
00246 }
00247 
00248 
00249 // ----------------------------------------------------------------------------
00250 // wxPackagePropertiesPanel - event handlers
00251 // ----------------------------------------------------------------------------
00252 
00253 void wxPackagePropertiesPanel::OnDetailsButton(wxCommandEvent &ev)
00254 {
00255     OnUserChange();
00256 
00257     switch (ev.GetId())
00258     {
00259     case ID_PROP_NEW_DOWNLOADLINK:
00260         {
00261             wxString newentry;
00262             if (GetDownloadLink(&newentry))
00263                 m_pDownloadLinks->Append(newentry);
00264         }
00265         break;
00266 
00267     case ID_PROP_NEW_DOC:
00268         {
00269             wxPackageDataWithRef ref;
00270             if (GetDoc(&ref, ref))
00271                 m_pDocs->Append(wxGetLabelFor(ref),
00272                                 (void *)new wxPackageDataWithRef(ref));
00273         }
00274         break;
00275 
00276     case ID_PROP_NEW_SCREENSHOT:
00277         {
00278             wxPackageDataWithRef ref;
00279             if (GetScreenshot(&ref))
00280                 m_pScreenshots->Append(wxGetLabelFor(ref),
00281                                        (void *)new wxPackageDataWithRef(ref));
00282         }
00283         break;
00284 
00285     case ID_PROP_LOGO_REF:
00286         {
00287             wxPackageReferenceEditDlg dlg(this);
00288 
00289             // force the user to choose a path which is "under" the project directory path
00290             dlg.SetLocalRoot(m_strRoot);
00291             dlg.SetWildcard(wxPROPPANEL_IMAGE_WILDCARD);
00292 
00293             dlg.SetRef(m_logo);
00294             if (dlg.ShowModal() == wxID_OK)
00295                 m_logo = dlg.GetRef();
00296         }
00297         break;
00298 
00299     case ID_PROP_DELETE_DOWNLOADLINK:
00300         {
00301             wxListBox *p = NULL;
00302             switch (ev.GetId())
00303             {
00304                 case ID_PROP_DELETE_AUTHOR: p=m_pAuthors; break;
00305                 case ID_PROP_DELETE_MAINTAINER: p=m_pMaintainers; break;
00306                 case ID_PROP_DELETE_DOWNLOADLINK: p=m_pDownloadLinks; break;
00307                 default: wxASSERT(0);
00308             }
00309             wxASSERT(p->GetSelection() != wxNOT_FOUND);
00310             p->Delete(p->GetSelection());
00311         }
00312         break;
00313 
00314         // listboxes with untyped data which we have to delete ourselves
00315     case ID_PROP_DELETE_DOC:
00316     case ID_PROP_DELETE_SCREENSHOT:
00317         {
00318             wxListBox *p = NULL;
00319             switch (ev.GetId())
00320             {
00321                 case ID_PROP_DELETE_DOC:
00322                     p=m_pDocs;
00323                     break;
00324                 case ID_PROP_DELETE_SCREENSHOT:
00325                     p=m_pScreenshots;
00326                     break;
00327 
00328                 default: wxASSERT(0);
00329             }
00330             wxASSERT(p->GetSelection() != wxNOT_FOUND);
00331             wxDeletePackageDataWithRefFromListbox(p, p->GetSelection());
00332         }
00333         break;
00334     }
00335 }
00336 
00337 void wxPackagePropertiesPanel::OnDetailsListBoxDClick(wxCommandEvent &ev)
00338 {
00339     OnUserChange();
00340 
00341     switch (ev.GetId())
00342     {
00343         case ID_PROP_DOWNLOADLINKS:
00344         {
00345             int idx = m_pDownloadLinks->GetSelection();
00346             if (idx == wxNOT_FOUND)
00347             {
00348                 // this may happen on wxMSW 's listboxes when they have > 0 items
00349                 // and the user clicks on the empty space
00350                 return;
00351             }
00352 
00353             wxString newentry;
00354             if (GetDownloadLink(&newentry, m_pDownloadLinks->GetString(idx)))
00355                 m_pDownloadLinks->SetString(idx, newentry);
00356         }
00357         break;
00358 
00359         case ID_PROP_DOCS:
00360         {
00361             int idx = m_pDocs->GetSelection();
00362             if (idx == wxNOT_FOUND)
00363             {
00364                 // this may happen on wxMSW 's listboxes when they have > 0 items
00365                 // and the user clicks on the empty space
00366                 return;
00367             }
00368 
00369             wxPackageDataWithRef newentry;
00370             if (GetDoc(&newentry, wxGetPackageDataWithRefFromListbox(m_pDocs, idx)))
00371             {
00372                 m_pDocs->SetString(idx, wxGetLabelFor(newentry));
00373                 wxUpdatePackageDataWithRefInListbox(m_pDocs, idx, newentry);
00374             }
00375         }
00376         break;
00377 
00378         case ID_PROP_SCREENSHOTS:
00379         {
00380             int idx = m_pScreenshots->GetSelection();
00381             if (idx == wxNOT_FOUND)
00382             {
00383                 // this may happen on wxMSW 's listboxes when they have > 0 items
00384                 // and the user clicks on the empty space
00385                 return;
00386             }
00387 
00388             wxPackageDataWithRef newentry;
00389             if (GetScreenshot(&newentry,
00390                               wxGetPackageDataWithRefFromListbox(m_pScreenshots, idx)))
00391             {
00392                 m_pScreenshots->SetString(idx, wxGetLabelFor(newentry));
00393                 wxUpdatePackageDataWithRefInListbox(m_pScreenshots, idx, newentry);
00394             }
00395         }
00396         break;
00397     }
00398 }
00399 
00400 void wxPackagePropertiesPanel::OnDetailsPageUpdateUI(wxUpdateUIEvent &WXUNUSED(ev))
00401 {
00402     DisableIfNoSelection(ID_PROP_DELETE_DOWNLOADLINK, m_pDownloadLinks);
00403     DisableIfNoSelection(ID_PROP_DELETE_DOC, m_pDocs);
00404     DisableIfNoSelection(ID_PROP_DELETE_SCREENSHOT, m_pScreenshots);
00405 }

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1