[virt-tools-list] [remote-viewer PATCH 3/3] remote-viewer: Removed connect dialog from remote-viewer.c
Lukas Venhoda
lvenhoda at redhat.com
Wed Jun 10 12:47:27 UTC 2015
Removed original connect dialog code from remote-viewer.c
Changed retval check of connect dialog from 0 to GTK_RESPONSE_ACCEPT
---
src/remote-viewer.c | 162 +---------------------------------------------------
1 file changed, 2 insertions(+), 160 deletions(-)
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 937d06d..38cdb90 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -46,6 +46,7 @@
#include "virt-viewer-file.h"
#include "virt-viewer-session.h"
#include "remote-viewer.h"
+#include "remote-viewer-connect.h"
#ifndef G_VALUE_INIT /* see bug https://bugzilla.gnome.org/show_bug.cgi?id=654793 */
#define G_VALUE_INIT { 0, { { 0 } } }
@@ -87,7 +88,6 @@ static gboolean remote_viewer_start(VirtViewerApp *self, GError **error);
static gboolean remote_viewer_activate(VirtViewerApp *self, GError **error);
static void remote_viewer_window_added(VirtViewerApp *self, VirtViewerWindow *win);
static void spice_foreign_menu_updated(RemoteViewer *self);
-static gint connect_dialog(GtkWindow *main_window, gchar **uri);
#endif
static void
@@ -1016,162 +1016,6 @@ error:
#endif
-static void entry_icon_release_cb(GtkEntry* entry, gpointer data G_GNUC_UNUSED)
-{
- gtk_entry_set_text(entry, "");
- gtk_widget_grab_focus(GTK_WIDGET(entry));
-}
-
-static void entry_changed_cb(GtkEditable* entry, gpointer data G_GNUC_UNUSED)
-{
- gboolean rtl = (gtk_widget_get_direction(GTK_WIDGET(entry)) == GTK_TEXT_DIR_RTL);
- gboolean active = gtk_entry_get_text_length(GTK_ENTRY(entry)) > 0;
-
- g_object_set(entry,
- "secondary-icon-name", active ? (rtl ? "edit-clear-rtl-symbolic" : "edit-clear-symbolic") : NULL,
- "secondary-icon-activatable", active,
- "secondary-icon-sensitive", active,
- NULL);
-}
-
-static void
-recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpointer data)
-{
- GtkRecentInfo *info;
- GtkWidget *entry = data;
- const gchar *uri;
-
- info = gtk_recent_chooser_get_current_item(chooser);
- if (info == NULL)
- return;
-
- uri = gtk_recent_info_get_uri(info);
- g_return_if_fail(uri != NULL);
-
- gtk_entry_set_text(GTK_ENTRY(entry), uri);
-
- gtk_recent_info_unref(info);
-}
-
-static void
-recent_item_activated_dialog_cb(GtkRecentChooser *chooser G_GNUC_UNUSED, gpointer data)
-{
- gtk_dialog_response(GTK_DIALOG (data), GTK_RESPONSE_ACCEPT);
-}
-
-static void make_label_light(GtkLabel* label)
-{
- PangoAttrList* attributes = pango_attr_list_new();
-#if GTK_CHECK_VERSION(3, 0, 0)
- gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(label)), "dim-label");
-#else
- GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(label));
- GdkColor* c = &style->text[GTK_STATE_INSENSITIVE];
- pango_attr_list_insert(attributes, pango_attr_foreground_new(c->red, c->green, c->blue));
-#endif
- pango_attr_list_insert(attributes, pango_attr_scale_new(0.9));
- gtk_label_set_attributes(label, attributes);
- pango_attr_list_unref(attributes);
-}
-
-static void make_label_bold(GtkLabel* label)
-{
- PangoAttrList* attributes = pango_attr_list_new();
- pango_attr_list_insert(attributes, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
- gtk_label_set_attributes(label, attributes);
- pango_attr_list_unref(attributes);
-
-}
-
-static gint
-connect_dialog(GtkWindow *main_window, gchar **uri)
-{
- GtkWidget *dialog, *area, *box, *label, *entry, *recent;
-#if !GTK_CHECK_VERSION(3, 0, 0)
- GtkWidget *alignment;
-#endif
- GtkRecentFilter *rfilter;
- gint retval;
-
- /* Create the widgets */
- dialog = gtk_dialog_new_with_buttons(_("Connection details"),
- main_window,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- GTK_STOCK_CONNECT,
- GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
- gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
- area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- box = gtk_vbox_new(FALSE, 6);
- gtk_container_set_border_width(GTK_CONTAINER(box), 5);
- gtk_box_pack_start(GTK_BOX(area), box, TRUE, TRUE, 0);
-
- label = gtk_label_new_with_mnemonic(_("_Connection Address"));
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
- entry = GTK_WIDGET(gtk_entry_new());
- gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
- g_object_set(entry, "width-request", 200, NULL);
- g_signal_connect(entry, "changed", G_CALLBACK(entry_changed_cb), entry);
- g_signal_connect(entry, "icon-release", G_CALLBACK(entry_icon_release_cb), entry);
- gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
- make_label_bold(GTK_LABEL(label));
-
- label = gtk_label_new(_("For example, spice://foo.example.org:5900"));
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- make_label_light(GTK_LABEL(label));
-#if GTK_CHECK_VERSION(3, 0, 0)
- gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
- gtk_widget_set_margin_bottom(label, 12);
-#else
- alignment = gtk_alignment_new(0, 0, 1, 1);
- gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 12, 0, 0);
- gtk_container_add(GTK_CONTAINER(alignment), label);
- gtk_box_pack_start(GTK_BOX(box), alignment, TRUE, TRUE, 0);
-#endif
-
- label = gtk_label_new_with_mnemonic(_("_Recent Connections"));
- make_label_bold(GTK_LABEL(label));
- gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-
- recent = GTK_WIDGET(gtk_recent_chooser_widget_new());
- gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER(recent), FALSE);
- gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(recent), GTK_RECENT_SORT_MRU);
- gtk_box_pack_start(GTK_BOX(box), recent, TRUE, TRUE, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), recent);
-
- rfilter = gtk_recent_filter_new();
- gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
- gtk_recent_filter_add_mime_type(rfilter, "application/x-vnc");
- gtk_recent_filter_add_mime_type(rfilter, "application/x-virt-viewer");
- gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), rfilter);
- gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(recent), FALSE);
- g_signal_connect(recent, "selection-changed",
- G_CALLBACK(recent_selection_changed_dialog_cb), entry);
- g_signal_connect(recent, "item-activated",
- G_CALLBACK(recent_item_activated_dialog_cb), dialog);
-
- /* show and wait for response */
- gtk_widget_show_all(dialog);
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- *uri = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
- g_strstrip(*uri);
- retval = 0;
- } else {
- *uri = NULL;
- retval = -1;
- }
- gtk_widget_destroy(dialog);
-
- return retval;
-}
-
-
#ifdef HAVE_OVIRT
static OvirtVm *
choose_vm(GtkWindow *main_window,
@@ -1221,7 +1065,6 @@ remote_viewer_start(VirtViewerApp *app, GError **err)
RemoteViewer *self = REMOTE_VIEWER(app);
RemoteViewerPrivate *priv = self->priv;
- VirtViewerWindow *main_window;
GFile *file = NULL;
VirtViewerFile *vvfile = NULL;
gboolean ret = FALSE;
@@ -1252,9 +1095,8 @@ remote_viewer_start(VirtViewerApp *app, GError **err)
} else {
#endif
retry_dialog:
- main_window = virt_viewer_app_get_main_window(app);
if (priv->open_recent_dialog) {
- if (connect_dialog(virt_viewer_window_get_window(main_window), &guri) != 0) {
+ if (connect_dialog(&guri) != GTK_RESPONSE_ACCEPT) {
g_set_error_literal(&error,
VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED,
_("No connection was chosen"));
--
2.4.2
More information about the virt-tools-list
mailing list