aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..b5eb616
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,51 @@
+#include "file.h"
+#include "image.h"
+#include "input.h"
+#include "window.h"
+#include <gtk-3.0/gtk/gtk.h>
+
+void print_help()
+{
+ printf("usage: qwe [filename]\n");
+}
+
+static void activate(GtkApplication *app, gpointer user_data)
+{
+ print_help();
+}
+
+static void open(GApplication *app, GFile **files, gint n_files,
+ const gchar *hint)
+{
+ if (n_files != 1) {
+ print_help();
+ return;
+ }
+
+ create_main_window(app);
+
+ char *curr_filename = g_file_get_path(files[0]);
+ int i = scan(curr_filename);
+ if (i < 0) {
+ printf("failed to load file\n");
+ return;
+ }
+
+ i = load_image(curr_filename);
+ if (i < 0) {
+ printf("failed to load file\n");
+ quit();
+ }
+}
+
+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;
+}