1 /*-
2 * Copyright (C) 2007-2011 Peter de Ridder <peter@xfce.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #ifdef HAVE_STDLIB_H
24 #include <stdlib.h>
25 #endif
26
27 #include <glib.h>
28 #include <gtk/gtk.h>
29
30 #include <libxfce4util/libxfce4util.h>
31
32 #include <subversion-1/svn_client.h>
33 #include <subversion-1/svn_pools.h>
34
35 #include "tsh-common.h"
36 #include "tsh-dialog-common.h"
37 #include "tsh-notify-dialog.h"
38 #include "tsh-lock-dialog.h"
39
40 #include "tsh-lock.h"
41
42 struct thread_args {
43 svn_client_ctx_t *ctx;
44 apr_pool_t *pool;
45 TshNotifyDialog *dialog;
46 gchar **files;
47 gchar *message;
48 gboolean steal;
49 };
50
lock_thread(gpointer user_data)51 static gpointer lock_thread (gpointer user_data)
52 {
53 struct thread_args *args = user_data;
54 svn_error_t *err;
55 apr_array_header_t *paths;
56 svn_client_ctx_t *ctx = args->ctx;
57 apr_pool_t *subpool, *pool = args->pool;
58 TshNotifyDialog *dialog = args->dialog;
59 gchar **files = args->files;
60 gchar *message = args->message;
61 gboolean steal = args->steal;
62 gint size, i;
63 gchar *error_str;
64
65 g_free (args);
66
67 size = files?g_strv_length(files):0;
68
69 subpool = svn_pool_create (pool);
70
71 if(size)
72 {
73 paths = apr_array_make (subpool, size, sizeof (const char *));
74
75 for (i = 0; i < size; i++)
76 {
77 APR_ARRAY_PUSH (paths, const char *) = files[i];
78 }
79 }
80 else
81 {
82 paths = apr_array_make (subpool, 1, sizeof (const char *));
83
84 APR_ARRAY_PUSH (paths, const char *) = ""; // current directory
85 }
86
87 if ((err = svn_client_lock(paths, message, steal, ctx, subpool)))
88 {
89 svn_pool_destroy (subpool);
90
91 error_str = tsh_strerror(err);
92
93 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
94 gdk_threads_enter();
95 tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
96 tsh_notify_dialog_done (dialog);
97 gdk_threads_leave();
98 G_GNUC_END_IGNORE_DEPRECATIONS
99
100 g_free(error_str);
101
102 svn_error_clear(err);
103 return GINT_TO_POINTER (FALSE);
104 tsh_reset_cancel();
105 }
106
107 svn_pool_destroy (subpool);
108
109 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
110 gdk_threads_enter();
111 tsh_notify_dialog_done (dialog);
112 gdk_threads_leave();
113 G_GNUC_END_IGNORE_DEPRECATIONS
114
115 tsh_reset_cancel();
116 return GINT_TO_POINTER (TRUE);
117 }
118
tsh_lock(gchar ** files,svn_client_ctx_t * ctx,apr_pool_t * pool)119 GThread *tsh_lock (gchar **files, svn_client_ctx_t *ctx, apr_pool_t *pool)
120 {
121 GtkWidget *dialog;
122 struct thread_args *args;
123 gchar *message;
124 gboolean steal;
125
126 dialog = tsh_lock_dialog_new (NULL, NULL, 0);
127 if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
128 {
129 gtk_widget_destroy (dialog);
130 return NULL;
131 }
132
133 message = tsh_lock_dialog_get_message (TSH_LOCK_DIALOG (dialog));
134 steal = tsh_lock_dialog_get_steal (TSH_LOCK_DIALOG (dialog));
135
136 gtk_widget_destroy (dialog);
137
138 dialog = tsh_notify_dialog_new (_("Lock"), NULL, 0);
139 g_signal_connect(dialog, "cancel-clicked", tsh_cancel, NULL);
140 tsh_dialog_start (GTK_DIALOG (dialog), TRUE);
141
142 ctx->notify_func2 = tsh_notify_func2;
143 ctx->notify_baton2 = dialog;
144
145 args = g_malloc (sizeof (struct thread_args));
146 args->ctx = ctx;
147 args->pool = pool;
148 args->dialog = TSH_NOTIFY_DIALOG (dialog);
149 args->files = files;
150 args->message = message;
151 args->steal = steal;
152
153 return g_thread_new (NULL, lock_thread, args);
154 }
155
156