1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *---------------------------------------------------------------------------*/
33 #include <libanjuta/anjuta-debug.h>
34 #include <libanjuta/interfaces/ianjuta-wizard.h>
35 #include <libanjuta/interfaces/ianjuta-file.h>
39 *---------------------------------------------------------------------------*/
42 npw_open_project_template (GFile
*destination
, GFile
*tarfile
, gpointer data
, GError
*error
)
44 NPWPlugin
*plugin
= (NPWPlugin
*)data
;
48 gchar
*tarname
= g_file_get_path (tarfile
);
50 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin
)->shell
),_("Unable to extract project template %s: %s"), tarname
, error
->message
);
54 /* Show the project wizard dialog, loading only the new projects */
55 npw_plugin_show_wizard (plugin
, destination
);
60 npw_install_project_template_with_callback (NPWPlugin
*plugin
, GFile
*file
, NPWTarCompleteFunc callback
, GError
**error
)
62 GFileInputStream
*stream
;
70 /* Check if tarfile exist */
71 stream
= g_file_read (file
, NULL
, error
);
76 g_input_stream_close (G_INPUT_STREAM (stream
), NULL
, NULL
);
78 /* Get name without extension */
79 name
= g_file_get_basename (file
);
80 ext
= strchr (name
, '.');
81 if (ext
!= NULL
) *ext
= '\0';
83 /* Create a directory for template */
84 path
= g_build_filename (g_get_user_data_dir (), "anjuta", "templates", name
, NULL
);
86 dest
= g_file_new_for_path (path
);
88 ok
= g_file_make_directory_with_parents (dest
, NULL
, &err
);
91 if (err
->code
== G_IO_ERROR_EXISTS
)
93 /* Allow to overwrite directories */
99 g_object_unref (dest
);
105 ok
= npw_tar_extract (dest
, file
, callback
, plugin
, error
);
106 g_object_unref (dest
);
112 *---------------------------------------------------------------------------*/
114 /* Display the project wizard selection dialog using only templates in the
115 * specified directory if non NULL */
117 npw_plugin_show_wizard (NPWPlugin
*plugin
, GFile
*project
)
119 if (plugin
->install
!= NULL
)
121 /* New project wizard is busy copying project file */
123 else if (plugin
->druid
== NULL
)
125 /* Create a new project wizard druid */
126 npw_druid_new (plugin
, project
);
129 if (plugin
->druid
!= NULL
)
131 /* New project wizard druid is waiting for user inputs */
132 npw_druid_show (plugin
->druid
);
139 /*---------------------------------------------------------------------------*/
141 /* Used in dispose */
142 static gpointer parent_class
;
145 npw_plugin_instance_init (GObject
*obj
)
147 NPWPlugin
*plugin
= ANJUTA_PLUGIN_NPW (obj
);
149 plugin
->druid
= NULL
;
150 plugin
->install
= NULL
;
154 /* dispose is used to unref object created with instance_init */
157 npw_plugin_dispose (GObject
*obj
)
159 NPWPlugin
*plugin
= ANJUTA_PLUGIN_NPW (obj
);
161 /* Warning this function could be called several times */
162 if (plugin
->view
!= NULL
)
164 g_object_remove_weak_pointer (G_OBJECT (plugin
->view
),
165 (gpointer
*)(gpointer
)&plugin
->view
);
169 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
173 npw_plugin_finalize (GObject
*obj
)
175 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
178 /* finalize used to free object created with instance init is not used */
181 npw_plugin_activate (AnjutaPlugin
*plugin
)
183 DEBUG_PRINT ("%s", "Project Wizard Plugin: Activating project wizard plugin...");
188 npw_plugin_deactivate (AnjutaPlugin
*plugin
)
190 DEBUG_PRINT ("%s", "Project Wizard Plugin: Deactivating project wizard plugin...");
195 npw_plugin_class_init (GObjectClass
*klass
)
197 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
199 parent_class
= g_type_class_peek_parent (klass
);
201 plugin_class
->activate
= npw_plugin_activate
;
202 plugin_class
->deactivate
= npw_plugin_deactivate
;
203 klass
->dispose
= npw_plugin_dispose
;
204 klass
->finalize
= npw_plugin_finalize
;
207 /* IAnjutaWizard implementation
208 *---------------------------------------------------------------------------*/
211 iwizard_activate (IAnjutaWizard
*wiz
, GError
**err
)
213 npw_plugin_show_wizard (ANJUTA_PLUGIN_NPW (wiz
), NULL
);
217 iwizard_iface_init (IAnjutaWizardIface
*iface
)
219 iface
->activate
= iwizard_activate
;
222 /* IAnjutaFile implementation
223 *---------------------------------------------------------------------------*/
226 ifile_open (IAnjutaFile
*ifile
, GFile
* file
, GError
**error
)
228 NPWPlugin
*plugin
= ANJUTA_PLUGIN_NPW (ifile
);
231 info
= g_file_query_info (file
, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
, 0, NULL
, NULL
);
234 if (strcmp(g_file_info_get_content_type (info
), "application/x-anjuta-project-template") == 0)
236 npw_plugin_show_wizard (plugin
, file
);
240 npw_install_project_template_with_callback (plugin
, file
, npw_open_project_template
, error
);
242 g_object_unref (info
);
247 ifile_get_file (IAnjutaFile
* ifile
, GError
** error
)
253 ifile_iface_init(IAnjutaFileIface
*iface
)
255 iface
->open
= ifile_open
;
256 iface
->get_file
= ifile_get_file
;
259 ANJUTA_PLUGIN_BEGIN (NPWPlugin
, npw_plugin
);
260 ANJUTA_PLUGIN_ADD_INTERFACE (ifile
, IANJUTA_TYPE_FILE
);
261 ANJUTA_PLUGIN_ADD_INTERFACE (iwizard
, IANJUTA_TYPE_WIZARD
);
264 ANJUTA_SIMPLE_PLUGIN (NPWPlugin
, npw_plugin
);
266 /* Control access to anjuta message view to avoid a closed view
267 *---------------------------------------------------------------------------*/
270 on_message_buffer_flush (IAnjutaMessageView
*view
, const gchar
*line
,
273 npw_plugin_print_view (plugin
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
, "");
277 npw_plugin_create_view (NPWPlugin
* plugin
)
279 if (plugin
->view
== NULL
)
281 IAnjutaMessageManager
* man
;
283 man
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
284 IAnjutaMessageManager
, NULL
);
286 ianjuta_message_manager_add_view (man
, _("New Project Assistant"),
288 if (plugin
->view
!= NULL
)
290 g_signal_connect (G_OBJECT (plugin
->view
), "buffer_flushed",
291 G_CALLBACK (on_message_buffer_flush
), plugin
);
292 g_object_add_weak_pointer (G_OBJECT (plugin
->view
),
293 (gpointer
*)(gpointer
)&plugin
->view
);
298 ianjuta_message_view_clear (plugin
->view
, NULL
);
305 npw_plugin_append_view (NPWPlugin
* plugin
, const gchar
* text
)
309 ianjuta_message_view_buffer_append (plugin
->view
, text
, NULL
);
314 npw_plugin_print_view (NPWPlugin
* plugin
, IAnjutaMessageViewType type
,
315 const gchar
* summary
, const gchar
* details
)
319 ianjuta_message_view_append (plugin
->view
, type
, summary
, details
, NULL
);