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.
23 #include "giggle-remote-branch.h"
24 #include "giggle-enums.h"
26 typedef struct GiggleRemoteBranchPriv GiggleRemoteBranchPriv
;
28 struct GiggleRemoteBranchPriv
{
29 GiggleRemoteDirection direction
;
39 static void remote_branch_finalize (GObject
*object
);
40 static void remote_branch_get_property (GObject
*object
,
44 static void remote_branch_set_property (GObject
*object
,
49 G_DEFINE_TYPE (GiggleRemoteBranch
, giggle_remote_branch
, G_TYPE_OBJECT
)
51 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_REMOTE_BRANCH, GiggleRemoteBranchPriv))
54 giggle_remote_branch_class_init (GiggleRemoteBranchClass
*class)
56 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
58 object_class
->finalize
= remote_branch_finalize
;
59 object_class
->get_property
= remote_branch_get_property
;
60 object_class
->set_property
= remote_branch_set_property
;
62 g_object_class_install_property (object_class
,
64 g_param_spec_enum ("direction",
66 "The direction of the remote branch (push or pull)",
67 GIGGLE_TYPE_REMOTE_DIRECTION
,
68 GIGGLE_REMOTE_DIRECTION_PULL
,
70 g_object_class_install_property (object_class
,
72 g_param_spec_string ("refspec",
74 "The specification for the head to be synchronized",
78 g_type_class_add_private (object_class
, sizeof (GiggleRemoteBranchPriv
));
82 giggle_remote_branch_init (GiggleRemoteBranch
*remote_branch
)
84 GiggleRemoteBranchPriv
*priv
;
86 priv
= GET_PRIV (remote_branch
);
90 remote_branch_finalize (GObject
*object
)
92 GiggleRemoteBranchPriv
*priv
;
94 priv
= GET_PRIV (object
);
96 g_free (priv
->refspec
);
99 G_OBJECT_CLASS (giggle_remote_branch_parent_class
)->finalize (object
);
103 remote_branch_get_property (GObject
*object
,
108 GiggleRemoteBranchPriv
*priv
;
110 priv
= GET_PRIV (object
);
114 g_value_set_enum (value
, priv
->direction
);
117 g_value_set_string (value
, priv
->refspec
);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
126 remote_branch_set_property (GObject
*object
,
131 GiggleRemoteBranchPriv
*priv
;
133 priv
= GET_PRIV (object
);
137 priv
->direction
= g_value_get_enum (value
);
138 g_object_notify (object
, "direction");
141 giggle_remote_branch_set_refspec (GIGGLE_REMOTE_BRANCH (object
), g_value_get_string (value
));
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
150 giggle_remote_branch_new (GiggleRemoteDirection direction
,
151 const gchar
*refspec
)
153 return g_object_new (GIGGLE_TYPE_REMOTE_BRANCH
,
154 "direction", direction
,
159 GiggleRemoteDirection
160 giggle_remote_branch_get_direction (GiggleRemoteBranch
*self
)
162 g_return_val_if_fail (GIGGLE_IS_REMOTE_BRANCH (self
), GIGGLE_REMOTE_DIRECTION_PULL
);
164 return GET_PRIV (self
)->direction
;
168 giggle_remote_branch_get_refspec (GiggleRemoteBranch
*branch
)
170 g_return_val_if_fail (GIGGLE_IS_REMOTE_BRANCH (branch
), NULL
);
172 return GET_PRIV (branch
)->refspec
;
176 giggle_remote_branch_set_refspec (GiggleRemoteBranch
*self
,
177 const gchar
*refspec
)
179 GiggleRemoteBranchPriv
*priv
;
181 g_return_if_fail (GIGGLE_IS_REMOTE_BRANCH (self
));
183 priv
= GET_PRIV (self
);
185 if (priv
->refspec
== refspec
) {
189 g_free (priv
->refspec
);
190 priv
->refspec
= g_strdup (refspec
);
191 g_object_notify (G_OBJECT (self
), "refspec");