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