]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gnome/gvfs.cpp
compilation fix after wxGTK_CONV changes
[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 // RCS-ID: $Id$
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/gtk/gnome/gvfs.h"
19
20 #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS
21
22 #include "wx/mimetype.h"
23 #include "wx/gtk/private.h"
24 #include "wx/module.h"
25 #include "wx/dynlib.h"
26 #include "wx/log.h"
27
28 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
29
30 #include "wx/html/forcelnk.h"
31 FORCE_LINK_ME(gnome_vfs)
32
33 //----------------------------------------------------------------------------
34 // wxGnomeVFSLibrary
35 //----------------------------------------------------------------------------
36
37 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
38 typedef rettype (* name ## Type) args ; \
39 name ## Type pfn_ ## name; \
40 rettype name args \
41 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
42
43 #define wxDL_METHOD_LOAD( lib, name, success ) \
44 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
45 if (!success) return;
46
47 class wxGnomeVFSLibrary
48 {
49 public:
50 wxGnomeVFSLibrary();
51 ~wxGnomeVFSLibrary();
52
53 bool IsOk();
54 void InitializeMethods();
55
56 private:
57 bool m_ok;
58 wxDynamicLibrary *m_gnome_vfs_lib;
59
60 public:
61 wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init,
62 (), (), FALSE )
63 wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown,
64 (), (), /**/ )
65
66 wxDL_METHOD_DEFINE( GnomeVFSResult, gnome_vfs_mime_set_icon,
67 (const char *mime_type, const char *filename), (mime_type, filename), GNOME_VFS_OK )
68 };
69
70 wxGnomeVFSLibrary::wxGnomeVFSLibrary()
71 {
72 m_gnome_vfs_lib = NULL;
73
74 wxLogNull log;
75
76 m_gnome_vfs_lib = new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") );
77 m_ok = m_gnome_vfs_lib->IsLoaded();
78 if (!m_ok) return;
79
80 InitializeMethods();
81 }
82
83 wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
84 {
85 if (m_gnome_vfs_lib)
86 delete m_gnome_vfs_lib;
87 }
88
89 bool wxGnomeVFSLibrary::IsOk()
90 {
91 return m_ok;
92 }
93
94 void wxGnomeVFSLibrary::InitializeMethods()
95 {
96 m_ok = false;
97 bool success;
98
99 wxDL_METHOD_LOAD( m_gnome_vfs_lib, gnome_vfs_init, success )
100 wxDL_METHOD_LOAD( m_gnome_vfs_lib, gnome_vfs_shutdown, success )
101
102 m_ok = true;
103 }
104
105 static wxGnomeVFSLibrary* gs_lgvfs = NULL;
106
107 //----------------------------------------------------------------------------
108 // wxGnomeVFSMimeTypesManagerFactory
109 //----------------------------------------------------------------------------
110
111 wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
112 {
113 return new wxGnomeVFSMimeTypesManagerImpl;
114 }
115
116
117 //----------------------------------------------------------------------------
118 // wxGnomeVFSMimeTypesManagerImpl
119 //----------------------------------------------------------------------------
120
121 bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString& strType,
122 const wxString& strIcon,
123 wxMimeTypeCommands *entry,
124 const wxArrayString& strExtensions,
125 const wxString& strDesc)
126 {
127 int nIndex = AddToMimeData(strType, strIcon, entry, strExtensions, strDesc, true);
128
129 if ( nIndex == wxNOT_FOUND )
130 return false;
131
132 if (m_mailcapStylesInited & wxMAILCAP_GNOME)
133 {
134 // User modificationt to the MIME database
135 // are not supported :-)
136 }
137
138 return false;
139 }
140
141 //----------------------------------------------------------------------------
142 // wxGnomeVFSModule
143 //----------------------------------------------------------------------------
144
145 class wxGnomeVFSModule: public wxModule
146 {
147 public:
148 wxGnomeVFSModule() {}
149 bool OnInit();
150 void OnExit();
151
152 private:
153 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule)
154 };
155
156 bool wxGnomeVFSModule::OnInit()
157 {
158 gs_lgvfs = new wxGnomeVFSLibrary;
159 if (gs_lgvfs->IsOk())
160 {
161 if (gs_lgvfs->gnome_vfs_init())
162 wxMimeTypesManagerFactory::SetFactory( new wxGnomeVFSMimeTypesManagerFactory );
163 }
164 return true;
165 }
166
167 void wxGnomeVFSModule::OnExit()
168 {
169 if (gs_lgvfs->IsOk())
170 gs_lgvfs->gnome_vfs_shutdown();
171
172 delete gs_lgvfs;
173 }
174
175 IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule)
176
177 #endif
178 // wxUSE_LIBGNOMEVS
179 // wxUSE_MIMETYPE