Add support for returning item location to wxGTK wxMimeTypesManager.
This is a squash merge of gtk_mimetype branch from https://github.com/Hanmac/wxWidgets.git with some extra minor cleanup. Closes https://github.com/wxWidgets/wxWidgets/pull/293
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
#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();
|
||||
|
||||
|
||||
52
src/gtk/mimetype.cpp
Normal file
52
src/gtk/mimetype.cpp
Normal file
@@ -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 <hanmac@gmx.de>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_MIMETYPE
|
||||
|
||||
#include "wx/gtk/mimetype.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#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> gicon(g_content_type_get_icon(type));
|
||||
if ( !gicon )
|
||||
return wxString();
|
||||
|
||||
GtkIconTheme *theme(gtk_icon_theme_get_default());
|
||||
if ( !theme )
|
||||
return wxString();
|
||||
|
||||
wxGtkObject<GtkIconInfo> 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
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user