search: Set focus chain (see bgo#665945)
[anjuta.git] / plugins / subversion / svn-cat-command.c
blob423e4108a81860c67b244f63d8259e5847a01b8b
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 "svn-cat-command.h"
27 struct _SvnCatCommandPriv
29 gchar *path;
30 glong revision;
31 GQueue *output;
34 G_DEFINE_TYPE (SvnCatCommand, svn_cat_command, SVN_TYPE_COMMAND);
36 static void
37 svn_cat_command_init (SvnCatCommand *self)
39 self->priv = g_new0 (SvnCatCommandPriv, 1);
42 static void
43 svn_cat_command_finalize (GObject *object)
45 SvnCatCommand *self;
46 GList *current_output;
48 self = SVN_CAT_COMMAND (object);
50 g_free (self->priv->path);
52 current_output = self->priv->output->head;
54 while (current_output)
56 g_free (current_output->data);
57 current_output = g_list_next (current_output);
60 g_queue_free (self->priv->output);
62 g_free (self->priv);
64 G_OBJECT_CLASS (svn_cat_command_parent_class)->finalize (object);
67 static guint
68 svn_cat_command_run (AnjutaCommand *command)
70 SvnCatCommand *self;
71 SvnCommand *svn_command;
72 svn_opt_revision_t revision;
73 svn_opt_revision_t peg_revision;
74 svn_stream_t *cat_stream;
75 apr_file_t *cat_input;
76 apr_file_t *cat_output;
77 apr_size_t read_size;
78 gchar *line;
79 svn_error_t *error;
80 apr_status_t apr_error;
82 self = SVN_CAT_COMMAND (command);
83 svn_command = SVN_COMMAND (command);
85 apr_file_pipe_create (&cat_output, &cat_input,
86 svn_command_get_pool (svn_command));
87 apr_file_pipe_timeout_set (cat_output, 0);
88 apr_file_pipe_timeout_set (cat_input, 0);
89 cat_stream = svn_stream_from_aprfile2 (cat_input, FALSE,
90 svn_command_get_pool (svn_command));
92 revision.kind = svn_opt_revision_number;
93 revision.value.number = self->priv->revision;
94 peg_revision.kind = svn_opt_revision_unspecified;
96 error = svn_client_cat2 (cat_stream,
97 self->priv->path,
98 &peg_revision,
99 &revision,
100 svn_command_get_client_context (svn_command),
101 svn_command_get_pool (svn_command));
103 if (error)
105 svn_command_set_error (svn_command, error);
106 return 1;
109 while (apr_file_eof (cat_output) != APR_EOF)
111 read_size = 80;
112 line = g_new0 (gchar, (read_size + 1));
114 apr_error = apr_file_read (cat_output, line, &read_size);
116 if (apr_error)
117 break;
119 if (strlen (line))
121 anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (command));
122 g_queue_push_tail (self->priv->output, g_strdup (line));
123 anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (command));
125 g_free (line);
127 anjuta_command_notify_data_arrived (command);
131 return 0;
134 static void
135 svn_cat_command_class_init (SvnCatCommandClass *klass)
137 GObjectClass* object_class = G_OBJECT_CLASS (klass);
138 AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
140 object_class->finalize = svn_cat_command_finalize;
141 command_class->run = svn_cat_command_run;
145 SvnCatCommand *
146 svn_cat_command_new (const gchar *path, glong revision)
148 SvnCatCommand *self;
150 self = g_object_new (SVN_TYPE_CAT_COMMAND, NULL);
151 self->priv->path = svn_command_make_canonical_path (SVN_COMMAND (self),
152 path);
153 self->priv->revision = revision;
154 self->priv->output = g_queue_new ();
156 return self;
159 void
160 svn_cat_command_destroy (SvnCatCommand *self)
162 g_object_unref (self);
165 GQueue *
166 svn_cat_command_get_output (SvnCatCommand *self)
168 return self->priv->output;