]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkapplicationwindow.c
Updated Norwegian nynorsk translation
[~andy/gtk] / gtk / gtkapplicationwindow.c
index 3bf318f3bc535c7a270fd079b0da57fbefec636b..9b27edf207a6143f1a81117cf6718a5b17eeabd8 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Ryan Lortie <desrt@desrt.ca>
  */
 #include "gtkapplicationwindow.h"
 
 #include "gtkapplicationprivate.h"
+#include "gtkwindowprivate.h"
 #include "gtkmodelmenu.h"
 #include "gactionmuxer.h"
 #include "gtkaccelgroup.h"
 #include "gtkaccelmap.h"
 #include "gtkintl.h"
+#include "gtksettings.h"
 
 #include <gdk/gdk.h>
 #ifdef GDK_WINDOWING_X11
 #include <gdk/x11/gdkx.h>
 #endif
 
+#ifdef HAVE_GIO_UNIX
+#include <gio/gdesktopappinfo.h>
+#endif
+
 /**
  * SECTION:gtkapplicationwindow
  * @title: GtkApplicationWindow
  * prefix.  Actions must be addressed with the prefixed name when
  * referring to them from a #GMenuModel.
  *
+ * Note that widgets that are placed inside a GtkApplicationWindow
+ * can also activate these actions, if they implement the
+ * GtkActionable interface.
+ *
  * As with #GtkApplication, the GDK lock will be acquired when
  * processing actions arriving from other processes and should therefore
  * be held when activating actions locally (if GDK threads are enabled).
@@ -67,7 +75,7 @@
  * will display the application menu, but not the menubar.
  *
  * If the desktop environment does not display the menubar, then
- * #GApplicationWindow will automatically show a #GtkMenubar for it.
+ * #GtkApplicationWindow will automatically show a #GtkMenuBar for it.
  * (see the #GtkApplication docs for some screenshots of how this
  * looks on different platforms).
  * This behaviour can be overridden with the #GtkApplicationWindow:show-menubar
  * ]]>
  * </programlisting>
  * </example>
+ *
+ * The XML format understood by #GtkBuilder for #GMenuModel consists
+ * of a toplevel <tag class="starttag">menu</tag> element, which contains
+ * one or more <tag class="starttag">item</tag> elements. Each
+ * <tag class="starttag">item</tag> element contains
+ * <tag class="starttag">attribute</tag> and <tag class="starttag">link</tag>
+ * elements with a mandatory name attribute.
+ * <tag class="starttag">link</tag> elements have the same content
+ * model as <tag class="starttag">menu</tag>.
+ *
+ * Attribute values can be translated using gettext, like other #GtkBuilder
+ * content. <tag class="starttag">attribute</tag> elements can be marked for
+ * translation with a <literal>translatable="yes"</literal> attribute.
+ * It is also possible to specify message context and translator comments,
+ * using the context and comments attributes. To make use of this, the
+ * #GtkBuilder must have been given the gettext domain to use.
  */
 
 typedef GSimpleActionGroupClass GtkApplicationWindowActionsClass;
@@ -194,6 +218,8 @@ struct _GtkApplicationWindowPrivate
   GDBusConnection *session;
   gchar           *object_path;
   guint            export_id;
+
+  guint            id;
 };
 
 static void
@@ -233,6 +259,32 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
     }
 }
 
+static gchar *
+gtk_application_window_get_app_desktop_name (void)
+{
+  gchar *retval = NULL;
+
+#ifdef HAVE_GIO_UNIX
+  GDesktopAppInfo *app_info;
+  const gchar *app_name = NULL;
+  gchar *desktop_file;
+
+  desktop_file = g_strconcat (g_get_prgname (), ".desktop", NULL);
+  app_info = g_desktop_app_info_new (desktop_file);
+  g_free (desktop_file);
+
+  if (app_info != NULL)
+    app_name = g_app_info_get_name (G_APP_INFO (app_info));
+
+  if (app_name != NULL)
+    retval = g_strdup (app_name);
+
+  g_clear_object (&app_info);
+#endif /* HAVE_GIO_UNIX */
+
+  return retval;
+}
+
 static void
 gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
                                                     GtkSettings          *settings)
@@ -257,7 +309,27 @@ gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window
           app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
 
           if (app_menu != NULL)
-            g_menu_append_submenu (window->priv->app_menu_section, _("Application"), app_menu);
+            {
+              const gchar *app_name;
+              gchar *name;
+
+              app_name = g_get_application_name ();
+              if (app_name != g_get_prgname ())
+                {
+                  /* the app has set its application name, use it */
+                  name = g_strdup (app_name);
+                }
+              else
+                {
+                  /* get the name from .desktop file */
+                  name = gtk_application_window_get_app_desktop_name ();
+                  if (name == NULL)
+                    name = g_strdup (_("Application"));
+                }
+
+              g_menu_append_submenu (window->priv->app_menu_section, name, app_menu);
+              g_free (name);
+            }
         }
     }
 }
@@ -367,10 +439,10 @@ add_accel_closure (gpointer         data,
   if (accel_key == 0)
     return;
 
-  if (!g_str_has_prefix (accel_path, "<Actions>/"))
+  if (!g_str_has_prefix (accel_path, "<GAction>/"))
     return;
 
-  path = accel_path + strlen ("<Actions>/");
+  path = accel_path + strlen ("<GAction>/");
   p = strchr (path, '/');
   if (p)
     {
@@ -635,6 +707,8 @@ gtk_application_window_real_size_allocate (GtkWidget     *widget,
       gint menubar_height;
       GtkWidget *child;
 
+      _gtk_window_set_allocation (GTK_WINDOW (widget), allocation);
+
       gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL);
 
       menubar_allocation.height = menubar_height;
@@ -654,8 +728,6 @@ gtk_application_window_real_size_allocate (GtkWidget     *widget,
 
           gtk_widget_size_allocate (child, &child_allocation);
         }
-
-      gtk_widget_set_allocation (widget, allocation);
     }
   else
     GTK_WIDGET_CLASS (gtk_application_window_parent_class)
@@ -698,18 +770,25 @@ gtk_application_window_real_realize (GtkWidget *widget)
 
     gdkwindow = gtk_widget_get_window (GTK_WIDGET (window));
 
-    if (GDK_IS_X11_WINDOW (gdkwindow))
+    if (GDK_IS_X11_WINDOW (gdkwindow) && window->priv->session)
       {
-        const gchar *unique_id;
-        const gchar *app_id;
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_ID",
+                                          g_application_get_application_id (G_APPLICATION (application)));
+
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_UNIQUE_BUS_NAME",
+                                          g_dbus_connection_get_unique_name (window->priv->session));
 
-        gdk_x11_window_set_utf8_property (gdkwindow, "_DBUS_OBJECT_PATH", window->priv->object_path);
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_OBJECT_PATH",
+                                          g_application_get_dbus_object_path (G_APPLICATION (application)));
 
-        unique_id = g_dbus_connection_get_unique_name (window->priv->session);
-        gdk_x11_window_set_utf8_property (gdkwindow, "_DBUS_UNIQUE_NAME", unique_id);
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_WINDOW_OBJECT_PATH",
+                                          window->priv->object_path);
 
-        app_id = g_application_get_application_id (G_APPLICATION (application));
-        gdk_x11_window_set_utf8_property (gdkwindow, "_DBUS_APPLICATION_ID", app_id);
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APP_MENU_OBJECT_PATH",
+                                          gtk_application_get_app_menu_object_path (application));
+
+        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_MENUBAR_OBJECT_PATH",
+                                          gtk_application_get_menubar_object_path (application));
       }
   }
 #endif
@@ -732,11 +811,13 @@ gtk_application_window_real_unrealize (GtkWidget *widget)
 gboolean
 gtk_application_window_publish (GtkApplicationWindow *window,
                                 GDBusConnection      *session,
-                                const gchar          *object_path)
+                                const gchar          *object_path,
+                                guint                 object_id)
 {
   g_assert (window->priv->session == NULL);
   g_assert (window->priv->export_id == 0);
   g_assert (window->priv->object_path == NULL);
+  g_assert (window->priv->id == 0);
 
   window->priv->export_id = g_dbus_connection_export_action_group (session, object_path,
                                                                    G_ACTION_GROUP (window->priv->actions),
@@ -747,6 +828,7 @@ gtk_application_window_publish (GtkApplicationWindow *window,
 
   window->priv->session = session;
   window->priv->object_path = g_strdup (object_path);
+  window->priv->id = object_id;
 
   return TRUE;
 }
@@ -757,10 +839,12 @@ gtk_application_window_unpublish (GtkApplicationWindow *window)
   g_assert (window->priv->session != NULL);
   g_assert (window->priv->export_id != 0);
   g_assert (window->priv->object_path != NULL);
+  g_assert (window->priv->id != 0);
 
   g_dbus_connection_unexport_action_group (window->priv->session, window->priv->export_id);
   window->priv->session = NULL;
   window->priv->export_id = 0;
+  window->priv->id = 0;
 
   g_free (window->priv->object_path);
   window->priv->object_path = NULL;
@@ -997,3 +1081,35 @@ gtk_application_window_create_observer (GtkApplicationWindow *window,
 
   return g_simple_action_observer_new (window->priv->muxer, action_name, target);
 }
+
+GActionObservable *
+gtk_application_window_get_observable (GtkApplicationWindow *window)
+{
+  return G_ACTION_OBSERVABLE (window->priv->muxer);
+}
+
+GtkAccelGroup *
+gtk_application_window_get_accel_group (GtkApplicationWindow *window)
+{
+  return window->priv->accels;
+}
+
+/**
+ * gtk_application_window_get_id:
+ * @window: a #GtkApplicationWindow
+ *
+ * Returns the unique ID of the window. If the window has not yet been added to
+ * a #GtkApplication, returns <literal>0</literal>.
+ *
+ * Returns: the unique ID for @window, or <literal>0</literal> if the window
+ *   has not yet been added to a #GtkApplication
+ *
+ * Since: 3.6
+ */
+guint
+gtk_application_window_get_id (GtkApplicationWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), 0);
+
+  return window->priv->id;
+}