]>
Commit | Line | Data |
---|---|---|
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 | ||
1d115baf RR |
18 | #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS |
19 | ||
09a09455 PC |
20 | #include "wx/gtk/gnome/gvfs.h" |
21 | ||
e4db172a WS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/log.h" | |
02761f6c | 24 | #include "wx/module.h" |
e4db172a WS |
25 | #endif |
26 | ||
1d115baf | 27 | #include "wx/mimetype.h" |
1d115baf | 28 | #include "wx/dynlib.h" |
1d115baf RR |
29 | |
30 | #include <libgnomevfs/gnome-vfs-mime-handlers.h> | |
31 | ||
09a09455 PC |
32 | #include "wx/link.h" |
33 | wxFORCE_LINK_THIS_MODULE(gnome_vfs) | |
1d115baf RR |
34 | |
35 | //---------------------------------------------------------------------------- | |
36 | // wxGnomeVFSLibrary | |
37 | //---------------------------------------------------------------------------- | |
38 | ||
1d115baf RR |
39 | class wxGnomeVFSLibrary |
40 | { | |
41 | public: | |
42 | wxGnomeVFSLibrary(); | |
43 | ~wxGnomeVFSLibrary(); | |
44 | ||
ced3df77 | 45 | private: |
1d115baf | 46 | bool IsOk(); |
ced3df77 | 47 | bool InitializeMethods(); |
1d115baf | 48 | |
ced3df77 VZ |
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; | |
1d115baf RR |
55 | |
56 | public: | |
57 | wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init, | |
58 | (), (), FALSE ) | |
59 | wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown, | |
60 | (), (), /**/ ) | |
e4db172a | 61 | |
1d115baf RR |
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 | ||
66 | wxGnomeVFSLibrary::wxGnomeVFSLibrary() | |
67 | { | |
1d115baf RR |
68 | wxLogNull log; |
69 | ||
ced3df77 VZ |
70 | m_libGnomeVFS.Load("libgnomevfs-2.so.0"); |
71 | m_ok = m_libGnomeVFS.IsLoaded() && InitializeMethods(); | |
1d115baf RR |
72 | } |
73 | ||
74 | wxGnomeVFSLibrary::~wxGnomeVFSLibrary() | |
75 | { | |
1d115baf RR |
76 | } |
77 | ||
78 | bool wxGnomeVFSLibrary::IsOk() | |
79 | { | |
80 | return m_ok; | |
81 | } | |
82 | ||
ced3df77 | 83 | bool wxGnomeVFSLibrary::InitializeMethods() |
1d115baf | 84 | { |
ced3df77 VZ |
85 | wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_init ) |
86 | wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_shutdown ) | |
e4db172a | 87 | |
ced3df77 | 88 | return true; |
1d115baf RR |
89 | } |
90 | ||
91 | static wxGnomeVFSLibrary* gs_lgvfs = NULL; | |
92 | ||
93 | //---------------------------------------------------------------------------- | |
94 | // wxGnomeVFSMimeTypesManagerFactory | |
95 | //---------------------------------------------------------------------------- | |
96 | ||
97 | wxMimeTypesManagerImpl *wxGnomeVFSMimeTypesManagerFactory::CreateMimeTypesManagerImpl() | |
98 | { | |
99 | return new wxGnomeVFSMimeTypesManagerImpl; | |
100 | } | |
101 | ||
102 | ||
103 | //---------------------------------------------------------------------------- | |
104 | // wxGnomeVFSMimeTypesManagerImpl | |
105 | //---------------------------------------------------------------------------- | |
106 | ||
107 | bool wxGnomeVFSMimeTypesManagerImpl::DoAssociation(const wxString& strType, | |
108 | const wxString& strIcon, | |
109 | wxMimeTypeCommands *entry, | |
110 | const wxArrayString& strExtensions, | |
111 | const wxString& strDesc) | |
112 | { | |
113 | int nIndex = AddToMimeData(strType, strIcon, entry, strExtensions, strDesc, true); | |
e4db172a | 114 | |
1d115baf RR |
115 | if ( nIndex == wxNOT_FOUND ) |
116 | return false; | |
117 | ||
118 | if (m_mailcapStylesInited & wxMAILCAP_GNOME) | |
119 | { | |
120 | // User modificationt to the MIME database | |
121 | // are not supported :-) | |
122 | } | |
e4db172a | 123 | |
1d115baf RR |
124 | return false; |
125 | } | |
126 | ||
127 | //---------------------------------------------------------------------------- | |
128 | // wxGnomeVFSModule | |
129 | //---------------------------------------------------------------------------- | |
130 | ||
131 | class wxGnomeVFSModule: public wxModule | |
132 | { | |
133 | public: | |
134 | wxGnomeVFSModule() {} | |
135 | bool OnInit(); | |
136 | void OnExit(); | |
137 | ||
138 | private: | |
139 | DECLARE_DYNAMIC_CLASS(wxGnomeVFSModule) | |
140 | }; | |
141 | ||
142 | bool wxGnomeVFSModule::OnInit() | |
143 | { | |
144 | gs_lgvfs = new wxGnomeVFSLibrary; | |
145 | if (gs_lgvfs->IsOk()) | |
146 | { | |
147 | if (gs_lgvfs->gnome_vfs_init()) | |
b1d8cb44 | 148 | wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory ); |
1d115baf RR |
149 | } |
150 | return true; | |
151 | } | |
152 | ||
153 | void wxGnomeVFSModule::OnExit() | |
154 | { | |
155 | if (gs_lgvfs->IsOk()) | |
156 | gs_lgvfs->gnome_vfs_shutdown(); | |
e4db172a | 157 | |
1d115baf RR |
158 | delete gs_lgvfs; |
159 | } | |
160 | ||
161 | IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule) | |
162 | ||
ced3df77 | 163 | #endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE |