1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#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();
auth_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); */
}
|