1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: src/gtk/mimetype.cpp 3 // Purpose: classes and functions to manage MIME types 4 // Author: Hans Mackowiak 5 // Created: 2016-06-05 6 // Copyright: (c) 2016 Hans Mackowiak <hanmac@gmx.de> 7 // Licence: wxWindows licence 8 ///////////////////////////////////////////////////////////////////////////// 9 10 #include "wx/wxprec.h" 11 12 #if wxUSE_MIMETYPE 13 14 #include "wx/gtk/mimetype.h" 15 16 #include "wx/gtk/private/wrapgtk.h" 17 18 #include "wx/gtk/private/string.h" 19 #include "wx/gtk/private/object.h" 20 21 #if defined(__UNIX__) GetIconFromMimeType(const wxString & mime)22wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) 23 { 24 wxString icon; 25 #if GTK_CHECK_VERSION(2,14,0) 26 if (!wx_is_at_least_gtk2(14)) 27 return icon; 28 29 wxGtkString type(g_content_type_from_mime_type(mime.utf8_str())); 30 31 wxGtkObject<GIcon> gicon(g_content_type_get_icon(type)); 32 if ( !gicon ) 33 return icon; 34 35 GtkIconTheme *theme(gtk_icon_theme_get_default()); 36 if ( !theme ) 37 return icon; 38 39 // Notice that we can't use wxGtkObject here because a special function 40 // needs to be used for freeing this object prior to GTK+ 3.8. 41 GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon 42 ( 43 theme, 44 gicon, 45 256, 46 GTK_ICON_LOOKUP_NO_SVG 47 ); 48 49 if ( giconinfo ) 50 { 51 icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); 52 53 wxGCC_WARNING_SUPPRESS(deprecated-declarations) 54 gtk_icon_info_free(giconinfo); 55 wxGCC_WARNING_RESTORE() 56 } 57 #endif // GTK_CHECK_VERSION(2,14,0) 58 return icon; 59 } 60 #endif // defined(__UNIX__) 61 CreateMimeTypesManagerImpl()62wxMimeTypesManagerImpl *wxGTKMimeTypesManagerFactory::CreateMimeTypesManagerImpl() 63 { 64 return new wxGTKMimeTypesManagerImpl(); 65 } 66 67 #endif // wxUSE_MIMETYPE 68