1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gvfs.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME VFS support
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS
19 #include "wx/gtk/gnome/gvfs.h"
23 #include "wx/module.h"
26 #include "wx/mimetype.h"
27 #include "wx/dynlib.h"
29 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
32 wxFORCE_LINK_THIS_MODULE(gnome_vfs
)
34 //----------------------------------------------------------------------------
36 //----------------------------------------------------------------------------
38 class wxGnomeVFSLibrary
46 bool InitializeMethods();
48 wxDynamicLibrary m_libGnomeVFS
;
50 // only true if we successfully loaded the library above
52 // don't rename this field, it's used by wxDL_XXX macros internally
56 wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
,
58 wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown
,
61 wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
,
62 (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK
)
65 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
69 m_libGnomeVFS
.Load("libgnomevfs-2.so.0");
70 m_ok
= m_libGnomeVFS
.IsLoaded() && InitializeMethods();
73 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
75 // we crash on exit later (i.e. after main() finishes) if we unload this
76 // library, apparently it inserts some hooks in other libraries to which we
77 // link implicitly (GTK+ itself?) which are not uninstalled when it's
78 // unloaded resulting in this crash, so just leave it in memory -- it's a
80 m_libGnomeVFS
.Detach();
83 bool wxGnomeVFSLibrary::IsOk()
88 bool wxGnomeVFSLibrary::InitializeMethods()
90 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_init
);
91 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_shutdown
);
96 static wxGnomeVFSLibrary
* gs_lgvfs
= NULL
;
98 //----------------------------------------------------------------------------
99 // wxGnomeVFSMimeTypesManagerFactory
100 //----------------------------------------------------------------------------
102 wxMimeTypesManagerImpl
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
104 return new wxGnomeVFSMimeTypesManagerImpl
;
108 //----------------------------------------------------------------------------
109 // wxGnomeVFSMimeTypesManagerImpl
110 //----------------------------------------------------------------------------
112 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
113 const wxString
& strIcon
,
114 wxMimeTypeCommands
*entry
,
115 const wxArrayString
& strExtensions
,
116 const wxString
& strDesc
)
129 //----------------------------------------------------------------------------
131 //----------------------------------------------------------------------------
133 class wxGnomeVFSModule
: public wxModule
136 wxGnomeVFSModule() {}
141 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
144 bool wxGnomeVFSModule::OnInit()
146 gs_lgvfs
= new wxGnomeVFSLibrary
;
147 if (gs_lgvfs
->IsOk())
149 if (gs_lgvfs
->gnome_vfs_init())
150 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
155 void wxGnomeVFSModule::OnExit()
157 if (gs_lgvfs
->IsOk())
158 gs_lgvfs
->gnome_vfs_shutdown();
163 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)
165 #endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE