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 #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS
20 #include "wx/gtk/gnome/gvfs.h"
24 #include "wx/module.h"
27 #include "wx/mimetype.h"
28 #include "wx/dynlib.h"
30 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
33 wxFORCE_LINK_THIS_MODULE(gnome_vfs
)
35 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
39 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
40 typedef rettype (* name ## Type) args ; \
41 name ## Type pfn_ ## name; \
43 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
45 #define wxDL_METHOD_LOAD( lib, name, success ) \
46 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
49 class wxGnomeVFSLibrary
56 void InitializeMethods();
60 wxDynamicLibrary
*m_gnome_vfs_lib
;
63 wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
,
65 wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown
,
68 wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
,
69 (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK
)
72 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
74 m_gnome_vfs_lib
= NULL
;
78 m_gnome_vfs_lib
= new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") );
79 m_ok
= m_gnome_vfs_lib
->IsLoaded();
85 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
88 delete m_gnome_vfs_lib
;
91 bool wxGnomeVFSLibrary::IsOk()
96 void wxGnomeVFSLibrary::InitializeMethods()
101 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_init
, success
)
102 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_shutdown
, success
)
107 static wxGnomeVFSLibrary
* gs_lgvfs
= NULL
;
109 //----------------------------------------------------------------------------
110 // wxGnomeVFSMimeTypesManagerFactory
111 //----------------------------------------------------------------------------
113 wxMimeTypesManagerImpl
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
115 return new wxGnomeVFSMimeTypesManagerImpl
;
119 //----------------------------------------------------------------------------
120 // wxGnomeVFSMimeTypesManagerImpl
121 //----------------------------------------------------------------------------
123 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
124 const wxString
& strIcon
,
125 wxMimeTypeCommands
*entry
,
126 const wxArrayString
& strExtensions
,
127 const wxString
& strDesc
)
129 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
131 if ( nIndex
== wxNOT_FOUND
)
134 if (m_mailcapStylesInited
& wxMAILCAP_GNOME
)
136 // User modificationt to the MIME database
137 // are not supported :-)
143 //----------------------------------------------------------------------------
145 //----------------------------------------------------------------------------
147 class wxGnomeVFSModule
: public wxModule
150 wxGnomeVFSModule() {}
155 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
158 bool wxGnomeVFSModule::OnInit()
160 gs_lgvfs
= new wxGnomeVFSLibrary
;
161 if (gs_lgvfs
->IsOk())
163 if (gs_lgvfs
->gnome_vfs_init())
164 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
169 void wxGnomeVFSModule::OnExit()
171 if (gs_lgvfs
->IsOk())
172 gs_lgvfs
->gnome_vfs_shutdown();
177 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)