summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..69778bd
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,121 @@
+#define _POSIX_C_SOURCE 200809L
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gtk-3.0/gtk/gtk.h>
+#include "auth.h"
+#include "http.h"
+#include "timeline.h"
+#include "window.h"
+
+static GtkWidget *window;
+static GtkWidget *box;
+static GtkWidget *instance_name_box, *email_box, *password_box;
+static GtkWidget *submit_button;
+
+static void submit_login_form()
+{
+ const char *instance_name, *email, *password;
+ instance_name = gtk_entry_get_text(GTK_ENTRY(instance_name_box));
+ email = gtk_entry_get_text(GTK_ENTRY(email_box));
+ password = gtk_entry_get_text(GTK_ENTRY(password_box));
+ g_print("\n%s\n%s\n%s\n", instance_name, email, password);
+ char *in = strdup(instance_name);
+ int ok;
+ ok = register_app(in);
+ fprintf(stderr, "submit_login_form(): return val %d\n", ok);
+ free(in);
+}
+
+static void submit_button_clicked(GtkButton *button, gpointer user_data)
+{
+ submit_login_form();
+}
+
+static void activate(GtkApplication *app, gpointer user_data)
+{
+ window = gtk_application_window_new(app);
+ gtk_window_set_title(GTK_WINDOW(window), "ap_client");
+ gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
+ gtk_container_set_border_width(GTK_CONTAINER(window), 10);
+
+ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
+ gtk_widget_set_valign(GTK_WIDGET(box), GTK_ALIGN_CENTER);
+ gtk_widget_set_halign(GTK_WIDGET(box), GTK_ALIGN_CENTER);
+
+ instance_name_box = gtk_entry_new();
+ gtk_entry_set_placeholder_text(
+ GTK_ENTRY(instance_name_box), "Instance domain");
+
+ email_box = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(email_box), "Email");
+
+ password_box = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(password_box), "Password");
+
+ submit_button = gtk_button_new();
+ g_signal_connect(GTK_BUTTON(submit_button), "clicked",
+ G_CALLBACK(submit_button_clicked), G_OBJECT(window));
+ gtk_button_set_label(GTK_BUTTON(submit_button), "Submit");
+
+ gtk_container_add(GTK_CONTAINER(window), box);
+ gtk_container_add(GTK_CONTAINER(box), instance_name_box);
+ gtk_container_add(GTK_CONTAINER(box), email_box);
+ gtk_container_add(GTK_CONTAINER(box), password_box);
+ gtk_container_add(GTK_CONTAINER(box), submit_button);
+
+ gtk_widget_show_all(window);
+}
+
+int main(int argc, char **argv)
+{
+ /* gtk_init(&argc, &argv); */
+ /* create_main_window(); */
+ /* gtk_main(); */
+ if (http_init()) {
+ fprintf(stderr, "main(): failed to load http library\n");
+ return EXIT_FAILURE;
+ }
+
+ GtkApplication *app;
+ int status;
+
+ app = gtk_application_new("org.gtk.ap_client", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+ status = g_application_run(G_APPLICATION(app), argc, argv);
+ g_object_unref(app);
+
+ http_cleanup();
+
+ return status;
+
+ /* char *text; */
+ /* struct timeline *t; */
+ /* char *url = "https://mstdn.io/api/v1/timelines/home"; */
+ /* char *token = */
+ /* "580acfb412e927c2030fb5519f417b03ced1482c862d44376922cd81ee8a3655";
+ */
+
+ /* text = request(url, token); */
+ /* if (!text) { */
+ /* fprintf(stderr, "main(): failed to get http response\n"); */
+ /* return EXIT_FAILURE; */
+ /* } */
+
+ /* t = timeline_from_json(text); */
+ /* if (t == NULL) { */
+ /* fprintf(stderr, "main(): failed to parse timeline\n"); */
+ /* return EXIT_FAILURE; */
+ /* } */
+
+ /* for (size_t i = 0; i < t->size; i++) { */
+ /* printf("status id: %s\n", t->statuses[i]->id); */
+ /* printf("content: %s\n", t->statuses[i]->content); */
+ /* printf("reblog count: %d\n", t->statuses[i]->reblogs_count); */
+ /* printf("fav count: %d\n", t->statuses[i]->favourites_count); */
+ /* printf("\n"); */
+ /* } */
+
+ /* free(text); */
+ /* timeline_free(t); */
+}