scorpius/src/main.c

104 lines
2.7 KiB
C

#include <gtk/gtk.h>
#include "../include/gemgui.h"
#include "../include/gemparse.h"
GtkEntryBuffer *pathBarContent = NULL;
GtkWidget *render = NULL;
GtkWidget *scrollbar = NULL;
char links[1024][20];
static void makeRender (const char *path);
static void
loadPage (const char *link)
{
makeRender (link);
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
}
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 (const char *path)
{
if (render == NULL)
{
render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (scrollbar), render);
}
else
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
parseFile (path);
}
/* This function's goal is to build the main interface */
static void
build_interface (GtkWidget *window,
char *path)
{
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), "Scorpius");
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 (path);
}
/* 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), "Scorpius");
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
build_interface (window, (char *)user_data);
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), (argc >= 2) ? argv[1] : "readme.gmi");
status = g_application_run(G_APPLICATION (app), 1, argv);
g_object_unref (app);
return status;
}