[gnome-disk-utility] Add a connect to server dialog and use it in Palimpsest



commit b2cf1b1dfda63b1c3bebf613aeb2fa5264555f69
Author: David Zeuthen <davidz redhat com>
Date:   Mon Dec 7 09:32:05 2009 -0500

    Add a connect to server dialog and use it in Palimpsest
    
    We actually don't connect to the server just yet - that's for a future
    patch.

 configure.ac                               |    2 +
 src/gdu-gtk/Makefile.am                    |    4 +
 src/gdu-gtk/gdu-connect-to-server-dialog.c |  273 ++++++++++++++++++++++++++++
 src/gdu-gtk/gdu-connect-to-server-dialog.h |   60 ++++++
 src/gdu-gtk/gdu-gtk-types.h                |    2 +-
 src/gdu-gtk/gdu-gtk.h                      |    1 +
 src/palimpsest/gdu-shell.c                 |   25 +++-
 7 files changed, 364 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fb9ca1d..a90b264 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,6 +130,7 @@ GTK2_REQUIRED=2.17.2
 UNIQUE_REQUIRED=1.0
 LIBNOTIFY_REQUIRED=0.3.0
 NAUTILUS_REQUIRED=2.24.0
+AVAHI_UI_REQUIRED=0.6.25
 
 UDISKS_REQUIRED=1.0.0
 UDISKS_NEXT_ABI_INCOMPATIBLE_VERSION=1.1.0
@@ -150,6 +151,7 @@ PKG_CHECK_MODULES(LIBNOTIFY, [libnotify  >= $LIBNOTIFY_REQUIRED])
 PKG_CHECK_MODULES(UDISKS, [udisks  >= $UDISKS_REQUIRED udisks < $UDISKS_NEXT_ABI_INCOMPATIBLE_VERSION])
 PKG_CHECK_MODULES(X11, [x11])
 PKG_CHECK_MODULES(LIBATASMART, [libatasmart >= 0.14])
+PKG_CHECK_MODULES(AVAHI_UI, [avahi-ui >= $AVAHI_UI_REQUIRED])
 
 # *************
 # Documentation
diff --git a/src/gdu-gtk/Makefile.am b/src/gdu-gtk/Makefile.am
index bdff6a7..59cc788 100644
--- a/src/gdu-gtk/Makefile.am
+++ b/src/gdu-gtk/Makefile.am
@@ -54,6 +54,7 @@ libgdu_gtkinclude_HEADERS =              				\
 	gdu-add-component-linux-md-dialog.h				\
 	gdu-edit-linux-md-dialog.h					\
 	gdu-drive-benchmark-dialog.h					\
+	gdu-connect-to-server-dialog.h					\
 	$(NULL)
 
 libgdu_gtk_la_SOURCES =                 	               				\
@@ -85,6 +86,7 @@ libgdu_gtk_la_SOURCES =                 	               				\
 	gdu-add-component-linux-md-dialog.h	gdu-add-component-linux-md-dialog.c	\
 	gdu-edit-linux-md-dialog.h		gdu-edit-linux-md-dialog.c		\
 	gdu-drive-benchmark-dialog.h		gdu-drive-benchmark-dialog.c		\
+	gdu-connect-to-server-dialog.h		gdu-connect-to-server-dialog.c		\
 	$(NULL)
 
 libgdu_gtk_la_CPPFLAGS = 				\
@@ -109,6 +111,7 @@ libgdu_gtk_la_CFLAGS = 					\
 	$(WARN_CFLAGS)					\
 	$(AM_CFLAGS)					\
 	$(LIBATASMART_CFLAGS)				\
+	$(AVAHI_UI_CFLAGS)				\
 	$(NULL)
 
 libgdu_gtk_la_LIBADD = 					\
@@ -120,6 +123,7 @@ libgdu_gtk_la_LIBADD = 					\
 	$(GTK2_LIBS)					\
 	$(INTLLIBS)					\
 	$(LIBATASMART_LIBS)				\
+	$(AVAHI_UI_LIBS)				\
 	$(NULL)
 
 libgdu_gtk_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
diff --git a/src/gdu-gtk/gdu-connect-to-server-dialog.c b/src/gdu-gtk/gdu-connect-to-server-dialog.c
new file mode 100644
index 0000000..e3dc690
--- /dev/null
+++ b/src/gdu-gtk/gdu-connect-to-server-dialog.c
@@ -0,0 +1,273 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * 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.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#define _GNU_SOURCE
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+#include <avahi-ui/avahi-ui.h>
+
+#include "gdu-connect-to-server-dialog.h"
+
+struct GduConnectToServerDialogPrivate
+{
+        gchar *address;
+
+        GtkWidget *hostname_entry;
+        GtkWidget *username_entry;
+};
+
+enum
+{
+        PROP_0,
+        PROP_ADDRESS,
+};
+
+G_DEFINE_TYPE (GduConnectToServerDialog, gdu_connect_to_server_dialog, GTK_TYPE_DIALOG);
+
+static void gdu_connect_to_server_dialog_constructed (GObject *object);
+
+static void
+gdu_connect_to_server_dialog_finalize (GObject *object)
+{
+        GduConnectToServerDialog *dialog = GDU_CONNECT_TO_SERVER_DIALOG (object);
+
+        g_free (dialog->priv->address);
+
+        if (G_OBJECT_CLASS (gdu_connect_to_server_dialog_parent_class)->finalize != NULL)
+                G_OBJECT_CLASS (gdu_connect_to_server_dialog_parent_class)->finalize (object);
+}
+
+static void
+gdu_connect_to_server_dialog_get_property (GObject    *object,
+                                           guint       property_id,
+                                           GValue     *value,
+                                           GParamSpec *pspec)
+{
+        GduConnectToServerDialog *dialog = GDU_CONNECT_TO_SERVER_DIALOG (object);
+
+        switch (property_id) {
+        case PROP_ADDRESS:
+                g_value_set_string (value, dialog->priv->address);
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gdu_connect_to_server_dialog_class_init (GduConnectToServerDialogClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        g_type_class_add_private (klass, sizeof (GduConnectToServerDialogPrivate));
+
+        object_class->get_property = gdu_connect_to_server_dialog_get_property;
+        object_class->constructed  = gdu_connect_to_server_dialog_constructed;
+        object_class->finalize     = gdu_connect_to_server_dialog_finalize;
+
+        g_object_class_install_property (object_class,
+                                         PROP_ADDRESS,
+                                         g_param_spec_string ("address",
+                                                              _("Address"),
+                                                              _("The chosen address"),
+                                                              NULL,
+                                                              G_PARAM_READABLE |
+                                                              G_PARAM_STATIC_NAME |
+                                                              G_PARAM_STATIC_NICK |
+                                                              G_PARAM_STATIC_BLURB));
+}
+
+static void
+gdu_connect_to_server_dialog_init (GduConnectToServerDialog *dialog)
+{
+        dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog, GDU_TYPE_CONNECT_TO_SERVER_DIALOG, GduConnectToServerDialogPrivate);
+}
+
+GtkWidget *
+gdu_connect_to_server_dialog_new (GtkWindow *parent)
+{
+        return GTK_WIDGET (g_object_new (GDU_TYPE_CONNECT_TO_SERVER_DIALOG,
+                                         "transient-for", parent,
+                                         NULL));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+gchar *
+gdu_connect_to_server_dialog_get_address  (GduConnectToServerDialog *dialog)
+{
+        g_return_val_if_fail (GDU_IS_CONNECT_TO_SERVER_DIALOG (dialog), NULL);
+        return g_strdup (dialog->priv->address);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_dns_sd_clicked (GtkButton *button,
+                   gpointer   user_data)
+{
+        GduConnectToServerDialog *dialog = GDU_CONNECT_TO_SERVER_DIALOG (user_data);
+        GtkWidget *service_dialog;
+        gint response;
+
+        service_dialog = aui_service_dialog_new (_("Choose Server"),
+                                                 gtk_window_get_transient_for (GTK_WINDOW (dialog)),
+                                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                 GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                                 NULL);
+
+        aui_service_dialog_set_browse_service_types (AUI_SERVICE_DIALOG (service_dialog),
+                                                     "_udisks-ssh._tcp",
+                                                     NULL);
+        gtk_widget_show_all (service_dialog);
+        response = gtk_dialog_run (GTK_DIALOG (service_dialog));
+
+        if (response == GTK_RESPONSE_OK) {
+                const gchar *hostname;
+                hostname = aui_service_dialog_get_host_name (AUI_SERVICE_DIALOG (service_dialog));
+                gtk_entry_set_text (GTK_ENTRY (dialog->priv->hostname_entry), hostname);
+        }
+
+        gtk_widget_destroy (service_dialog);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_hostname_entry_changed (GtkEditable *editable,
+                           gpointer     user_data)
+{
+        GduConnectToServerDialog *dialog = GDU_CONNECT_TO_SERVER_DIALOG (user_data);
+        gboolean sensitive;
+        const gchar *text;
+
+        sensitive = FALSE;
+        text = gtk_entry_get_text (GTK_ENTRY (dialog->priv->hostname_entry));
+        if (text != NULL && strlen (text) > 0)
+                sensitive = TRUE;
+
+        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+                                           GTK_RESPONSE_OK,
+                                           sensitive);
+}
+
+static void
+gdu_connect_to_server_dialog_constructed (GObject *object)
+{
+        GduConnectToServerDialog *dialog = GDU_CONNECT_TO_SERVER_DIALOG (object);
+        GtkWidget *content_area;
+        GtkWidget *button;
+        GtkWidget *label;
+        GtkWidget *table;
+        GtkWidget *entry;
+        GtkWidget *vbox;
+        gint row;
+
+        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+        gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
+        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 0);
+        gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
+        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6);
+
+        gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Server"));
+
+        gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+        button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+                                        GTK_STOCK_CONNECT,
+                                        GTK_RESPONSE_OK);
+
+        button = gtk_button_new_with_mnemonic (_("_Browse..."));
+        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
+                            button,
+                            FALSE,
+                            FALSE,
+                            0);
+        gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
+                                            button,
+                                            TRUE);
+        /* Translators: this is the tooltip for the "Browse..." button */
+        gtk_widget_set_tooltip_text (button, _("Discover servers on the local network"));
+        g_signal_connect (button,
+                          "clicked",
+                          G_CALLBACK (on_dns_sd_clicked),
+                          dialog);
+
+        content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+        gtk_container_set_border_width (GTK_CONTAINER (content_area), 10);
+
+        vbox = content_area;
+        gtk_box_set_spacing (GTK_BOX (vbox), 6);
+
+        /* -------------------------------------------------------------------------------- */
+
+        table = gtk_table_new (3, 2, FALSE);
+
+        gtk_table_set_col_spacings (GTK_TABLE (table), 12);
+        gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+        gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
+
+        row = 0;
+
+
+        label = gtk_label_new (NULL);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("Server _Address:"));
+        gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+                          GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+
+        entry = gtk_entry_new ();
+        gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row + 1,
+                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+        gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+        dialog->priv->hostname_entry = entry;
+        row++;
+
+        label = gtk_label_new (NULL);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("_User Name:"));
+        gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+                          GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+
+        entry = gtk_entry_new ();
+        gtk_entry_set_text (GTK_ENTRY (entry), g_get_user_name ());
+        gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row + 1,
+                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+        gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+        dialog->priv->username_entry = entry;
+        row++;
+
+        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+                                           GTK_RESPONSE_OK,
+                                           FALSE);
+        g_signal_connect (dialog->priv->hostname_entry,
+                          "changed",
+                          G_CALLBACK (on_hostname_entry_changed),
+                          dialog);
+
+        if (G_OBJECT_CLASS (gdu_connect_to_server_dialog_parent_class)->constructed != NULL)
+                G_OBJECT_CLASS (gdu_connect_to_server_dialog_parent_class)->constructed (object);
+}
+
diff --git a/src/gdu-gtk/gdu-connect-to-server-dialog.h b/src/gdu-gtk/gdu-connect-to-server-dialog.h
new file mode 100644
index 0000000..b115dcb
--- /dev/null
+++ b/src/gdu-gtk/gdu-connect-to-server-dialog.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * 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.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_CONNECT_TO_SERVER_DIALOG_H
+#define __GDU_CONNECT_TO_SERVER_DIALOG_H
+
+#include <gdu-gtk/gdu-gtk.h>
+
+G_BEGIN_DECLS
+
+#define GDU_TYPE_CONNECT_TO_SERVER_DIALOG         (gdu_connect_to_server_dialog_get_type())
+#define GDU_CONNECT_TO_SERVER_DIALOG(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GDU_TYPE_CONNECT_TO_SERVER_DIALOG, GduConnectToServerDialog))
+#define GDU_CONNECT_TO_SERVER_DIALOG_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GDU_TYPE_CONNECT_TO_SERVER_DIALOG, GduConnectToServerDialogClass))
+#define GDU_IS_CONNECT_TO_SERVER_DIALOG(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDU_TYPE_CONNECT_TO_SERVER_DIALOG))
+#define GDU_IS_CONNECT_TO_SERVER_DIALOG_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GDU_TYPE_CONNECT_TO_SERVER_DIALOG))
+#define GDU_CONNECT_TO_SERVER_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDU_TYPE_CONNECT_TO_SERVER_DIALOG, GduConnectToServerDialogClass))
+
+typedef struct GduConnectToServerDialogClass   GduConnectToServerDialogClass;
+typedef struct GduConnectToServerDialogPrivate GduConnectToServerDialogPrivate;
+
+struct GduConnectToServerDialog
+{
+        GtkDialog parent;
+
+        /*< private >*/
+        GduConnectToServerDialogPrivate *priv;
+};
+
+struct GduConnectToServerDialogClass
+{
+        GtkDialogClass parent_class;
+};
+
+GType       gdu_connect_to_server_dialog_get_type    (void) G_GNUC_CONST;
+GtkWidget*  gdu_connect_to_server_dialog_new         (GtkWindow                 *parent);
+gchar      *gdu_connect_to_server_dialog_get_address (GduConnectToServerDialog  *dialog);
+
+G_END_DECLS
+
+#endif  /* __GDU_CONNECT_TO_SERVER_DIALOG_H */
+
diff --git a/src/gdu-gtk/gdu-gtk-types.h b/src/gdu-gtk/gdu-gtk-types.h
index 33e2948..e2f97d7 100644
--- a/src/gdu-gtk/gdu-gtk-types.h
+++ b/src/gdu-gtk/gdu-gtk-types.h
@@ -61,7 +61,7 @@ typedef struct GduDiskSelectionWidget       GduDiskSelectionWidget;
 typedef struct GduAddComponentLinuxMdDialog GduAddComponentLinuxMdDialog;
 typedef struct GduEditLinuxMdDialog         GduEditLinuxMdDialog;
 typedef struct GduDriveBenchmarkDialog      GduDriveBenchmarkDialog;
-
+typedef struct GduConnectToServerDialog     GduConnectToServerDialog;
 
 G_END_DECLS
 
diff --git a/src/gdu-gtk/gdu-gtk.h b/src/gdu-gtk/gdu-gtk.h
index 0a6b445..e04f6bc 100644
--- a/src/gdu-gtk/gdu-gtk.h
+++ b/src/gdu-gtk/gdu-gtk.h
@@ -53,6 +53,7 @@
 #include <gdu-gtk/gdu-add-component-linux-md-dialog.h>
 #include <gdu-gtk/gdu-edit-linux-md-dialog.h>
 #include <gdu-gtk/gdu-drive-benchmark-dialog.h>
+#include <gdu-gtk/gdu-connect-to-server-dialog.h>
 #undef __GDU_GTK_INSIDE_GDU_GTK_H
 
 G_BEGIN_DECLS
diff --git a/src/palimpsest/gdu-shell.c b/src/palimpsest/gdu-shell.c
index f46ae2b..ecaae02 100644
--- a/src/palimpsest/gdu-shell.c
+++ b/src/palimpsest/gdu-shell.c
@@ -1317,7 +1317,7 @@ create_linux_md_do (CreateLinuxMdData *data)
 }
 
 static void
-new_linud_md_array_callback (GtkAction *action, gpointer user_data)
+new_linux_md_array_callback (GtkAction *action, gpointer user_data)
 {
         GduShell *shell = GDU_SHELL (user_data);
         GtkWidget *dialog;
@@ -1354,6 +1354,25 @@ new_linud_md_array_callback (GtkAction *action, gpointer user_data)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+on_file_connect_action (GtkAction *action,
+                        gpointer   user_data)
+{
+        GduShell *shell = GDU_SHELL (user_data);
+        GtkWidget *dialog;
+        gint response;
+
+        dialog = gdu_connect_to_server_dialog_new (GTK_WINDOW (shell->priv->app_window));
+        gtk_widget_show_all (dialog);
+        response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+        g_debug ("response = %d", response);
+
+        gtk_widget_destroy (dialog);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
 quit_action_callback (GtkAction *action, gpointer user_data)
 {
         gtk_main_quit ();
@@ -1399,6 +1418,7 @@ static const gchar *ui =
         "      <menu action='file-new'>"
         "        <menuitem action='file-new-linux-md-array'/>"
         "      </menu>"
+        "      <menuitem action='file-connect'/>"
         "      <menuitem action='quit'/>"
         "    </menu>"
 #if 0
@@ -1444,8 +1464,9 @@ static const gchar *ui =
 
 static GtkActionEntry entries[] = {
         {"file", NULL, N_("_File"), NULL, NULL, NULL },
+        {"file-connect", "gtk-connect", N_("_Connect to server"), NULL, N_("Connect to a remote server and manage disks"), G_CALLBACK (on_file_connect_action)},
         {"file-new", NULL, N_("_New"), NULL, NULL, NULL },
-        {"file-new-linux-md-array", "gdu-raid-array", N_("Software _RAID Array"), NULL, N_("Create a new Software RAID array"), G_CALLBACK (new_linud_md_array_callback)},
+        {"file-new-linux-md-array", "gdu-raid-array", N_("Software _RAID Array"), NULL, N_("Create a new Software RAID array"), G_CALLBACK (new_linux_md_array_callback)},
         {"edit", NULL, N_("_Edit"), NULL, NULL, NULL },
         {"help", NULL, N_("_Help"), NULL, NULL, NULL },
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]