]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gnome/gvfs.cpp
Include wx/button.h according to precompiled headers of wx/wx.h (with other minor...
[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
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
e4db172a
WS
22#ifndef WX_PRECOMP
23 #include "wx/log.h"
24#endif
25
1d115baf
RR
26#include "wx/mimetype.h"
27#include "wx/gtk/private.h"
28#include "wx/module.h"
29#include "wx/dynlib.h"
1d115baf
RR
30
31#include <libgnomevfs/gnome-vfs-mime-handlers.h>
32
33#include "wx/html/forcelnk.h"
34FORCE_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
50class wxGnomeVFSLibrary
51{
52public:
53 wxGnomeVFSLibrary();
54 ~wxGnomeVFSLibrary();
55
56 bool IsOk();
57 void InitializeMethods();
58
59private:
60 bool m_ok;
61 wxDynamicLibrary *m_gnome_vfs_lib;
62
63public:
64 wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init,
65 (), (), FALSE )
66 wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown,
67 (), (), /**/ )
e4db172a 68
1d115baf
RR
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
73wxGnomeVFSLibrary::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
86wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
87{
88 if (m_gnome_vfs_lib)
89 delete m_gnome_vfs_lib;
90}
91
92bool wxGnomeVFSLibrary::IsOk()
93{
94 return m_ok;
95}
96
97void 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 )
e4db172a 104
1d115baf
RR
105 m_ok = true;
106}
107
108static wxGnomeVFSLibrary* gs_lgvfs = NULL;
109
110//----------------------------------------------------------------------------
111// wxGnomeVFSMimeTypesManagerFactory
112//----------------------------------------------------------------------------
113
114wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
115{
116 return new wxGnomeVFSMimeTypesManagerImpl;
117}
118
119
120//----------------------------------------------------------------------------
121// wxGnomeVFSMimeTypesManagerImpl
122//----------------------------------------------------------------------------
123
124bool 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);
e4db172a 131
1d115baf
RR
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 }
e4db172a 140
1d115baf
RR
141 return false;
142}
143
144//----------------------------------------------------------------------------
145// wxGnomeVFSModule
146//----------------------------------------------------------------------------
147
148class wxGnomeVFSModule: public wxModule
149{
150public:
151 wxGnomeVFSModule() {}
152 bool OnInit();
153 void OnExit();
154
155private:
156 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule)
157};
158
159bool wxGnomeVFSModule::OnInit()
160{
161 gs_lgvfs = new wxGnomeVFSLibrary;
162 if (gs_lgvfs->IsOk())
163 {
164 if (gs_lgvfs->gnome_vfs_init())
165 wxMimeTypesManagerFactory::SetFactory( new wxGnomeVFSMimeTypesManagerFactory );
166 }
167 return true;
168}
169
170void wxGnomeVFSModule::OnExit()
171{
172 if (gs_lgvfs->IsOk())
173 gs_lgvfs->gnome_vfs_shutdown();
e4db172a 174
1d115baf
RR
175 delete gs_lgvfs;
176}
177
178IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule)
179
180#endif
181 // wxUSE_LIBGNOMEVS
182 // wxUSE_MIMETYPE