]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/gnome/gvfs.cpp
new file added
[wxWidgets.git] / src / gtk / gnome / gvfs.cpp
... / ...
CommitLineData
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"
33wxFORCE_LINK_THIS_MODULE(gnome_vfs)
34
35//----------------------------------------------------------------------------
36// wxGnomeVFSLibrary
37//----------------------------------------------------------------------------
38
39class wxGnomeVFSLibrary
40{
41public:
42 wxGnomeVFSLibrary();
43 ~wxGnomeVFSLibrary();
44 bool IsOk();
45
46private:
47 bool InitializeMethods();
48
49 wxDynamicLibrary m_libGnomeVFS;
50
51 // only true if we successfully loaded the library above
52 //
53 // don't rename this field, it's used by wxDL_XXX macros internally
54 bool m_ok;
55
56public:
57 wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init,
58 (), (), FALSE )
59 wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown,
60 (), () )
61
62 wxDL_METHOD_DEFINE( GnomeVFSResult, gnome_vfs_mime_set_icon,
63 (const char *mime_type, const char *filename), (mime_type, filename), GNOME_VFS_OK )
64};
65
66wxGnomeVFSLibrary::wxGnomeVFSLibrary()
67{
68 wxLogNull log;
69
70 m_libGnomeVFS.Load("libgnomevfs-2.so.0");
71 m_ok = m_libGnomeVFS.IsLoaded() && InitializeMethods();
72}
73
74wxGnomeVFSLibrary::~wxGnomeVFSLibrary()
75{
76 // we crash on exit later (i.e. after main() finishes) if we unload this
77 // library, apparently it inserts some hooks in other libraries to which we
78 // link implicitly (GTK+ itself?) which are not uninstalled when it's
79 // unloaded resulting in this crash, so just leave it in memory -- it's a
80 // lesser evil
81 m_libGnomeVFS.Detach();
82}
83
84bool wxGnomeVFSLibrary::IsOk()
85{
86 return m_ok;
87}
88
89bool wxGnomeVFSLibrary::InitializeMethods()
90{
91 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_init );
92 wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_shutdown );
93
94 return true;
95}
96
97static wxGnomeVFSLibrary* gs_lgvfs = NULL;
98
99//----------------------------------------------------------------------------
100// wxGnomeVFSMimeTypesManagerFactory
101//----------------------------------------------------------------------------
102
103wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl()
104{
105 return new wxGnomeVFSMimeTypesManagerImpl;
106}
107
108
109//----------------------------------------------------------------------------
110// wxGnomeVFSMimeTypesManagerImpl
111//----------------------------------------------------------------------------
112
113bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString& strType,
114 const wxString& strIcon,
115 wxMimeTypeCommands *entry,
116 const wxArrayString& strExtensions,
117 const wxString& strDesc)
118{
119 return AddToMimeData
120 (
121 strType,
122 strIcon,
123 entry,
124 strExtensions,
125 strDesc,
126 true
127 ) != wxNOT_FOUND;
128}
129
130//----------------------------------------------------------------------------
131// wxGnomeVFSModule
132//----------------------------------------------------------------------------
133
134class wxGnomeVFSModule: public wxModule
135{
136public:
137 wxGnomeVFSModule() {}
138 bool OnInit();
139 void OnExit();
140
141private:
142 DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule)
143};
144
145bool wxGnomeVFSModule::OnInit()
146{
147 gs_lgvfs = new wxGnomeVFSLibrary;
148 if (gs_lgvfs->IsOk())
149 {
150 if (gs_lgvfs->gnome_vfs_init())
151 wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory );
152 }
153 return true;
154}
155
156void wxGnomeVFSModule::OnExit()
157{
158 if (gs_lgvfs->IsOk())
159 gs_lgvfs->gnome_vfs_shutdown();
160
161 delete gs_lgvfs;
162}
163
164IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule)
165
166#endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE