1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: dialog.h 3 // Purpose: wxCurlDownloadDialog, wxCurlUploadDialog 4 // Author: Francesco Montorsi 5 // Created: 2007/04/14 6 // RCS-ID: $Id: dialog.h 1240 2010-03-10 23:54:25Z frm $ 7 // Copyright: (c) 2007 Francesco Montorsi 8 // Licence: wxWidgets licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WXCURL_DIALOG_H_ 12 #define _WXCURL_DIALOG_H_ 13 14 #include "wx/dialog.h" 15 #include "wx/curl/thread.h" 16 #include "wx/curl/panel.h" 17 18 // forward declarations 19 //class WXDLLIMPEXP_CORE wxStaticText; 20 //class WXDLLIMPEXP_CORE wxTextCtrl; 21 //class WXDLLIMPEXP_CORE wxGauge; 22 //class WXDLLIMPEXP_CORE wxStaticBitmap; 23 24 25 //! Possible wxCurlTransferDialog styles. 26 enum wxCurlTransferDialogStyle 27 { 28 wxCTDS_ELAPSED_TIME = 0x0001, //!< The dialog shows the elapsed time. 29 wxCTDS_ESTIMATED_TIME = 0x0002, //!< The dialog shows the estimated total time. 30 wxCTDS_REMAINING_TIME = 0x0004, //!< The dialog shows the remaining time. 31 wxCTDS_SPEED = 0x0008, //!< The dialog shows the transfer speed. 32 wxCTDS_SIZE = 0x0010, //!< The dialog shows the size of the resource to download/upload. 33 wxCTDS_URL = 0x0020, //!< The dialog shows the URL involved in the transfer. 34 35 // styles related to the use of wxCurlConnectionSettingsDialog: 36 37 wxCTDS_CONN_SETTINGS_AUTH = 0x0040, //!< The dialog allows the user to change the authentication settings. 38 wxCTDS_CONN_SETTINGS_PORT = 0x0080, //!< The dialog allows the user to change the port for the transfer. 39 wxCTDS_CONN_SETTINGS_PROXY = 0x0100, //!< The dialog allows the user to change the proxy settings. 40 41 wxCTDS_CONN_SETTINGS_ALL = wxCTDS_CONN_SETTINGS_AUTH|wxCTDS_CONN_SETTINGS_PORT|wxCTDS_CONN_SETTINGS_PROXY, 42 43 wxCTDS_SHOW_ALL = wxCTDS_ELAPSED_TIME|wxCTDS_ESTIMATED_TIME|wxCTDS_REMAINING_TIME| 44 wxCTDS_SPEED|wxCTDS_SIZE|wxCTDS_URL|wxCTDS_CONN_SETTINGS_ALL, 45 46 wxCTDS_CAN_ABORT = 0x0200, //!< The transfer can be aborted by the user. 47 wxCTDS_CAN_START = 0x0400, //!< The transfer won't start automatically. The user needs to start it. 48 wxCTDS_CAN_PAUSE = 0x0800, //!< The transfer can be paused. 49 50 wxCTDS_AUTO_CLOSE = 0x1000, //!< The dialog auto closes when transfer is complete. 51 52 // by default all available features are enabled: 53 wxCTDS_DEFAULT_STYLE = wxCTDS_CAN_START|wxCTDS_CAN_PAUSE|wxCTDS_CAN_ABORT|wxCTDS_SHOW_ALL|wxCTDS_AUTO_CLOSE 54 }; 55 56 //! The return flag of . 57 enum wxCurlDialogReturnFlag 58 { 59 wxCDRF_SUCCESS, //!< Download successfully completed. 60 wxCDRF_USER_ABORTED, //!< User aborted the download. 61 wxCDRF_FAILED //!< Invalid URL / other networking problem happened. 62 }; 63 64 65 // ---------------------------------------------------------------------------- 66 // wxCurlTransferDialog 67 // ---------------------------------------------------------------------------- 68 69 //! The base class for wxCurlDownloadDialog and wxCurlUploadDialog. 70 class WXDLLIMPEXP_CURL wxCurlTransferDialog : public wxDialog 71 { 72 public: wxCurlTransferDialog()73 wxCurlTransferDialog() 74 { 75 m_bTransferComplete = false; 76 #ifdef __WXDEBUG__ 77 m_bVerbose = true; 78 #else 79 m_bVerbose = false; 80 #endif 81 82 // some of these may remain NULL: 83 m_pElapsedTime = m_pEstimatedTime = m_pRemainingTime = NULL; 84 m_pSpeed = m_pSize = NULL; 85 m_pBitmap = NULL; 86 m_pURL = NULL; 87 m_pGauge = NULL; 88 m_pLastEvent = NULL; 89 m_pThread = NULL; 90 m_nStyle = 0; 91 } 92 93 bool Create(const wxString &url, 94 const wxString& title, 95 const wxString& message = wxEmptyString, 96 const wxString& sizeLabel = _("Transferred:"), 97 const wxBitmap& bitmap = wxNullBitmap, 98 wxWindow *parent = NULL, 99 long style = wxCTDS_DEFAULT_STYLE); 100 ~wxCurlTransferDialog()101 ~wxCurlTransferDialog() 102 { 103 wxDELETE(m_pLastEvent); 104 wxDELETE(m_pThread); 105 } 106 107 108 //! Shows the dialog as modal. If the wxCTDS_CAN_START flag was not given, 109 //! then the transfer starts automatically. 110 //! Note that you should use this function instead of wxDialog::ShowModal(). 111 wxCurlDialogReturnFlag RunModal(); 112 113 /* not yet tested 114 //! Shows the dialog as modeless. 115 bool Show(const bool show); 116 */ 117 118 //! Returns true if the creation of the dialog was successful. IsOk()119 bool IsOk() const { return m_pThread != NULL && m_pThread->IsOk(); } 120 121 //! Returns the exit code of the dialog (call after #RunModal). GetReturnCode()122 virtual wxCurlDialogReturnFlag GetReturnCode() const 123 { return (wxCurlDialogReturnFlag)wxDialog::GetReturnCode(); } 124 125 //! Sets the internal wxCurlBase object to be verbose. SetVerbose(bool enable)126 void SetVerbose(bool enable) 127 { m_bVerbose=enable; } 128 129 //! Returns true if the internal wxCurlBase is verbose (on by default in debug builds). IsVerbose()130 bool IsVerbose() const 131 { return m_bVerbose; } 132 133 virtual void EndModal(int retCode); 134 135 protected: // internal utils 136 137 138 wxStaticText *AddSizerRow(wxSizer *sz, const wxString &name); 139 void CreateControls(const wxString &url, const wxString &msg, 140 const wxString& sizeLabel, const wxBitmap &bitmap); 141 void UpdateLabels(wxCurlProgressBaseEvent *ev); 142 143 // returns true if the error can be ignored 144 bool HandleCurlThreadError(wxCurlThreadError err, wxCurlBaseThread *p, 145 const wxString &url = wxEmptyString); 146 HasFlag(wxCurlTransferDialogStyle flag)147 bool HasFlag(wxCurlTransferDialogStyle flag) const 148 { return (m_nStyle & flag) != 0; } 149 150 151 // change access policy: 152 ShowModal()153 virtual int ShowModal() 154 { return wxDialog::ShowModal(); } 155 SetReturnCode(wxCurlDialogReturnFlag ret)156 virtual void SetReturnCode(wxCurlDialogReturnFlag ret) 157 { wxDialog::SetReturnCode(ret); } 158 159 public: // event handlers 160 161 void OnEndPerform(wxCurlEndPerformEvent &); 162 163 void OnAbort(wxCommandEvent &); 164 void OnConnSettings(wxCommandEvent &); 165 void OnPauseResume(wxCommandEvent &); 166 void OnStart(wxCommandEvent &); 167 168 void OnAbortUpdateUI(wxUpdateUIEvent &); 169 void OnConnSettingsUpdateUI(wxUpdateUIEvent &); 170 void OnStartUpdateUI(wxUpdateUIEvent &); 171 void OnPauseResumeUpdateUI(wxUpdateUIEvent &); 172 173 void OnClose(wxCloseEvent &ev); 174 175 protected: 176 177 wxCurlBaseThread *m_pThread; 178 wxCurlProgressBaseEvent *m_pLastEvent; 179 bool m_bTransferComplete; 180 181 // wxWindow's style member is too small for all our flags and wxWindow/wxDialog ones. 182 // So we use our own... 183 long m_nStyle; 184 185 // should we be verbose? 186 bool m_bVerbose; 187 188 protected: // controls 189 190 wxStaticText* m_pURL; 191 wxStaticText* m_pSpeed; 192 wxStaticText* m_pSize; 193 wxGauge* m_pGauge; 194 wxStaticBitmap* m_pBitmap; 195 196 wxStaticText* m_pElapsedTime; 197 wxStaticText* m_pRemainingTime; 198 wxStaticText* m_pEstimatedTime; 199 200 private: 201 DECLARE_EVENT_TABLE() 202 }; 203 204 205 // ---------------------------------------------------------------------------- 206 // wxCurlDownloadDialog 207 // ---------------------------------------------------------------------------- 208 209 //! An highly-configurable dialog which shows progress about a download. 210 class WXDLLIMPEXP_CURL wxCurlDownloadDialog : public wxCurlTransferDialog 211 { 212 public: wxCurlDownloadDialog()213 wxCurlDownloadDialog() { } 214 215 wxCurlDownloadDialog(const wxString &url, 216 wxOutputStream *out, 217 const wxString& title = wxS("Downloading..."), 218 const wxString& message = wxEmptyString, 219 const wxBitmap& bitmap = wxNullBitmap, 220 wxWindow *parent = NULL, 221 long style = wxCTDS_DEFAULT_STYLE) 222 { Create(url, out, title, message, bitmap, parent, style); } 223 224 bool Create(const wxString &url, 225 wxOutputStream *out, 226 const wxString& title = wxS("Downloading..."), 227 const wxString& message = wxEmptyString, 228 const wxBitmap& bitmap = wxNullBitmap, 229 wxWindow *parent = NULL, 230 long style = wxCTDS_DEFAULT_STYLE); 231 232 //! Returns the output stream where data has been downloaded. 233 //! This function can be used only when the download has been completed. GetOutputStream()234 wxOutputStream *GetOutputStream() const 235 { return wx_static_cast(wxCurlDownloadThread*, m_pThread)->GetOutputStream(); } 236 237 public: // event handlers 238 239 void OnDownload(wxCurlDownloadEvent &); 240 241 private: 242 DECLARE_EVENT_TABLE() 243 DECLARE_DYNAMIC_CLASS(wxCurlDownloadDialog) 244 }; 245 246 247 // ---------------------------------------------------------------------------- 248 // wxCurlUploadDialog 249 // ---------------------------------------------------------------------------- 250 251 //! An highly-configurable dialog which shows progress about an upload. 252 class WXDLLIMPEXP_CURL wxCurlUploadDialog : public wxCurlTransferDialog 253 { 254 public: wxCurlUploadDialog()255 wxCurlUploadDialog() { } 256 257 wxCurlUploadDialog(const wxString &url, 258 wxInputStream *in, 259 const wxString& title = wxS("Uploading..."), 260 const wxString& message = wxEmptyString, 261 const wxBitmap& bitmap = wxNullBitmap, 262 wxWindow *parent = NULL, 263 long style = wxCTDS_DEFAULT_STYLE) 264 { Create(url, in, title, message, bitmap, parent, style); } 265 266 bool Create(const wxString &url, 267 wxInputStream *in, 268 const wxString& title = wxS("Uploading..."), 269 const wxString& message = wxEmptyString, 270 const wxBitmap& bitmap = wxNullBitmap, 271 wxWindow *parent = NULL, 272 long style = wxCTDS_DEFAULT_STYLE); 273 274 275 public: // event handlers 276 277 void OnUpload(wxCurlUploadEvent &); 278 279 private: 280 DECLARE_EVENT_TABLE() 281 DECLARE_DYNAMIC_CLASS(wxCurlUploadDialog) 282 }; 283 284 285 // ---------------------------------------------------------------------------- 286 // wxCurlConnectionSettingsDialog 287 // ---------------------------------------------------------------------------- 288 289 //! A dialog which simply wraps a wxCurlConnectionSettingsPanel. 290 //! For a list of supported styles, please see wxCurlConnectionSettingsPanel. 291 class WXDLLIMPEXP_CURL wxCurlConnectionSettingsDialog : public wxDialog 292 { 293 public: wxCurlConnectionSettingsDialog()294 wxCurlConnectionSettingsDialog() { m_pPanel = NULL; } 295 296 wxCurlConnectionSettingsDialog(const wxString& title, 297 const wxString& message = wxEmptyString, 298 wxWindow *parent = NULL, 299 long style = wxCCSP_DEFAULT_STYLE) 300 { Create(title, message, parent, style); } 301 302 bool Create(const wxString& title = wxS("Connection settings..."), 303 const wxString& message = wxEmptyString, 304 wxWindow *parent = NULL, 305 long style = wxCCSP_DEFAULT_STYLE); 306 307 public: 308 309 //! Runs this dialog as modal and updates the given wxCurlBase instance if needed 310 //! (i.e. if the user hits OK and not Cancel). 311 void RunModal(wxCurlBase *pcurl); 312 313 protected: 314 315 wxCurlConnectionSettingsPanel *m_pPanel; 316 317 // change access policy: 318 ShowModal()319 virtual int ShowModal() 320 { return wxDialog::ShowModal(); } 321 322 private: 323 DECLARE_DYNAMIC_CLASS(wxCurlConnectionSettingsDialog) 324 }; 325 326 327 #endif // _WXCURL_DIALOG_H_ 328 329