-
Notifications
You must be signed in to change notification settings - Fork 0
/
crystalball.c
76 lines (55 loc) · 2.05 KB
/
crystalball.c
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
//Copyright (C) 2017 Arc676/Alessandro Vinciguerra
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation (version 3)
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program. If not, see <http://www.gnu.org/licenses/>.
//See README and LICENSE for more details
#include <gtk/gtk.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
GtkWidget *aboutWindow;
GtkTextBuffer *transcript;
GtkEntry *question;
void windowDestroyed(){
gtk_main_quit();
}
void ask() {
GtkTextIter end;
gtk_text_buffer_get_end_iter(transcript, &end);
const char * userQ = gtk_entry_get_text(question);
char * answer = "um....";
char * toAppend = malloc(strlen(userQ) + strlen(answer) + 10);
sprintf(toAppend, "Q: %s\nA: %s\n", userQ, answer);
gtk_text_buffer_insert(transcript, &end, toAppend, -1);
free(toAppend);
}
void clear() {
gtk_text_buffer_set_text(transcript, "Crystal Ball Transcript\n", -1);
}
void about() {
gtk_widget_show(aboutWindow);
}
int main(int argc, char * argv[]){
gtk_init(&argc, &argv);
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "CrystalBall.glade", NULL);
GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
gtk_builder_connect_signals(builder, NULL);
aboutWindow = GTK_WIDGET(gtk_builder_get_object(builder, "aboutWindow"));
GtkTextView *transcriptView = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "transcript"));
transcript = gtk_text_view_get_buffer(transcriptView);
question = GTK_ENTRY(gtk_builder_get_object(builder, "questionField"));
g_object_unref(builder);
// initialize interface and other stuff
clear();
srand(time(NULL));
gtk_widget_show(window);
gtk_main();
return 0;
}