* plugins/project-wizard/templates/terminal.wiz,
[anjuta-git-plugin.git] / src / about.c
blob2fb6d4dee2f686b9886db0d51f435ab0942716a6
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 about.c
4 Copyright (C) 2002 Naba Kumar <naba@gnome.org>
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
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <gtk/gtkaboutdialog.h>
26 #include <libanjuta/anjuta-plugin-manager.h>
28 #include "about.h"
30 #define ANJUTA_PIXMAP_LOGO "anjuta_logo.png"
31 #define ABOUT_AUTHORS "AUTHORS"
32 #define MAX_CAR 256
33 #define MAX_CREDIT 500
35 const gchar *authors[MAX_CREDIT];
36 const gchar *documenters[MAX_CREDIT];
37 gchar *translators;
40 static gchar*
41 about_read_line(FILE *fp)
43 static gchar tpn[MAX_CAR];
44 char *pt;
45 char c;
47 pt = tpn;
48 while( ((c=getc(fp))!='\n') && (c!=EOF) && ((pt-tpn)<MAX_CAR) )
49 *(pt++)=c;
50 *pt = '\0';
51 if ( c!=EOF)
52 return tpn;
53 else
54 return NULL;
57 static gchar*
58 about_read_developers(FILE *fp, gchar *line, gint *index, const gchar **tab)
62 if (*index < MAX_CREDIT)
63 tab[(*index)++] = g_strdup_printf("%s", line);
64 if ( !(line = about_read_line(fp)))
65 return NULL;
66 line = g_strchomp(line);
68 while (!g_str_has_suffix(line, ":") );
70 return line;
73 static gchar*
74 read_documenters(FILE *fp, gchar *line, gint *index, const gchar **tab)
78 if (*index < MAX_CREDIT)
79 tab[(*index)++] = g_strdup_printf("%s", line);
80 if ( !(line = about_read_line(fp)))
81 return NULL;
82 line = g_strchomp(line);
84 while ( !g_str_has_suffix(line, ":") );
86 return line;
89 static gchar*
90 read_translators(FILE *fp, gchar *line)
92 gboolean found = FALSE;
93 gchar *env_lang = getenv("LANG");
97 if ( !(line = about_read_line(fp)))
98 return NULL;
100 line = g_strchug(line);
101 if (!found && g_str_has_prefix(line, env_lang) )
103 found = TRUE;
104 gchar *tmp = g_strdup(line + strlen(env_lang));
105 tmp = g_strchug(tmp);
106 translators = g_strconcat("\n\n", tmp, NULL);
107 g_free(tmp);
109 line = g_strchomp(line);
111 while ( !g_str_has_suffix(line, ":") );
113 return line;
116 static void
117 about_read_file(void)
119 FILE *fp;
120 gchar *line;
121 gint i_auth = 0;
122 gint i_doc = 0;
124 fp = fopen(PACKAGE_DATA_DIR"/"ABOUT_AUTHORS, "r");
126 g_return_if_fail (fp != NULL);
127 line = about_read_line(fp);
130 line = g_strchomp(line);
131 if (g_str_has_suffix(line, "Developer:") ||
132 g_str_has_suffix(line, "Developers:") ||
133 g_str_has_suffix(line, "Contributors:") ||
134 g_str_has_suffix(line, "Note:"))
136 line = about_read_developers(fp, line, &i_auth, authors);
138 else if (g_str_has_suffix(line, "Website:") ||
139 g_str_has_suffix(line, "Documenters:") )
141 line = read_documenters(fp, line, &i_doc, documenters);
143 else if (g_str_has_suffix(line, "Translators:") )
145 line = read_translators(fp, line);
147 else
148 line = about_read_line(fp);
150 while (line);
151 fclose(fp);
154 static void
155 about_free_credit(void)
157 gint i = 0;
159 gchar** ptr = (gchar**) authors;
160 for(i=0; ptr[i]; i++)
161 g_free (ptr[i]);
162 ptr = (gchar**) documenters;
163 for(i=0; ptr[i]; i++)
164 g_free (ptr[i]);
166 g_free(translators);
169 GtkWidget *
170 about_box_new ()
172 GtkWidget *dialog;
173 GdkPixbuf *pix;
175 /* Parse AUTHORS file */
176 about_read_file();
178 pix = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"ANJUTA_PIXMAP_LOGO,
179 NULL);
181 dialog = gtk_about_dialog_new();
182 gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), "Anjuta");
183 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
184 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
185 _("Copyright (c) Naba Kumar"));
186 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
187 _("Integrated Development Environment"));
188 gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(dialog),
189 NULL);
190 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://www.anjuta.org");
191 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pix);
193 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors);
194 gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), documenters);
195 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), translators);
196 /* We should fill this!
197 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), ???);*/
198 /* Free authors, documenters, translators */
199 about_free_credit();
200 g_object_unref (pix);
201 return dialog;
204 static void
205 on_about_plugin_activate (GtkMenuItem *item, AnjutaPluginDescription *desc)
207 gchar *name = NULL;
208 gchar *authors = NULL;
209 gchar **authors_v = NULL;
210 gchar *icon = NULL;
211 gchar *d = NULL;
212 GdkPixbuf *pix = NULL;
213 GtkWidget *dialog;
215 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
216 "Name", &name);
217 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
218 "Description", &d);
219 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
220 "Icon", &icon);
221 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
222 "Authors", &authors);
223 if (icon)
225 gchar *path = g_build_filename (PACKAGE_PIXMAPS_DIR, icon, NULL);
226 pix = gdk_pixbuf_new_from_file (path, NULL);
227 g_free (path);
229 if (authors)
231 authors_v = g_strsplit(authors, ",", -1);
233 dialog = gtk_about_dialog_new();
234 gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), name);
235 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
236 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
237 _("Anjuta Plugin"));
238 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),d);
239 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pix);
241 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog),
242 (const gchar **)authors_v);
244 gtk_widget_show (dialog);
245 g_object_unref (pix);
246 g_strfreev (authors_v);
247 g_free (name);
248 g_free (d);
249 g_free (authors);
250 g_free (icon);
253 void
254 about_create_plugins_submenu (AnjutaShell *shell, GtkWidget *menuitem)
256 GtkWidget *submenu;
257 GList *plugin_descs, *node;
259 g_return_if_fail (ANJUTA_IS_SHELL (shell));
260 g_return_if_fail (GTK_IS_MENU_ITEM (menuitem));
262 submenu = gtk_menu_new ();
263 gtk_widget_show (submenu);
264 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
266 plugin_descs =
267 anjuta_plugin_manager_query (anjuta_shell_get_plugin_manager (shell, NULL),
268 NULL, NULL, NULL, NULL);
269 node = plugin_descs;
270 while (node)
272 gchar *label;
273 GtkWidget *item;
274 AnjutaPluginDescription *desc = node->data;
275 if (anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
276 "Name", &label))
278 gchar *authors;
279 if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
280 "Authors", &authors))
282 item = gtk_menu_item_new_with_label (label);
283 gtk_widget_show (item);
284 g_signal_connect (G_OBJECT (item), "activate",
285 G_CALLBACK (on_about_plugin_activate),
286 desc);
287 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
288 g_free (authors);
290 g_free (label);
292 node = g_list_next (node);