scorpius/src/main.c

98 lines
2.5 KiB
C

#include <gtk/gtk.h>
#include "../include/gemgui.h"
#include "../include/gemparse.h"
GtkEntryBuffer *pathBarContent = NULL;
GtkWidget *render = NULL;
GtkWidget *scrollbar = NULL;
static void
loadPage (const char *link)
{
printf("Loading page : %s\n", link);
}
void
linkAction (GtkWidget *widget,
gpointer data)
{
loadPage ((const char*)data);
}
static void
goAction (GtkWidget *widget,
gpointer data)
{
loadPage ((const char*)gtk_entry_buffer_get_text (pathBarContent));
}
static void
makeRender (void)
{
if (render != NULL)
gtk_widget_destroy (render);
render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
parseFile ("test.gmi");
gtk_container_add (GTK_CONTAINER (scrollbar), render);
}
/* This function's goal is to build the main interface */
static void
build_interface (GtkWidget *window)
{
GtkWidget *pathBar;
GtkWidget *headerBar;
GtkWidget *goButtonBox;
GtkWidget *goButton;
/* Building title bar */
scrollbar = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), scrollbar);
headerBar = gtk_header_bar_new ();
gtk_header_bar_set_title(GTK_HEADER_BAR (headerBar), "GTK Gemini Browser");
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerBar), TRUE);
gtk_window_set_titlebar (GTK_WINDOW (window), headerBar);
pathBarContent = gtk_entry_buffer_new (NULL, -1);
pathBar = gtk_entry_new_with_buffer (pathBarContent);
goButtonBox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
goButton = gtk_button_new_with_label ("Go !");
g_signal_connect (goButton, "clicked", G_CALLBACK (goAction), NULL);
gtk_container_add (GTK_CONTAINER (goButtonBox), goButton);
gtk_container_add (GTK_CONTAINER (headerBar), pathBar);
gtk_container_add (GTK_CONTAINER (headerBar), goButtonBox);
makeRender ();
}
/* This function's goal is to create the window then show it */
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "MDViewer");
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
build_interface (window);
gtk_widget_show_all (window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("ovh.rdelaage.mdviewer", 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);
return status;
}