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
46 void InitializeMethods();
50 wxDynamicLibrary
*m_gnome_vfs_lib
;
53 wxDL_METHOD_DEFINE( gboolean
, gnome_vfs_init
,
55 wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown
,
58 wxDL_METHOD_DEFINE( GnomeVFSResult
, gnome_vfs_mime_set_icon
,
59 (const char *mime_type
, const char *filename
), (mime_type
, filename
), GNOME_VFS_OK
)
62 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
64 m_gnome_vfs_lib
= NULL
;
68 m_gnome_vfs_lib
= new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") );
69 m_ok
= m_gnome_vfs_lib
->IsLoaded();
75 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
78 delete m_gnome_vfs_lib
;
81 bool wxGnomeVFSLibrary::IsOk()
86 void wxGnomeVFSLibrary::InitializeMethods()
91 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_init
, success
)
92 wxDL_METHOD_LOAD( m_gnome_vfs_lib
, gnome_vfs_shutdown
, success
)
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
)
119 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
121 if ( nIndex
== wxNOT_FOUND
)
124 if (m_mailcapStylesInited
& wxMAILCAP_GNOME
)
126 // User modificationt to the MIME database
127 // are not supported :-)
133 //----------------------------------------------------------------------------
135 //----------------------------------------------------------------------------
137 class wxGnomeVFSModule
: public wxModule
140 wxGnomeVFSModule() {}
145 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
148 bool wxGnomeVFSModule::OnInit()
150 gs_lgvfs
= new wxGnomeVFSLibrary
;
151 if (gs_lgvfs
->IsOk())
153 if (gs_lgvfs
->gnome_vfs_init())
154 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
159 void wxGnomeVFSModule::OnExit()
161 if (gs_lgvfs
->IsOk())
162 gs_lgvfs
->gnome_vfs_shutdown();
167 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)