1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include "giggle-git-write-config.h"
27 typedef struct GiggleGitWriteConfigPriv GiggleGitWriteConfigPriv
;
29 struct GiggleGitWriteConfigPriv
{
35 static void git_write_config_finalize (GObject
*object
);
36 static void git_write_config_get_property (GObject
*object
,
40 static void git_write_config_set_property (GObject
*object
,
45 static gboolean
git_write_config_get_command_line (GiggleJob
*job
,
46 gchar
**command_line
);
47 static void git_write_config_handle_output (GiggleJob
*job
,
48 const gchar
*output_str
,
52 G_DEFINE_TYPE (GiggleGitWriteConfig
, giggle_git_write_config
, GIGGLE_TYPE_JOB
)
54 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_WRITE_CONFIG, GiggleGitWriteConfigPriv))
65 giggle_git_write_config_class_init (GiggleGitWriteConfigClass
*class)
67 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
68 GiggleJobClass
*job_class
= GIGGLE_JOB_CLASS (class);
70 object_class
->finalize
= git_write_config_finalize
;
71 object_class
->get_property
= git_write_config_get_property
;
72 object_class
->set_property
= git_write_config_set_property
;
74 job_class
->get_command_line
= git_write_config_get_command_line
;
75 job_class
->handle_output
= git_write_config_handle_output
;
77 g_object_class_install_property (object_class
,
79 g_param_spec_boolean ("global",
81 "Whether the setting is global",
84 g_object_class_install_property (object_class
,
86 g_param_spec_string ("field",
88 "configuration field to modify",
91 g_object_class_install_property (object_class
,
93 g_param_spec_string ("value",
95 "value to assign to the field",
99 g_type_class_add_private (object_class
, sizeof (GiggleGitWriteConfigPriv
));
103 giggle_git_write_config_init (GiggleGitWriteConfig
*config
)
108 git_write_config_finalize (GObject
*object
)
110 GiggleGitWriteConfigPriv
*priv
;
112 priv
= GET_PRIV (object
);
114 g_free (priv
->field
);
115 g_free (priv
->value
);
117 G_OBJECT_CLASS (giggle_git_write_config_parent_class
)->finalize (object
);
121 git_write_config_get_property (GObject
*object
,
126 GiggleGitWriteConfigPriv
*priv
;
128 priv
= GET_PRIV (object
);
132 g_value_set_boolean (value
, priv
->global
);
135 g_value_set_string (value
, priv
->field
);
138 g_value_set_string (value
, priv
->value
);
141 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
147 git_write_config_set_property (GObject
*object
,
152 GiggleGitWriteConfigPriv
*priv
;
154 priv
= GET_PRIV (object
);
158 priv
->global
= g_value_get_boolean (value
);
162 g_free (priv
->field
);
164 priv
->field
= g_value_dup_string (value
);
168 g_free (priv
->value
);
170 priv
->value
= g_value_dup_string (value
);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
179 git_write_config_get_command_line (GiggleJob
*job
,
180 gchar
**command_line
)
182 GiggleGitWriteConfigPriv
*priv
;
184 priv
= GET_PRIV (job
);
186 *command_line
= g_strdup_printf (GIT_COMMAND
" repo-config %s %s \"%s\"",
187 (priv
->global
) ? "--global" : "",
188 priv
->field
, priv
->value
);
193 git_write_config_handle_output (GiggleJob
*job
,
194 const gchar
*output_str
,
201 giggle_git_write_config_new (const gchar
*field
,
204 g_return_val_if_fail (field
!= NULL
, NULL
);
206 return g_object_new (GIGGLE_TYPE_GIT_WRITE_CONFIG
,