示例#1
0
EphyWebApplication *
ephy_web_application_for_profile_directory (const char *profile_dir)
{
  EphyWebApplication *app;
  char *desktop_file_path;
  const char *id;
  GDesktopAppInfo *desktop_info;
  const char *exec;
  int argc;
  char **argv;
  GFile *file;
  GFileInfo *file_info;
  guint64 created;
  GDate *date;

  id = get_app_id_from_profile_directory (profile_dir);
  if (!id)
    return NULL;

  app = g_new0 (EphyWebApplication, 1);
  app->id = g_strdup (id);

  app->desktop_file = get_app_desktop_filename (id);
  desktop_file_path = g_build_filename (profile_dir, app->desktop_file, NULL);
  desktop_info = g_desktop_app_info_new_from_filename (desktop_file_path);
  if (!desktop_info) {
    ephy_web_application_free (app);
    g_free (desktop_file_path);
    return NULL;
  }

  app->name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
  app->icon_url = g_desktop_app_info_get_string (desktop_info, "Icon");
  exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
  if (g_shell_parse_argv (exec, &argc, &argv, NULL)) {
    app->url = g_strdup (argv[argc - 1]);
    g_strfreev (argv);
  }

  g_object_unref (desktop_info);

  file = g_file_new_for_path (desktop_file_path);

  /* FIXME: this should use TIME_CREATED but it does not seem to be working. */
  file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
  created = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

  date = g_date_new ();
  g_date_set_time_t (date, (time_t)created);
  g_date_strftime (app->install_date, 127, "%x", date);

  g_date_free (date);
  g_object_unref (file);
  g_object_unref (file_info);
  g_free (desktop_file_path);

  return app;
}
示例#2
0
文件: main.c 项目: cristiklein/gthumb
static void
gth_application_init (GthApplication *app)
{
#ifdef GDK_WINDOWING_X11

	GDesktopAppInfo *app_info;

	app_info = g_desktop_app_info_new ("gthumb.desktop");
	if (app_info == NULL)
		return;

	if (g_desktop_app_info_has_key (app_info, "Name")) {
		char *app_name;

		app_name = g_desktop_app_info_get_string (app_info, "Name");
		g_set_application_name (app_name);

		g_free (app_name);
	}

	if (g_desktop_app_info_has_key (app_info, "Icon")) {
		char *icon;

		icon = g_desktop_app_info_get_string (app_info, "Icon");
		if (g_path_is_absolute (icon))
			gtk_window_set_default_icon_from_file (icon, NULL);
		else
			gtk_window_set_default_icon_name (icon);

		g_free (icon);
	}

	g_object_unref (app_info);

#else

	/* manually set name and icon */

	g_set_application_name (_("gThumb"));
	gtk_window_set_default_icon_name ("gthumb");

#endif
}
示例#3
0
static GList *
xde_entry(MenuContext *ctx, GMenuTreeEntry *ent)
{
	GDesktopAppInfo *info;
	GList *text = NULL;
	const char *name;
	char *esc1, *esc2, *cmd, *p;
	char *icon = NULL, *wrap, *s;
	GIcon *gicon = NULL;
	gboolean notify;
	char *wmclass, *appid;

	if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info)
	    || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL)
	    || !g_app_info_should_show(G_APP_INFO(info)))
		return (text);
	name = g_app_info_get_name(G_APP_INFO(info));

	esc1 = g_markup_escape_text(name, -1);

	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);
	wrap = ctx->wmm.wrap(ctx, strdup(icon));

	notify = g_desktop_app_info_get_boolean(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY);
	wmclass = g_desktop_app_info_get_string(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS);

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
	    && (p = strstr(appid, ".desktop")))
		*p = '\0';

	if (options.launch) {
		cmd = g_strdup_printf("xdg-launch --pointer %s", appid);
	} else {
		cmd = xde_get_command(info, appid, icon);
	}

	esc2 = g_markup_escape_text(cmd, -1);

	s = g_strdup_printf("%s<item label=\"%s\"%s>\n", ctx->indent, esc1, wrap);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s  <action name=\"Execute\">\n", ctx->indent);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s    <command>%s</command>\n", ctx->indent, esc2);
	text = g_list_append(text, s);

	if (!options.launch && (notify || wmclass)) {
		/* don't put launch specifics if we are launching with xdg-launch */
		s = g_strdup_printf("%s    <startupnotify>\n", ctx->indent);
		text = g_list_append(text, s);
		if (notify) {
			s = g_strdup_printf("%s      <enabled>yes</enabled>\n", ctx->indent);
			text = g_list_append(text, s);
		}
		if (wmclass) {
			s = g_strdup_printf("%s      <wmclass>%s</wmclass>\n", ctx->indent,
					    wmclass);
			text = g_list_append(text, s);
		}
		s = g_strdup_printf("%s      <name>%s</name>\n", ctx->indent, esc1);
		text = g_list_append(text, s);
		if (icon) {
			s = g_strdup_printf("%s      <icon>%s</icon>\n", ctx->indent, icon);
			text = g_list_append(text, s);
		}
		s = g_strdup_printf("%s    </startupnotify>\n", ctx->indent);
		text = g_list_append(text, s);
	}

	s = g_strdup_printf("%s  </action>\n", ctx->indent);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s</item>\n", ctx->indent);
	text = g_list_append(text, s);

	free(wrap);
	free(icon);
	g_free(wmclass);
	free(appid);
	g_free(esc1);
	g_free(esc2);
	free(cmd);
	return (text);
}
示例#4
0
int main() {
	auto tree=gmenu_tree_new(menu_name, GMENU_TREE_FLAGS_NONE); //no need flags, defaults is good enough
	
	{
		char lang[locale_size]; //here we get system locale string
		strcpy(lang,getenv("LANG"));
		char* country=0; //and parse it to 3 strings - lang, country, modifier
		char* modifier=0;
		//char* enc=0; //it could be useful somewhere else. let it be commented
		for(int i=0;lang[i];++i){
			switch(lang[i]){
				case '_':
					lang[i]=0;
					country=lang+i+1;
					break;
				case '@':
					lang[i]=0;
					modifier=lang+i+1;
					break;
				case '.':
					lang[i]=0;
					//enc=lang+i+1;
					break;
			}
		}

		{
			int loc_i=0; //current locale index
			if(*lang&&country&&modifier){
				strcpy(locales[loc_i++]+4,(std::string("[")+lang+"_"+country+"@"+modifier+"]").c_str());
			}
			if(*lang&&country){
				strcpy(locales[loc_i++]+4,(std::string("[")+lang+"_"+country+"]").c_str());
			}
			if(*lang&&modifier){
				strcpy(locales[loc_i++]+4,(std::string("[")+lang+"@"+modifier+"]").c_str());
			}
			if(*lang){
				strcpy(locales[loc_i++]+4,(std::string("[")+lang+"]").c_str());
			}
			locales[loc_i+1][0]=0; //barier to stop in case of buggy .desktop entry
		}
	}
	
	while(!gmenu_tree_load_sync(tree,NULL)){ //wait for load
		usleep(sync_wait_time);
	}
	
	qu.push(gmenu_tree_get_root_directory(tree)); //push root menu dir in queue
	while(!qu.empty()){ //while queue not empty, create menu for first dir
		auto& dir=qu.front();
		
		{
			const char* name=gmenu_tree_directory_get_menu_id(dir); //menu id used as unique fvwm menu suffix
			printf("DestroyMenu \"FvwmMenu%s\"\n",name);
			printf("AddToMenu \"FvwmMenu%s\"\n",name);
		}
		
		auto it=gmenu_tree_directory_iter(dir); //iterator
		decltype(gmenu_tree_iter_next(it)) next_type; //iterator type
		while ((next_type=gmenu_tree_iter_next(it))!=GMENU_TREE_ITEM_INVALID){
			switch (next_type){ 
				case GMENU_TREE_ITEM_DIRECTORY:{ //add directory function popup and queue it
					auto cur=gmenu_tree_iter_get_directory(it);
					printf("+ \"%s\" Popup \"FvwmMenu%s\"\n",
						gmenu_tree_directory_get_name(cur),
						gmenu_tree_directory_get_menu_id(cur));
					qu.push(cur);
					break;
				}
				case GMENU_TREE_ITEM_ENTRY:{
					auto cur=gmenu_tree_iter_get_entry(it);
					auto inf=gmenu_tree_entry_get_app_info(cur);
					std::string exec=g_desktop_app_info_get_string(inf,"Exec"); //get exec command
					int index;
					while((index=exec.find('%'))!=-1){ //delete all % params
						exec.erase(index,2);
					}
					int loc_i=0;
					char* name=0;
					do{ //find localised name in standard specified order
						name=g_desktop_app_info_get_string(inf,locales[loc_i]);
						++loc_i;
					}while(!name&&locales[loc_i][0]);
					if(name){ //if name not empty
						printf("+ \"%s\" Exec exec %s\n",name,exec.c_str()); //add menu entry
					}
					break;
				}
				case GMENU_TREE_ITEM_SEPARATOR:{ //add empty menu entry
					printf("+ \"\" Nop");
				}
				default:{ //TODO: add other types if needed
					
				}
			}
		}
		gmenu_tree_iter_unref(it); //unref iterator (dunno why, but why not?)
		printf("\n"); //just for better readability
		
		qu.pop();
	}
	return 0;
}