changed the refresh hotkey
[giggle.git] / libgiggle / giggle-remote-branch.c
blob4148dd846904d8836bd0679ef7e85c03ecff30ae
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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.
21 #include <config.h>
23 #include "giggle-remote-branch.h"
24 #include "giggle-enums.h"
26 typedef struct GiggleRemoteBranchPriv GiggleRemoteBranchPriv;
28 struct GiggleRemoteBranchPriv {
29 GiggleRemoteDirection direction;
30 gchar *refspec;
33 enum {
34 PROP_0,
35 PROP_DIRECTION,
36 PROP_REFSPEC
39 static void remote_branch_finalize (GObject *object);
40 static void remote_branch_get_property (GObject *object,
41 guint param_id,
42 GValue *value,
43 GParamSpec *pspec);
44 static void remote_branch_set_property (GObject *object,
45 guint param_id,
46 const GValue *value,
47 GParamSpec *pspec);
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))
53 static void
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,
63 PROP_DIRECTION,
64 g_param_spec_enum ("direction",
65 "Direction",
66 "The direction of the remote branch (push or pull)",
67 GIGGLE_TYPE_REMOTE_DIRECTION,
68 GIGGLE_REMOTE_DIRECTION_PULL,
69 G_PARAM_READWRITE));
70 g_object_class_install_property (object_class,
71 PROP_REFSPEC,
72 g_param_spec_string ("refspec",
73 "RefSpec",
74 "The specification for the head to be synchronized",
75 NULL,
76 G_PARAM_READWRITE));
78 g_type_class_add_private (object_class, sizeof (GiggleRemoteBranchPriv));
81 static void
82 giggle_remote_branch_init (GiggleRemoteBranch *remote_branch)
84 GiggleRemoteBranchPriv *priv;
86 priv = GET_PRIV (remote_branch);
89 static void
90 remote_branch_finalize (GObject *object)
92 GiggleRemoteBranchPriv *priv;
94 priv = GET_PRIV (object);
96 g_free (priv->refspec);
97 priv->refspec = NULL;
99 G_OBJECT_CLASS (giggle_remote_branch_parent_class)->finalize (object);
102 static void
103 remote_branch_get_property (GObject *object,
104 guint param_id,
105 GValue *value,
106 GParamSpec *pspec)
108 GiggleRemoteBranchPriv *priv;
110 priv = GET_PRIV (object);
112 switch (param_id) {
113 case PROP_DIRECTION:
114 g_value_set_enum (value, priv->direction);
115 break;
116 case PROP_REFSPEC:
117 g_value_set_string (value, priv->refspec);
118 break;
119 default:
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
121 break;
125 static void
126 remote_branch_set_property (GObject *object,
127 guint param_id,
128 const GValue *value,
129 GParamSpec *pspec)
131 GiggleRemoteBranchPriv *priv;
133 priv = GET_PRIV (object);
135 switch (param_id) {
136 case PROP_DIRECTION:
137 priv->direction = g_value_get_enum (value);
138 g_object_notify (object, "direction");
139 break;
140 case PROP_REFSPEC:
141 giggle_remote_branch_set_refspec (GIGGLE_REMOTE_BRANCH (object), g_value_get_string (value));
142 break;
143 default:
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
145 break;
149 GiggleRemoteBranch *
150 giggle_remote_branch_new (GiggleRemoteDirection direction,
151 const gchar *refspec)
153 return g_object_new (GIGGLE_TYPE_REMOTE_BRANCH,
154 "direction", direction,
155 "refspec", refspec,
156 NULL);
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;
167 gchar const *
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;
175 void
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) {
186 return;
189 g_free (priv->refspec);
190 priv->refspec = g_strdup (refspec);
191 g_object_notify (G_OBJECT (self), "refspec");