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 class wxGnomeVFSLibrary
47 bool InitializeMethods();
49 wxDynamicLibrary m_libGnomeVFS
;
51 // only true if we successfully loaded the library above
53 // don't rename this field, it's used by wxDL_XXX macros internally
57 wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
,
59 wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown
,
62 wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
,
63 (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK
)
66 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
70 m_libGnomeVFS
.Load("libgnomevfs-2.so.0");
71 m_ok
= m_libGnomeVFS
.IsLoaded() && InitializeMethods();
74 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
76 // we crash on exit later (i.e. after main() finishes) if we unload this
77 // library, apparently it inserts some hooks in other libraries to which we
78 // link implicitly (GTK+ itself?) which are not uninstalled when it's
79 // unloaded resulting in this crash, so just leave it in memory -- it's a
81 m_libGnomeVFS
.Detach();
84 bool wxGnomeVFSLibrary::IsOk()
89 bool wxGnomeVFSLibrary::InitializeMethods()
91 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_init
);
92 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_shutdown
);
97 static wxGnomeVFSLibrary
* gs_lgvfs
= NULL
;
99 //----------------------------------------------------------------------------
100 // wxGnomeVFSMimeTypesManagerFactory
101 //----------------------------------------------------------------------------
103 wxMimeTypesManagerImpl
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
105 return new wxGnomeVFSMimeTypesManagerImpl
;
109 //----------------------------------------------------------------------------
110 // wxGnomeVFSMimeTypesManagerImpl
111 //----------------------------------------------------------------------------
113 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
114 const wxString
& strIcon
,
115 wxMimeTypeCommands
*entry
,
116 const wxArrayString
& strExtensions
,
117 const wxString
& strDesc
)
130 //----------------------------------------------------------------------------
132 //----------------------------------------------------------------------------
134 class wxGnomeVFSModule
: public wxModule
137 wxGnomeVFSModule() {}
142 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
145 bool wxGnomeVFSModule::OnInit()
147 gs_lgvfs
= new wxGnomeVFSLibrary
;
148 if (gs_lgvfs
->IsOk())
150 if (gs_lgvfs
->gnome_vfs_init())
151 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
156 void wxGnomeVFSModule::OnExit()
158 if (gs_lgvfs
->IsOk())
159 gs_lgvfs
->gnome_vfs_shutdown();
164 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)
166 #endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE