glade: Fix make file some files were not installed
[anjuta.git] / plugins / subversion / subversion-vcs-interface.c
blob0309f5f07f601e92f43a3ad28bf4a140991a7d05
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2008 <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 "subversion-vcs-interface.h"
27 void
28 subversion_ivcs_iface_init (IAnjutaVcsIface *iface)
30 iface->add = subversion_ivcs_add;
31 iface->checkout = subversion_ivcs_checkout;
32 iface->diff = subversion_ivcs_diff;
33 iface->query_status = subversion_ivcs_query_status;
34 iface->remove = subversion_ivcs_remove;
37 void
38 subversion_ivcs_add (IAnjutaVcs *obj, GList *files, AnjutaAsyncNotify *notify,
39 GError **err)
41 GList *path_list;
42 SvnAddCommand *add_command;
44 path_list = anjuta_util_convert_gfile_list_to_path_list (files);
45 add_command = svn_add_command_new_list (path_list, FALSE, TRUE);
47 anjuta_util_glist_strings_free (path_list);
49 g_signal_connect (G_OBJECT (add_command), "command-finished",
50 G_CALLBACK (g_object_unref),
51 NULL);
53 if (notify)
55 g_signal_connect_swapped (G_OBJECT (add_command), "command-finished",
56 G_CALLBACK (anjuta_async_notify_notify_finished),
57 notify);
60 anjuta_command_start (ANJUTA_COMMAND (add_command));
64 void
65 subversion_ivcs_checkout (IAnjutaVcs *obj,
66 const gchar *repository_location, GFile *dest,
67 GCancellable *cancel,
68 AnjutaAsyncNotify *notify, GError **err)
70 GError *error;
71 gchar *path;
72 SvnCheckoutCommand *checkout_command;
73 Subversion *plugin;
75 error = NULL;
76 g_file_make_directory (dest, NULL, &error);
77 if (error)
79 if (error->code != G_IO_ERROR_EXISTS)
81 g_propagate_error (err, error);
82 return;
84 g_error_free (error);
87 path = g_file_get_path (dest);
88 checkout_command = svn_checkout_command_new (repository_location, path);
89 plugin = ANJUTA_PLUGIN_SUBVERSION (obj);
91 g_free (path);
93 create_message_view (plugin);
95 g_signal_connect (G_OBJECT (checkout_command), "data-arrived",
96 G_CALLBACK (on_command_info_arrived),
97 plugin);
99 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
100 G_CALLBACK (g_object_unref),
101 NULL);
103 if (cancel)
105 g_signal_connect_swapped (G_OBJECT (cancel), "cancelled",
106 G_CALLBACK (anjuta_command_cancel),
107 checkout_command);
110 if (notify)
112 g_signal_connect_swapped (G_OBJECT (checkout_command),
113 "command-finished",
114 G_CALLBACK (anjuta_async_notify_notify_finished),
115 notify);
118 anjuta_command_start (ANJUTA_COMMAND (checkout_command));
121 static void
122 on_diff_command_data_arrived (AnjutaCommand *command,
123 IAnjutaVcsDiffCallback callback)
125 GQueue *output;
126 gchar *line;
128 output = svn_diff_command_get_output (SVN_DIFF_COMMAND (command));
130 while (g_queue_peek_head (output))
132 line = g_queue_pop_head (output);
133 callback (g_object_get_data (G_OBJECT (command), "file"), line,
134 g_object_get_data (G_OBJECT (command), "user-data"));
135 g_free (line);
139 void
140 subversion_ivcs_diff (IAnjutaVcs *obj, GFile* file,
141 IAnjutaVcsDiffCallback callback, gpointer user_data,
142 GCancellable* cancel, AnjutaAsyncNotify *notify,
143 GError **err)
145 gchar *path;
146 SvnDiffCommand *diff_command;
148 path = g_file_get_path (file);
149 diff_command = svn_diff_command_new (path, SVN_DIFF_REVISION_NONE,
150 SVN_DIFF_REVISION_NONE,
151 ANJUTA_PLUGIN_SUBVERSION (obj)->project_root_dir,
152 TRUE);
154 g_free (path);
156 g_object_set_data_full (G_OBJECT (diff_command), "file",
157 g_object_ref (file),
158 (GDestroyNotify) g_object_unref);
159 g_object_set_data (G_OBJECT (diff_command), "user-data", user_data);
161 g_signal_connect (G_OBJECT (diff_command), "command-finished",
162 G_CALLBACK (g_object_unref),
163 NULL);
165 g_signal_connect (G_OBJECT (diff_command), "data-arrived",
166 G_CALLBACK (on_diff_command_data_arrived),
167 callback);
169 if (cancel)
171 g_signal_connect_swapped (G_OBJECT (cancel), "cancelled",
172 G_CALLBACK (anjuta_command_cancel),
173 diff_command);
176 if (notify)
178 g_signal_connect_swapped (G_OBJECT (diff_command), "command-finished",
179 G_CALLBACK (anjuta_async_notify_notify_finished),
180 notify);
183 anjuta_command_start (ANJUTA_COMMAND (diff_command));
186 /* FIXME: The stuff in subversion-ui-utils.c should be namespaced. */
187 static void
188 on_ivcs_status_command_data_arrived (AnjutaCommand *command,
189 IAnjutaVcsStatusCallback callback)
191 GQueue *status_queue;
192 SvnStatus *status;
193 gchar *path;
194 GFile *file;
196 status_queue = svn_status_command_get_status_queue (SVN_STATUS_COMMAND (command));
198 while (g_queue_peek_head (status_queue))
200 status = g_queue_pop_head (status_queue);
201 path = svn_status_get_path (status);
202 file = g_file_new_for_path (path);
204 if (file)
206 callback (file,
207 svn_status_get_vcs_status (status),
208 g_object_get_data (G_OBJECT (command), "user-data"));
210 g_object_unref (file);
213 svn_status_destroy (status);
214 g_free (path);
218 void
219 subversion_ivcs_query_status (IAnjutaVcs *obj, GFile *file,
220 IAnjutaVcsStatusCallback callback,
221 gpointer user_data, GCancellable *cancel,
222 AnjutaAsyncNotify *notify, GError **err)
224 gchar *path;
225 SvnStatusCommand *status_command;
227 path = g_file_get_path (file);
228 status_command = svn_status_command_new (path, FALSE, TRUE);
230 g_free (path);
232 g_object_set_data (G_OBJECT (status_command), "user-data", user_data);
234 g_signal_connect (G_OBJECT (status_command), "data-arrived",
235 G_CALLBACK (on_ivcs_status_command_data_arrived),
236 callback);
238 g_signal_connect (G_OBJECT (status_command), "command-finished",
239 G_CALLBACK (g_object_unref),
240 NULL);
242 if (cancel)
244 g_signal_connect_swapped (G_OBJECT (cancel), "cancelled",
245 G_CALLBACK (anjuta_command_cancel),
246 status_command);
249 if (notify)
251 g_signal_connect_swapped (G_OBJECT (status_command), "command-finished",
252 G_CALLBACK (anjuta_async_notify_notify_finished),
253 notify);
256 anjuta_command_start (ANJUTA_COMMAND (status_command));
259 void
260 subversion_ivcs_remove (IAnjutaVcs *obj, GList *files,
261 AnjutaAsyncNotify *notify, GError **err)
263 GList *path_list;
264 SvnRemoveCommand *remove_command;
266 path_list = anjuta_util_convert_gfile_list_to_path_list (files);
267 remove_command = svn_remove_command_new_list (path_list, NULL, FALSE);
269 anjuta_util_glist_strings_free (path_list);
271 g_signal_connect (G_OBJECT (remove_command), "command-finished",
272 G_CALLBACK (g_object_unref),
273 NULL);
275 if (notify)
277 g_signal_connect_swapped (G_OBJECT (remove_command), "command-finished",
278 G_CALLBACK (anjuta_async_notify_notify_finished),
279 notify);
282 anjuta_command_start (ANJUTA_COMMAND (remove_command));