Add a progress signal to AnjutaCommand and its subclasses in libanjuta
[anjuta-git-plugin.git] / libanjuta / anjuta-command.c
blob7a0b5b2bf26f3bcefe74d83633e965e921a21c4c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "anjuta-command.h"
27 struct _AnjutaCommandPriv
29 gchar *error_message;
32 enum
34 DATA_ARRIVED,
35 COMMAND_FINISHED,
36 PROGRESS,
38 LAST_SIGNAL
42 static guint anjuta_command_signals[LAST_SIGNAL] = { 0 };
44 G_DEFINE_TYPE (AnjutaCommand, anjuta_command, G_TYPE_OBJECT);
46 static void
47 anjuta_command_init (AnjutaCommand *self)
49 self->priv = g_new0 (AnjutaCommandPriv, 1);
52 static void
53 anjuta_command_finalize (GObject *object)
55 AnjutaCommand *self;
57 self = ANJUTA_COMMAND (object);
59 g_free (self->priv->error_message);
60 g_free (self->priv);
62 G_OBJECT_CLASS (anjuta_command_parent_class)->finalize (object);
65 static void
66 anjuta_command_class_init (AnjutaCommandClass *klass)
68 GObjectClass* object_class = G_OBJECT_CLASS (klass);
70 object_class->finalize = anjuta_command_finalize;
72 klass->run = NULL;
73 klass->start = NULL;
74 klass->notify_data_arrived = NULL;
75 klass->notify_complete = NULL;
76 klass->notify_progress = NULL;
77 klass->set_error_message = anjuta_command_set_error_message;
78 klass->get_error_message = anjuta_command_get_error_message;
79 klass->progress = NULL;
81 anjuta_command_signals[DATA_ARRIVED] =
82 g_signal_new ("data-arrived",
83 G_OBJECT_CLASS_TYPE (klass),
84 G_SIGNAL_RUN_FIRST,
86 NULL, NULL,
87 g_cclosure_marshal_VOID__VOID,
88 G_TYPE_NONE,
89 0);
91 anjuta_command_signals[COMMAND_FINISHED] =
92 g_signal_new ("command-finished",
93 G_OBJECT_CLASS_TYPE (klass),
94 G_SIGNAL_RUN_FIRST,
96 NULL, NULL,
97 g_cclosure_marshal_VOID__UINT ,
98 G_TYPE_NONE, 1,
99 G_TYPE_UINT);
101 anjuta_command_signals[PROGRESS] =
102 g_signal_new ("progress",
103 G_OBJECT_CLASS_TYPE (klass),
104 G_SIGNAL_RUN_FIRST,
105 G_STRUCT_OFFSET (AnjutaCommandClass, progress),
106 NULL, NULL,
107 g_cclosure_marshal_VOID__FLOAT ,
108 G_TYPE_NONE, 1,
109 G_TYPE_FLOAT);
112 void
113 anjuta_command_start (AnjutaCommand *self)
115 ANJUTA_COMMAND_GET_CLASS (self)->start (self);
118 void
119 anjuta_command_notify_data_arrived (AnjutaCommand *self)
121 ANJUTA_COMMAND_GET_CLASS (self)->notify_data_arrived (self);
124 void
125 anjuta_command_notify_complete (AnjutaCommand *self, guint return_code)
127 ANJUTA_COMMAND_GET_CLASS (self)->notify_complete (self, return_code);
130 void
131 anjuta_command_notify_progress (AnjutaCommand *self, gfloat progress)
133 ANJUTA_COMMAND_GET_CLASS (self)->notify_progress (self, progress);
136 void
137 anjuta_command_set_error_message (AnjutaCommand *self, gchar *error_message)
139 if (self->priv->error_message)
140 g_free (error_message);
142 self->priv->error_message = g_strdup (error_message);
145 gchar *
146 anjuta_command_get_error_message (AnjutaCommand *self)
148 return g_strdup (self->priv->error_message);