2023-04-05 13:09:05 +02:00
|
|
|
#include <gtk/gtk.h>
|
2023-04-05 15:53:13 +02:00
|
|
|
#include <gio/gio.h>
|
2023-04-05 22:33:15 +02:00
|
|
|
#include <gtk-layer-shell/gtk-layer-shell.h>
|
2023-04-05 13:09:05 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COL_PIXBUF,
|
|
|
|
COL_DISPLAY_NAME,
|
|
|
|
COL_FILE,
|
|
|
|
COL_FILE_INFO,
|
|
|
|
NUM_COLS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkListStore *create_desktop_list(void)
|
2023-04-05 20:55:01 +02:00
|
|
|
{
|
2023-04-05 22:33:15 +02:00
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
2023-04-05 20:55:01 +02:00
|
|
|
GDir *dir;
|
|
|
|
GFile *file;
|
2023-04-05 22:33:15 +02:00
|
|
|
GFileInfo *file_info;
|
|
|
|
const gchar *file_name, *display_name;
|
|
|
|
GtkIconTheme *theme;
|
|
|
|
GdkPixbuf *pixbuf;
|
2023-04-05 20:55:01 +02:00
|
|
|
|
|
|
|
const gchar* desktop_path = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
|
|
|
|
printf("n %s\n", desktop_path);
|
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
theme = gtk_icon_theme_get_default();
|
|
|
|
|
|
|
|
store = gtk_list_store_new(NUM_COLS,
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_FILE,
|
|
|
|
G_TYPE_FILE_INFO);
|
2023-04-05 20:55:01 +02:00
|
|
|
|
|
|
|
dir = g_dir_open(desktop_path, 0, 0);
|
|
|
|
|
|
|
|
while ( (file_name = g_dir_read_name(dir)) ) {
|
|
|
|
printf("g %s\n", file_name);
|
2023-04-05 19:00:08 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
file = g_file_new_for_path(g_build_filename(desktop_path, file_name, NULL));
|
|
|
|
display_name = g_filename_to_utf8(file_name, -1, 0, 0, 0);
|
|
|
|
file_info = g_file_query_info(file, "standard::*,ownser::user", 0, 0, 0);
|
|
|
|
pixbuf = gtk_icon_info_load_icon(
|
|
|
|
gtk_icon_theme_lookup_by_gicon(
|
|
|
|
theme,
|
|
|
|
g_file_info_get_icon(file_info),
|
|
|
|
48, 0), 0);
|
|
|
|
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter,
|
|
|
|
COL_PIXBUF, pixbuf,
|
|
|
|
COL_DISPLAY_NAME, display_name,
|
|
|
|
COL_FILE, file,
|
|
|
|
COL_FILE_INFO, file_info,
|
|
|
|
-1
|
|
|
|
);
|
|
|
|
}
|
2023-04-05 19:00:08 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
return GTK_LIST_STORE(store);
|
2023-04-05 19:00:08 +02:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:45:08 +02:00
|
|
|
static void activate_cb(GtkIconView *icon_view, GtkTreePath *tree_path, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GFile *file;
|
|
|
|
char* file_uri;
|
|
|
|
store = GTK_LIST_STORE (user_data);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (store),
|
|
|
|
&iter, tree_path);
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
|
|
|
|
COL_FILE, &file,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
file_uri = g_file_get_uri(file);
|
|
|
|
printf("uri %s\n", file_uri);
|
|
|
|
|
|
|
|
g_app_info_launch_default_for_uri(file_uri, 0, 0);
|
|
|
|
}
|
2023-04-05 19:55:43 +02:00
|
|
|
|
2023-04-05 13:09:05 +02:00
|
|
|
static void activate (GtkApplication* app, gpointer user_data)
|
|
|
|
{
|
2023-04-05 22:33:15 +02:00
|
|
|
GtkWidget *window, *icon_view;
|
|
|
|
GtkListStore *model;
|
2023-04-05 13:09:05 +02:00
|
|
|
|
|
|
|
window = gtk_application_window_new(app);
|
|
|
|
gtk_window_set_title(GTK_WINDOW (window), "Window");
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW (window), 200, 200);
|
2023-04-05 15:53:13 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
gtk_layer_init_for_window(GTK_WINDOW(window));
|
|
|
|
gtk_layer_set_layer(GTK_WINDOW(window), GTK_LAYER_SHELL_LAYER_BOTTOM);
|
|
|
|
|
2023-04-05 20:55:01 +02:00
|
|
|
model = create_desktop_list();
|
2023-04-05 22:33:15 +02:00
|
|
|
icon_view = gtk_icon_view_new_with_model(GTK_TREE_MODEL(model));
|
|
|
|
|
|
|
|
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
|
|
|
|
GTK_SELECTION_MULTIPLE);
|
|
|
|
gtk_icon_view_set_text_column(GTK_ICON_VIEW (icon_view), COL_DISPLAY_NAME);
|
|
|
|
gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW (icon_view), COL_PIXBUF);
|
2023-04-05 15:53:13 +02:00
|
|
|
|
2023-04-05 22:45:08 +02:00
|
|
|
g_signal_connect(icon_view, "item-activated", G_CALLBACK(activate_cb), model);
|
2023-04-05 15:53:13 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
gtk_container_add(GTK_CONTAINER(window), icon_view);
|
|
|
|
gtk_widget_grab_focus (icon_view);
|
2023-04-05 20:55:01 +02:00
|
|
|
|
2023-04-05 22:33:15 +02:00
|
|
|
gtk_widget_show_all (window);
|
2023-04-05 13:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkApplication *app;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
|
|
|
|
g_signal_connect(app, "activate", G_CALLBACK (activate), NULL);
|
|
|
|
status = g_application_run(G_APPLICATION (app), argc, argv);
|
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|