Commit e1092e9a authored by Christian Kellner's avatar Christian Kellner Committed by Christian Kellner

Implement GtkMountOperation, a subclass of GMountOperation to be used with

2008-03-17  Christian Kellner  <gicmo@gnome.org>

        Implement GtkMountOperation, a subclass of GMountOperation
        to be used with gio wherever there is the need to ask the
        user for credentials or questions while mounting a volume.
        This is bug #522245

        * gtk/gtkmountoperation.c:
        * gtk/gtkmountoperation.h:      
        Implement GtkMountOperation.
        
        * gtk/gtk.h: Add gtkmountoperation.h
        * gtk/Makefile.am: Add gtkmountoperation.[hc]
        * gtk/gtk.symbols: Add symbols of GtkMountOperation.
        * tests/testmountoperation.c: Test program for it.
        * tests/Makefile.am: Add testmountoperation.


svn path=/trunk/; revision=19894
parent 519ba608
2008-03-17 Christian Kellner <gicmo@gnome.org>
Implement GtkMountOperation, a subclass of GMountOperation
to be used with gio wherever there is the need to ask the
user for credentials or questions while mounting a volume.
This is bug #522245
* gtk/gtkmountoperation.c:
* gtk/gtkmountoperation.h:
Implement GtkMountOperation.
* gtk/gtk.h: Add gtkmountoperation.h
* gtk/Makefile.am: Add gtkmountoperation.[hc]
* gtk/gtk.symbols: Add symbols of GtkMountOperation.
* tests/testmountoperation.c: Test program for it.
* tests/Makefile.am: Add testmountoperation.
2008-03-17 Emmanuele Bassi <ebassi@gnome.org>
* gtk/gtkcontainer.c: Properly document
......
......@@ -229,6 +229,7 @@ gtk_public_h_sources = \
gtkmessagedialog.h \
gtkmisc.h \
gtkmodules.h \
gtkmountoperation.h \
gtknotebook.h \
gtkobject.h \
gtkpagesetup.h \
......@@ -489,6 +490,7 @@ gtk_base_c_sources = \
gtkmisc.c \
gtkmnemonichash.c \
gtkmodules.c \
gtkmountoperation.c \
gtknotebook.c \
gtkobject.c \
gtkpagesetup.c \
......
......@@ -119,6 +119,7 @@
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkmisc.h>
#include <gtk/gtkmodules.h>
#include <gtk/gtkmountoperation.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkobject.h>
#include <gtk/gtkpaned.h>
......
......@@ -2404,6 +2404,18 @@ gtk_misc_set_padding
#endif
#endif
#if IN_HEADER(__GTK_MOUNT_OPERATION_H__)
#if IN_FILE(__GTK_MOUNT_OPERATION_C__)
gtk_mount_operation_get_type G_GNUC_CONST
gtk_mount_operation_new
gtk_mount_operation_is_showing
gtk_mount_operation_set_parent
gtk_mount_operation_get_parent
gtk_mount_operation_set_screen
gtk_mount_operation_get_screen
#endif
#endif
#if IN_HEADER(__GTK_NOTEBOOK_H__)
#if IN_FILE(__GTK_NOTEBOOK_C__)
gtk_notebook_append_page
......
This diff is collapsed.
/* GTK - The GIMP Toolkit
* Copyright (C) Christian Kellner <gicmo@gnome.org>
*
* 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.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_MOUNT_OPERATION_H__
#define __GTK_MOUNT_OPERATION_H__
#include <glib.h>
#include <gio/gio.h>
#include <gdk/gdkscreen.h>
#include <gtk/gtkwindow.h>
G_BEGIN_DECLS
#define GTK_TYPE_MOUNT_OPERATION (gtk_mount_operation_get_type ())
#define GTK_MOUNT_OPERATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_MOUNT_OPERATION, GtkMountOperation))
#define GTK_MOUNT_OPERATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GTK_TYPE_MOUNT_OPERATION, GtkMountOperationClass))
#define GTK_IS_MOUNT_OPERATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_MOUNT_OPERATION))
#define GTK_IS_MOUNT_OPERATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_MOUNT_OPERATION))
#define GTK_MOUNT_OPERATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_MOUNT_OPERATION, GtkMountOperationClass))
typedef struct GtkMountOperation GtkMountOperation;
typedef struct GtkMountOperationClass GtkMountOperationClass;
typedef struct GtkMountOperationPrivate GtkMountOperationPrivate;
struct GtkMountOperation
{
GMountOperation parent_instance;
GtkMountOperationPrivate *priv;
};
struct GtkMountOperationClass
{
GMountOperationClass parent_class;
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
GType gtk_mount_operation_get_type (void);
GMountOperation *gtk_mount_operation_new (GtkWindow *parent);
gboolean gtk_mount_operation_is_showing (GtkMountOperation *op);
void gtk_mount_operation_set_parent (GtkMountOperation *op,
GtkWindow *parent);
GtkWindow * gtk_mount_operation_get_parent (GtkMountOperation *op);
void gtk_mount_operation_set_screen (GtkMountOperation *op,
GdkScreen *screen);
GdkScreen *gtk_mount_operation_get_screen (GtkMountOperation *op);
G_END_DECLS
#endif /* __GTK_MOUNT_OPERATION_H__ */
......@@ -77,6 +77,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testinput \
testmenus \
testmenubars \
testmountoperation \
testmultidisplay \
testmultiscreen \
testnotebookdnd \
......@@ -150,6 +151,7 @@ testinput_DEPENDENCIES = $(TEST_DEPS)
testimage_DEPENDENCIES = $(TEST_DEPS)
testmenus_DEPENDENCIES = $(TEST_DEPS)
testmenubars_DEPENDENCIES = $(TEST_DEPS)
testmountoperation_DEPENDENCIES = $(TEST_DEPS)
testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
......@@ -203,6 +205,7 @@ testinput_LDADD = $(LDADDS)
testimage_LDADD = $(LDADDS)
testmenus_LDADD = $(LDADDS)
testmenubars_LDADD = $(LDADDS)
testmountoperation_LDADD = $(LDADDS)
testmultidisplay_LDADD = $(LDADDS)
testmultiscreen_LDADD = $(LDADDS)
testnotebookdnd_LDADD = $(LDADDS)
......
/* testmultidisplay.c
* Copyright (C) 2008 Christian Kellner
* Author: Christian Kellner <gicmo@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*/
#include <config.h>
#include <gtk/gtk.h>
#include <gtk/gtkmountoperation.h>
static gboolean ask_question = FALSE;
static gboolean anonymous = FALSE;
static gboolean dont_ask_username = FALSE;
static gboolean dont_ask_domain = FALSE;
static gboolean dont_ask_password = FALSE;
static gboolean dont_save_password = FALSE;
static void
got_reply (GMountOperation *op,
GMountOperationResult result,
gpointer user_data)
{
if (result == G_MOUNT_OPERATION_HANDLED)
{
if (ask_question)
{
gint choice = g_mount_operation_get_choice (op);
g_print ("User chose: %d\n", choice);
}
else
{
if (anonymous)
g_print ("Anymous: %s\n",
g_mount_operation_get_anonymous (op) ? "true" : "false");
if (!dont_ask_username)
g_print ("Username: %s\n", g_mount_operation_get_username (op));
if (!dont_ask_domain)
g_print ("Domain: %s\n", g_mount_operation_get_domain (op));
if (!dont_ask_password)
g_print ("Password: %s\n", g_mount_operation_get_password (op));
if (!dont_save_password)
{
GPasswordSave pw_save;
pw_save = g_mount_operation_get_password_save (op);
g_print ("Save password: ");
switch (pw_save)
{
case G_PASSWORD_SAVE_NEVER:
g_print ("never");
break;
case G_PASSWORD_SAVE_FOR_SESSION:
g_print ("session");
break;
case G_PASSWORD_SAVE_PERMANENTLY:
g_print ("forever");
break;
default:
g_assert_not_reached ();
}
g_print ("\n");
}
}
}
else if (result == G_MOUNT_OPERATION_ABORTED)
g_print ("Operation aborted.\n");
else if (G_MOUNT_OPERATION_UNHANDLED)
g_assert_not_reached ();
gtk_main_quit ();
}
int
main (int argc, char *argv[])
{
GMountOperation *op;
gboolean force_rtl = FALSE;
GError *error = NULL;
GOptionEntry options[] = {
{ "ask-question", 'q', 0, G_OPTION_ARG_NONE, &ask_question, "Ask a question not a password.", NULL },
{ "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
{ "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, "Anonymous login allowed.", NULL },
{ "no-username", 'u', 0, G_OPTION_ARG_NONE, &dont_ask_username, "Don't ask for the username.", NULL },
{ "no-password", 'p', 0, G_OPTION_ARG_NONE, &dont_ask_password, "Don't ask for the password.", NULL },
{ "no-domain", 'd', 0, G_OPTION_ARG_NONE, &dont_ask_domain, "Don't ask for the domain.", NULL },
{ "no-pw-save", 's', 0, G_OPTION_ARG_NONE, &dont_save_password, "Don't show password save options.", NULL },
{ NULL }
};
if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error))
{
g_print ("Failed to parse args: %s\n", error->message);
g_error_free (error);
return 1;
}
if (force_rtl)
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
op = gtk_mount_operation_new (NULL);
g_signal_connect (op, "reply", G_CALLBACK (got_reply), NULL);
if (ask_question)
{
static const char *choices[] = {
"Yes", "No", "Sauerkraut", NULL
};
g_signal_emit_by_name (op, "ask_question", "Foo\nbar", choices);
}
else
{
GAskPasswordFlags flags;
flags = 0;
if (!dont_ask_password)
flags |= G_ASK_PASSWORD_NEED_PASSWORD;
if (!dont_ask_username)
flags |= G_ASK_PASSWORD_NEED_USERNAME;
if (!dont_ask_domain)
flags |= G_ASK_PASSWORD_NEED_DOMAIN;
if (anonymous)
flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
if (!dont_save_password)
flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
g_signal_emit_by_name (op, "ask_password",
argc > 1 ? argv[1] : "Credentials needed",
argc > 2 ? argv[2] : "default user",
argc > 3 ? argv[3] : "default domain",
flags);
}
gtk_main ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment