gnome: main window layout
Refs #66715
Change-Id: I7bc09ae7c46aca1a80a18adb3b811c968c52eaaf
diff --git a/src/ring_client.cpp b/src/ring_client.cpp
index b354c69..d234b5b 100644
--- a/src/ring_client.cpp
+++ b/src/ring_client.cpp
@@ -38,6 +38,19 @@
#include <callmodel.h>
#include "ring_client_options.h"
+#include "ringmainwindow.h"
+
+struct _RingClientClass
+{
+ GtkApplicationClass parent_class;
+};
+
+struct _RingClient
+{
+ GtkApplication parent;
+};
+
+typedef struct _RingClientPrivate RingClientPrivate;
struct _RingClientPrivate {
/* main window */
@@ -46,7 +59,7 @@
QCoreApplication *qtapp;
};
-G_DEFINE_TYPE(RingClient, ring_client, GTK_TYPE_APPLICATION);
+G_DEFINE_TYPE_WITH_PRIVATE(RingClient, ring_client, GTK_TYPE_APPLICATION);
#define RING_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_CLIENT_TYPE, RingClientPrivate))
@@ -88,6 +101,9 @@
GtkSettings *gtk_settings = gtk_settings_get_default();
g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme",
FALSE, NULL);
+ /* enable button icons */
+ g_object_set(G_OBJECT(gtk_settings), "gtk-button-images",
+ TRUE, NULL);
/* init libRingClient and make sure its connected to the dbus */
try {
@@ -106,15 +122,9 @@
}
/* create an empty window */
- priv->win = gtk_application_window_new(GTK_APPLICATION(app));
-
- /* test gresources */
- GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
- if (icon == NULL) {
- g_debug("Could not load icon: %s", error->message);
- g_error_free(error);
- } else
- gtk_window_set_icon(GTK_WINDOW(priv->win), icon);
+ if (priv->win == NULL) {
+ priv->win = ring_main_window_new(GTK_APPLICATION(app));
+ }
gtk_window_present(GTK_WINDOW(priv->win));
@@ -148,10 +158,6 @@
static void
ring_client_class_init(RingClientClass *klass)
{
- g_debug("ring_client_class_init()");
-
- g_type_class_add_private(klass, sizeof(RingClientPrivate));
-
G_APPLICATION_CLASS(klass)->command_line = ring_client_command_line;
G_APPLICATION_CLASS(klass)->shutdown = ring_client_shutdown;
}
@@ -160,6 +166,6 @@
ring_client_new()
{
return (RingClient *)g_object_new(ring_client_get_type(),
- "application-id", "cx.ring.RingGnome",
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE, NULL);
+ "application-id", "cx.ring.RingGnome",
+ "flags", G_APPLICATION_HANDLES_COMMAND_LINE, NULL);
}
diff --git a/src/ring_client.h b/src/ring_client.h
index 95d85b3..5ec5623 100644
--- a/src/ring_client.h
+++ b/src/ring_client.h
@@ -33,28 +33,19 @@
#include <gtk/gtk.h>
+G_BEGIN_DECLS
+
// #define RING_GSETTINGS_SCHEMA "cx.ring.RingGnome"
#define RING_CLIENT_TYPE (ring_client_get_type())
#define RING_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), RING_CLIENT_TYPE, RingClient))
-typedef struct _RingClientPrivate RingClientPrivate;
-typedef struct _RingClientClass RingClientClass;
-typedef struct _RingClient RingClient;
-
-struct _RingClientClass
-{
- GtkApplicationClass parent_class;
-};
-
-struct _RingClient
-{
- GtkApplication parent;
- /* Private */
- RingClientPrivate *priv;
-};
+typedef struct _RingClientClass RingClientClass;
+typedef struct _RingClient RingClient;
/* Public interface */
-GType ring_client_get_type(void) G_GNUC_CONST;
-RingClient *ring_client_new(void);
+GType ring_client_get_type (void) G_GNUC_CONST;
+RingClient *ring_client_new (void);
+
+G_END_DECLS
#endif /* RING_CLIENT_H_ */
diff --git a/src/ring_client_options.h b/src/ring_client_options.h
index e05e9bc..db6881e 100644
--- a/src/ring_client_options.h
+++ b/src/ring_client_options.h
@@ -33,14 +33,10 @@
#include <glib.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+G_BEGIN_DECLS
GOptionContext *ring_client_options_get_context(void);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+G_END_DECLS
#endif /* RING_CLIENT_OPTIONS_H_ */
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
new file mode 100644
index 0000000..c3869df
--- /dev/null
+++ b/src/ringmainwindow.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2015 Savoir-Faire Linux Inc.
+ * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+#include "ringmainwindow.h"
+
+#include <gtk/gtk.h>
+
+struct _RingMainWindow
+{
+ GtkApplicationWindow parent;
+};
+
+struct _RingMainWindowClass
+{
+ GtkApplicationWindowClass parent_class;
+};
+
+typedef struct _RingMainWindowPrivate RingMainWindowPrivate;
+
+struct _RingMainWindowPrivate
+{
+ GtkWidget *gears;
+ GtkWidget *gears_image;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW);
+
+#define RING_MAIN_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_MAIN_WINDOW_TYPE, RingMainWindowPrivate))
+
+static void
+ring_main_window_init(RingMainWindow *win)
+{
+ RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
+ gtk_widget_init_template(GTK_WIDGET(win));
+
+ /* set window icon */
+ GError *error = NULL;
+ GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
+ if (icon == NULL) {
+ g_debug("Could not load icon: %s", error->message);
+ g_error_free(error);
+ } else
+ gtk_window_set_icon(GTK_WINDOW(win), icon);
+
+ /* set menu icon */
+ GdkPixbuf* ring_gears = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-logo-blue",
+ -1, 22, TRUE, &error);
+ if (ring_gears == NULL) {
+ g_debug("Could not load icon: %s", error->message);
+ g_error_free(error);
+ } else
+ gtk_image_set_from_pixbuf(GTK_IMAGE(priv->gears_image), ring_gears);
+
+ /* gears menu */
+ GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui");
+ GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
+ gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(priv->gears), menu);
+ g_object_unref(builder);
+}
+
+static void
+ring_main_window_class_init(RingMainWindowClass *klass)
+{
+ gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
+ "/cx/ring/RingGnome/ringmainwindow.ui");
+
+ gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, gears);
+ gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, gears_image);
+}
+
+GtkWidget *
+ring_main_window_new (GtkApplication *app)
+{
+ return (GtkWidget *)g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
+}
diff --git a/src/ringmainwindow.h b/src/ringmainwindow.h
new file mode 100644
index 0000000..ba7e124
--- /dev/null
+++ b/src/ringmainwindow.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Savoir-Faire Linux Inc.
+ * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+#ifndef _RINGMAINWINDOW_H
+#define _RINGMAINWINDOW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define RING_MAIN_WINDOW_TYPE (ring_main_window_get_type ())
+#define RING_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RING_MAIN_WINDOW_TYPE, RingMainWindow))
+
+
+typedef struct _RingMainWindow RingMainWindow;
+typedef struct _RingMainWindowClass RingMainWindowClass;
+
+
+GType ring_main_window_get_type (void) G_GNUC_CONST;
+GtkWidget *ring_main_window_new (GtkApplication *app);
+
+G_END_DECLS
+
+#endif /* _RINGMAINWINDOW_H */