1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
5
* Copyright (C) 2011 Red Hat, Inc.
7
* Nautilus is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of the
10
* License, or (at your option) any later version.
12
* Nautilus is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public
18
* License along with this program; see the file COPYING. If not,
19
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
22
* Author: Cosimo Cecchi <cosimoc@redhat.com>
27
#include "nautilus-progress-info-manager.h"
29
struct _NautilusProgressInfoManagerPriv {
30
GList *progress_infos;
38
static NautilusProgressInfoManager *singleton = NULL;
40
static guint signals[LAST_SIGNAL] = { 0, };
42
G_DEFINE_TYPE (NautilusProgressInfoManager, nautilus_progress_info_manager,
46
nautilus_progress_info_manager_finalize (GObject *obj)
48
NautilusProgressInfoManager *self = NAUTILUS_PROGRESS_INFO_MANAGER (obj);
50
if (self->priv->progress_infos != NULL) {
51
g_list_free_full (self->priv->progress_infos, g_object_unref);
54
G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->finalize (obj);
58
nautilus_progress_info_manager_constructor (GType type,
60
GObjectConstructParam *props)
64
if (singleton != NULL) {
65
return g_object_ref (singleton);
68
retval = G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->constructor
69
(type, n_props, props);
71
singleton = NAUTILUS_PROGRESS_INFO_MANAGER (retval);
72
g_object_add_weak_pointer (retval, (gpointer) &singleton);
78
nautilus_progress_info_manager_init (NautilusProgressInfoManager *self)
80
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_INFO_MANAGER,
81
NautilusProgressInfoManagerPriv);
85
nautilus_progress_info_manager_class_init (NautilusProgressInfoManagerClass *klass)
89
oclass = G_OBJECT_CLASS (klass);
90
oclass->constructor = nautilus_progress_info_manager_constructor;
91
oclass->finalize = nautilus_progress_info_manager_finalize;
93
signals[NEW_PROGRESS_INFO] =
94
g_signal_new ("new-progress-info",
95
G_TYPE_FROM_CLASS (klass),
98
g_cclosure_marshal_VOID__OBJECT,
101
NAUTILUS_TYPE_PROGRESS_INFO);
103
g_type_class_add_private (klass, sizeof (NautilusProgressInfoManagerPriv));
107
progress_info_finished_cb (NautilusProgressInfo *info,
108
NautilusProgressInfoManager *self)
110
self->priv->progress_infos =
111
g_list_remove (self->priv->progress_infos, info);
114
NautilusProgressInfoManager *
115
nautilus_progress_info_manager_new (void)
117
return g_object_new (NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NULL);
121
nautilus_progress_info_manager_add_new_info (NautilusProgressInfoManager *self,
122
NautilusProgressInfo *info)
124
if (g_list_find (self->priv->progress_infos, info) != NULL) {
125
g_warning ("Adding two times the same progress info object to the manager");
129
self->priv->progress_infos =
130
g_list_prepend (self->priv->progress_infos, g_object_ref (info));
132
g_signal_connect (info, "finished",
133
G_CALLBACK (progress_info_finished_cb), self);
135
g_signal_emit (self, signals[NEW_PROGRESS_INFO], 0, info);
139
nautilus_progress_info_manager_get_all_infos (NautilusProgressInfoManager *self)
141
return self->priv->progress_infos;