Code: Select all
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* gtk-foobar.c
* Copyright (C) Arnel A. Borja 2011 <galeon@ymail.com>
*
* gtk-foobar 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, either version 3 of the License, or
* (at your option) any later version.
*
* gtk-foobar 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/>.
*/
#include "gtk-foobar.h"
#include <glib/gi18n.h>
/* For testing propose use the local (not installed) ui file */
/* #define UI_FILE PACKAGE_DATA_DIR"/gtk_foobar/ui/gtk_foobar.ui" */
#define UI_FILE "src/gtk_foobar.ui"
G_DEFINE_TYPE (Gtkfoobar, gtk_foobar, GTK_TYPE_APPLICATION);
/* Create a new window loading a file */
static void
gtk_foobar_new_window (GApplication *app,
GFile *file)
{
GtkWidget *window;
GtkBuilder *builder;
GError* error = NULL;
/* Load UI from file */
builder = gtk_builder_new ();
if (!gtk_builder_add_from_file (builder, UI_FILE, &error))
{
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
}
/* Auto-connect signal handlers */
gtk_builder_connect_signals (builder, NULL);
/* Get the window object from the ui file */
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_object_unref (builder);
gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (app));
if (file != NULL)
{
/* TODO: Add code here to open the file in the new window */
}
gtk_widget_show_all (GTK_WIDGET (window));
}
/* GApplication implementation */
static void
gtk_foobar_activate (GApplication *application)
{
gtk_foobar_new_window (application, NULL);
}
static void
gtk_foobar_open (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint)
{
gint i;
for (i = 0; i < n_files; i++)
gtk_foobar_new_window (application, files[i]);
}
static void
gtk_foobar_init (Gtkfoobar *object)
{
}
static void
gtk_foobar_finalize (GObject *object)
{
G_OBJECT_CLASS (gtk_foobar_parent_class)->finalize (object);
}
static void
gtk_foobar_class_init (GtkfoobarClass *klass)
{
G_APPLICATION_CLASS (klass)->activate = gtk_foobar_activate;
G_APPLICATION_CLASS (klass)->open = gtk_foobar_open;
G_OBJECT_CLASS (klass)->finalize = gtk_foobar_finalize;
}
Gtkfoobar *
gtk_foobar_new (void)
{
g_type_init ();
return g_object_new (gtk_foobar_get_type (),
"application-id", "org.gnome.gtk_foobar",
"flags", G_APPLICATION_HANDLES_OPEN,
NULL);
}
Code: Select all
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* gtk-foobar.h
* Copyright (C) Arnel A. Borja 2011 <galeon@ymail.com>
*
* gtk-foobar 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, either version 3 of the License, or
* (at your option) any later version.
*
* gtk-foobar 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/>.
*/
#ifndef _GTK_FOOBAR_
#define _GTK_FOOBAR_
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTK_FOOBAR_TYPE_APPLICATION (gtk_foobar_get_type ())
#define GTK_FOOBAR_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_FOOBAR_TYPE_APPLICATION, Gtkfoobar))
#define GTK_FOOBAR_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_FOOBAR_TYPE_APPLICATION, GtkfoobarClass))
#define GTK_FOOBAR_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_FOOBAR_TYPE_APPLICATION))
#define GTK_FOOBAR_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_FOOBAR_TYPE_APPLICATION))
#define GTK_FOOBAR_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_FOOBAR_TYPE_APPLICATION, GtkfoobarClass))
typedef struct _GtkfoobarClass GtkfoobarClass;
typedef struct _Gtkfoobar Gtkfoobar;
struct _GtkfoobarClass
{
GtkApplicationClass parent_class;
};
struct _Gtkfoobar
{
GtkApplication parent_instance;
};
GType gtk_foobar_get_type (void) G_GNUC_CONST;
Gtkfoobar *gtk_foobar_new (void);
/* Callbacks */
G_END_DECLS
#endif /* _APPLICATION_H_ */
Not sure though. I have free time this summer until I enter college on half of June. After that, I only have time on Sunday to Monday (don't have classes in Monday). I don't have enough time last time when I'm still in high school.TJF wrote:I would realy appreciate your (and any other) help. Be prepared that I'll will ask for. Hopefully you won't run out of time again.Galeon wrote:I could help if you want to. I love creating packages hehe...