GTK-headers 2.22.0 for FreeBasic

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

GTK-headers 2.22.0 for FreeBasic

Post by TJF »

FreeBasic-headers for GTK version 2.22.0 are available now.

Features, compared to 'gtk/gtk.bi':
  • All new functions available, e.g. GtkBuilder or Cairo
    More compiler features are translated (e.g. G_DISABLE_DEPRECATED)
    Small bugs are fixed (e.g. gtk_tree_item_new_with_label("NoGo") is working now)
    Can also be used with older GTK versions
    Untranslated C-source is included as FreeBasic comment for further translation (mostly asm-code for optimisation)
All 503 files are translated into a single *.bi file called GTK-2.22.0_TJF.bi (1.6 Mb). This file includes:
  • atk-1.32.0
    cairo-1.10.0
    gdk-2.90.1
    glib-2.27.0
    gtk-2.22.0
    pango-1.28.3
If need be, the headers can be separated.

This file is part of the package GTK+tobac2.2.2 (details and download at http://www.freebasic-portal.de/download ... 0-131.html)

To use it, just unpack the zip file and copy 'inc/GTK-2.22.0_TJF.bi' into your folder '*/freebasic/inc/gtk'. Then use
#INCLUDE "gtk/GTK-2.22.0_TJF.bi"
in your source.

I use the bindings in 5 projects, without trouble. Please test and report.

Enjoy!
turboguppy
Posts: 31
Joined: Oct 22, 2010 19:52
Location: Flint, MI, USA

Post by turboguppy »

The gtk-2.22.0_TJF.bi doesn't seem to support gtkgl.bi.

I tried to run the test program in the examples (opengl_button.bas) with this binding and it didn't recognize the gtkgl functions.

I tried using the TJF.bi and gtkgl.bi together, but the gtkgl.bi includes several other .bi files, and those .bi files include some of the gtk.bi series of files that you included in the TJF.bi -- so we get duplicated definition errors.

Seems like an easy fix... But then you're more of an expert than I am by a long shot!
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

turboguppy wrote:I tried to run the test program in the examples (opengl_button.bas) with this binding and it didn't recognize the gtkgl functions.
Thank you for reporting! It seems to be a bug. I will look it up.
turboguppy wrote:I tried using the TJF.bi and gtkgl.bi together, ...
... But then you're more of an expert than I am by a long shot!
This is dangerous ...
turboguppy wrote:Seems like an easy fix...
Seeming easy fixes likely be time-consuming ...
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

No bug! gtk/gtkgl.bi belongs to a separate library, the GTK OpenGl extension.

So, I made a new header compatible with GTK-2.22.0_TJF.bi. For Deatils see:
http://www.freebasic.net/forum/viewtopic.php?t=16790
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

I am experimenting with the GVariant stuff. And I found a number of macros that were not translated. I replaced macros in gvariant.h with the following macros
(I tested one, the rest are more or less the same)

Code: Select all

#DEFINE G_VARIANT_TYPE_BOOLEAN (cast( GVariantType ptr,@"b"))
#DEFINE G_VARIANT_TYPE_BYTE (cast( GVariantType ptr,@"y"))
#DEFINE G_VARIANT_TYPE_INT16 (cast( GVariantType ptr,@"n"))
#DEFINE G_VARIANT_TYPE_UINT16 (cast( GVariantType ptr,@"q"))
#DEFINE G_VARIANT_TYPE_INT32 (cast( GVariantType ptr,@"i"))
#DEFINE G_VARIANT_TYPE_UINT32 (cast( GVariantType ptr,@"u"))
#DEFINE G_VARIANT_TYPE_INT64 (cast( GVariantType ptr,@"x"))
#DEFINE G_VARIANT_TYPE_UINT64 (cast( GVariantType ptr,@"t"))
#DEFINE G_VARIANT_TYPE_DOUBLE (cast( GVariantType ptr,@"d"))
#DEFINE G_VARIANT_TYPE_STRING (cast( GVariantType ptr,@"s"))
#DEFINE G_VARIANT_TYPE_OBJECT_PATH (cast( GVariantType ptr,@"o"))
#DEFINE G_VARIANT_TYPE_SIGNATURE (cast( GVariantType ptr,@"g"))
#DEFINE G_VARIANT_TYPE_VARIANT (cast( GVariantType ptr,@"v"))
#DEFINE G_VARIANT_TYPE_HANDLE (cast( GVariantType ptr,@"h"))
#DEFINE G_VARIANT_TYPE_UNIT (cast( GVariantType ptr,@"()"))
#DEFINE G_VARIANT_TYPE_ANY (cast( GVariantType ptr,@"*"))
#DEFINE G_VARIANT_TYPE_BASIC (cast( GVariantType ptr,@"?"))
#DEFINE G_VARIANT_TYPE_MAYBE (cast( GVariantType ptr,@"m*"))
#DEFINE G_VARIANT_TYPE_ARRAY (cast(GVariantType ptr,@"a*"))
#DEFINE G_VARIANT_TYPE_TUPLE (cast( GVariantType ptr,@"r"))
#DEFINE G_VARIANT_TYPE_DICT_ENTRY (cast( GVariantType ptr,@"{?*}"))
#DEFINE G_VARIANT_TYPE_DICTIONARY (cast( GVariantType ptr,@"a{?*}"))
#DEFINE G_VARIANT_TYPE_STRING_ARRAY (cast( GVariantType ptr,@"as"))
#DEFINE G_VARIANT_TYPE_BYTESTRING (cast( GVariantType ptr,@"ay"))
#DEFINE G_VARIANT_TYPE_BYTESTRING_ARRAY (cast( GVariantType ptr,@"aay"))
I also found some macros that were not commented out and are not correct. These are part of gtype.h

Code: Select all

#DEFINE G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
The _C_ can be replaced with an arbitrary piece of code so it could be something like

Code: Select all

scope
_C_
end scope
The above macro is part of a bunch of macros inside gtype.bi that work together (some macros 'need' variables declared in other macros in order to work). All of these macros are needed when using the gtype system. Their use is optional but these macros also prevent you from forgetting to implement stuff that is needed to (for example) register a type with the gobject system.

Most of the macro code can be translated to fb easily.
Most... except for that C keyword called volatile that is. I don't know what should be done with that keyword (perhaps just drop the volatile and hope it'll work?).

Great job on the gtk+ header files. It's nice to be able to mess around with gvariant and other stuff.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

AGS wrote:I am experimenting with the GVariant stuff. And I found a number of macros that were not translated. I replaced macros in gvariant.h with the following macros
(I tested one, the rest are more or less the same)

Code: Select all

#DEFINE G_VARIANT_TYPE_BOOLEAN (cast( GVariantType ptr,@"b"))
#DEFINE G_VARIANT_TYPE_BYTE (cast( GVariantType ptr,@"y"))
#DEFINE G_VARIANT_TYPE_INT16 (cast( GVariantType ptr,@"n"))
#DEFINE G_VARIANT_TYPE_UINT16 (cast( GVariantType ptr,@"q"))
#DEFINE G_VARIANT_TYPE_INT32 (cast( GVariantType ptr,@"i"))
#DEFINE G_VARIANT_TYPE_UINT32 (cast( GVariantType ptr,@"u"))
#DEFINE G_VARIANT_TYPE_INT64 (cast( GVariantType ptr,@"x"))
#DEFINE G_VARIANT_TYPE_UINT64 (cast( GVariantType ptr,@"t"))
#DEFINE G_VARIANT_TYPE_DOUBLE (cast( GVariantType ptr,@"d"))
#DEFINE G_VARIANT_TYPE_STRING (cast( GVariantType ptr,@"s"))
#DEFINE G_VARIANT_TYPE_OBJECT_PATH (cast( GVariantType ptr,@"o"))
#DEFINE G_VARIANT_TYPE_SIGNATURE (cast( GVariantType ptr,@"g"))
#DEFINE G_VARIANT_TYPE_VARIANT (cast( GVariantType ptr,@"v"))
#DEFINE G_VARIANT_TYPE_HANDLE (cast( GVariantType ptr,@"h"))
#DEFINE G_VARIANT_TYPE_UNIT (cast( GVariantType ptr,@"()"))
#DEFINE G_VARIANT_TYPE_ANY (cast( GVariantType ptr,@"*"))
#DEFINE G_VARIANT_TYPE_BASIC (cast( GVariantType ptr,@"?"))
#DEFINE G_VARIANT_TYPE_MAYBE (cast( GVariantType ptr,@"m*"))
#DEFINE G_VARIANT_TYPE_ARRAY (cast(GVariantType ptr,@"a*"))
#DEFINE G_VARIANT_TYPE_TUPLE (cast( GVariantType ptr,@"r"))
#DEFINE G_VARIANT_TYPE_DICT_ENTRY (cast( GVariantType ptr,@"{?*}"))
#DEFINE G_VARIANT_TYPE_DICTIONARY (cast( GVariantType ptr,@"a{?*}"))
#DEFINE G_VARIANT_TYPE_STRING_ARRAY (cast( GVariantType ptr,@"as"))
#DEFINE G_VARIANT_TYPE_BYTESTRING (cast( GVariantType ptr,@"ay"))
#DEFINE G_VARIANT_TYPE_BYTESTRING_ARRAY (cast( GVariantType ptr,@"aay"))
From my point of view, you should add a CONST into the CAST, like

Code: Select all

#DEFINE G_VARIANT_TYPE_BOOLEAN (CAST(CONST GVariantType PTR, @!"b"))
#DEFINE G_VARIANT_TYPE_BYTE (CAST(CONST GVariantType PTR, @!"y"))
#DEFINE G_VARIANT_TYPE_INT16 (CAST(CONST GVariantType PTR, @!"n"))
#DEFINE G_VARIANT_TYPE_UINT16 (CAST(CONST GVariantType PTR, @!"q"))
#DEFINE G_VARIANT_TYPE_INT32 (CAST(CONST GVariantType PTR, @!"i"))
#DEFINE G_VARIANT_TYPE_UINT32 (CAST(CONST GVariantType PTR, @!"u"))
#DEFINE G_VARIANT_TYPE_INT64 (CAST(CONST GVariantType PTR, @!"x"))
#DEFINE G_VARIANT_TYPE_UINT64 (CAST(CONST GVariantType PTR, @!"t"))
#DEFINE G_VARIANT_TYPE_DOUBLE (CAST(CONST GVariantType PTR, @!"d"))
#DEFINE G_VARIANT_TYPE_STRING (CAST(CONST GVariantType PTR, @!"s"))
#DEFINE G_VARIANT_TYPE_OBJECT_PATH (CAST(CONST GVariantType PTR, @!"o"))
#DEFINE G_VARIANT_TYPE_SIGNATURE (CAST(CONST GVariantType PTR, @!"g"))
#DEFINE G_VARIANT_TYPE_VARIANT (CAST(CONST GVariantType PTR, @!"v"))
#DEFINE G_VARIANT_TYPE_HANDLE (CAST(CONST GVariantType PTR, @!"h"))
#DEFINE G_VARIANT_TYPE_UNIT (CAST(CONST GVariantType PTR, @!"()"))
#DEFINE G_VARIANT_TYPE_ANY (CAST(CONST GVariantType PTR, @!"*"))
#DEFINE G_VARIANT_TYPE_BASIC (CAST(CONST GVariantType PTR, @!"?"))
#DEFINE G_VARIANT_TYPE_MAYBE (CAST(CONST GVariantType PTR, @!"m*"))
#DEFINE G_VARIANT_TYPE_ARRAY (CAST(CONST GVariantType PTR, @!"a*"))
#DEFINE G_VARIANT_TYPE_TUPLE (CAST(CONST GVariantType PTR, @!"r"))
#DEFINE G_VARIANT_TYPE_DICT_ENTRY (CAST(CONST GVariantType PTR, @!"{?*}"))
#DEFINE G_VARIANT_TYPE_DICTIONARY (CAST(CONST GVariantType PTR, @!"a{?*}"))
#DEFINE G_VARIANT_TYPE_STRING_ARRAY (CAST(CONST GVariantType PTR, @!"as"))
#DEFINE G_VARIANT_TYPE_BYTESTRING (CAST(CONST GVariantType PTR, @!"ay"))
#DEFINE G_VARIANT_TYPE_BYTESTRING_ARRAY (CAST(CONST GVariantType PTR, @!"aay"))
(I've to check why h_2_bi didn't translate the casts.)
AGS wrote:Most of the macro code can be translated to fb easily.
Most... except for that C keyword called volatile that is. I don't know what should be done with that keyword (perhaps just drop the volatile and hope it'll work?).
h_2_bi drops volatile. Since there are no bug reports, I think it'll work.
AGS wrote:Great job on the gtk+ header files. It's nice to be able to mess around with gvariant and other stuff.
Thank you! Possitive feedback is motivating.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

There has been some talk on the forum for creating new header files for the fb distribution. And I'm wondering what is the best way to go when it comes to GTK+.

I know there is a version 3.0 on the way (they're at 2.99 at the moment). Creating header files for anything in between 2.22 and 2.99 seems to be a bit much (I think).

GTK+ 3 is a big update. I've checked and there are numerous new symbols. Apart from that I would not be surprised there are going to be a lot more changes (lots of work involved creating bindings for version 3).

Are you going to do GTK+ 3 (as it arrives) or do the version(s) in between as well? Your efforts to keep the GTK+ bindings up to date are very much appreciated.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

AGS wrote:Are you going to do GTK+ 3 (as it arrives) or do the version(s) in between as well? Your efforts to keep the GTK+ bindings up to date are very much appreciated.
Have a look at this post:

http://www.freebasic.net/forum/viewtopi ... ht=#149357

My 2.90.1 version is experimental. From my point of view there is no need for publishing it.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Post by dkl »

Hey TJF, what do you think: Could your header translations be added to freebasic-headers, and be distributed along with FB? It would be really awesome to have the new GTK translations (and others of course!) in FB.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

dkl wrote:Hey TJF, what do you think: Could your header translations be added to freebasic-headers
No, they cannot:
freebasic-headers wrote:... Our headers are translated using SWIG then edited by a person to ensure correctness.
I'm using h_2_bi.bas :-(

dkl wrote:... , and be distributed along with FB? It would be really awesome to have the new GTK translations (and others of course!) in FB.
No problem, GTK-2.22.0_TJF.bi is licensed under LGPLv2, so add it to the distro. (Hurra, I'll get some refund on my FB payments :-)

There are major differences between 2.22 and 3.0 (coming soon, spreaded over 14 files, one for each major lib, no windows installer yet). Which one will you add (adding both makes sense but it'll be more than 3 MB -- unpacked)?
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Post by dkl »

Well, don't let that SWIG-statement stop you! SWIG doesn't have to be used, that would be silly.

I'm thinking along the lines of adding the new headers in form of multiple files, similar to the current headers; well, at least one file per library. It should of course resemble the original C headers in one way or another, as long as it's still possible to maintain, but doesn't strictly have to be "one header per module" (afterall, it's a binding, not documentation).

If it's too big, then it can still be an optional download (maybe in the future we can distribute FB in form of multiple packages, then the GTK binding would come as, for example, the "freebasic-gtk-dev" package).
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Post by Galeon »

Well, separating each library into each header file is much better than having a very long header that have "everything". I think the naming should be changed, you don't need to add the version to each header, that can be added to the headers of the headers (lol) as comments, or be listed in a readme file or something like that, just like in the official GTK+ C development headers for Windows in the GTK+ site. Each file can be "gtk.bi", "gdk.bi", etc.
I also think that you should provide the options of h_2_bi used to recreate the headers, just like in the official headers above. I'm not sure myself, but I thought there are sections in the LGPL that says that it's necessary, you even have to provide the tarballs of the libraries used, though I think that's quite an overkill.
I'm looking forward for the GTK+ 3.0 headers, especially for GObjects, since there is the new GObject in GTK+ that needs it (GtkApplication). I'm planning to use it in the future.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

Galeon wrote:I'm looking forward for the GTK+ 3.0 headers, especially for GObjects, since there is the new GObject in GTK+ that needs it (GtkApplication). I'm planning to use it in the future.
FYI: GtkApplication is based on gio.bi.

dkl wrote:Well, don't let that SWIG-statement stop you! SWIG doesn't have to be used, that would be silly.
At the front page I like to see a note on h_2_bi.bas as well.
dkl wrote:I'm thinking along the lines of adding the new headers in form of multiple files, similar to the current headers; well, at least one file per library. It should of course resemble the original C headers in one way or another, as long as it's still possible to maintain, but doesn't strictly have to be "one header per module" (afterall, it's a binding, not documentation).
I prepared my headers to separate them. Comments mark each start and each end of a C header, so everybody could separate them. Since nobody did it, today I think it's not very neccessary. (When I made this headers, my major concerns were about h_2_bi development.)

But anyway, the next generation will be separated into 14 files, one for each major lib.
dkl wrote:If it's too big, then it can still be an optional download (maybe in the future we can distribute FB in form of multiple packages, then the GTK binding would come as, for example, the "freebasic-gtk-dev" package).
This seems to be a very good idea. I'm not keen on making packages, neither for windows nor for LINUX. Anybody want to help?
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Post by Galeon »

TJF wrote:
Galeon wrote:I'm looking forward for the GTK+ 3.0 headers, especially for GObjects, since there is the new GObject in GTK+ that needs it (GtkApplication). I'm planning to use it in the future.
FYI: GtkApplication is based on gio.bi.
Iie, GtkApplication is in GTK+ (gtk.h).
From GTK+ Manual:
GtkApplication

GtkApplication — Application class

Synopsis

#include <gtk/gtk.h>

struct GtkApplication;
GtkApplication * gtk_application_new (const gchar *application_id,
GApplicationFlags flags);
void gtk_application_add_window (GtkApplication *application,
GtkWindow *window);
void gtk_application_remove_window (GtkApplication *application,
GtkWindow *window);
GList * gtk_application_get_windows (GtkApplication *application);
Object Hierarchy

GObject
+----GApplication
+----GtkApplication

Description

GtkApplication is a class that handles many important aspects of a GTK+ application in a convenient fashion, without enforcing a one-size-fits-all application model.

Currently, GtkApplication handles GTK+ initialization, application uniqueness, provides some basic scriptability by exporting 'actions', and manages a list of toplevel windows whose life-cycle is automatically tied to the life-cycle of your application.
You need to be able to create GObject's to be able to use it. A new feature of GTK+, it automatically adds the common things you need in many GTK+ applications (read the manual for more info). Please check the examples from your nearest DevHelp available :).
TJF wrote:
dkl wrote:If it's too big, then it can still be an optional download (maybe in the future we can distribute FB in form of multiple packages, then the GTK binding would come as, for example, the "freebasic-gtk-dev" package).
This seems to be a very good idea. I'm not keen on making packages, neither for windows nor for LINUX. Anybody want to help?
I could help if you want to. I love creating packages hehe...
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

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.
Post Reply