PRIVATE JSObjectRef _init_category_table() { JSObjectRef items = json_array_create(); GList* app_infos = g_app_info_get_all(); GList* iter = app_infos; for (gsize i=0, skip=0; iter != NULL; i++, iter = g_list_next(iter)) { GAppInfo* info = iter->data; if (!g_app_info_should_show(info)) { skip++; continue; } record_category_info(G_DESKTOP_APP_INFO(info)); json_array_insert_nobject(items, i - skip, info, g_object_ref, g_object_unref); g_object_unref(info); } g_list_free(app_infos); //the element of GAppInfo should free by JSRunTime not here! return items; }
const char * cinnamon_app_get_keywords (CinnamonApp *app) { const char * const *keywords; const char *keyword; gint i; gchar *ret = NULL; if (app->keywords) return app->keywords; if (app->entry) keywords = g_desktop_app_info_get_keywords (G_DESKTOP_APP_INFO (gmenu_tree_entry_get_app_info (app->entry))); else keywords = NULL; if (keywords != NULL) { GString *keyword_list = g_string_new(NULL); for (i = 0; keywords[i] != NULL; i++) { keyword = keywords[i]; g_string_append_printf (keyword_list, "%s;", keyword); } ret = g_string_free (keyword_list, FALSE); } app->keywords = ret; return ret; }
static void scan_startup_wm_class_to_id (ShellAppSystem *self) { ShellAppSystemPrivate *priv = self->priv; GList *apps, *l; g_hash_table_remove_all (priv->startup_wm_class_to_id); apps = g_app_info_get_all (); for (l = apps; l != NULL; l = l->next) { GAppInfo *info = l->data; const char *startup_wm_class, *id, *old_id; id = g_app_info_get_id (info); startup_wm_class = g_desktop_app_info_get_startup_wm_class (G_DESKTOP_APP_INFO (info)); if (startup_wm_class == NULL) continue; /* In case multiple .desktop files set the same StartupWMClass, prefer * the one where ID and StartupWMClass match */ old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class); if (old_id == NULL || strcmp (id, startup_wm_class) == 0) g_hash_table_insert (priv->startup_wm_class_to_id, g_strdup (startup_wm_class), g_strdup (id)); } g_list_free_full (apps, g_object_unref); }
static char * app_info_get_id (GAppInfo *app_info) { const char *desktop_id; char *ret; const char *filename; int l; desktop_id = g_app_info_get_id (app_info); if (desktop_id != NULL) { ret = g_strdup (desktop_id); } else { filename = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app_info)); ret = g_path_get_basename (filename); } if (G_UNLIKELY (g_str_has_suffix (ret, ".desktop") == FALSE)) { g_free (ret); return NULL; } l = strlen (desktop_id); *(ret + l - strlen(".desktop")) = '\0'; return ret; }
gboolean fm_app_info_launch (GAppInfo *appinfo, GList *files, GAppLaunchContext *launch_context, GError **error) { gboolean supported = FALSE, ret = FALSE; if (G_IS_DESKTOP_APP_INFO (appinfo)) { const char*id = g_app_info_get_id (appinfo); if (id) // this is an installed application { // load the desktop entry file to obtain more info GKeyFile *kf = g_key_file_new (); char *rel_path = g_strconcat ("applications/", id, NULL); char *full_desktop_path; supported = g_key_file_load_from_data_dirs (kf, rel_path, &full_desktop_path, 0, NULL); g_free (rel_path); if (supported) { ret = do_launch (appinfo, full_desktop_path, kf, files, launch_context, error); g_free (full_desktop_path); } g_key_file_free (kf); } else { const char *file = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (appinfo)); if (file) // this is a desktop entry file { // load the desktop entry file to obtain more info GKeyFile *kf = g_key_file_new (); supported = g_key_file_load_from_file (kf, file, 0, NULL); if (supported) ret = do_launch (appinfo, file, kf, files, launch_context, error); g_key_file_free (kf); } else { // If this is created with fm_app_info_create_from_commandline () if (g_object_get_data (G_OBJECT (appinfo), "flags")) { supported = TRUE; ret = do_launch (appinfo, NULL, NULL, files, launch_context, error); } } } } else supported = FALSE; if (!supported) // fallback to GAppInfo::launch return g_app_info_launch (appinfo, files, launch_context, error); return ret; }
static struct default_db_t * get_default_helper (const gchar * desktop_path) { g_return_val_if_fail(desktop_path != NULL, NULL); gchar * basename = g_path_get_basename(desktop_path); g_return_val_if_fail(basename != NULL, NULL); gboolean found = FALSE; gint i; gint length = G_N_ELEMENTS(default_db); for (i = 0; i < length && !found; i++) { if (default_db[i].desktop_file) { if (g_strcmp0(default_db[i].desktop_file, basename) == 0) { found = TRUE; } } else if (default_db[i].uri_scheme) { GAppInfo *info = g_app_info_get_default_for_uri_scheme(default_db[i].uri_scheme); if (!info) { continue; } const gchar * filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(info)); if (!filename) { g_object_unref(info); continue; } gchar * default_basename = g_path_get_basename(filename); g_object_unref(info); if (g_strcmp0(default_basename, basename) == 0) { found = TRUE; } g_free(default_basename); } } g_free(basename); if (found) { return &default_db[i - 1]; } return NULL; }
char * mpl_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; #if 0 GdkAppLaunchContextPrivate *priv; #endif GdkDisplay *display; GdkScreen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; #if 0 GIcon *icon; #endif guint32 timestamp; char *startup_id; #if 0 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv; if (priv->screen) { screen = priv->screen; display = gdk_screen_get_display (priv->screen); } else if (priv->display) { display = priv->display; screen = gdk_display_get_default_screen (display); } else { display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); } #else display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); #endif files_count = g_list_length (files); if (files_count == 0) description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); else if (files_count == 1) description = g_strdup_printf (_("Opening %s"), get_display_name (files->data)); else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; #if 0 if (priv->icon_name) icon_name = g_strdup (priv->icon_name); else { icon = NULL; if (priv->icon != NULL) icon = g_object_ref (priv->icon); else if (files_count == 1) icon = get_icon (files->data); if (icon == NULL) { icon = g_app_info_get_icon (info); g_object_ref (icon); } if (icon) icon_name = gicon_to_string (icon); g_object_unref (icon); } #endif binary_name = g_app_info_get_executable (info); #if 0 timestamp = priv->timestamp; if (timestamp == GDK_CURRENT_TIME) #endif timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen)); #if 0 if (priv->workspace > -1) workspace_str = g_strdup_printf ("%d", priv->workspace); else #endif workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); add_startup_timeout (screen, startup_id); return startup_id; }
/** * fm_app_info_launch * @appinfo: application info to launch * @files: (element-type GFile): files to use in run substitutions * @launch_context: (allow-none): a launch context * @error: (out) (allow-none): location to store error * * Launches desktop application doing substitutions in application info. * * Returns: %TRUE if application was launched. * * Since: 0.1.15 */ gboolean fm_app_info_launch(GAppInfo *appinfo, GList *files, GAppLaunchContext *launch_context, GError **error) { gboolean supported = FALSE, ret = FALSE; if(G_IS_DESKTOP_APP_INFO(appinfo)) { const char *id; #if GLIB_CHECK_VERSION(2,24,0) /* if GDesktopAppInfo knows the filename then let use it */ id = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(appinfo)); if(id) /* this is a desktop entry file */ { /* load the desktop entry file to obtain more info */ GKeyFile* kf = g_key_file_new(); supported = g_key_file_load_from_file(kf, id, 0, NULL); if(supported) ret = do_launch(appinfo, id, kf, files, launch_context, error); g_key_file_free(kf); id = NULL; } else /* otherwise try application id */ #endif id = g_app_info_get_id(appinfo); if(id) /* this is an installed application */ { /* load the desktop entry file to obtain more info */ GKeyFile* kf = g_key_file_new(); char* rel_path = g_strconcat("applications/", id, NULL); char* full_desktop_path; supported = g_key_file_load_from_data_dirs(kf, rel_path, &full_desktop_path, 0, NULL); g_free(rel_path); if(supported) { ret = do_launch(appinfo, full_desktop_path, kf, files, launch_context, error); g_free(full_desktop_path); } g_key_file_free(kf); } else { #if GLIB_CHECK_VERSION(2,24,0) if (!supported) /* it was launched otherwise, see above */ #endif { /* If this is created with fm_app_info_create_from_commandline() */ if(g_object_get_data(G_OBJECT(appinfo), "flags")) { supported = TRUE; ret = do_launch(appinfo, NULL, NULL, files, launch_context, error); } } } } else supported = FALSE; if(!supported) /* fallback to GAppInfo::launch */ return g_app_info_launch(appinfo, files, launch_context, error); return ret; }
static char * gdk_x11_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; GdkDisplay *display; GdkX11Screen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; GIcon *icon; guint32 timestamp; char *startup_id; GFileInfo *fileinfo; GdkAppLaunchContext *ctx; ctx = GDK_APP_LAUNCH_CONTEXT (context); display = ctx->display; screen = GDK_X11_DISPLAY (display)->screen; fileinfo = NULL; files_count = g_list_length (files); if (files_count == 0) { description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); } else if (files_count == 1) { gchar *display_name; if (g_file_is_native (files->data)) fileinfo = g_file_query_info (files->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_ICON, 0, NULL, NULL); display_name = get_display_name (files->data, fileinfo); description = g_strdup_printf (_("Opening %s"), display_name); g_free (display_name); } else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; if (ctx->icon_name) icon_name = g_strdup (ctx->icon_name); else { icon = NULL; if (ctx->icon != NULL) icon = g_object_ref (ctx->icon); else if (files_count == 1) icon = get_icon (files->data, fileinfo); if (icon == NULL) { icon = g_app_info_get_icon (info); if (icon != NULL) g_object_ref (icon); } if (icon != NULL) { icon_name = gicon_to_string (icon); g_object_unref (icon); } } binary_name = g_app_info_get_executable (info); timestamp = ctx->timestamp; if (timestamp == GDK_CURRENT_TIME) timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_x11_screen_get_screen_number (screen)); if (ctx->workspace > -1) workspace_str = g_strdup_printf ("%d", ctx->workspace); else workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); if (fileinfo) g_object_unref (fileinfo); add_startup_timeout (screen, startup_id); return startup_id; }
void caja_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri, *uri_scheme; GList *locations, *l; GFile *location; CajaFile *file; gboolean result; GError *error; GdkDisplay *display; GdkAppLaunchContext *launch_context; CajaIconInfo *icon; int count, total; g_assert (uris != NULL); /* count the number of uris with local paths */ count = 0; total = g_list_length (uris); locations = NULL; for (l = uris; l != NULL; l = l->next) { uri = l->data; location = g_file_new_for_uri (uri); if (g_file_is_native (location)) { count++; } locations = g_list_prepend (locations, location); } locations = g_list_reverse (locations); if (parent_window != NULL) { display = gtk_widget_get_display (GTK_WIDGET (parent_window)); } else { display = gdk_display_get_default (); } launch_context = gdk_display_get_app_launch_context (display); if (parent_window != NULL) { gdk_app_launch_context_set_screen (launch_context, gtk_window_get_screen (parent_window)); } file = caja_file_get_by_uri (uris->data); icon = caja_file_get_icon (file, 48, 0); caja_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, caja_icon_info_get_used_name (icon)); g_object_unref (icon); } error = NULL; result = g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (application), uris, G_APP_LAUNCH_CONTEXT (launch_context), G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, gather_pid_callback, application, &error); g_object_unref (launch_context); if (!result) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED) { uri_scheme = g_uri_parse_scheme (uris->data); application_cannot_open_location (application, file, uri_scheme, parent_window); g_free (uri_scheme); } else { #ifdef NEW_MIME_COMPLETE caja_program_chooser_show_invalid_message (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window); #else g_warning ("Cannot open app: %s\n", error->message); #endif } g_error_free (error); } else { for (l = uris; l != NULL; l = l->next) { file = caja_file_get_by_uri (l->data); caja_recent_add_file (file, application); caja_file_unref (file); } } g_list_free_full (locations, g_object_unref); }
static GAppInfo* app_info_create_from_commandline(const char *commandline, const char *application_name, const char *bin_name, const char *mime_type, gboolean terminal, gboolean keep) { GAppInfo* app = NULL; char* dirname = g_build_filename (g_get_user_data_dir (), "applications", NULL); const char* app_basename = strrchr(bin_name, '/'); if(app_basename) app_basename++; else app_basename = bin_name; if(g_mkdir_with_parents(dirname, 0700) == 0) { char *filename = NULL; int fd; #if GLIB_CHECK_VERSION(2, 37, 6) if (mime_type && application_name[0]) { /* SF bug #871: new GLib has ids cached so we do a trick here: we create a dummy app before really creating the file */ app = g_app_info_create_from_commandline(commandline, app_basename, 0, NULL); if (app) { g_app_info_remove_supports_type(app, mime_type, NULL); filename = g_strdup(g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(app))); g_object_unref(app); app = NULL; } } if (filename) fd = g_open(filename, O_RDWR, 0); else #endif { filename = g_strdup_printf ("%s/userapp-%s-XXXXXX.desktop", dirname, app_basename); fd = g_mkstemp (filename); } if(fd != -1) { GString* content = g_string_sized_new(256); g_string_printf(content, "[" G_KEY_FILE_DESKTOP_GROUP "]\n" G_KEY_FILE_DESKTOP_KEY_TYPE "=" G_KEY_FILE_DESKTOP_TYPE_APPLICATION "\n" G_KEY_FILE_DESKTOP_KEY_NAME "=%s\n" G_KEY_FILE_DESKTOP_KEY_EXEC "=%s\n" G_KEY_FILE_DESKTOP_KEY_CATEGORIES "=Other;\n" G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY "=true\n", application_name, commandline ); if(mime_type) g_string_append_printf(content, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE "=%s\n", mime_type); g_string_append_printf(content, G_KEY_FILE_DESKTOP_KEY_TERMINAL "=%s\n", terminal ? "true" : "false"); if(terminal) g_string_append_printf(content, "X-KeepTerminal=%s\n", keep ? "true" : "false"); close(fd); /* g_file_set_contents() may fail creating duplicate */ if(g_file_set_contents(filename, content->str, content->len, NULL)) { char *fbname = g_path_get_basename(filename); app = G_APP_INFO(g_desktop_app_info_new(fbname)); g_free(fbname); if (app == NULL) { g_warning("failed to load %s as an application", filename); g_unlink(filename); } /* if there is mime_type set then created application will be saved for the mime type (see fm_choose_app_for_mime_type() below) but if not then we should remove this temp. file */ else if (!mime_type || !application_name[0]) /* save the name so this file will be removed later */ g_object_weak_ref(G_OBJECT(app), on_temp_appinfo_destroy, g_strdup(filename)); } else g_unlink(filename); g_string_free(content, TRUE); } g_free(filename); } g_free(dirname); return app; }