open-with: initial implementation of GtkOpenWithDialog

This commit is contained in:
Cosimo Cecchi 2010-11-16 13:47:51 +01:00
parent f350c4c1b2
commit be18ca45f0
6 changed files with 1466 additions and 0 deletions

View File

@ -246,6 +246,7 @@ gtk_public_h_sources = \
gtkmountoperation.h \
gtknotebook.h \
gtkoffscreenwindow.h \
gtkopenwithdialog.h \
gtkorientable.h \
gtkpagesetup.h \
gtkpaned.h \
@ -516,6 +517,7 @@ gtk_base_c_sources = \
gtkmountoperation.c \
gtknotebook.c \
gtkoffscreenwindow.c \
gtkopenwithdialog.c \
gtkorientable.c \
gtkpagesetup.c \
gtkpaned.c \

View File

@ -129,6 +129,7 @@
#include <gtk/gtkmountoperation.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkoffscreenwindow.h>
#include <gtk/gtkopenwithdialog.h>
#include <gtk/gtkorientable.h>
#include <gtk/gtkpagesetup.h>
#include <gtk/gtkpapersize.h>

1291
gtk/gtkopenwithdialog.c Normal file

File diff suppressed because it is too large Load Diff

78
gtk/gtkopenwithdialog.h Normal file
View File

@ -0,0 +1,78 @@
/*
* gtkopenwithdialog.h: an open-with dialog
*
* Copyright (C) 2004 Novell, Inc.
* Copyright (C) 2007, 2010 Red Hat, Inc.
*
* 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 the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Dave Camp <dave@novell.com>
* Alexander Larsson <alexl@redhat.com>
* Cosimo Cecchi <ccecchi@redhat.com>
*/
#ifndef __GTK_OPEN_WITH_DIALOG_H__
#define __GTK_OPEN_WITH_DIALOG_H__
#include <gtk/gtkdialog.h>
#include <gio/gio.h>
#define GTK_TYPE_OPEN_WITH_DIALOG\
(gtk_open_with_dialog_get_type ())
#define GTK_OPEN_WITH_DIALOG(obj)\
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OPEN_WITH_DIALOG, GtkOpenWithDialog))
#define GTK_OPEN_WITH_DIALOG_CLASS(klass)\
(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OPEN_WITH_DIALOG, GtkOpenWithDialogClass))
#define GTK_IS_OPEN_WITH_DIALOG(obj)\
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OPEN_WITH_DIALOG))
typedef struct _GtkOpenWithDialog GtkOpenWithDialog;
typedef struct _GtkOpenWithDialogClass GtkOpenWithDialogClass;
typedef struct _GtkOpenWithDialogPrivate GtkOpenWithDialogPrivate;
struct _GtkOpenWithDialog {
GtkDialog parent;
/*< private >*/
GtkOpenWithDialogPrivate *priv;
};
struct _GtkOpenWithDialogClass {
GtkDialogClass parent_class;
void (*application_selected) (GtkOpenWithDialog *dialog,
GAppInfo *application);
/* padding for future class expansion */
gpointer padding[16];
};
typedef enum {
GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE = 0,
GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT
} GtkOpenWithDialogMode;
GType gtk_open_with_dialog_get_type (void);
GtkWidget * gtk_open_with_dialog_new (GtkWindow *parent,
GtkDialogFlags flags,
GtkOpenWithDialogMode mode,
GFile *file);
GtkWidget * gtk_open_with_dialog_new_for_content_type (GtkWindow *parent,
GtkDialogFlags flags,
const gchar *content_type);
#endif /* __GTK_OPEN_WITH_DIALOG_H__ */

View File

@ -66,6 +66,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testoffscreen \
testoffscreenwindow \
testorientable \
testopenwith \
testprint \
testrecentchooser \
testrecentchoosermenu \
@ -153,6 +154,7 @@ testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
testoffscreen_DEPENDENCIES = $(TEST_DEPS)
testoffscreenwindow_DEPENDENCIES = $(TEST_DEPS)
testopenwith_DEPENDENCIES = $(TEST_DEPS)
testorientable_DEPENDENCIES = $(TEST_DEPS)
testprint_DEPENDENCIES = $(TEST_DEPS)
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
@ -225,6 +227,7 @@ testnotebookdnd_LDADD = $(LDADDS)
testnouiprint_LDADD = $(LDADDS)
testoffscreen_LDADD = $(LDADDS)
testoffscreenwindow_LDADD = $(LDADDS)
testopenwith_LDADD = $(LDADDS)
testorientable_LDADD = $(LDADDS)
testprint_LDADD = $(LDADDS)
testrecentchooser_LDADD = $(LDADDS)
@ -375,6 +378,9 @@ testoffscreen_SOURCES = \
testoffscreenwindow_SOURCES = \
testoffscreenwindow.c
testopenwith_SOURCES = \
testopenwith.c
testwindows_SOURCES = \
testwindows.c

88
tests/testopenwith.c Normal file
View File

@ -0,0 +1,88 @@
/* testopenwith.c
* Copyright (C) 2010 Red Hat, Inc.
* Authors: Cosimo Cecchi
*
* 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 <stdlib.h>
#include <gtk/gtk.h>
static void
dialog_response_cb (GtkDialog *dialog,
gint response_id,
gpointer _user_data)
{
g_print ("Response: %d\n", response_id);
gtk_widget_destroy (GTK_WIDGET (dialog));
gtk_main_quit ();
}
int
main (int argc,
char **argv)
{
GOptionContext *context;
GError *error = NULL;
gchar **files = NULL;
GtkWidget *dialog;
GFile *file;
GOptionEntry entries[] = {
{ G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME,
G_OPTION_ARG_FILENAME_ARRAY, &files, NULL, NULL},
{ NULL }
};
g_type_init ();
context = g_option_context_new ("- Test for GtkOpenWithDialog");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, &error);
if (error != NULL)
{
g_critical ("Error: %s\n", error->message);
g_error_free (error);
g_option_context_free (context);
return EXIT_FAILURE;
}
g_option_context_free (context);
if (files == NULL || files[0] == NULL)
{
g_critical ("You need to specify a file path.");
return EXIT_FAILURE;
}
file = g_file_new_for_commandline_arg (files[0]);
dialog = gtk_open_with_dialog_new (NULL, 0, GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT,
file);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (dialog_response_cb), NULL);
gtk_main ();
return EXIT_SUCCESS;
}