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; }
PRIVATE GList* _get_x_category(GDesktopAppInfo* info) { GList* categories = NULL; const char* all_categories = g_desktop_app_info_get_categories(info); if (all_categories == NULL) { categories = g_list_append(categories, GINT_TO_POINTER(OTHER_CATEGORY_ID)); return categories; } g_debug("[%s] %s", __func__, g_desktop_app_info_get_filename(info)); gboolean has_other_id = FALSE; gchar** x_categories = g_strsplit(all_categories, ";", 0); for (int i = 0; x_categories[i] != NULL && x_categories[i][0] != '\0'; ++i) { char* lower_case = g_utf8_casefold(x_categories[i], -1); int id = find_category_id(lower_case); g_free(lower_case); g_debug("[%s] #%s#:category name:#%s#:%d", __func__, x_categories[i], lower_case, id); if (id == OTHER_CATEGORY_ID) has_other_id = TRUE; categories = g_list_append(categories, GINT_TO_POINTER(id)); } if (has_other_id) categories = _remove_other_category(categories); if (categories == NULL) categories = g_list_append(categories, GINT_TO_POINTER(OTHER_CATEGORY_ID)); for (GList* iter = g_list_first(categories); iter != NULL; iter = g_list_next(iter)) g_debug("[%s] using %d", __func__, GPOINTER_TO_INT(iter->data)); g_strfreev(x_categories); return categories; }
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; }
JS_EXPORT_API char* dentry_get_appid(Entry* e) { char* basename = g_path_get_basename(g_desktop_app_info_get_filename(e)); char* ext_spe = strchr(basename, '.'); if (ext_spe == NULL) { return basename; } else { char* app_id = g_strndup(basename, ext_spe - basename); g_free(basename); return app_id; } }
QString LauncherApplication::desktop_file() const { if (m_application != NULL) { return m_application->desktop_file(); } if (m_appInfo != NULL) { return QString::fromUtf8(g_desktop_app_info_get_filename((GDesktopAppInfo*)m_appInfo.data())); } return QString(""); }
QUrl DeclarativeDragItemWithUrl::decodeUri(const QString& uri) { if (uri.startsWith("application://")) { QString desktopFileName = uri.mid(14); QByteArray bytes = desktopFileName.toUtf8(); GObjectScopedPointer<GDesktopAppInfo> appInfo(g_desktop_app_info_new(bytes.constData())); if (appInfo.isNull()) { return QUrl(uri); } QString filePath = QString::fromUtf8(g_desktop_app_info_get_filename(appInfo.data())); return QUrl("file://" + filePath); } else { return QUrl(uri); } }
JS_EXPORT_API double launcher_weight(GDesktopAppInfo* info, const char* key) { double weight = 0.0; /* desktop file information */ const char* path = g_desktop_app_info_get_filename(info); char* basename = g_path_get_basename(path); *strchr(basename, '.') = '\0'; weight += _get_weight(basename, key, _pred, FILENAME_WEIGHT); g_free(basename); const char* gname = g_desktop_app_info_get_generic_name(info); weight += _get_weight(gname, key, _pred, GENERIC_NAME_WEIGHT); const char* const* keys = g_desktop_app_info_get_keywords(info); if (keys != NULL) { size_t n = g_strv_length((char**)keys); for (size_t i=0; i<n; i++) { weight += _get_weight(keys[i], key, _pred, KEYWORD_WEIGHT); } } const char* categories = g_desktop_app_info_get_categories(info); if (categories) { gchar** category_names = g_strsplit(categories, ";", -1); gsize len = g_strv_length(category_names) - 1; for (gsize i = 0; i < len; ++i) { weight += _get_weight(category_names[i], key, _pred, CATEGORY_WEIGHT); } g_strfreev(category_names); } /* application information */ const char* name = g_app_info_get_name((GAppInfo*)info); weight += _get_weight(name, key, _pred, NAME_WEIGHT); const char* dname = g_app_info_get_display_name((GAppInfo*)info); weight += _get_weight(dname, key, _pred, DISPLAY_NAME_WEIGHT); const char* desc = g_app_info_get_description((GAppInfo*)info); weight += _get_weight(desc, key, _pred, DESCRIPTION_WEIGHT); const char* exec = g_app_info_get_executable((GAppInfo*)info); weight += _get_weight(exec, key, _pred, EXECUTABLE_WEIGHT); return weight; }
GList* get_deepin_categories(GDesktopAppInfo* info) { char* basename = g_path_get_basename(g_desktop_app_info_get_filename(info)); GList* categories = NULL; char* sql = g_strdup_printf("select first_category_name " "from desktop " "where desktop_name like \"%s\";", basename); g_debug("[%s] app: %s", __func__, basename); g_free(basename); search_database(get_category_name_db_path(), sql, (SQLEXEC_CB)_get_all_possible_categories, &categories); g_free(sql); return categories; }
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; }
static void _launch_desktop_file (ClutterActor *actor, const gchar *desktop_id) { GDesktopAppInfo *app_info; const gchar *path; app_info = g_desktop_app_info_new (desktop_id); if (!app_info) return; path = g_desktop_app_info_get_filename (app_info); if (penge_utils_launch_for_desktop_file (actor, path)) penge_utils_signal_activated (actor); g_object_unref (app_info); }
static GKeyFile* _read_as_key_file(GDesktopAppInfo* app) { char const* filename = g_desktop_app_info_get_filename(app); if (filename == NULL) return NULL; GError* error = NULL; GKeyFile* file = g_key_file_new(); g_key_file_load_from_file(file, filename, G_KEY_FILE_NONE, &error); if (error != NULL) { g_warning("[%s] %s", __func__, error->message); g_error_free(error); g_key_file_unref(file); return NULL; } return file; }
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; }
char* get_desktop_file_basename(GDesktopAppInfo* file) { const char* filename = g_desktop_app_info_get_filename(file); return g_path_get_basename(filename); }
static GFile* _get_gfile_from_gapp(GDesktopAppInfo* info) { return g_file_new_for_commandline_arg(g_desktop_app_info_get_filename(info)); }
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; }
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; }
/** * 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 VALUE rg_filename(VALUE self) { return CSTR2RVAL(g_desktop_app_info_get_filename(_SELF(self))); }