Clean up last commit

This commit is contained in:
Lassebq 2023-10-15 13:00:14 +03:00 committed by Geronymos
parent f807b553a3
commit b9be0581e4
2 changed files with 19 additions and 20 deletions

View file

@ -9,6 +9,7 @@
- [X] Start default application for the active file - [X] Start default application for the active file
- [X] Update the Icons on changes to the directory (added/removed files) - [X] Update the Icons on changes to the directory (added/removed files)
- [X] Drag and Drop Files from/to the Desktop - [X] Drag and Drop Files from/to the Desktop
- [X] Launching Apps from the Desktop
- [ ] Multi-Monitor Support - [ ] Multi-Monitor Support
- [ ] Thumbnails for Images/Documents - [ ] Thumbnails for Images/Documents
- [ ] Sort Rows of List Store based on Name/Type/Date - [ ] Sort Rows of List Store based on Name/Type/Date

View file

@ -43,32 +43,29 @@ void append_row_from_file(GtkListStore *store, GFile *file)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GFileInfo *file_info; GFileInfo *file_info;
GdkPixbuf *pixbuf;
GAppInfo *app;
const gchar *display_name = NULL; const gchar *display_name = NULL;
GdkPixbuf *pixbuf = NULL; GdkPixbuf *icon = NULL;
GKeyFile *keyfile = g_key_file_new (); GKeyFile *keyfile = g_key_file_new ();
file_info = g_file_query_info(file, "standard::*,ownser::user", 0, 0, 0); file_info = g_file_query_info(file, "standard::*,ownser::user", 0, 0, 0);
if (g_key_file_load_from_file (keyfile, g_file_get_path(file), G_KEY_FILE_NONE, NULL)) if (g_key_file_load_from_file (keyfile, g_file_get_path(file), G_KEY_FILE_NONE, NULL))
{ {
GAppInfo* app = (GAppInfo*)g_desktop_app_info_new_from_keyfile (keyfile); app = (GAppInfo*)g_desktop_app_info_new_from_keyfile (keyfile);
if(app) { if (app) {
display_name = g_app_info_get_display_name(app); display_name = g_app_info_get_display_name(app);
pixbuf = gtk_icon_info_load_icon( icon = g_app_info_get_icon(app);
gtk_icon_theme_lookup_by_gicon(
theme,
g_app_info_get_icon(app),
48, 0), 0);
} }
} }
if(!display_name) if (!display_name)
display_name = g_file_info_get_display_name(file_info); display_name = g_file_info_get_display_name(file_info);
if(!pixbuf) if (!icon)
pixbuf = gtk_icon_info_load_icon( icon = g_file_info_get_icon(file_info);
gtk_icon_theme_lookup_by_gicon(
theme, pixbuf = gtk_icon_info_load_icon(
g_file_info_get_icon(file_info), gtk_icon_theme_lookup_by_gicon(theme, icon, 48, 0), 0);
48, 0), 0);
gtk_list_store_append(store, &iter); gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, gtk_list_store_set(store, &iter,
@ -171,19 +168,20 @@ static GtkListStore *create_desktop_list(void)
return GTK_LIST_STORE(store); return GTK_LIST_STORE(store);
} }
static void launch_desktop_shortcut(GFile *desktop_file) { static void launch_default_or_app_for_file(GFile *desktop_file) {
GAppInfo *app;
GKeyFile *keyfile = g_key_file_new (); GKeyFile *keyfile = g_key_file_new ();
if (g_key_file_load_from_file (keyfile, g_file_get_path(desktop_file), G_KEY_FILE_NONE, NULL)) if (g_key_file_load_from_file (keyfile, g_file_get_path(desktop_file), G_KEY_FILE_NONE, NULL))
{ {
GAppInfo* app = (GAppInfo*)g_desktop_app_info_new_from_keyfile (keyfile); app = (GAppInfo*)g_desktop_app_info_new_from_keyfile (keyfile);
if(app) { if (app) {
GAppLaunchContext* app_context = g_app_launch_context_new (); GAppLaunchContext* app_context = g_app_launch_context_new ();
g_app_info_launch(app, NULL, app_context, NULL); g_app_info_launch(app, NULL, app_context, NULL);
g_clear_object (&app_context); g_clear_object (&app_context);
return; return;
} }
} }
// Not a .desktop, trying xdg open // Not a .desktop, falling back to xdg open
char* file_uri = g_file_get_uri(desktop_file); char* file_uri = g_file_get_uri(desktop_file);
g_app_info_launch_default_for_uri(file_uri, 0, 0); g_app_info_launch_default_for_uri(file_uri, 0, 0);
} }
@ -199,7 +197,7 @@ static void activate_cb(GtkIconView *icon_view, GtkTreePath *tree_path, gpointer
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_FILE, &file, -1); gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_FILE, &file, -1);
launch_desktop_shortcut(file); launch_default_or_app_for_file(file);
} }
static void activate (GtkApplication* app, gpointer user_data) static void activate (GtkApplication* app, gpointer user_data)