Galeon wrote:Iie, GtkApplication is in GTK+ (gtk.h).
Lie? Be sure that I red parts of the documentation yet. Yes, it's in GtkApplication.h which should be included via gtk.h. But it's based on g_application which is in gio.h.
Example (mind the
GApplication PTRs):
Code: Select all
#INCLUDE ONCE "TJF/gtk.bi"
SUB new_window (BYVAL app AS GApplication PTR, _
BYVAL file AS GFile PTR)
VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_application (GTK_WINDOW (win), GTK_APPLICATION (app))
gtk_window_set_title (GTK_WINDOW (win), "Bloatpad")
VAR scrolled = gtk_scrolled_window_new (NULL, NULL)
VAR vie = gtk_text_view_new ()
gtk_container_add (GTK_CONTAINER (scrolled), vie)
gtk_container_add (GTK_CONTAINER (win), scrolled)
IF file THEN
DIM AS gchar PTR contents
DIM AS gsize length
IF g_file_load_contents (file, NULL, @contents, @length, NULL, NULL) THEN
VAR buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (vie))
gtk_text_buffer_set_text (buffer, contents, length)
g_free (contents)
END IF
END IF
gtk_widget_show_all (GTK_WIDGET (win))
END SUB
TYPE AS GtkApplication BloatPad
TYPE AS GtkApplicationClass BloatPadClass
G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION)
SUB bloat_pad_open CDECL(BYVAL app AS GApplication PTR, _
BYVAL files AS GFile PTR PTR, _
BYVAL n_files AS gint, _
BYVAL hint AS CONST gchar PTR)
FOR i AS gint = 0 TO n_files - 1
new_window (app, files[i])
NEXT
END SUB
SUB bloat_pad_activate CDECL(BYVAL app AS GApplication PTR)
new_window (app, NULL)
END SUB
SUB bloat_pad_finalize CDECL(BYVAL object AS GObject PTR)
G_OBJECT_CLASS (bloat_pad_parent_class)->finalize (object)
END SUB
SUB bloat_pad_init CDECL(BYVAL app AS BloatPad PTR)
END SUB
SUB bloat_pad_class_init CDECL(BYVAL clas AS BloatPadClass PTR)
G_OBJECT_CLASS(clas)->finalize = @bloat_pad_finalize
G_APPLICATION_CLASS(clas)->activate = @bloat_pad_activate
G_APPLICATION_CLASS(clas)->open_TJF = @bloat_pad_open
END SUB
FUNCTION bloat_pad_new () AS BloatPad PTR
g_type_init ()
RETURN g_object_new (bloat_pad_get_type (), _
"application-id", "org.gtk.Test.bloatpad", _
"flags", G_APPLICATION_HANDLES_OPEN, _
NULL)
END FUNCTION
VAR bloat_pad = bloat_pad_new ()
VAR status = g_application_run (G_APPLICATION (bloat_pad), __FB_ARGC__, __FB_ARGV__)
g_object_unref (bloat_pad)
END status
And another example without GUI
Code: Select all
#INCLUDE ONCE "TJF/gio.bi"
#INCLUDE ONCE "crt.bi"
FUNCTION command_line CDECL( _
BYVAL application AS GApplication PTR, _
BYVAL cmdline AS GApplicationCommandLine PTR _
) AS INTEGER STATIC
DIM AS gint argc
DIM AS gchar PTR PTR argv
argv = g_application_command_line_get_arguments (cmdline, @argc)
FOR i AS gint = 0 TO argc - 1
g_print (!"handling argument %s remotely\n", argv[i])
NEXT
g_strfreev (argv)
RETURN 0
END FUNCTION
FUNCTION test_local_cmdline CDECL( _
BYVAL application AS GApplication PTR, _
BYVAL arguments AS gchar PTR PTR PTR, _
BYVAL exit_status AS gint PTR) AS gboolean STATIC
DIM AS gchar PTR PTR argv
DIM AS gint i, j
argv = *arguments
i = 1
WHILE argv[i]
IF g_str_has_prefix (argv[i], "--local-") THEN
g_print (!"handling argument %s locally\n", argv[i])
g_free (argv[i])
j = i
WHILE argv[j]
argv[j] = argv[j + 1]
j += 1
WEND
ELSE
g_print (!"not handling argument %s locally\n", argv[i])
i += 1
END IF
WEND
*exit_status = 0
RETURN FALSE
END FUNCTION
TYPE AS GApplication TestApplication
TYPE AS GApplicationClass TestApplicationClass
G_DEFINE_TYPE(TestApplication, test_application, G_TYPE_APPLICATION)
SUB test_application_finalize CDECL(BYVAL object AS GObject PTR)
G_OBJECT_CLASS (test_application_parent_class)->finalize(object)
END SUB
SUB test_application_init CDECL(BYVAL app AS TestApplication PTR)
END SUB
SUB test_application_class_init CDECL(BYVAL clas AS TestApplicationClass PTR)
G_OBJECT_CLASS(clas)->finalize = @test_application_finalize
G_APPLICATION_CLASS(clas)->local_command_line = @test_local_cmdline
END SUB
FUNCTION test_application_new (BYVAL application_id AS CONST gchar PTR, _
BYVAL flags AS GApplicationFlags) AS GApplication PTR
g_return_val_if_fail(g_application_id_is_valid (application_id), NULL)
g_type_init()
RETURN g_object_new(test_application_get_type (), _
"application-id", application_id, _
"flags", flags, _
NULL)
END FUNCTION
VAR status = -1
VAR app = test_application_new ("org.gtk.TestApplication", 0)
IF app THEN
g_application_set_inactivity_timeout (app, 10000)
g_signal_connect(app, "command-line", G_CALLBACK (@command_line), NULL)
status = g_application_run (app, __FB_ARGC__, __FB_ARGV__)
g_object_unref (app)
END IF
END status
Of course, this is all based on GLib and GObject, which will be included by GIO. Anyway, without GIO no GtkApplication.
Galeon wrote:I could help if you want to. I love creating packages hehe...
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.