daveimp.cpp

Go to the documentation of this file.
00001 // $Id: daveimp.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 "daveimp.h"
00106 #include "fileutil.h"
00107 
00108 //#include "resimmap.h"     //For _R(IDS_HTMLIMPORT_FILEDOWNLOAD)
00109 //#include "bevres.h"
00110 #include "davedlg.h"            //For URLImportDlg
00111 
00112 #include "gendwnd.h"        //For the download operation
00113 //#include "webster.h"
00114 
00115 #include "xshelpid.h"       //For the help ID
00116 
00117 CC_IMPLEMENT_DYNCREATE(OpBevel, OpMenuImport)
00118 
00119 #define new CAM_DEBUG_NEW
00120 
00121 /********************************************************************************************
00122 
00123 >   BOOL OpBevel::Init()
00124 
00125     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00126     Created:    6/6/97
00127     Returns:    TRUE if worked, FALSE if failed (out of memory)
00128     Purpose:    Declares the OpDescriptor
00129     Errors:     -
00130 
00131 ********************************************************************************************/
00132 
00133 BOOL OpBevel::Init()
00134 {
00135     return RegisterOpDescriptor(
00136                                     0,                          // Tool ID
00137                                     _R(IDS_DAVEBEVEL),                  // String resource ID
00138                                     CC_RUNTIME_CLASS(OpBevel),  // Runtime class
00139                                     OPTOKEN_BEVEL,          // Token string
00140                                     GetState,                   // GetState function
00141                                     _R(IDH_Command_Import_from_Web),                            // help ID GTODO: Is this needed?
00142                                     _R(IDBBL_URLIMPORT),            // bubble help
00143                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00144                                     _R(IDC_FILEURLIMPORT),          // control ID
00145                                     SYSTEMBAR_FILE,             // Bar ID   
00146                                     TRUE,                       // Receive system messages
00147                                     FALSE,                      // Smart duplicate operation
00148                                     TRUE,                       // Clean operation
00149                                     0,      // String for one copy only error
00150                                     (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00151                                 );  
00152 
00153 }
00154 
00155 /********************************************************************************************
00156 
00157 >   void OpBevel::Do(OpDescriptor*)
00158 
00159     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00160     Created:    6/6/97
00161     Purpose:    Imports a URL into the current document
00162     Errors:     -
00163 
00164 ********************************************************************************************/
00165 
00166 void OpBevel::Do(OpDescriptor*)
00167 {
00168     //First display our Import from URL dialog and get a filename from it
00169     WebAddress urlToGet;
00170 
00171     m_pDlg = new DaveDlg;
00172 
00173     m_pDlg->DoCreate();
00174 
00175     //And if the user clicked OK
00176     /*
00177     if (ok)
00178     {
00179 
00180         //So, is the URL we've got back a local filename?
00181         if (urlToGet.IsLocalFile())
00182         {
00183             //Yes. So get it as a pathname
00184             PathName pthToGet=urlToGet.GetPathName();
00185 
00186             //And first get a pointer to the All filter
00187             Filter* pAllFilter=GetAllFilter();
00188 
00189             //And if we found it
00190             if (pAllFilter)
00191             {
00192                 //Then import the pathname
00193                 String_256 strToGet=pthToGet.GetPath();
00194 
00195                 DoImport(pthToGet, pAllFilter, &strToGet);
00196             }
00197 
00198         }
00199         else
00200         {
00201             //No, it's a URL.
00202 
00203             //So download it
00204             ImportURL(urlToGet);
00205         }
00206     }
00207     */
00208 
00209 
00210 
00211 
00212 }
00213 
00214 /********************************************************************************************
00215 
00216 >   OpBevel::OpBevel()
00217 
00218     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00219     Created:    6/6/97
00220     Purpose:    Default constructor
00221 
00222 ********************************************************************************************/
00223 
00224 OpBevel::OpBevel()
00225 {
00226     OpFlags.HasOwnTimeIndicator = TRUE; // The OpBevel op has its own time indicator
00227 }
00228 
00229 /********************************************************************************************
00230 
00231 >   OpState OpBevel::GetState(String_256*, OpDescriptor*)
00232 
00233     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00234     Created:    6/6/97
00235     Purpose:    This item is always available, so long as a document is visible.
00236 
00237 ********************************************************************************************/
00238 
00239 OpState OpBevel::GetState(String_256*, OpDescriptor*)
00240 {
00241     OpState OpSt;
00242 
00243     return OpSt;
00244 }
00245 
00246 /*****************************************************************
00247 
00248   Toolkit functions
00249 
00250   ****************************************************************/
00251 
00252  /********************************************************************************************
00253 
00254 >   BOOL OpBevel::ImportURL(WebAddress urlToGet)
00255 
00256     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00257     Created:    6/6/97
00258     Inputs:     urlToGet    The URL to import
00259     Purpose:    Imports the URL given
00260 
00261 ********************************************************************************************/
00262 
00263 BOOL OpBevel::ImportURL(WebAddress urlToGet)
00264 {
00265     //First, set up some variables. We must do this now because I'm 
00266     //going to use a goto in a moment
00267     GenericDownloadParam* Param;
00268     OpDescriptor* pOpDesc;
00269     PathName pthTemp;
00270 
00271     //We want to import urlToGet using the best available filter
00272 
00273     //To get the best available filter, we simply download to the "All" filter
00274     //So get a pointer to the All filter
00275     Filter* pAllFilter=GetAllFilter();
00276 
00277     //Check we found it
00278     if (pAllFilter==NULL)
00279         goto ReturnError;
00280 
00281     //Now, get ready to download the file. This is rather complex.
00282 
00283     //First create a new set of download parameters
00284     //This object will be deleted when the download finishes
00285     Param = new GenericDownloadParam;
00286     
00287     //Now find the generic download OpDescriptor
00288     pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_OPGENERICDOWNLOAD);
00289 
00290     //And check we found it
00291     if (pOpDesc==NULL)
00292         goto ReturnError;
00293   
00294     //Now, create a temporary file to download to
00295     pthTemp=FileUtil::GetTemporaryPathName();
00296 
00297     //And now fill in our parameters
00298     Param->type = TYPE_HTML;
00299     Param->priority = AsynchDownload::PRIORITY_NORMAL;
00300     Param->strDescription = String_256(_R(IDS_HTMLIMPORT_FILEDOWNLOAD));
00301     Param->file = pthTemp.GetPath();
00302 
00303     Param->strURL = urlToGet.GetWebAddress();
00304                 
00305     Param->Output = NULL;
00306 
00307     Param->m_pFilter = pAllFilter;
00308     Param->m_Op = this;                     
00309     Param->pDoc = Document::GetCurrent();
00310 
00311     //And, finally, start the download going, if we've got a URL to download
00312     if (!Param->strURL.IsEmpty())
00313         pOpDesc->Invoke((OpParam*) Param);
00314     
00315     //And return TRUE
00316     return TRUE;
00317 
00318 ReturnError:
00319     if (Param)
00320         delete Param;
00321 
00322     return FALSE;
00323 }
00324 
00325  /********************************************************************************************
00326 
00327 >   Filter* OpBevel::GetAllFilter()
00328 
00329     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00330     Created:    10/6/97
00331     Inputs:     -
00332     Purpose:    Gets a pointer to the All filter.
00333     
00334 ********************************************************************************************/
00335 
00336 Filter* OpBevel::GetAllFilter()
00337 {
00338     //So get a pointer to the All filter
00339     return Filter::FindFilterFromID(FILTERID_GENERIC);
00340         
00341 }
00342 
00343 

Generated on Sat Nov 10 03:45:00 2007 for Camelot by  doxygen 1.4.4