From f8f3159f9b98b024043bd8de2c5e15dd2adf03ca Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 20 Oct 2018 18:47:23 +0530 Subject: Switched to gtk_init and gtk_main from gtk_application --- src/main.c | 71 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 4289f9f..21dd14e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,51 +1,56 @@ +#include +#include +#include +#include + #include "file.h" #include "image.h" -#include "input.h" #include "window.h" -#include -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; } -- cgit v1.2.3