Compare commits
3 Commits
659e14ba1b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d29dc3d7e | |||
| 51ff8ae6e1 | |||
| 2aaa456ddd |
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@ CC=clang
|
||||
CFLAGS=`pkg-config --cflags gtk4`
|
||||
CLIBS=`pkg-config --libs gtk4`
|
||||
SOURCES= main.c
|
||||
EXECUTABLE=shakalizator
|
||||
EXECUTABLE=shakalizator.out
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(EXECUTABLE)
|
||||
|
||||
50
main.c
50
main.c
@@ -3,16 +3,62 @@
|
||||
|
||||
typedef struct{
|
||||
GtkApplication *app;
|
||||
GtkWidget *window;
|
||||
GtkWidget *window , *box ,*input, *image;
|
||||
char dir[256];
|
||||
} Appdata;
|
||||
|
||||
static void app_activate (GtkApplication *app, gpointer *user_data);
|
||||
static void load_image(Appdata *data){
|
||||
GError *error = NULL;
|
||||
if (data->image != NULL){
|
||||
gtk_box_remove(data->box,GTK_WIDGET(data->image));
|
||||
}
|
||||
GdkPixbuf *pix = gdk_pixbuf_new_from_file (("%s", data->dir), &error);
|
||||
if (pix == NULL){
|
||||
g_printerr("Error loading file: #%d %s\n", error->code, error->message);
|
||||
g_error_free(error);
|
||||
exit (1);
|
||||
}
|
||||
data->image = gtk_image_new_from_pixbuf(pix);
|
||||
gtk_box_append(GTK_BOX(data->box),data->image);
|
||||
}
|
||||
|
||||
// activates after enter dir in input
|
||||
void on_entry_activate(GtkEntry *entry, Appdata *data){
|
||||
const gchar *user_text;
|
||||
user_text = gtk_editable_get_text(GTK_EDITABLE(entry));
|
||||
g_print("input: %s\n", user_text);
|
||||
// check empty input
|
||||
if (strcmp(user_text, "") == 0 || strcmp(user_text, " ") == 0){
|
||||
snprintf(data->dir, sizeof(data->dir), "/");
|
||||
gtk_editable_set_text(GTK_EDITABLE(data->input), "/");
|
||||
}
|
||||
else{
|
||||
snprintf(data->dir, sizeof(data->dir), "%s", user_text);
|
||||
gtk_editable_set_text(GTK_EDITABLE(data->input), ("%s", data->dir));
|
||||
}
|
||||
load_image(data);
|
||||
}
|
||||
|
||||
// make input line
|
||||
static void input_dir(Appdata *data){
|
||||
data->input = gtk_entry_new();
|
||||
gtk_editable_set_text(GTK_EDITABLE(data->input), ("%s", data->dir));
|
||||
g_signal_connect(data->input, "activate", G_CALLBACK(on_entry_activate), data);
|
||||
g_print("Set input line\n");
|
||||
gtk_box_append (GTK_BOX (data->box), data->input);
|
||||
}
|
||||
|
||||
static void app_activate (GtkApplication *app, gpointer *user_data){
|
||||
Appdata *data = (Appdata *)user_data;
|
||||
data->window = gtk_application_window_new (GTK_APPLICATION(app));
|
||||
gtk_window_set_title (GTK_WINDOW (data->window), "Shakalizator");
|
||||
gtk_window_set_default_size (GTK_WINDOW (data->window), 600, 400);
|
||||
gtk_window_set_application(GTK_WINDOW(data->window),app);
|
||||
gtk_window_present(GTK_WINDOW(data->window));
|
||||
data->box = gtk_box_new(GTK_ORIENTATION_VERTICAL,10);
|
||||
gtk_widget_set_valign(data->box,GTK_ALIGN_START);
|
||||
gtk_window_set_child(GTK_WINDOW(data->window), data->box);
|
||||
input_dir(data);
|
||||
printf("Present window %d\n", data->window);
|
||||
g_print("Started\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user