diff options
author | nirav <nirav@teisuu.com> | 2018-10-20 18:47:23 +0530 |
---|---|---|
committer | Dandelion <nirav@teisuu.com> | 2018-10-20 18:47:23 +0530 |
commit | f8f3159f9b98b024043bd8de2c5e15dd2adf03ca (patch) | |
tree | 0ccaa16120845ef816199dc02f2866c4be1fbba3 /src/main.c | |
parent | a7488f38fef1960086af860063f1958fb75d58f3 (diff) | |
download | im-f8f3159f9b98b024043bd8de2c5e15dd2adf03ca.tar.gz im-f8f3159f9b98b024043bd8de2c5e15dd2adf03ca.zip |
Switched to gtk_init and gtk_main from gtk_application
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 71 |
1 files changed, 38 insertions, 33 deletions
@@ -1,51 +1,56 @@ +#include <gtk-3.0/gtk/gtk.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + #include "file.h" #include "image.h" -#include "input.h" #include "window.h" -#include <gtk-3.0/gtk/gtk.h> -void print_help() +void print_usage() { - printf("usage: qwe [filename]\n"); + printf("qwe [filename]\n"); } -static void activate(GtkApplication *app, gpointer user_data) +void print_version() { - print_help(); + printf("0.01\n"); } -static void open(GApplication *app, GFile **files, gint n_files, - const gchar *hint) +int main(int argc, char **argv) { - if (n_files != 1) { - print_help(); - return; - } + gtk_init(&argc, &argv); - create_main_window(app); + int opt; + while ((opt = getopt(argc, argv, "hv")) != -1) { + switch (opt) { + case '?': + print_usage(); + exit(EXIT_FAILURE); + case 'h': + print_usage(); + exit(EXIT_SUCCESS); + case 'v': + print_version(); + exit(EXIT_SUCCESS); + } + } - char *curr_filename = g_file_get_path(files[0]); - int i = scan(curr_filename); - if (i < 0) { - printf("failed to load file\n"); - quit(); + if (optind >= argc) { + print_usage(); + exit(EXIT_FAILURE); } - i = load_image(curr_filename); - if (i < 0) { - printf("failed to load file\n"); - quit(); + // load the specified image + if (load_image(argv[optind])) { + exit(EXIT_FAILURE); } -} -int main(int argc, char *argv[]) -{ - GtkApplication *app; - int status; - app = gtk_application_new("org.gtk.qwe", G_APPLICATION_HANDLES_OPEN); - g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); - g_signal_connect(app, "open", G_CALLBACK(open), NULL); - status = g_application_run(G_APPLICATION(app), argc, argv); - g_object_unref(app); - return status; + // scan other supported image file in the same dir + scan(argv[optind]); + + create_main_window(); + gtk_main(); + + return EXIT_SUCCESS; } |