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()
78 bool wxGnomeVFSLibrary::IsOk()
83 bool wxGnomeVFSLibrary::InitializeMethods()
85 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_init
);
86 wxDL_METHOD_LOAD( m_libGnomeVFS
, gnome_vfs_shutdown
);
91 static wxGnomeVFSLibrary
* gs_lgvfs
= NULL
;
93 //----------------------------------------------------------------------------
94 // wxGnomeVFSMimeTypesManagerFactory
95 //----------------------------------------------------------------------------
97 wxMimeTypesManagerImpl
*wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
99 return new wxGnomeVFSMimeTypesManagerImpl
;
103 //----------------------------------------------------------------------------
104 // wxGnomeVFSMimeTypesManagerImpl
105 //----------------------------------------------------------------------------
107 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
108 const wxString
& strIcon
,
109 wxMimeTypeCommands
*entry
,
110 const wxArrayString
& strExtensions
,
111 const wxString
& strDesc
)
113 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
115 if ( nIndex
== wxNOT_FOUND
)
118 if (m_mailcapStylesInited
& wxMAILCAP_GNOME
)
120 // User modificationt to the MIME database
121 // are not supported :-)
127 //----------------------------------------------------------------------------
129 //----------------------------------------------------------------------------
131 class wxGnomeVFSModule
: public wxModule
134 wxGnomeVFSModule() {}
139 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule
)
142 bool wxGnomeVFSModule::OnInit()
144 gs_lgvfs
= new wxGnomeVFSLibrary
;
145 if (gs_lgvfs
->IsOk())
147 if (gs_lgvfs
->gnome_vfs_init())
148 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory
);
153 void wxGnomeVFSModule::OnExit()
155 if (gs_lgvfs
->IsOk())
156 gs_lgvfs
->gnome_vfs_shutdown();
161 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule
, wxModule
)
163 #endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE