1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/gnome/gvfs.cpp 
   3 // Author:      Robert Roebling 
   4 // Purpose:     Implement GNOME VFS support 
   7 // Copyright:   Robert Roebling 
   8 // Licence:     wxWindows Licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 // For compilers that support precompilation, includes "wx/wx.h". 
  12 #include "wx/wxprec.h" 
  18 #include "wx/gtk/gnome/gvfs.h" 
  20 #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS 
  22 #include "wx/mimetype.h" 
  23 #include "wx/gtk/private.h" 
  24 #include "wx/module.h" 
  25 #include "wx/dynlib.h" 
  28 #include <libgnomevfs/gnome-vfs-mime-handlers.h> 
  30 #include "wx/html/forcelnk.h" 
  31 FORCE_LINK_ME(gnome_vfs
) 
  33 //---------------------------------------------------------------------------- 
  35 //---------------------------------------------------------------------------- 
  37 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \ 
  38     typedef rettype (* name ## Type) args ; \ 
  39     name ## Type pfn_ ## name; \ 
  41     { if (m_ok) return pfn_ ## name shortargs ; return defret; } 
  43 #define wxDL_METHOD_LOAD( lib, name, success ) \ 
  44     pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \ 
  47 class wxGnomeVFSLibrary
 
  54     void InitializeMethods(); 
  58     wxDynamicLibrary 
*m_gnome_vfs_lib
; 
  61     wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
, 
  63     wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown
, 
  66     wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
, 
  67         (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK 
) 
  70 wxGnomeVFSLibrary::wxGnomeVFSLibrary() 
  72     m_gnome_vfs_lib 
= NULL
; 
  76     m_gnome_vfs_lib 
= new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") ); 
  77     m_ok 
= m_gnome_vfs_lib
->IsLoaded(); 
  83 wxGnomeVFSLibrary::~wxGnomeVFSLibrary() 
  86         delete m_gnome_vfs_lib
; 
  89 bool wxGnomeVFSLibrary::IsOk() 
  94 void wxGnomeVFSLibrary::InitializeMethods() 
  99     wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_init
, success 
) 
 100     wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_shutdown
, success 
) 
 105 static wxGnomeVFSLibrary
* gs_lgvfs 
= NULL
; 
 107 //---------------------------------------------------------------------------- 
 108 // wxGnomeVFSMimeTypesManagerFactory 
 109 //---------------------------------------------------------------------------- 
 111 wxMimeTypesManagerImpl 
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl() 
 113     return new wxGnomeVFSMimeTypesManagerImpl
; 
 117 //---------------------------------------------------------------------------- 
 118 // wxGnomeVFSMimeTypesManagerImpl 
 119 //---------------------------------------------------------------------------- 
 121 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
, 
 122                        const wxString
& strIcon
, 
 123                        wxMimeTypeCommands 
*entry
, 
 124                        const wxArrayString
& strExtensions
, 
 125                        const wxString
& strDesc
) 
 127     int nIndex 
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true); 
 129     if ( nIndex 
== wxNOT_FOUND 
) 
 132     if (m_mailcapStylesInited 
& wxMAILCAP_GNOME
) 
 134         // User modificationt to the MIME database 
 135         // are not supported :-) 
 141 //---------------------------------------------------------------------------- 
 143 //---------------------------------------------------------------------------- 
 145 class wxGnomeVFSModule
: public wxModule
 
 148     wxGnomeVFSModule() {} 
 153     DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
) 
 156 bool wxGnomeVFSModule::OnInit() 
 158     gs_lgvfs 
= new wxGnomeVFSLibrary
; 
 159     if (gs_lgvfs
->IsOk()) 
 161         if (gs_lgvfs
->gnome_vfs_init()) 
 162             wxMimeTypesManagerFactory::SetFactory( new wxGnomeVFSMimeTypesManagerFactory 
); 
 167 void wxGnomeVFSModule::OnExit() 
 169     if (gs_lgvfs
->IsOk()) 
 170         gs_lgvfs
->gnome_vfs_shutdown(); 
 175 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)