1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* CTK - The GIMP Toolkit
 * ctkrecentchooserwidget.c: embeddable recently used resources chooser widget
 * Copyright (C) 2006 Emmanuele Bassi
 * 
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "ctkrecentchooserwidget.h"
#include "ctkrecentchooserdefault.h"
#include "ctkrecentchooserutils.h"
#include "ctkorientable.h"
#include "ctktypebuiltins.h"

/**
 * SECTION:ctkrecentchooserwidget
 * @Short_description: Displays recently used files
 * @Title: CtkRecentChooserWidget
 * @See_also:#CtkRecentChooser, #CtkRecentChooserDialog
 *
 * #CtkRecentChooserWidget is a widget suitable for selecting recently used
 * files.  It is the main building block of a #CtkRecentChooserDialog.  Most
 * applications will only need to use the latter; you can use
 * #CtkRecentChooserWidget as part of a larger window if you have special needs.
 *
 * Note that #CtkRecentChooserWidget does not have any methods of its own.
 * Instead, you should use the functions that work on a #CtkRecentChooser.
 *
 * Recently used files are supported since CTK+ 2.10.
 */


struct _CtkRecentChooserWidgetPrivate
{
  CtkRecentManager *manager;
  
  CtkWidget *chooser;
};

static void     ctk_recent_chooser_widget_set_property (GObject               *object,
						        guint                  prop_id,
						        const GValue          *value,
						        GParamSpec            *pspec);
static void     ctk_recent_chooser_widget_get_property (GObject               *object,
						        guint                  prop_id,
						        GValue                *value,
						        GParamSpec            *pspec);
static void     ctk_recent_chooser_widget_finalize     (GObject               *object);


G_DEFINE_TYPE_WITH_CODE (CtkRecentChooserWidget,<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_CODE is a macro then please configure it.
		         ctk_recent_chooser_widget,
			 CTK_TYPE_BOX,
                         G_ADD_PRIVATE (CtkRecentChooserWidget)
			 G_IMPLEMENT_INTERFACE (CTK_TYPE_RECENT_CHOOSER,
						_ctk_recent_chooser_delegate_iface_init))

static void
ctk_recent_chooser_widget_constructed (GObject *gobject)
{
  CtkRecentChooserWidget *self = CTK_RECENT_CHOOSER_WIDGET (gobject);

  self->priv->chooser = _ctk_recent_chooser_default_new (self->priv->manager);

  ctk_container_add (CTK_CONTAINER (self), self->priv->chooser);
  ctk_widget_show (self->priv->chooser);
  _ctk_recent_chooser_set_delegate (CTK_RECENT_CHOOSER (self),
				    CTK_RECENT_CHOOSER (self->priv->chooser));
}

static void
ctk_recent_chooser_widget_set_property (GObject      *object,
				        guint         prop_id,
				        const GValue *value,
				        GParamSpec   *pspec)
{
  CtkRecentChooserWidgetPrivate *priv;

  priv = ctk_recent_chooser_widget_get_instance_private (CTK_RECENT_CHOOSER_WIDGET (object));
  
  switch (prop_id)
    {
    case CTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
      priv->manager = g_value_get_object (value);
      break;
    default:
      g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
      break;
    }
}

static void
ctk_recent_chooser_widget_get_property (GObject    *object,
				        guint       prop_id G_GNUC_UNUSED,
				        GValue     *value,
				        GParamSpec *pspec)
{
  CtkRecentChooserWidgetPrivate *priv;

  priv = ctk_recent_chooser_widget_get_instance_private (CTK_RECENT_CHOOSER_WIDGET (object));

  g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
}

static void
ctk_recent_chooser_widget_finalize (GObject *object)
{
  CtkRecentChooserWidget *self = CTK_RECENT_CHOOSER_WIDGET (object);

  self->priv->manager = NULL;
  
  G_OBJECT_CLASS (ctk_recent_chooser_widget_parent_class)->finalize (object);
}

static void
ctk_recent_chooser_widget_class_init (CtkRecentChooserWidgetClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->constructed = ctk_recent_chooser_widget_constructed;
  gobject_class->set_property = ctk_recent_chooser_widget_set_property;
  gobject_class->get_property = ctk_recent_chooser_widget_get_property;
  gobject_class->finalize = ctk_recent_chooser_widget_finalize;

  _ctk_recent_chooser_install_properties (gobject_class);
}

static void
ctk_recent_chooser_widget_init (CtkRecentChooserWidget *widget)
{
  widget->priv = ctk_recent_chooser_widget_get_instance_private (widget);

  ctk_orientable_set_orientation (CTK_ORIENTABLE (widget),
                                  CTK_ORIENTATION_VERTICAL);
}

/*
 * Public API
 */

/**
 * ctk_recent_chooser_widget_new:
 * 
 * Creates a new #CtkRecentChooserWidget object.  This is an embeddable widget
 * used to access the recently used resources list.
 *
 * Returns: a new #CtkRecentChooserWidget
 *
 * Since: 2.10
 */
CtkWidget *
ctk_recent_chooser_widget_new (void)
{
  return g_object_new (CTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
}

/**
 * ctk_recent_chooser_widget_new_for_manager:
 * @manager: a #CtkRecentManager
 *
 * Creates a new #CtkRecentChooserWidget with a specified recent manager.
 *
 * This is useful if you have implemented your own recent manager, or if you
 * have a customized instance of a #CtkRecentManager object.
 *
 * Returns: a new #CtkRecentChooserWidget
 *
 * Since: 2.10
 */
CtkWidget *
ctk_recent_chooser_widget_new_for_manager (CtkRecentManager *manager)
{
  g_return_val_if_fail (manager == NULL || CTK_IS_RECENT_MANAGER (manager), NULL);
  
  return g_object_new (CTK_TYPE_RECENT_CHOOSER_WIDGET,
  		       "recent-manager", manager,
  		       NULL);
}