00001 // $Id: urlimp.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // The "Import from URL..." menu item 00099 00100 #include "camtypes.h" 00101 00102 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 //#include "barsdlgs.h" //For _R(IDD_BARCONTROLSTORE) 00104 00105 #include "urlimp.h" 00106 #include "fileutil.h" 00107 00108 //#include "resimmap.h" //For _R(IDS_HTMLIMPORT_FILEDOWNLOAD) 00109 #include "urldlg.h" //For URLImportDlg 00110 00111 #include "gendwnd.h" //For the download operation 00112 //#include "webster.h" 00113 00114 #include "xshelpid.h" //For the help ID 00115 00116 CC_IMPLEMENT_DYNCREATE(OpURLImport, OpMenuImport) 00117 00118 #define new CAM_DEBUG_NEW 00119 00120 /******************************************************************************************** 00121 00122 > BOOL OpURLImport::Init() 00123 00124 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00125 Created: 6/6/97 00126 Returns: TRUE if worked, FALSE if failed (out of memory) 00127 Purpose: Declares the OpDescriptor 00128 Errors: - 00129 00130 ********************************************************************************************/ 00131 00132 BOOL OpURLImport::Init() 00133 { 00134 return RegisterOpDescriptor( 00135 0, // Tool ID 00136 _R(IDS_URLIMPORT), // String resource ID 00137 CC_RUNTIME_CLASS(OpURLImport), // Runtime class 00138 OPTOKEN_URLIMPORT, // Token string 00139 GetState, // GetState function 00140 _R(IDH_Command_Import_from_Web), // help ID GTODO: Is this needed? 00141 _R(IDBBL_URLIMPORT), // bubble help 00142 _R(IDD_BARCONTROLSTORE), // resource ID 00143 _R(IDC_FILEURLIMPORT), // control ID 00144 SYSTEMBAR_FILE, // Bar ID 00145 TRUE, // Receive system messages 00146 FALSE, // Smart duplicate operation 00147 TRUE, // Clean operation 00148 0, // String for one copy only error 00149 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags 00150 ); 00151 00152 } 00153 00154 /******************************************************************************************** 00155 00156 > void OpURLImport::Do(OpDescriptor*) 00157 00158 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00159 Created: 6/6/97 00160 Purpose: Imports a URL into the current document 00161 Errors: - 00162 00163 ********************************************************************************************/ 00164 00165 void OpURLImport::Do(OpDescriptor*) 00166 { 00167 //First display our Import from URL dialog and get a filename from it 00168 WebAddress urlToGet; 00169 00170 BOOL ok=URLImportDlg::OpenAndGetURL(&urlToGet); 00171 00172 //And if the user clicked OK 00173 if (ok) 00174 { 00175 00176 //So, is the URL we've got back a local filename? 00177 if (urlToGet.IsLocalFile()) 00178 { 00179 //Yes. So get it as a pathname 00180 PathName pthToGet=urlToGet.GetPathName(); 00181 00182 //And first get a pointer to the All filter 00183 Filter* pAllFilter=GetAllFilter(); 00184 00185 //And if we found it 00186 if (pAllFilter) 00187 { 00188 //Then import the pathname 00189 String_256 strToGet=pthToGet.GetPath(); 00190 00191 DoImport(pthToGet, pAllFilter, &strToGet); 00192 } 00193 00194 } 00195 else 00196 { 00197 //No, it's a URL. 00198 00199 // Added by Craig Hamilton 30/8/00. 00200 // Add some error checking to find whether the user has entered a valid URL 00201 00202 PathName pthToGet = urlToGet.GetPathName(); 00203 String_256 str256 = pthToGet.GetLocation(FALSE); 00204 CString s = str256; 00205 00206 if((s == "")) 00207 { 00208 // ERROR 00209 MessageBox(NULL,"There was a problem downloading from the specified URL. Make sure the URL is spelled correctly.","Error from Xara X",MB_OK | MB_ICONWARNING); 00210 return; 00211 } 00212 // End added. 00213 00214 //So download it 00215 ImportURL(urlToGet); 00216 } 00217 } 00218 00219 00220 00221 00222 00223 } 00224 00225 /******************************************************************************************** 00226 00227 > OpURLImport::OpURLImport() 00228 00229 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00230 Created: 6/6/97 00231 Purpose: Default constructor 00232 00233 ********************************************************************************************/ 00234 00235 OpURLImport::OpURLImport() 00236 { 00237 OpFlags.HasOwnTimeIndicator = TRUE; // The OpURLImport op has its own time indicator 00238 } 00239 00240 /******************************************************************************************** 00241 00242 > OpState OpURLImport::GetState(String_256*, OpDescriptor*) 00243 00244 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00245 Created: 6/6/97 00246 Purpose: This item is always available, so long as a document is visible. 00247 00248 ********************************************************************************************/ 00249 00250 OpState OpURLImport::GetState(String_256*, OpDescriptor*) 00251 { 00252 OpState OpSt; 00253 00254 return OpSt; 00255 } 00256 00257 /***************************************************************** 00258 00259 Toolkit functions 00260 00261 ****************************************************************/ 00262 00263 /******************************************************************************************** 00264 00265 > BOOL OpURLImport::ImportURL(WebAddress urlToGet) 00266 00267 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00268 Created: 6/6/97 00269 Inputs: urlToGet The URL to import 00270 Purpose: Imports the URL given 00271 00272 ********************************************************************************************/ 00273 00274 BOOL OpURLImport::ImportURL(WebAddress urlToGet) 00275 { 00276 //First, set up some variables. We must do this now because I'm 00277 //going to use a goto in a moment 00278 GenericDownloadParam* Param; 00279 OpDescriptor* pOpDesc; 00280 PathName pthTemp; 00281 00282 //We want to import urlToGet using the best available filter 00283 00284 //To get the best available filter, we simply download to the "All" filter 00285 //So get a pointer to the All filter 00286 Filter* pAllFilter=GetAllFilter(); 00287 00288 //Check we found it 00289 if (pAllFilter==NULL) 00290 goto ReturnError; 00291 00292 //Now, get ready to download the file. This is rather complex. 00293 00294 //First create a new set of download parameters 00295 //This object will be deleted when the download finishes 00296 Param = new GenericDownloadParam; 00297 00298 //Now find the generic download OpDescriptor 00299 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_OPGENERICDOWNLOAD); 00300 00301 //And check we found it 00302 if (pOpDesc==NULL) 00303 goto ReturnError; 00304 00305 //Now, create a temporary file to download to 00306 pthTemp=FileUtil::GetTemporaryPathName(); 00307 00308 //And now fill in our parameters 00309 Param->type = TYPE_HTML; 00310 Param->priority = AsynchDownload::PRIORITY_NORMAL; 00311 Param->strDescription = String_256(_R(IDS_HTMLIMPORT_FILEDOWNLOAD)); 00312 Param->file = pthTemp.GetPath(); 00313 00314 Param->strURL = urlToGet.GetWebAddress(); 00315 00316 Param->Output = NULL; 00317 00318 Param->m_pFilter = pAllFilter; 00319 Param->m_Op = this; 00320 Param->pDoc = Document::GetCurrent(); 00321 00322 //And, finally, start the download going, if we've got a URL to download 00323 if (!Param->strURL.IsEmpty()) 00324 pOpDesc->Invoke((OpParam*) Param); 00325 00326 //And return TRUE 00327 return TRUE; 00328 00329 ReturnError: 00330 if (Param) 00331 delete Param; 00332 00333 return FALSE; 00334 } 00335 00336 /******************************************************************************************** 00337 00338 > Filter* OpURLImport::GetAllFilter() 00339 00340 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00341 Created: 10/6/97 00342 Inputs: - 00343 Purpose: Gets a pointer to the All filter. 00344 00345 ********************************************************************************************/ 00346 00347 Filter* OpURLImport::GetAllFilter() 00348 { 00349 //So get a pointer to the All filter 00350 return Filter::FindFilterFromID(FILTERID_GENERIC); 00351 00352 } 00353 00354