|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="aboutdialog.c" xml:lang="de">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">AboutDialog (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#windows"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="dialog.c"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="messagedialog.c"/>
|
|
Packit |
1470ea |
<revision version="0.2" date="2012-08-07" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Monica Kochofar</name>
|
|
Packit |
1470ea |
<email its:translate="no">monicakochofar@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Informationen zur Anwendung anzeigen</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Mario Blättermann</mal:name>
|
|
Packit |
1470ea |
<mal:email>mario.blaettermann@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011, 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>AboutDialog</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
|
|
Packit |
1470ea |
An AboutDialog example using Gtk.ApplicationWindow and Menu
|
|
Packit |
1470ea |
<note>You need to be running Gtk3.4 or later for this to work </note>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function in which reacts to the "response" signal from the user in
|
|
Packit |
1470ea |
* the message dialog window.
|
|
Packit |
1470ea |
* This function is used to destroy the dialog window.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
on_close (GtkDialog *dialog,
|
|
Packit |
1470ea |
gint response_id,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* This will cause the dialog to be destroyed */
|
|
Packit |
1470ea |
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the response signal "activate" related to the SimpleAction
|
|
Packit |
1470ea |
* "about_action".
|
|
Packit |
1470ea |
* This function is used to cause the about dialog window to popup.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
about_cb (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *about_dialog;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
about_dialog = gtk_about_dialog_new ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Lists of authors/ documentators to be used later, they must be initialized
|
|
Packit |
1470ea |
* in a null terminated array of strings.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
const gchar *authors[] = {"GNOME Documentation Team", NULL};
|
|
Packit |
1470ea |
const gchar *documenters[] = {"GNOME Documentation Team", NULL};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* We fill in the information for the about dialog */
|
|
Packit |
1470ea |
gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG (about_dialog), "AboutDialog Example");
|
|
Packit |
1470ea |
gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (about_dialog), "Copyright \xc2\xa9 2012 GNOME Documentation Team");
|
|
Packit |
1470ea |
gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (about_dialog), authors);
|
|
Packit |
1470ea |
gtk_about_dialog_set_documenters (GTK_ABOUT_DIALOG (about_dialog), documenters);
|
|
Packit |
1470ea |
gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG (about_dialog), "GNOME Developer Website");
|
|
Packit |
1470ea |
gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (about_dialog), "http://developer.gnome.org");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* We do not wish to show the title, which in this case would be
|
|
Packit |
1470ea |
* "AboutDialog Example". We have to reset the title of the messagedialog
|
|
Packit |
1470ea |
* window after setting the program name.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (about_dialog), "");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* To close the aboutdialog when "close" is clicked we connect the response
|
|
Packit |
1470ea |
* signal to on_close
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
g_signal_connect (GTK_DIALOG (about_dialog), "response",
|
|
Packit |
1470ea |
G_CALLBACK (on_close), NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Show the about dialog */
|
|
Packit |
1470ea |
gtk_widget_show (about_dialog);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GSimpleAction *about_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a window with a title and a default size */
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "AboutDialog Example");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a new simple action, giving it a NULL parameter type. It will
|
|
Packit |
1470ea |
* always be NULL for actions invoked from a menu. (e.g clicking on an "ok"
|
|
Packit |
1470ea |
* or "cancel" button)
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
about_action = g_simple_action_new ("about", NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Connect the "activate" signal to the appropriate callback function.
|
|
Packit |
1470ea |
* It will indicate that the action was just activated.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
g_signal_connect (about_action, "activate", G_CALLBACK (about_cb),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Adds the about_action to the overall action map. An Action map is an
|
|
Packit |
1470ea |
* interface that contains a number of named GAction instances
|
|
Packit |
1470ea |
* (such as about_action)
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (about_action));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback function for the response signal "activate" from the "quit" action
|
|
Packit |
1470ea |
* found in the function directly below.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
quit_cb (GSimpleAction *simple,
|
|
Packit |
1470ea |
GVariant *parameter,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GApplication *application = user_data;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
g_application_quit (application);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Startup function for the menu we are creating in this sample */
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
startup (GApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GMenu *menu;
|
|
Packit |
1470ea |
GSimpleAction *quit_action;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Initialize the GMenu, and add a menu item with label "About" and action
|
|
Packit |
1470ea |
* "win.about". Also add another menu item with label "Quit" and action
|
|
Packit |
1470ea |
* "app.quit"
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
menu = g_menu_new ();
|
|
Packit |
1470ea |
g_menu_append (menu, "About", "win.about");
|
|
Packit |
1470ea |
g_menu_append (menu, "Quit", "app.quit");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a new simple action for the application. (In this case it is the
|
|
Packit |
1470ea |
* "quit" action.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
quit_action = g_simple_action_new ("quit", NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Ensure that the menu we have just created is set for the overall application */
|
|
Packit |
1470ea |
gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (menu));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
g_signal_connect (quit_action,
|
|
Packit |
1470ea |
"activate",
|
|
Packit |
1470ea |
G_CALLBACK (quit_cb),
|
|
Packit |
1470ea |
app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit_action));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Startup function for the application */
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkAboutDialog.html">GtkAboutDialog</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/stable/GMenu.html">GMenu</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/stable/GActionMap.html">GActionMap</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|