]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gnome/gvfs.cpp
No changes, just change data structures used by mouse capture code.
[wxWidgets.git] / src / gtk / gnome / gvfs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gvfs.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME VFS support
5 // Created: 03/17/06
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
17 #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS
18
19 #include "wx/gtk/gnome/gvfs.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/module.h"
24 #endif
25
26 #include "wx/mimetype.h"
27 #include "wx/dynlib.h"
28
29 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
30
31 #include "wx/link.h"
32 wxFORCE_LINK_THIS_MODULE(gnome_vfs)
33
34 //----------------------------------------------------------------------------
35 // wxGnomeVFSLibrary
36 //----------------------------------------------------------------------------
37
38 class wxGnomeVFSLibrary
39 {
40 public:
41 wxGnomeVFSLibrary();
42 ~wxGnomeVFSLibrary();
43 bool IsOk();
44
45 private:
46 bool InitializeMethods();
47
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;
54
55 public:
56 wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init,
57 (), (), FALSE )
58 wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown,
59 (), () )
60
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
65 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
66 {
67 wxLogNull log;
68
69 m_libGnomeVFS.Load("libgnomevfs-2.so.0");
70 m_ok = m_libGnomeVFS.IsLoaded() && InitializeMethods();
71 }
72
73 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
74 {
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();
81 }
82
83 bool wxGnomeVFSLibrary::IsOk()
84 {
85 return m_ok;
86 }
87
88 bool wxGnomeVFSLibrary::InitializeMethods()
89 {
90 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_init );
91 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_shutdown );
92
93 return true;
94 }
95
96 static wxGnomeVFSLibrary* gs_lgvfs = NULL;
97
98 //----------------------------------------------------------------------------
99 // wxGnomeVFSMimeTypesManagerFactory
100 //----------------------------------------------------------------------------
101
102 wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
103 {
104 return new wxGnomeVFSMimeTypesManagerImpl;
105 }
106
107
108 //----------------------------------------------------------------------------
109 // wxGnomeVFSMimeTypesManagerImpl
110 //----------------------------------------------------------------------------
111
112 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString& strType,
113 const wxString& strIcon,
114 wxMimeTypeCommands *entry,
115 const wxArrayString& strExtensions,
116 const wxString& strDesc)
117 {
118 return AddToMimeData
119 (
120 strType,
121 strIcon,
122 entry,
123 strExtensions,
124 strDesc,
125 true
126 ) != wxNOT_FOUND;
127 }
128
129 //----------------------------------------------------------------------------
130 // wxGnomeVFSModule
131 //----------------------------------------------------------------------------
132
133 class wxGnomeVFSModule: public wxModule
134 {
135 public:
136 wxGnomeVFSModule() {}
137 bool OnInit();
138 void OnExit();
139
140 private:
141 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule)
142 };
143
144 bool wxGnomeVFSModule::OnInit()
145 {
146 gs_lgvfs = new wxGnomeVFSLibrary;
147 if (gs_lgvfs->IsOk())
148 {
149 if (gs_lgvfs->gnome_vfs_init())
150 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory );
151 }
152 return true;
153 }
154
155 void wxGnomeVFSModule::OnExit()
156 {
157 if (gs_lgvfs->IsOk())
158 gs_lgvfs->gnome_vfs_shutdown();
159
160 delete gs_lgvfs;
161 }
162
163 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule)
164
165 #endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE