View Single Post
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#38
Sure, this is what I use in my app-search-widget
(feel free to look at the whole source code and steal
what you need :-))

Code:
#define DESKTOP_ENTRY_CONFIG_GROUP "Desktop Entry" 
#define TEXTDOMAIN_KEY "X-Text-Domain"
#define NAME_KEY "Name"
#define COMMENT_KEY "Comment"
static
gchar* 
_retrieve_app_comment(GKeyFile* key_file)
{
  if(g_key_file_has_key(key_file, DESKTOP_ENTRY_CONFIG_GROUP, TEXTDOMAIN_KEY, NULL) &&
     g_key_file_has_key(key_file, DESKTOP_ENTRY_CONFIG_GROUP, COMMENT_KEY, NULL))
  {
    gchar* text_domain = g_key_file_get_string(key_file, DESKTOP_ENTRY_CONFIG_GROUP, TEXTDOMAIN_KEY, NULL);
    gchar* app_comment_key = g_key_file_get_string(key_file, DESKTOP_ENTRY_CONFIG_GROUP, COMMENT_KEY, NULL);
    gchar* app_comment = g_strdup(dgettext(text_domain, app_comment_key));
    g_free(text_domain);
    if(g_strcmp0(app_comment, app_comment_key) == 0)
    {
      g_free(app_comment);
      app_comment = NULL;
    }
    g_free(app_comment_key);
    return app_comment;
  }
  else if(g_key_file_has_key(key_file, DESKTOP_ENTRY_CONFIG_GROUP, COMMENT_KEY, NULL))
  {
    gchar* app_comment = g_key_file_get_string(key_file, DESKTOP_ENTRY_CONFIG_GROUP, COMMENT_KEY, NULL);
    gchar* comment = g_strdup(dgettext(GETTEXT_PACKAGE, app_comment));
    g_free(app_comment);
    return comment;
  }
  return NULL;
}
You are using QT for your application, right?
I hope this helps anyway, feel free to ask if you have any
questions

Nicolai
 

The Following 3 Users Say Thank You to nicolai For This Useful Post: