Re: Glib::get_system_data_dirs() returns no useful result



2012/4/17 Mateusz Marzantowicz <mmarzantowicz osdf com pl>:
> 17.04.2012 13:48, Krzesimir Nowak:
>> 2012/4/17 Mateusz Marzantowicz <mmarzantowicz osdf com pl>:
>>> Hello,
>>>
>>> I was trying to use Glib::get_system_data_dirs() function which is a
>>> wrapper over GTK+ function: g_get_system_data_dirs().
>>>
>>> GTK+ function works as expected and returns correct results (paths), the
>>> glibmm C++ version returns empty vector (size() method on this vector == 0).
>>>
>>> After fighting some time, I checked the source code of glibmm library
>>> and I'm now confused. Below is an extract form file:
>>> glib/glibmm/miscutils.cc, lines 124-139 :
>>>
>>> --- START CODE ---
>>> std::vector<std::string> get_system_data_dirs()
>>> {
>>>  //TODO: Use a utility function:
>>>  std::vector<std::string> result;
>>>  const char* const * cresult = g_get_system_data_dirs();
>>>  if(cresult)
>>>    return result;
>>>
>>>  for(const gchar* const * iter = cresult; *iter != 0; ++iter)
>>>  {
>>>    result.push_back(
>>>      convert_const_gchar_ptr_to_stdstring(*iter));
>>>  }
>>>
>>>  return result;
>>> }
>>> --- END CODE ---
>>>
>>> Now it is clear to me why it is not working as expected. The first if
>>> checks for cresult being not null but returns empty result which never
>>> at that point would contain data from g_get_system_data_dirs().
>>>
>>> Because I'm new to GTK+ and gtkmm/glibmm, sorry if the answer is obvious
>>> but why the hell is this code like this? Maybe this function should be
>>> used in some special manner that I'm not aware of?
>> Seemingly this function was not used so often that no one noticed it
>> before or didn't bother to ask about it or file a bug. Just a classic
>> case of typo + copypasta.
>>
>> Fixed in master:
>> http://git.gnome.org/browse/glibmm/commit/?id=64b20b098dd24aeb6cea9b95ea861ddd58fde778
> Wow! How quick, thanks a lot for this solution and commit.
>
> You wrote that this function is not used very often, but I'm curious
> what is the recommended way of finding path to XML file for use in
> Gtk::UIManager::add_ui_from_file() method? I was trying to obtain path
> to data directory (/usr/local/share/ in my case.) If
> Glib::get_system_data_dirs() is not used by people, is there a better
> way of doing this? I found that in some projects base on GTK+ they use
> automake/autoconf flags that are passed in compile time as preprocessor
> macro to source file, but is it really better approach?

What I meant is that seemingly this function was either rarely used by
glibmm users or if it is used then no one bothered to file a bug about
it. Instead they probably used the C version of it.

I guess that using Glib::get_system_data_dirs() together with
Glib::build_filename() is a way to go. Or use GResource. But this is
probably not yet wrapped in glibmm.

>
> Mateusz Marzantowicz


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]