Discussion:
[wxGTK] wxFileType::GetIcon does not work
Stefano Mtangoo
2014-02-02 10:52:51 UTC
Permalink
I have List control with files and want to put all known files to their
respective icons and generic icon for non ecognized files.
So used the function which under wxGTK returns false. Tracking down
debugger I found sTmp always is empty and since
I do not know how it the mime class works under GTK (I cannot find file
under src/gtk folder). So where do I go to pinpoint
whats the issue? I use post-wx3.0 svn version with GTK2, Ubuntu 13.04

Here is how I call it
wxIconLocation IconLocation;
wxFileType *FileType =
wxTheMimeTypesManager->GetFileTypeFromExtension(fname.GetExt()); // get the
file type for the extension
if(FileType) // if the file type was found
{
if(FileType->GetIcon(&IconLocation)) // if the icon for the file type
was found
{
imgIdx = m_imgList->Add(wxIcon(IconLocation));
}
else
{
imgIdx = 1; //generic aka unknown
}
}


Here is the function that returns mpty sTmp

bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const
{
wxString sTmp;
size_t i = 0;
while ( (i < m_index.GetCount() ) && sTmp.empty() )
{
sTmp = m_manager->m_aIcons[m_index[i]];
i++;
}

if ( sTmp.empty() )
return false;

if ( iconLoc )
{
iconLoc->SetFileName(sTmp);
}

return true;
}
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-02-02 14:24:32 UTC
Permalink
On Sun, 2 Feb 2014 02:52:51 -0800 (PST) Stefano Mtangoo wrote:

SM> I have List control with files and want to put all known files to their
SM> respective icons and generic icon for non ecognized files.
SM> So used the function which under wxGTK returns false.

Unfortunately wxMimeTypesManager implementation under Unix is hopelessly
out of date. It was written back in the nineties when the only way to get
this information was from the mailcap and mime.types files and then was
only partially and ad hoc updated to use the desktop environment files.
We really need to update it to use the Freedesktop spec:

http://www.freedesktop.org/wiki/Specifications/icon-theme-spec/

This does require a relatively important amount of work though, which is
why it hasn't been done so far.

FWIW we already have http://trac.wxwidgets.org/ticket/1410 but, as you can
see from the ticket number, it has been opened since quite a long time...

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Stefano Mtangoo
2014-02-03 07:38:20 UTC
Permalink
Post by Vadim Zeitlin
SM> I have List control with files and want to put all known files to their
SM> respective icons and generic icon for non ecognized files.
SM> So used the function which under wxGTK returns false.
Unfortunately wxMimeTypesManager implementation under Unix is hopelessly
out of date. It was written back in the nineties when the only way to get
this information was from the mailcap and mime.types files and then was
only partially and ad hoc updated to use the desktop environment files.
http://www.freedesktop.org/wiki/Specifications/icon-theme-spec/
Well looking at link it seems that its not that difficult to find icons.
The thing that confused me is they do not give a way to get current theme.
I found a link[1] that is GTK+ specific but not sure if that is correct
function
(I cannot understand what current screen means at all)

So as per link above, I will need to:
1. Get List of theme dirs in order said [$HOME/.icons ,
$XDG_DATA_DIRS/icons and /usr/share/pixmaps]
2. Get current System theme [Not sure how]
3. Search for the folder with icon theme name
4. Get folders depending on icon size
5. Get icon name [I don't know how]
6. search icon name (in number 5) in that folder under all context
[16x16/animations et al]

1.
http://www.gtk.org/api/2.6/gtk/GtkIconTheme.html#gtk-icon-theme-get-default
Post by Vadim Zeitlin
This does require a relatively important amount of work though, which is
why it hasn't been done so far.
FWIW we already have http://trac.wxwidgets.org/ticket/1410 but, as you can
see from the ticket number, it has been opened since quite a long time...
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-02-03 14:18:30 UTC
Permalink
On Sun, 2 Feb 2014 23:38:20 -0800 (PST) Stefano Mtangoo wrote:

SM> > http://www.freedesktop.org/wiki/Specifications/icon-theme-spec/
SM>
SM> Well looking at link it seems that its not that difficult to find icons.

Yes, but looking closer at it, this is not enough actually :-( What this
explains is how to find the icon by name and, first, we don't even need to
do it ourselves, as GtkIconTheme already can be used for this, and second
this doesn't really help us all that much because we still don't have the
icon name to find in the first place.

For the existing files we can launch `xdg-mime query filetype $file` to
get the MIME type of the file and then lookup "mime_$type_$subtype" icon.
But wxMimeTypesManager API allows to retrieve the information associated to
an extension, without providing any existing file (and this is pretty
useful in practice, too). So the question is how to do this...


SM> The thing that confused me is they do not give a way to get current theme.

This shouldn't be necessary anyhow, GtkIconTheme will use the correct
theme if you just create it and look for the icons lookup.

SM> I found a link[1] that is GTK+ specific but not sure if that is correct
SM> function
SM> (I cannot understand what current screen means at all)

The total display can consist of multiple screens. Windows calls them
"monitors" if it helps.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Stefano Mtangoo
2014-02-03 16:54:39 UTC
Permalink
Post by Vadim Zeitlin
SM> > http://www.freedesktop.org/wiki/Specifications/icon-theme-spec/
SM>
SM> Well looking at link it seems that its not that difficult to find icons.
Yes, but looking closer at it, this is not enough actually :-( What this
explains is how to find the icon by name and, first, we don't even need to
do it ourselves, as GtkIconTheme already can be used for this, and second
this doesn't really help us all that much because we still don't have the
icon name to find in the first place.
For the existing files we can launch `xdg-mime query filetype $file` to
get the MIME type of the file and then lookup "mime_$type_$subtype" icon.
But wxMimeTypesManager API allows to retrieve the information associated to
an extension, without providing any existing file (and this is pretty
useful in practice, too). So the question is how to do this...
The best I have got in my search is parsing /etc/mime.types
Am not sure how reliable it is and if it will change in near future.
Also am not sure its same in non Debian or even non Gnome distros

S.
Post by Vadim Zeitlin
SM> The thing that confused me is they do not give a way to get current theme.
This shouldn't be necessary anyhow, GtkIconTheme will use the correct
theme if you just create it and look for the icons lookup.
SM> I found a link[1] that is GTK+ specific but not sure if that is correct
SM> function
SM> (I cannot understand what current screen means at all)
The total display can consist of multiple screens. Windows calls them
"monitors" if it helps.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-02-03 16:57:52 UTC
Permalink
On Mon, 3 Feb 2014 08:54:39 -0800 (PST) Stefano Mtangoo wrote:

SM> The best I have got in my search is parsing /etc/mime.types

This is what the current code does and it's not enough. We really should
do what "xdg-mime query" does, except that ideally we should be using the
libraries for this instead of the programs (you can see which ones if you
look at xdg-mime source, it's a rather simple shell script).

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Stefano Mtangoo
2014-02-05 11:45:14 UTC
Permalink
Post by Vadim Zeitlin
SM> The best I have got in my search is parsing /etc/mime.types
This is what the current code does and it's not enough. We really should
do what "xdg-mime query" does, except that ideally we should be using the
libraries for this instead of the programs (you can see which ones if you
look at xdg-mime source, it's a rather simple shell script).
I asked on SO [1] and seems that GIO does that. I have tested an example
and it works without file being present.
It gives mime type even if the file is not there. I have not see n yet any
of its functions fo retrieving icon file/path.
I will explore and see if it can. But at least it have way to know mime
with no file present

Regards,
S.

[1]
http://stackoverflow.com/questions/21532227/get-mime-type-from-file-extension/21552150#21552150
Post by Vadim Zeitlin
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-02-05 14:59:04 UTC
Permalink
On Wed, 5 Feb 2014 03:45:14 -0800 (PST) Stefano Mtangoo wrote:

SM> > This is what the current code does and it's not enough. We really should
SM> > do what "xdg-mime query" does, except that ideally we should be using the
SM> > libraries for this instead of the programs (you can see which ones if you
SM> > look at xdg-mime source, it's a rather simple shell script).
SM>
SM> I asked on SO [1] and seems that GIO does that. I have tested an example
SM> and it works without file being present.
...
SM> http://stackoverflow.com/questions/21532227/get-mime-type-from-file-extension/21552150#21552150

Great, I didn't know about this function but it does indeed do exactly
what we need. So at least for wxGTK the problem should be now possible to
solve.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Stefano D. Mtangoo
2014-02-05 20:40:21 UTC
Permalink
Post by Vadim Zeitlin
SM> > This is what the current code does and it's not enough. We really should
SM> > do what "xdg-mime query" does, except that ideally we should be using the
SM> > libraries for this instead of the programs (you can see which ones if you
SM> > look at xdg-mime source, it's a rather simple shell script).
SM>
SM> I asked on SO [1] and seems that GIO does that. I have tested an example
SM> and it works without file being present.
...
SM> http://stackoverflow.com/questions/21532227/get-mime-type-from-file-extension/21552150#21552150
Great, I didn't know about this function but it does indeed do exactly
what we need. So at least for wxGTK the problem should be now possible to
solve.
So, where in sources is it supposed to go? I have checked sources and
they seem to be a bit complex (unlike other
widgets/files). Which function is supposed to be changed exactly, in wxGTK?
Last question: is GIO library linked before or it will be added dependency?
Post by Vadim Zeitlin
Regards,
VZ
--
Stefano D. Mtangoo
Mob: +255 754710410
Twitter: @mtangoo
Web. http://hosannahighertech.co.tz
Linkedin: http://www.linkedin.com/pub/stefano-mtangoo/45/644/281
/The purpose of man is to know his Maker Be known by his Maker
And make his Maker known So that others may know his Maker as their
Maker(Emeal Zwayne) /
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-02-05 21:13:10 UTC
Permalink
On Wed, 05 Feb 2014 23:40:21 +0300 Stefano D. Mtangoo wrote:

SDM> So, where in sources is it supposed to go? I have checked sources and
SDM> they seem to be a bit complex (unlike other widgets/files).

That's because we wanted to use different implementations depending on the
environment (Gnome/KDE). And also because, I think, some people who
modified this code subsequently didn't really understand how it was
supposed to work, so now it's even a bigger mess :-(

The important thing is to realize that wxMimeTypesManager is in wxBase,
however it must work differently for the non-GUI applications (which don't
use GTK+ nor GIO at all) and the GUI ones (which do). Hence the need to
virtualize it.

SDM> Which function is supposed to be changed exactly, in wxGTK?

It's not just a single function. You need to create a new
wxMimeTypesManagerFactory-derived factory class and implement its
CreateMimeTypesManagerImpl() method to return an object of the new
wxMimeTypesManagerImpl-derived class which would contain this code.

SDM> Last question: is GIO library linked before or it will be added dependency?

I'm pretty sure it's used by GTK+ itself and is already linked in.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Stefano D. Mtangoo
2014-02-06 21:52:34 UTC
Permalink
Post by Vadim Zeitlin
SDM> So, where in sources is it supposed to go? I have checked sources and
SDM> they seem to be a bit complex (unlike other widgets/files).
That's because we wanted to use different implementations depending on the
environment (Gnome/KDE). And also because, I think, some people who
modified this code subsequently didn't really understand how it was
supposed to work, so now it's even a bigger mess :-(
Is there any plan for someone who knows how it **was** supposed to work
to do cleaning? :)
Post by Vadim Zeitlin
The important thing is to realize that wxMimeTypesManager is in wxBase,
however it must work differently for the non-GUI applications (which don't
use GTK+ nor GIO at all) and the GUI ones (which do). Hence the need to
virtualize it.
SDM> Which function is supposed to be changed exactly, in wxGTK?
It's not just a single function. You need to create a new
wxMimeTypesManagerFactory-derived factory class and implement its
CreateMimeTypesManagerImpl() method to return an object of the new
wxMimeTypesManagerImpl-derived class which would contain this code.
Noted! I have few things to clear here and will definitely come back to
this thing!
Thanks a lot for your time.
S.
Post by Vadim Zeitlin
SDM> Last question: is GIO library linked before or it will be added dependency?
I'm pretty sure it's used by GTK+ itself and is already linked in.
Regards,
VZ
--
Stefano D. Mtangoo
Mob: +255 754710410
Twitter: @mtangoo
Web. http://hosannahighertech.co.tz
Linkedin: http://www.linkedin.com/pub/stefano-mtangoo/45/644/281
/The purpose of man is to know his Maker Be known by his Maker
And make his Maker known So that others may know his Maker as their
Maker(Emeal Zwayne) /
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...