~ubuntu-branches/ubuntu/lucid/giggle/lucid

« back to all changes in this revision

Viewing changes to src/giggle-git-read-config.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrea Corradi
  • Date: 2009-03-30 19:41:43 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090330194143-nyr9ze1xola1shm5
Tags: 0.4.91-1
* New upstream release (Closes:  #519014)
* Use Standards-Version 3.8.1
* Add new Build-Depends
* Update Homepage and watch file
* Update debian/copyright
* Remove patch
* Update path in debian/rules
* Remove defs option from LDFLAGS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * Copyright (C) 2007 Imendio AB
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
 
23
 
#include <string.h>
24
 
 
25
 
#include "giggle-git-read-config.h"
26
 
 
27
 
typedef struct GiggleGitReadConfigPriv GiggleGitReadConfigPriv;
28
 
 
29
 
struct GiggleGitReadConfigPriv {
30
 
        GHashTable *hash_table;
31
 
};
32
 
 
33
 
static void     git_read_config_finalize         (GObject           *object);
34
 
static void     git_read_config_get_property     (GObject           *object,
35
 
                                                  guint              param_id,
36
 
                                                  GValue            *value,
37
 
                                                  GParamSpec        *pspec);
38
 
static void     git_read_config_set_property     (GObject           *object,
39
 
                                                  guint              param_id,
40
 
                                                  const GValue      *value,
41
 
                                                  GParamSpec        *pspec);
42
 
 
43
 
static gboolean git_read_config_get_command_line (GiggleJob         *job,
44
 
                                                  gchar            **command_line);
45
 
static void     git_read_config_handle_output    (GiggleJob         *job,
46
 
                                                  const gchar       *output_str,
47
 
                                                  gsize              output_len);
48
 
 
49
 
 
50
 
G_DEFINE_TYPE (GiggleGitReadConfig, giggle_git_read_config, GIGGLE_TYPE_JOB)
51
 
 
52
 
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_READ_CONFIG, GiggleGitReadConfigPriv))
53
 
 
54
 
 
55
 
static void
56
 
giggle_git_read_config_class_init (GiggleGitReadConfigClass *class)
57
 
{
58
 
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
59
 
        GiggleJobClass *job_class    = GIGGLE_JOB_CLASS (class);
60
 
 
61
 
        object_class->finalize     = git_read_config_finalize;
62
 
        object_class->get_property = git_read_config_get_property;
63
 
        object_class->set_property = git_read_config_set_property;
64
 
 
65
 
        job_class->get_command_line = git_read_config_get_command_line;
66
 
        job_class->handle_output    = git_read_config_handle_output;
67
 
 
68
 
        g_type_class_add_private (object_class, sizeof (GiggleGitReadConfigPriv));
69
 
}
70
 
 
71
 
static void
72
 
giggle_git_read_config_init (GiggleGitReadConfig *read_config)
73
 
{
74
 
        GiggleGitReadConfigPriv *priv;
75
 
 
76
 
        priv = GET_PRIV (read_config);
77
 
 
78
 
        priv->hash_table = g_hash_table_new_full (g_str_hash,
79
 
                                                  g_str_equal,
80
 
                                                  g_free,
81
 
                                                  g_free);
82
 
}
83
 
 
84
 
static void
85
 
git_read_config_finalize (GObject *object)
86
 
{
87
 
        GiggleGitReadConfigPriv *priv;
88
 
 
89
 
        priv = GET_PRIV (object);
90
 
 
91
 
        g_hash_table_unref (priv->hash_table);
92
 
 
93
 
        G_OBJECT_CLASS (giggle_git_read_config_parent_class)->finalize (object);
94
 
}
95
 
 
96
 
static void
97
 
git_read_config_get_property (GObject    *object,
98
 
                              guint       param_id,
99
 
                              GValue     *value,
100
 
                              GParamSpec *pspec)
101
 
{
102
 
        GiggleGitReadConfigPriv *priv;
103
 
 
104
 
        priv = GET_PRIV (object);
105
 
        
106
 
        switch (param_id) {
107
 
        default:
108
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
109
 
                break;
110
 
        }
111
 
}
112
 
 
113
 
static void
114
 
git_read_config_set_property (GObject      *object,
115
 
                              guint         param_id,
116
 
                              const GValue *value,
117
 
                              GParamSpec   *pspec)
118
 
{
119
 
        GiggleGitReadConfigPriv *priv;
120
 
 
121
 
        priv = GET_PRIV (object);
122
 
 
123
 
        switch (param_id) {
124
 
        default:
125
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
126
 
                break;
127
 
        }
128
 
}
129
 
 
130
 
static gboolean
131
 
git_read_config_get_command_line (GiggleJob  *job,
132
 
                                  gchar     **command_line)
133
 
{
134
 
        *command_line = g_strdup_printf (GIT_COMMAND " repo-config --list");
135
 
        return TRUE;
136
 
}
137
 
 
138
 
static void
139
 
git_read_config_handle_output (GiggleJob   *job,
140
 
                               const gchar *output_str,
141
 
                               gsize        output_len)
142
 
{
143
 
        GiggleGitReadConfigPriv  *priv;
144
 
        gchar                   **lines, **line;
145
 
        gint                      i;
146
 
 
147
 
        priv = GET_PRIV (job);
148
 
        lines = g_strsplit (output_str, "\n", -1);
149
 
 
150
 
        for (i = 0; lines[i] && *lines[i]; i++) {
151
 
                line = g_strsplit (lines[i], "=", 2);
152
 
                g_hash_table_insert (priv->hash_table, g_strdup (line[0]), g_strdup (line[1]));
153
 
                g_strfreev (line);
154
 
        }
155
 
 
156
 
        g_strfreev (lines);
157
 
}
158
 
 
159
 
GiggleJob *
160
 
giggle_git_read_config_new (void)
161
 
{
162
 
        return g_object_new (GIGGLE_TYPE_GIT_READ_CONFIG, NULL);
163
 
}
164
 
 
165
 
GHashTable *
166
 
giggle_git_read_config_get_config (GiggleGitReadConfig *config)
167
 
{
168
 
        GiggleGitReadConfigPriv *priv;
169
 
 
170
 
        g_return_val_if_fail (GIGGLE_IS_GIT_READ_CONFIG (config), NULL);
171
 
 
172
 
        priv = GET_PRIV (config);
173
 
        return priv->hash_table;
174
 
}