]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gnome/gvfs.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / gtk / gnome / gvfs.cpp
CommitLineData
1d115baf
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/gnome/gvfs.cpp
3// Author: Robert Roebling
4// Purpose: Implement GNOME VFS support
5// Created: 03/17/06
1d115baf
RR
6// Copyright: Robert Roebling
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx/wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
1d115baf
RR
17#if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS
18
09a09455
PC
19#include "wx/gtk/gnome/gvfs.h"
20
e4db172a
WS
21#ifndef WX_PRECOMP
22 #include "wx/log.h"
02761f6c 23 #include "wx/module.h"
e4db172a
WS
24#endif
25
1d115baf 26#include "wx/mimetype.h"
1d115baf 27#include "wx/dynlib.h"
1d115baf
RR
28
29#include <libgnomevfs/gnome-vfs-mime-handlers.h>
30
09a09455
PC
31#include "wx/link.h"
32wxFORCE_LINK_THIS_MODULE(gnome_vfs)
1d115baf
RR
33
34//----------------------------------------------------------------------------
35// wxGnomeVFSLibrary
36//----------------------------------------------------------------------------
37
1d115baf
RR
38class wxGnomeVFSLibrary
39{
40public:
41 wxGnomeVFSLibrary();
42 ~wxGnomeVFSLibrary();
0a5b15da 43 bool IsOk();
1d115baf 44
ced3df77 45private:
ced3df77 46 bool InitializeMethods();
1d115baf 47
ced3df77
VZ
48 wxDynamicLibrary m_libGnomeVFS;
49
50 // only true if we successfully loaded the library above
51 //
52 // don't rename this field, it's used by wxDL_XXX macros internally
53 bool m_ok;
1d115baf
RR
54
55public:
56 wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init,
57 (), (), FALSE )
0a5b15da
MR
58 wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown,
59 (), () )
e4db172a 60
1d115baf
RR
61 wxDL_METHOD_DEFINE( GnomeVFSResult, gnome_vfs_mime_set_icon,
62 (const char *mime_type, const char *filename), (mime_type, filename), GNOME_VFS_OK )
63};
64
65wxGnomeVFSLibrary::wxGnomeVFSLibrary()
66{
1d115baf
RR
67 wxLogNull log;
68
ced3df77
VZ
69 m_libGnomeVFS.Load("libgnomevfs-2.so.0");
70 m_ok = m_libGnomeVFS.IsLoaded() && InitializeMethods();
1d115baf
RR
71}
72
73wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
74{
7d287e71
VZ
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
79 // lesser evil
80 m_libGnomeVFS.Detach();
1d115baf
RR
81}
82
83bool wxGnomeVFSLibrary::IsOk()
84{
85 return m_ok;
86}
87
ced3df77 88bool wxGnomeVFSLibrary::InitializeMethods()
1d115baf 89{
0a5b15da
MR
90 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_init );
91 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_shutdown );
e4db172a 92
ced3df77 93 return true;
1d115baf
RR
94}
95
96static wxGnomeVFSLibrary* gs_lgvfs = NULL;
97
98//----------------------------------------------------------------------------
99// wxGnomeVFSMimeTypesManagerFactory
100//----------------------------------------------------------------------------
101
102wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
103{
104 return new wxGnomeVFSMimeTypesManagerImpl;
105}
106
107
108//----------------------------------------------------------------------------
109// wxGnomeVFSMimeTypesManagerImpl
110//----------------------------------------------------------------------------
111
112bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString& strType,
113 const wxString& strIcon,
114 wxMimeTypeCommands *entry,
115 const wxArrayString& strExtensions,
116 const wxString& strDesc)
117{
07a9d3f9
VZ
118 return AddToMimeData
119 (
120 strType,
121 strIcon,
122 entry,
123 strExtensions,
124 strDesc,
125 true
126 ) != wxNOT_FOUND;
1d115baf
RR
127}
128
129//----------------------------------------------------------------------------
130// wxGnomeVFSModule
131//----------------------------------------------------------------------------
132
133class wxGnomeVFSModule: public wxModule
134{
135public:
136 wxGnomeVFSModule() {}
137 bool OnInit();
138 void OnExit();
139
140private:
141 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule)
142};
143
144bool wxGnomeVFSModule::OnInit()
145{
146 gs_lgvfs = new wxGnomeVFSLibrary;
147 if (gs_lgvfs->IsOk())
148 {
149 if (gs_lgvfs->gnome_vfs_init())
b1d8cb44 150 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory );
1d115baf
RR
151 }
152 return true;
153}
154
155void wxGnomeVFSModule::OnExit()
156{
157 if (gs_lgvfs->IsOk())
158 gs_lgvfs->gnome_vfs_shutdown();
e4db172a 159
1d115baf
RR
160 delete gs_lgvfs;
161}
162
163IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule)
164
ced3df77 165#endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE