diff --git a/docs/changes.txt b/docs/changes.txt index 88a20de802..e362ebcb4c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -92,6 +92,7 @@ wxGTK: - Implement setting link colours in wxHyperlinkCtrl for GTK+3 (Hanmac). - Support background colour in wxDataViewCtrl attributes. - Improve wxSpinCtrl best size calculation. +- Implement support for icon locations in wxMimeTypesManager (Hanmac). wxMSW: diff --git a/include/wx/gtk/mimetype.h b/include/wx/gtk/mimetype.h new file mode 100644 index 0000000000..4e5f144b35 --- /dev/null +++ b/include/wx/gtk/mimetype.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/gtk/mimetype.h +// Purpose: classes and functions to manage MIME types +// Author: Hans Mackowiak +// Created: 2016-06-05 +// Copyright: (c) 2016 Hans Mackowiak +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_GTK_MIMETYPE_IMPL_H +#define _WX_GTK_MIMETYPE_IMPL_H + +#include "wx/unix/mimetype.h" + +#if wxUSE_MIMETYPE + +class WXDLLIMPEXP_CORE wxGTKMimeTypesManagerImpl : public wxMimeTypesManagerImpl +{ +protected: + wxString GetIconFromMimeType(const wxString& mime) wxOVERRIDE; +}; + + +class WXDLLIMPEXP_CORE wxGTKMimeTypesManagerFactory : public wxMimeTypesManagerFactory +{ +public: + wxMimeTypesManagerImpl *CreateMimeTypesManagerImpl() wxOVERRIDE; +}; + +#endif // wxUSE_MIMETYPE + +#endif // _WX_GTK_MIMETYPE_IMPL_H diff --git a/include/wx/gtk/private/object.h b/include/wx/gtk/private/object.h index 472e4c3ede..ca09ed0d38 100644 --- a/include/wx/gtk/private/object.h +++ b/include/wx/gtk/private/object.h @@ -19,7 +19,7 @@ class wxGtkObject { public: explicit wxGtkObject(T *p) : m_ptr(p) { } - ~wxGtkObject() { g_object_unref(m_ptr); } + ~wxGtkObject() { if ( m_ptr ) g_object_unref(m_ptr); } operator T *() const { return m_ptr; } diff --git a/include/wx/unix/mimetype.h b/include/wx/unix/mimetype.h index 27b303bbe7..1436dd18e3 100644 --- a/include/wx/unix/mimetype.h +++ b/include/wx/unix/mimetype.h @@ -99,6 +99,8 @@ protected: const wxArrayString& strExtensions, const wxString& strDesc); + virtual wxString GetIconFromMimeType(const wxString& mime); + // give it access to m_aXXX variables friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl; }; diff --git a/samples/typetest/typetest.cpp b/samples/typetest/typetest.cpp index 67528d9789..8e4bf29b04 100644 --- a/samples/typetest/typetest.cpp +++ b/samples/typetest/typetest.cpp @@ -945,8 +945,11 @@ void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event)) else { wxString type, desc, open; + wxIconLocation loc; + filetype->GetMimeType(&type); filetype->GetDescription(&desc); + filetype->GetIcon(&loc); wxString filename = wxT("filename"); filename << wxT(".") << ext; @@ -958,6 +961,8 @@ void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event)) << wxT("\tDescription: ") << ( !desc ? wxString(wxEmptyString) : desc ) << wxT('\n') << wxT("\tCommand to open: ") << ( !open ? wxString("no") : open ) + << wxT('\n') + << wxT("\tIcon: ") << ( loc.IsOk() ? loc.GetFileName() : wxString("no") ) << wxT('\n'); delete filetype; diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 517541ea2e..f7124cefab 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -31,6 +31,7 @@ #include #include "wx/gtk/private.h" +#include "wx/gtk/mimetype.h" //----------------------------------------------------------------------------- // link GnomeVFS //----------------------------------------------------------------------------- @@ -435,6 +436,10 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) return false; } +#if wxUSE_MIMETYPE + wxMimeTypesManagerFactory::Set(new wxGTKMimeTypesManagerFactory()); +#endif + // we cannot enter threads before gtk_init is done gdk_threads_enter(); diff --git a/src/gtk/mimetype.cpp b/src/gtk/mimetype.cpp new file mode 100644 index 0000000000..31ee984ec5 --- /dev/null +++ b/src/gtk/mimetype.cpp @@ -0,0 +1,52 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/gtk/mimetype.cpp +// Purpose: classes and functions to manage MIME types +// Author: Hans Mackowiak +// Created: 2016-06-05 +// Copyright: (c) 2016 Hans Mackowiak +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_MIMETYPE + +#include "wx/gtk/mimetype.h" + +#include +#include + +#include "wx/gtk/private/string.h" +#include "wx/gtk/private/object.h" + +wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) +{ + wxGtkString type(g_content_type_from_mime_type(mime.utf8_str())); + + wxGtkObject gicon(g_content_type_get_icon(type)); + if ( !gicon ) + return wxString(); + + GtkIconTheme *theme(gtk_icon_theme_get_default()); + if ( !theme ) + return wxString(); + + wxGtkObject giconinfo(gtk_icon_theme_lookup_by_gicon + ( + theme, + gicon, + 256, + GTK_ICON_LOOKUP_NO_SVG + )); + if ( !giconinfo ) + return wxString(); + + return wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); +} + +wxMimeTypesManagerImpl *wxGTKMimeTypesManagerFactory::CreateMimeTypesManagerImpl() +{ + return new wxGTKMimeTypesManagerImpl(); +} + +#endif // wxUSE_MIMETYPE diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index b1c95644ef..9e46216efc 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -262,7 +262,9 @@ void wxMimeTypesManagerImpl::LoadXDGGlobs(const wxString& filename) wxArrayString exts; exts.Add( ext ); - AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true ); + wxString icon = GetIconFromMimeType(mime); + + AddToMimeData(mime, icon, NULL, exts, wxEmptyString, true ); } } @@ -687,6 +689,11 @@ wxFileType * wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) return GetFileTypeFromMimeType(strType); } +wxString wxMimeTypesManagerImpl::GetIconFromMimeType(const wxString& WXUNUSED(mime)) +{ + return wxString(); +} + bool wxMimeTypesManagerImpl::DoAssociation(const wxString& strType, const wxString& strIcon, wxMimeTypeCommands *entry, @@ -967,7 +974,7 @@ void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString& strMimeType, // reading mailcap may find image/* , while // reading mime.types finds image/gif and no match is made // this means all the get functions don't work fix this - wxString strIcon; + const wxString strIcon = GetIconFromMimeType(strMimeType); wxString sTmp = strExtensions; wxArrayString sExts;