/usr/share/help/de/gnome-devel-demos/messagedialog.c.page is in gnome-devel-docs 3.28.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | <?xml version="1.0" encoding="utf-8"?>
<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="messagedialog.c" xml:lang="de">
<info>
<title type="text">MessageDialog (C)</title>
<link type="guide" xref="c#windows"/>
<link type="seealso" xref="dialog.c"/>
<revision version="0.2" date="2012-08-07" status="draft"/>
<credit type="author copyright">
<name>Monica Kochofar</name>
<email its:translate="no">monicakochofar@gmail.com</email>
<years>2012</years>
</credit>
<desc>A message window</desc>
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
<mal:name>Mario Blättermann</mal:name>
<mal:email>mario.blaettermann@gmail.com</mal:email>
<mal:years>2011, 2013</mal:years>
</mal:credit>
</info>
<title>MessageDialog</title>
<media type="image" mime="image/png" src="media/messagedialog.png"/>
<p>A modal message dialog which can cause the world to explode.</p>
<note><p>
To test out the application once it has started running, you can click on the "Message Dialog" tab that appears in the top menubar of the screen.
</p></note>
<code mime="text/x-csrc" style="numbered">
#include <gtk/gtk.h>
/* Callback function in which reacts to the "response" signal from the user in
* the message dialog window.
* This function is used to interact with the user in the terminal.
*/
static void
on_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
/* If the button clicked gives response OK (response_id being -5) */
if (response_id == GTK_RESPONSE_OK)
g_print ("*boom*\n");
/* If the button clicked gives response CANCEL (response_id being -6) */
else if (response_id == GTK_RESPONSE_CANCEL)
g_print ("good choice\n");
/* If the message dialog is destroyed (for example by pressing escape) */
else if (response_id == GTK_RESPONSE_DELETE_EVENT)
g_print ("dialog closed or cancelled\n");
/* Destroy the dialog after one of the above actions have taken place */
gtk_widget_destroy (GTK_WIDGET (dialog));
}
/* Callback function for the response signal "activate" related to the SimpleAction
* message_action.
* This function is used to cause the message dialog window to popup.
*/
static void
message_cb (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
/* the parent variable in this case represents the window */
GtkWidget *message_dialog;
GtkWindow *parent = user_data;
/* Create a new message dialog, and set the parameters as follows:
* Dialog Flags - make the constructed dialog modal
* (modal windows prevent interaction with other windows in the application)
* Message Type - nonfatal warning message
* Buttons Type - use the ok and cancel buttons
* message_format - text that you want the user to see in the window
*/
message_dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_OK_CANCEL,
"This action will cause the universe to stop existing.");
gtk_widget_show_all (message_dialog);
g_signal_connect (GTK_DIALOG (message_dialog), "response",
G_CALLBACK (on_response), NULL);
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *label;
GSimpleAction *message_action;
/* Create a window with a title and a default size */
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "GMenu Example");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
/* Create a label and add it to the window */
label = gtk_label_new ("This application goes boom!");
gtk_container_add (GTK_CONTAINER (window), label);
/* Create a new simple action, giving it a NULL parameter type. It will
* always be NULL for actions invoked from a menu. (e.g clicking on an "ok"
* or "cancel" button)
*/
message_action = g_simple_action_new ("message", NULL);
/* Connect the "activate" signal to the appropriate callback function */
g_signal_connect (message_action, "activate", G_CALLBACK (message_cb),
GTK_WINDOW (window));
/* Adds the message_action to the overall action map. An Action map is an
* interface that contains a number of named GAction instances
* (such as message_action)
*/
g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (message_action));
gtk_widget_show_all (window);
}
/* Callback function for the response signal "activate" from the "quit" action
* in the function directly below.
*/
static void
quit_cb (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
GApplication *application = user_data;
g_application_quit (application);
}
/* Startup function for the menu we are creating in this sample */
static void
startup (GApplication *app,
gpointer user_data)
{
GMenu *menu;
GSimpleAction *quit_action;
/* Initialize the GMenu, and add a menu item with label "Message" and action
* "win.message". Also add another menu item with label "Quit" and action
* "app.quit"
*/
menu = g_menu_new ();
g_menu_append (menu, "Message", "win.message");
g_menu_append (menu, "Quit", "app.quit");
/* Create a new simple action for the application. (In this case it is the
* "quit" action.
*/
quit_action = g_simple_action_new ("quit", NULL);
/* Ensure that the menu we have just created is set for the overall application */
gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (menu));
g_signal_connect (quit_action,
"activate",
G_CALLBACK (quit_cb),
app);
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit_action));
}
/* Startup function for the application */
int
main (int argc, char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
</code>
<p>
In this sample we used the following:
</p>
<list>
<item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
<item><p><link href="http://developer.gnome.org/gio/stable/GApplication.html">GApplication</link></p></item>
<item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link></p></item>
<item><p><link href="http://developer.gnome.org/gtk3/stable/GtkMessageDialog.html">GtkMessageDialog</link></p></item>
<item><p><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html#g-simple-action-new">GSimpleAction</link></p></item>
<item><p><link href="http://developer.gnome.org/gio/stable/GActionMap.html">GActionMap</link></p></item>
<item><p><link href="http://developer.gnome.org/gio/stable/GMenu.html">GMenu</link></p></item>
</list>
</page>
|