1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4; coding: utf-8 -*- */
4 * Copyright (C) 2009 Sébastien Granjoux
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
27 #include "amp-source.h"
30 #include "am-scanner.h"
31 #include "am-properties.h"
32 #include "am-writer.h"
35 #include <libanjuta/interfaces/ianjuta-project.h>
37 #include <libanjuta/anjuta-debug.h>
39 #include <glib/gi18n.h>
46 *---------------------------------------------------------------------------*/
48 struct _AmpSourceNode
{
49 AnjutaProjectNode base
;
57 *---------------------------------------------------------------------------*/
60 amp_source_node_get_token (AmpSourceNode
*node
)
66 amp_source_node_add_token (AmpSourceNode
*node
, AnjutaToken
*token
)
72 amp_source_node_update_node (AmpSourceNode
*node
, AmpSourceNode
*new_node
)
74 node
->token
= new_node
->token
;
78 amp_source_node_new (GFile
*file
, AnjutaProjectNodeType type
)
80 AmpSourceNode
*node
= NULL
;
82 node
= g_object_new (AMP_TYPE_SOURCE_NODE
, NULL
);
83 node
->base
.file
= g_object_ref (file
);
84 node
->base
.type
= ANJUTA_PROJECT_SOURCE
| type
;
86 return ANJUTA_PROJECT_NODE (node
);
90 amp_source_node_new_valid (GFile
*file
, AnjutaProjectNodeType type
, GError
**error
)
92 /* Validate source name */
94 if (g_file_query_file_type (file
, G_FILE_QUERY_INFO_NONE
, NULL
) == G_FILE_TYPE_DIRECTORY
)
96 amp_set_error (error
, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED
,
97 _("Source file must be a regular file, not a directory"));
102 return amp_source_node_new (file
, type
);
106 amp_source_node_set_file (AmpSourceNode
*source
, GFile
*new_file
)
108 g_object_unref (source
->base
.file
);
109 source
->base
.file
= g_object_ref (new_file
);
115 amp_source_node_free (AmpSourceNode
*node
)
117 g_object_unref (G_OBJECT (node
));
120 /* AmpNode implementation
121 *---------------------------------------------------------------------------*/
124 amp_source_node_update (AmpNode
*node
, AmpNode
*new_node
)
126 amp_source_node_update_node (AMP_SOURCE_NODE (node
), AMP_SOURCE_NODE (new_node
));
132 amp_source_node_write (AmpNode
*node
, AmpNode
*parent
, AmpProject
*project
, GError
**error
)
134 return amp_source_node_create_token (project
, AMP_SOURCE_NODE (node
), error
);
138 amp_source_node_erase (AmpNode
*node
, AmpNode
*parent
, AmpProject
*project
, GError
**error
)
140 return amp_source_node_delete_token (project
, AMP_SOURCE_NODE (node
), error
);
146 /* GObjet implementation
147 *---------------------------------------------------------------------------*/
149 typedef struct _AmpSourceNodeClass AmpSourceNodeClass
;
151 struct _AmpSourceNodeClass
{
152 AmpNodeClass parent_class
;
155 G_DEFINE_DYNAMIC_TYPE (AmpSourceNode
, amp_source_node
, AMP_TYPE_NODE
);
158 amp_source_node_init (AmpSourceNode
*node
)
160 node
->base
.type
= ANJUTA_PROJECT_SOURCE
;
161 node
->base
.properties_info
= amp_get_source_property_list();
162 node
->base
.state
= ANJUTA_PROJECT_CAN_REMOVE
;
167 amp_source_node_finalize (GObject
*object
)
169 AmpSourceNode
*node
= AMP_SOURCE_NODE (object
);
171 G_OBJECT_CLASS (amp_source_node_parent_class
)->finalize (object
);
175 amp_source_node_class_init (AmpSourceNodeClass
*klass
)
177 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
178 AmpNodeClass
* node_class
;
180 object_class
->finalize
= amp_source_node_finalize
;
182 node_class
= AMP_NODE_CLASS (klass
);
183 node_class
->update
= amp_source_node_update
;
184 node_class
->write
= amp_source_node_write
;
185 node_class
->erase
= amp_source_node_erase
;
189 amp_source_node_class_finalize (AmpSourceNodeClass
*klass
)
194 amp_source_node_register (GTypeModule
*module
)
196 amp_source_node_register_type (module
);