[virt-tools-list] [PATCHv3 virt-viewer 07/10] Show preferences dialog
Marc-André Lureau
marcandre.lureau at gmail.com
Thu Mar 5 19:12:26 UTC 2015
Add a menu item Preferences under File and show the preferences dialog
---
src/virt-viewer-app.c | 28 +++++++++++++++++++++++++++-
src/virt-viewer-app.h | 1 +
src/virt-viewer-window.c | 9 +++++++++
src/virt-viewer.xml | 9 +++++++++
4 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 4800beb..0b11aa1 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -112,7 +112,7 @@ struct _VirtViewerAppPrivate {
GHashTable *displays;
GHashTable *initial_display_map;
gchar *clipboard;
-
+ GtkWidget *preferences;
gboolean direct;
gboolean verbose;
gboolean enable_accel;
@@ -1629,6 +1629,10 @@ virt_viewer_app_dispose (GObject *object)
VirtViewerApp *self = VIRT_VIEWER_APP(object);
VirtViewerAppPrivate *priv = self->priv;
+ if (priv->preferences)
+ gtk_widget_destroy(priv->preferences);
+ priv->preferences = NULL;
+
if (priv->windows) {
GList *tmp = priv->windows;
/* null-ify before unrefing, because we need
@@ -2401,6 +2405,28 @@ virt_viewer_app_get_windows(VirtViewerApp *self)
return self->priv->windows;
}
+void
+virt_viewer_app_show_preferences(VirtViewerApp *self, GtkWidget *parent)
+{
+ GtkWidget *preferences = self->priv->preferences;
+
+ if (!preferences) {
+ GtkBuilder *builder = virt_viewer_util_load_ui("virt-viewer-preferences.xml");
+
+ gtk_builder_connect_signals(builder, self);
+
+ preferences = GTK_WIDGET(gtk_builder_get_object(builder, "preferences"));
+ self->priv->preferences = preferences;
+
+ g_object_unref(builder);
+ }
+
+ gtk_window_set_transient_for(GTK_WINDOW(preferences),
+ GTK_WINDOW(parent));
+
+ gtk_window_present(GTK_WINDOW(preferences));
+}
+
static gboolean
option_kiosk_quit(G_GNUC_UNUSED const gchar *option_name,
const gchar *value,
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index f127b32..d214279 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -100,6 +100,7 @@ void virt_viewer_app_clear_hotkeys(VirtViewerApp *app);
gint virt_viewer_app_get_n_initial_displays(VirtViewerApp* self);
gint virt_viewer_app_get_initial_monitor_for_display(VirtViewerApp* self, gint display);
void virt_viewer_app_set_enable_accel(VirtViewerApp *app, gboolean enable);
+void virt_viewer_app_show_preferences(VirtViewerApp *app, GtkWidget *parent);
G_END_DECLS
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index c5f7c75..d668f74 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -58,6 +58,8 @@ void virt_viewer_window_menu_file_usb_device_selection(GtkWidget *menu, VirtView
void virt_viewer_window_menu_file_smartcard_insert(GtkWidget *menu, VirtViewerWindow *self);
void virt_viewer_window_menu_file_smartcard_remove(GtkWidget *menu, VirtViewerWindow *self);
void virt_viewer_window_menu_view_release_cursor(GtkWidget *menu, VirtViewerWindow *self);
+void virt_viewer_window_menu_preferences_cb(GtkWidget *menu, VirtViewerWindow *self);
+
/* Internal methods */
static void virt_viewer_window_enable_modifiers(VirtViewerWindow *self);
@@ -1018,6 +1020,13 @@ virt_viewer_window_menu_file_smartcard_remove(GtkWidget *menu G_GNUC_UNUSED,
}
G_MODULE_EXPORT void
+virt_viewer_window_menu_preferences_cb(GtkWidget *menu G_GNUC_UNUSED,
+ VirtViewerWindow *self)
+{
+ virt_viewer_app_show_preferences(self->priv->app, GTK_WIDGET(self->priv->window));
+}
+
+G_MODULE_EXPORT void
virt_viewer_window_menu_view_release_cursor(GtkWidget *menu G_GNUC_UNUSED,
VirtViewerWindow *self)
{
diff --git a/src/virt-viewer.xml b/src/virt-viewer.xml
index 849fc7d..07948bd 100644
--- a/src/virt-viewer.xml
+++ b/src/virt-viewer.xml
@@ -69,6 +69,15 @@
</object>
</child>
<child>
+ <object class="GtkMenuItem" id="menu-preferences">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Preferences</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="virt_viewer_window_menu_preferences_cb" swapped="no"/>
+ </object>
+ </child>
+ <child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
--
2.1.0
More information about the virt-tools-list
mailing list