Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

filetypes.h

Go to the documentation of this file.
00001 
00002 // Name:        filetypes.h
00003 // Author:      Joe Yates
00004 // Purpose:     File type information manager interface
00005 // Created:     2004-11-25
00006 // Copyright:   (c) Joe Yates
00007 // License:     BSD license (see the file 'LICENSE.txt')
00009 
00010 /*
00011 
00012 To do
00013 -----
00014 - Finish implementation of file type saving information,
00015 
00016 */
00017 
00018 #ifndef __filetypes_h__
00019 #define __filetypes_h__
00020 
00021 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00022 #pragma interface
00023 #endif
00024 
00025 #include "wx/defs.h"
00026 
00027 #ifndef WX_PRECOMP
00028   #include <wx/wx.h>
00029 #endif
00030 
00031 #include <wx/filename.h>
00032 #include <wx/image.h>
00033 
00034 // Declare a structure to handle extra verbs associated with a File Type
00035 /*
00036 The following commented out as all the wx Hash code in CVS HEAD is (was?) causing segfaults
00037 // WX_DECLARE_STRING_HASH_MAP(wxString, ExtraVerbs);
00038 */
00039 
00040 #if _MSC_VER > 1000
00041 # pragma warning (disable : 4786) // identifier was truncated to '255' characters in the browser information
00042 #endif // _MSC_VER > 1000
00043 
00044 #include <map>
00045 
00046 typedef std::map<wxString, wxString> ExtraVerbs;
00047 
00048 class wxFileType2
00049   {
00050   public:
00051     // ctor for valid instances
00052     wxFileType2(const wxString& sNewName);
00053 
00054     // ctor for invalid instances
00055     wxFileType2();
00056 
00057   public:
00058     bool            IsValid() const;
00059     bool            IsExecutable() const;
00060   
00061     // Properties interface
00062     wxString        GetName() const;
00063     void            SetName(const wxString& sNewName);
00064     wxString        GetDescription() const;
00065     void            SetDescription(const wxString& sNewDescription);
00066     wxIcon          GetIcon() const;
00067     wxFileName      GetIconPath(long * nIndex = NULL) const;
00068     void            SetIconPath(const wxFileName& fnmIcon, const long& nIndex = 0);
00069     wxString        GetDefaultCommand() const;
00070     void            SetDefaultCommand(const wxString& sNewDefaultCommand);
00071     wxString        GetVerb(const wxString& sVerb) const;
00072     void            SetVerb(const wxString& sVerb, const wxString& sValue);
00073     void            DeleteVerb(const wxString& sVerb);
00074     wxArrayString   GetExtensions() const;
00075     void            SetExtensions(const wxArrayString& asNewExtensions);
00076 
00077     // Static functions
00078     static bool     IsExecutable(const wxString& sFileType);
00079 
00080   private:
00081     wxString        sName;
00082     wxString        sDescription;
00083     wxIconLocation  icl;
00084     wxString        sCommand;
00085     wxArrayString   asExtensions;
00086     ExtraVerbs      exv;
00087   };
00088 
00089 class wxFileTypesImpl
00090   {
00091   public:
00092     virtual ~wxFileTypesImpl()
00093       {};
00094 
00095     // IsLoaded() is a NOOP on Windows,
00096     // on GTK it indicates if we've loaded the necessary libs
00097     virtual bool          IsLoaded() const                                = 0;
00098     virtual wxString      GetFileType(const wxString& sFileURL) const     = 0;
00099     virtual wxFileType2   LoadFileType(const wxString& sFileType) const   = 0;
00100     virtual bool          SaveFileType(const wxFileType2& fti) const      = 0;
00101   
00102     // Applications and commands
00103     virtual wxArrayString GetApplications(const wxString& sFileURL) const                                   = 0;
00104     virtual bool          AddApplication(const wxString& sFileURL, const wxString& sNewApplicationId) const = 0;
00105     virtual bool          RemoveApplication(const wxString& sFileURL, const wxString& sApplicationId) const = 0;
00106     virtual wxString      GetCommand(const wxString& sApplicationId) const                                  = 0;
00107     virtual bool          SetCommand(const wxString& sApplicationId, const wxString& sNewCommand) const     = 0;
00108   };
00109 
00110 
00111 /*
00112 
00113 File type source enumeration:
00114 
00115 wxFILE_TYPE_SOURCE_DEFAULT: the default source for the current state of the system.
00116   If a window manager is running under X, get data from that window manager.
00117 
00118 wxFILE_TYPE_SOURCE_MAILCAP: load data from traditional mailcap files.
00119 
00120 */
00121 
00122 enum wxFileTypeSource
00123   {
00124   wxFILE_TYPE_SOURCE_DEFAULT = 0,
00125   wxFILE_TYPE_SOURCE_MAILCAP = 1,
00126   wxFILE_TYPE_SOURCE_GNOME = 2,
00127   wxFILE_TYPE_SOURCE_KDE = 3,
00128   wxFILE_TYPE_SOURCE_WINDOWSREGISTRY = 4,
00129   };
00130 
00131 class wxFileTypesManager
00132   {
00133   public:
00134     wxFileTypesManager(const wxFileTypeSource& src = wxFILE_TYPE_SOURCE_DEFAULT);
00135     ~wxFileTypesManager();
00136 
00137   public:
00138     bool              IsLoaded() const;
00139     wxString          GetFileType(const wxString& sFileURL) const;
00140     wxFileType2       LoadFileType(const wxString& sFileType) const;
00141     bool              SaveFileType(const wxFileType2& fti) const;
00142 
00143     wxArrayString     GetApplications(const wxString& sFileURL) const;
00144     bool              AddApplication(const wxString& sFileURL, const wxString& sNewApplicationId) const;
00145     bool              RemoveApplication(const wxString& sFileURL, const wxString& sApplicationId) const;
00146     wxString          GetCommand(const wxString& sApplicationId) const;
00147     bool              SetCommand(const wxString& sApplicationId, const wxString& sNewCommand) const;
00148 
00149   private:
00150     wxFileTypesImpl * m_pImpl;
00151   };
00152 
00153 #ifdef __UNIX__
00154 #ifdef __WXGTK__
00155 #include <wx/gtk/gnome/gnomefiletypes.h>
00156 #endif
00157   // def __WXGTK__
00158 #endif
00159   // def __UNIX__
00160 #ifdef __WXMSW__
00161 #include <wx/msw/mswfiletypes.h>
00162 #endif
00163   // def __WXMSW__
00164 
00165 #endif
00166   // ndef __filetypes_h__

Generated on Wed Jan 25 08:13:09 2006 for Sherpa wxWidgets Classes by doxygen 1.3.6