Is there an advantage of using a "Template" based method in GTK+ apps? I am making my first GTK+ app, and I am finding on the internet that there are many variations of creating a GTK+ apps, some older looking methods, some newer, I looked at the GTK+ dev guide and it uses a complex looking "Template" with sub-classing etc. See: https://developer.gnome.org/gtk3/stable/ch01s04.html
My question is am I fine doing it with my method or should I be using templates / sub-classing?
My way:
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="window">
...
#include <gtk/gtk.h>
static void activate (GtkApplication* app, gpointer user_data) {
GtkBuilder *builder = gtk_builder_new_from_file ("gui.glade");
GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_builder_connect_signals (builder, NULL);
gtk_widget_show_all (window);
gtk_main ();
}
int main (int argc, char *argv[]) {
GtkApplication *app = gtk_application_new ("a.b.c", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
vs "Template" way:
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="ExampleAppWindow" parent="GtkApplicationWindow">
...
#include <gtk/gtk.h>
#include "exampleapp.h"
#include "exampleappwin.h"
struct _ExampleApp
{
GtkApplication parent;
};
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
static void
example_app_init (ExampleApp *app)
{
}
static void
example_app_activate (GApplication *app)
{
ExampleAppWindow *win;
win = example_app_window_new (EXAMPLE_APP (app));
gtk_window_present (GTK_WINDOW (win));
}
static void
example_app_open (GApplication *app,
GFile **files,
gint n_files,
const gchar *hint)
{
GList *windows;
ExampleAppWindow *win;
int i;
...