2008-06-16 Abderrahim Kitouni <a.kitouni@gmail.com>
[anjuta-git-plugin.git] / plugins / build / configurer.c
blob5aa1979800094f8fcaf258289d2cb7318f5f0d29
1 /*
2 * configurer.c Copyright (C) 2000 Kh. Naba Kumar Singh
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc., 59
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <signal.h>
28 #include <time.h>
30 #include <gnome.h>
32 #include <libanjuta/resources.h>
34 #include "anjuta.h"
35 #include "message-manager.h"
36 #include "text_editor.h"
37 #include "utilities.h"
38 #include "launcher.h"
39 #include "configurer.h"
40 #include "build_file.h"
42 static GtkWidget* create_configurer_dialog (Configurer* c);
43 static void on_configurer_response (GtkDialog *dialog, gint res, gpointer data);
44 static void on_configurer_entry_changed (GtkEditable *editable, gpointer data);
46 static void on_configurer_environment_changed (GtkEditable * editable,
47 gpointer user_data);
50 Configurer *
51 configurer_new (PropsID props)
53 Configurer *c = g_new0 (Configurer, 1);
54 c->props = props;
55 return c;
58 void
59 configurer_destroy (Configurer * c)
61 g_return_if_fail (c != NULL);
62 g_free (c);
65 void
66 configurer_show (Configurer * c)
68 gtk_widget_show (create_configurer_dialog (c));
71 static GtkWidget *
72 create_configurer_dialog (Configurer * c)
74 GtkWidget *dialog;
75 GtkWidget *entry;
76 gchar *options;
78 GladeXML *gxml;
79 gxml = glade_xml_new (GLADE_FILE_ANJUTA, "configurer_dialog", NULL);
80 dialog = glade_xml_get_widget (gxml, "configurer_dialog");
81 g_signal_connect (G_OBJECT (dialog), "response",
82 G_CALLBACK (on_configurer_response), c);
83 gtk_widget_show (dialog);
85 entry = glade_xml_get_widget (gxml, "configurer_entry");
86 options = prop_get (c->props, "project.configure.options");
87 if (options)
89 gtk_entry_set_text (GTK_ENTRY (entry), options);
90 g_free (options);
92 g_signal_connect (G_OBJECT (entry), "changed",
93 G_CALLBACK (on_configurer_entry_changed), c);
95 /* Not implemented yet
97 entry = glade_xml_get_widget (gxml, "configurer_environment_entry");
98 options = prop_get (c->props, "project.configure.environment");
99 if (options)
101 gtk_entry_set_text (GTK_ENTRY (entry), options);
102 g_free (options);
104 g_signal_connect (G_OBJECT (entry), "changed",
105 G_CALLBACK (on_configurer_environment_changed), c); */
107 g_object_unref (G_OBJECT (gxml));
109 /* gtk_accel_group_attach (app->accel_group, GTK_OBJECT (dialog)); */
110 return dialog;
113 static void
114 on_configurer_entry_changed (GtkEditable * editable, gpointer user_data)
116 Configurer *c = (Configurer *) user_data;
117 const gchar *options;
118 options = gtk_entry_get_text (GTK_ENTRY (editable));
119 if (options)
120 prop_set_with_key (c->props, "project.configure.options",
121 options);
122 else
123 prop_set_with_key (c->props, "project.configure.options", "");
126 /* FIXME: ... */
127 #if 0
128 static void
129 on_configurer_environment_changed (GtkEditable * editable, gpointer user_data)
131 Configurer *c = (Configurer *) user_data;
132 const gchar *options;
133 options = gtk_entry_get_text (GTK_ENTRY (editable));
134 if (options)
135 prop_set_with_key (c->props, "project.configure.environment",
136 options);
137 else
138 prop_set_with_key (c->props, "project.configure.environment", "");
140 #endif
142 static void
143 on_configurer_response (GtkDialog* dialog, gint res, gpointer user_data)
145 Configurer *cof;
146 gchar *tmp, *options;
147 cof = user_data;
149 g_return_if_fail (cof != NULL);
150 if (res == GTK_RESPONSE_OK)
152 g_return_if_fail (app->project_dbase->project_is_open);
154 chdir (app->project_dbase->top_proj_dir);
155 if (file_is_executable ("./configure") == FALSE)
157 anjuta_error (_
158 ("Project does not have an executable configure script.\n"
159 "Auto generate the Project first."));
160 return;
162 options = prop_get (cof->props, "project.configure.options");
163 if (options)
165 tmp = g_strconcat ("./configure ", options, NULL);
166 g_free (options);
168 else
170 tmp = g_strdup ("./configure ");
172 options = prop_get(cof->props, "project.configure.environment");
173 if (options)
175 gchar *tmp1 = g_strdup_printf("sh -c '%s %s'", options, tmp);
176 g_free(tmp);
177 tmp = tmp1;
179 #ifdef DEBUG
180 g_message("Executing '%s'\n", tmp);
181 #endif
182 if (build_execute_command (tmp) == FALSE)
184 anjuta_error ("Project configuration failed.");
185 g_free (tmp);
186 return;
188 g_free (tmp);
189 anjuta_update_app_status (TRUE, _("Configure"));
190 an_message_manager_clear (app->messages, MESSAGE_BUILD);
191 an_message_manager_append (app->messages, _("Configuring the Project...\n"), MESSAGE_BUILD);
192 an_message_manager_show (app->messages, MESSAGE_BUILD);
194 gtk_widget_destroy (GTK_WIDGET (dialog));