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
26 #include "wx/mimetype.h"
27 #include "wx/gtk/private.h"
28 #include "wx/module.h"
29 #include "wx/dynlib.h"
31 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
33 #include "wx/html/forcelnk.h"
34 FORCE_LINK_ME(gnome_vfs
)
36 //----------------------------------------------------------------------------
38 //----------------------------------------------------------------------------
40 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
41 typedef rettype (* name ## Type) args ; \
42 name ## Type pfn_ ## name; \
44 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
46 #define wxDL_METHOD_LOAD( lib, name, success ) \
47 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
50 class wxGnomeVFSLibrary
57 void InitializeMethods();
61 wxDynamicLibrary
*m_gnome_vfs_lib
;
64 wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
,
66 wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown
,
69 wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
,
70 (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK
)
73 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
75 m_gnome_vfs_lib
= NULL
;
79 m_gnome_vfs_lib
= new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") );
80 m_ok
= m_gnome_vfs_lib
->IsLoaded();
86 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
89 delete m_gnome_vfs_lib
;
92 bool wxGnomeVFSLibrary::IsOk()
97 void wxGnomeVFSLibrary::InitializeMethods()
102 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_init
, success
)
103 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_shutdown
, success
)
108 static wxGnomeVFSLibrary
* gs_lgvfs
= NULL
;
110 //----------------------------------------------------------------------------
111 // wxGnomeVFSMimeTypesManagerFactory
112 //----------------------------------------------------------------------------
114 wxMimeTypesManagerImpl
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
116 return new wxGnomeVFSMimeTypesManagerImpl
;
120 //----------------------------------------------------------------------------
121 // wxGnomeVFSMimeTypesManagerImpl
122 //----------------------------------------------------------------------------
124 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
125 const wxString
& strIcon
,
126 wxMimeTypeCommands
*entry
,
127 const wxArrayString
& strExtensions
,
128 const wxString
& strDesc
)
130 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
132 if ( nIndex
== wxNOT_FOUND
)
135 if (m_mailcapStylesInited
& wxMAILCAP_GNOME
)
137 // User modificationt to the MIME database
138 // are not supported :-)
144 //----------------------------------------------------------------------------
146 //----------------------------------------------------------------------------
148 class wxGnomeVFSModule
: public wxModule
151 wxGnomeVFSModule() {}
156 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
159 bool wxGnomeVFSModule::OnInit()
161 gs_lgvfs
= new wxGnomeVFSLibrary
;
162 if (gs_lgvfs
->IsOk())
164 if (gs_lgvfs
->gnome_vfs_init())
165 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
170 void wxGnomeVFSModule::OnExit()
172 if (gs_lgvfs
->IsOk())
173 gs_lgvfs
->gnome_vfs_shutdown();
178 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)