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