gtkfilechooserwidget.c 6.04 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Owen Taylor's avatar
Owen Taylor committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
 * gtkfilechooserwidget.c: Embeddable file selector widget
 * Copyright (C) 2003, 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
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Owen Taylor's avatar
Owen Taylor committed
17 18
 */

19
#include "config.h"
20
#include "gtkfilechooserprivate.h"
Matthias Clasen's avatar
Matthias Clasen committed
21

Owen Taylor's avatar
Owen Taylor committed
22
#include "gtkfilechooserwidget.h"
23
#include "gtkfilechooserdefault.h"
Owen Taylor's avatar
Owen Taylor committed
24
#include "gtkfilechooserutils.h"
25
#include "gtktypebuiltins.h"
26
#include "gtkfilechooserembed.h"
27
#include "gtkorientable.h"
28
#include "gtkintl.h"
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

/**
 * SECTION:gtkfilechooserwidget
 * @Short_description: File chooser widget that can be embedded in other widgets
 * @Title: GtkFileChooserWidget
 * @See_also: #GtkFileChooser, #GtkFileChooserDialog
 *
 * #GtkFileChooserWidget is a widget suitable for selecting files.
 * It is the main building block of a #GtkFileChooserDialog.  Most
 * applications will only need to use the latter; you can use
 * #GtkFileChooserWidget as part of a larger window if you have
 * special needs.
 *
 * Note that #GtkFileChooserWidget does not have any methods of its
 * own.  Instead, you should use the functions that work on a
 * #GtkFileChooser.
 */


Owen Taylor's avatar
Owen Taylor committed
49 50
#define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)

51
static void gtk_file_chooser_widget_finalize     (GObject                   *object);
52 53 54 55 56 57 58 59 60 61 62 63 64

static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
						      guint                  n_construct_properties,
						      GObjectConstructParam *construct_params);
static void     gtk_file_chooser_widget_set_property (GObject               *object,
						      guint                  prop_id,
						      const GValue          *value,
						      GParamSpec            *pspec);
static void     gtk_file_chooser_widget_get_property (GObject               *object,
						      guint                  prop_id,
						      GValue                *value,
						      GParamSpec            *pspec);

65
G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_BOX,
Matthias Clasen's avatar
Matthias Clasen committed
66 67 68
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
						_gtk_file_chooser_delegate_iface_init)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
Matthias Clasen's avatar
Matthias Clasen committed
69
						_gtk_file_chooser_embed_delegate_iface_init))
Owen Taylor's avatar
Owen Taylor committed
70 71 72 73 74 75

static void
gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);

76
  gobject_class->constructor = gtk_file_chooser_widget_constructor;
Owen Taylor's avatar
Owen Taylor committed
77 78
  gobject_class->set_property = gtk_file_chooser_widget_set_property;
  gobject_class->get_property = gtk_file_chooser_widget_get_property;
79
  gobject_class->finalize = gtk_file_chooser_widget_finalize;
Owen Taylor's avatar
Owen Taylor committed
80 81 82 83 84 85 86 87 88 89 90 91

  _gtk_file_chooser_install_properties (gobject_class);

  g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
}

static void
gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
{
  GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
								   GTK_TYPE_FILE_CHOOSER_WIDGET,
								   GtkFileChooserWidgetPrivate);
92
  chooser_widget->priv = priv;
93 94
  gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser_widget),
                                  GTK_ORIENTATION_VERTICAL);
95 96
}

97 98 99 100 101 102
static void
gtk_file_chooser_widget_finalize (GObject *object)
{
  GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);

  g_free (chooser->priv->file_system);
103

Matthias Clasen's avatar
Matthias Clasen committed
104
  G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
105 106
}

107 108 109 110 111 112 113
static GObject*
gtk_file_chooser_widget_constructor (GType                  type,
				     guint                  n_construct_properties,
				     GObjectConstructParam *construct_params)
{
  GtkFileChooserWidgetPrivate *priv;
  GObject *object;
Owen Taylor's avatar
Owen Taylor committed
114
  
Matthias Clasen's avatar
Matthias Clasen committed
115 116 117
  object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
									       n_construct_properties,
									       construct_params);
118 119
  priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);

Owen Taylor's avatar
Owen Taylor committed
120 121
  gtk_widget_push_composite_child ();

122
  priv->impl = _gtk_file_chooser_default_new ();
123
  
124
  gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
Owen Taylor's avatar
Owen Taylor committed
125 126
  gtk_widget_show (priv->impl);

127
  _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
Owen Taylor's avatar
Owen Taylor committed
128
				  GTK_FILE_CHOOSER (priv->impl));
129

130 131
  _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
					GTK_FILE_CHOOSER_EMBED (priv->impl));
Owen Taylor's avatar
Owen Taylor committed
132 133
  
  gtk_widget_pop_composite_child ();
134 135

  return object;
Owen Taylor's avatar
Owen Taylor committed
136 137 138 139 140 141 142 143 144
}

static void
gtk_file_chooser_widget_set_property (GObject         *object,
				      guint            prop_id,
				      const GValue    *value,
				      GParamSpec      *pspec)
{
  GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
145 146 147 148 149 150 151

  switch (prop_id)
    {
    default:
      g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
      break;
    }
Owen Taylor's avatar
Owen Taylor committed
152 153 154 155 156 157 158 159 160 161 162 163 164
}

static void
gtk_file_chooser_widget_get_property (GObject         *object,
				      guint            prop_id,
				      GValue          *value,
				      GParamSpec      *pspec)
{
  GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
  
  g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
}

165 166 167 168 169 170 171 172 173
/**
 * gtk_file_chooser_widget_new:
 * @action: Open or save mode for the widget
 * 
 * Creates a new #GtkFileChooserWidget.  This is a file chooser widget that can
 * be embedded in custom windows, and it is the same widget that is used by
 * #GtkFileChooserDialog.
 * 
 * Return value: a new #GtkFileChooserWidget
Matthias Clasen's avatar
Matthias Clasen committed
174 175
 *
 * Since: 2.4
176
 **/
Owen Taylor's avatar
Owen Taylor committed
177 178 179 180 181 182 183
GtkWidget *
gtk_file_chooser_widget_new (GtkFileChooserAction action)
{
  return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
		       "action", action,
		       NULL);
}