TheAifam5
TheAifam5

Reputation: 68

Initialization of GtkApplication - Should I use GObject's "init" or GtkApplication's "startup"?

I'm trying to create a GTK-3 Application and in the initialization process I want to check if the GSetting's value is set, otherwise I want to show a "startup" dialog which will be only on the first run visible.

The GObject's has a _init suffix which can be used for the class initialization. In that case the MyGtkApplication will be constructed, which is based on GtkApplication. The GtkApplication has the startup-thing which can be used for the initialization too.

In that example, I still need to implement the _init function for GApplicationClass.

GApplicationClass *gapp_class;

gapp_class = G_APPLICATION_CLASS (class);
gapp_class->startup = app_startup;

// This must be always implemented, because the MyGtkApplication is "GtkApplication"-based class.
void app_init(MyGtkApplication *app) {
  // Check and show the modal dialog if key does not exist?
}

// This will overwrite the GApplicatio's "startup".
void app_startup(GApplication *app) {
  // Check and show the modal dialog if key does not exist?
}

Currently app_init does not have a body.

What is the difference and which one should I use?

Regards, TheAifam5.

Upvotes: 2

Views: 436

Answers (1)

ptomato
ptomato

Reputation: 57860

init is basically the constructor of the GApplication object. Use it for initializing the object's private data and putting it into a consistent state.

startup is invoked when the application starts. In particular, after you have called g_application_run() and the main event loop is started, and the application has checked that it is the only instance running. You don't want to show dialog boxes before then, so startup is the right place to do that.

Upvotes: 2

Related Questions