Added Spanish translation
[anjuta.git] / src / about.c
blobce08781b7ded3f2409fb41a6db7b7dd83b74fd63
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/gtk.h>
26 #include <stdlib.h>
27 #include <libanjuta/anjuta-plugin-manager.h>
29 #include "about.h"
31 #define ANJUTA_PIXMAP_LOGO "anjuta_logo.png"
32 #define ABOUT_AUTHORS "AUTHORS"
33 #define MAX_CAR 256
34 #define MAX_CREDIT 500
36 static const gchar *authors[MAX_CREDIT];
37 static const gchar *documenters[MAX_CREDIT];
38 static gchar *translators;
41 static gchar*
42 about_read_line(FILE *fp)
44 static gchar tpn[MAX_CAR];
45 char *pt;
46 char c;
48 pt = tpn;
49 while( ((c=getc(fp))!='\n') && (c!=EOF) && ((pt-tpn)<MAX_CAR) )
50 *(pt++)=c;
51 *pt = '\0';
52 if ( c!=EOF)
53 return tpn;
54 else
55 return NULL;
58 static gchar*
59 about_read_developers(FILE *fp, gchar *line, gint *index, const gchar **tab)
63 if (*index < MAX_CREDIT)
64 tab[(*index)++] = g_strdup_printf("%s", line);
65 if ( !(line = about_read_line(fp)))
66 return NULL;
67 line = g_strchomp(line);
69 while (!g_str_has_suffix(line, ":") );
71 return line;
74 static gchar*
75 read_documenters(FILE *fp, gchar *line, gint *index, const gchar **tab)
79 if (*index < MAX_CREDIT)
80 tab[(*index)++] = g_strdup_printf("%s", line);
81 if ( !(line = about_read_line(fp)))
82 return NULL;
83 line = g_strchomp(line);
85 while ( !g_str_has_suffix(line, ":") );
87 return line;
90 static gchar*
91 read_translators(FILE *fp, gchar *line)
93 gboolean found = FALSE;
94 gchar *env_lang = getenv("LANG");
98 if ( !(line = about_read_line(fp)))
99 return NULL;
101 line = g_strchug(line);
102 if (!found && g_str_has_prefix(line, env_lang) )
104 found = TRUE;
105 gchar *tmp = g_strdup(line + strlen(env_lang));
106 tmp = g_strchug(tmp);
107 translators = g_strconcat("\n\n", tmp, NULL);
108 g_free(tmp);
110 line = g_strchomp(line);
112 while ( !g_str_has_suffix(line, ":") );
114 return line;
117 static void
118 about_read_file(void)
120 FILE *fp;
121 gchar *line;
122 gint i_auth = 0;
123 gint i_doc = 0;
125 fp = fopen(PACKAGE_DATA_DIR"/"ABOUT_AUTHORS, "r");
127 g_return_if_fail (fp != NULL);
128 line = about_read_line(fp);
131 line = g_strchomp(line);
132 if (g_str_has_suffix(line, "Developer:") ||
133 g_str_has_suffix(line, "Developers:") ||
134 g_str_has_suffix(line, "Contributors:") ||
135 g_str_has_suffix(line, "Note:"))
137 line = about_read_developers(fp, line, &i_auth, authors);
139 else if (g_str_has_suffix(line, "Website:") ||
140 g_str_has_suffix(line, "Documenters:") )
142 line = read_documenters(fp, line, &i_doc, documenters);
144 else if (g_str_has_suffix(line, "Translators:") )
146 line = read_translators(fp, line);
148 else
149 line = about_read_line(fp);
151 while (line);
152 fclose(fp);
155 static void
156 about_free_credit(void)
158 gint i = 0;
160 gchar** ptr = (gchar**) authors;
161 for(i=0; ptr[i]; i++)
162 g_free (ptr[i]);
163 ptr = (gchar**) documenters;
164 for(i=0; ptr[i]; i++)
165 g_free (ptr[i]);
167 g_free(translators);
170 GtkWidget *
171 about_box_new (GtkWindow *parent)
173 GtkWidget *dialog;
174 GError* error = NULL;
176 /* Parse AUTHORS file */
177 about_read_file();
179 dialog = gtk_about_dialog_new();
180 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
181 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
183 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), "Anjuta");
184 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
185 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
186 _("Copyright © Naba Kumar"));
187 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
188 _("Integrated Development Environment"));
189 gtk_about_dialog_set_license_type(GTK_ABOUT_DIALOG(dialog),
190 GTK_LICENSE_GPL_2_0);
191 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://www.anjuta.org");
192 gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(dialog), "anjuta");
194 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors);
195 gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), documenters);
196 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), translators);
197 /* We should fill this!
198 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), ???);*/
199 /* Free authors, documenters, translators */
200 about_free_credit();
201 return dialog;
204 static void
205 on_about_plugin_activate (GtkMenuItem *item, AnjutaShell *shell)
207 gchar *name = NULL;
208 gchar *authors = NULL;
209 gchar *license = NULL;
210 gchar **authors_v = NULL;
211 gchar *icon = NULL;
212 gchar *d = NULL;
213 GdkPixbuf *pix = NULL;
214 GtkWidget *dialog;
215 AnjutaPluginDescription *desc;
217 desc = g_object_get_data (G_OBJECT (item), "plugin-desc");
219 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
220 "Name", &name);
221 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
222 "Description", &d);
223 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
224 "Icon", &icon);
225 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
226 "Authors", &authors);
227 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
228 "License", &license);
229 if (icon)
231 gchar *path = g_build_filename (PACKAGE_PIXMAPS_DIR, icon, NULL);
232 pix = gdk_pixbuf_new_from_file (path, NULL);
233 g_free (path);
235 if (authors)
237 authors_v = g_strsplit(authors, ",", -1);
239 dialog = gtk_about_dialog_new();
240 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(shell));
241 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
243 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), name);
244 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
245 if (license)
246 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
247 license);
248 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),d);
249 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pix);
251 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog),
252 (const gchar **)authors_v);
254 gtk_widget_show (dialog);
256 g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
258 g_object_unref (pix);
259 g_strfreev (authors_v);
260 g_free (name);
261 g_free (d);
262 g_free (authors);
263 g_free (icon);
264 g_free (license);
267 void
268 about_create_plugins_submenu (AnjutaShell *shell, GtkWidget *menuitem)
270 GtkWidget *submenu;
271 GList *plugin_handles, *node;
273 g_return_if_fail (ANJUTA_IS_SHELL (shell));
274 g_return_if_fail (GTK_IS_MENU_ITEM (menuitem));
276 submenu = gtk_menu_new ();
277 gtk_widget_show (submenu);
278 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
280 plugin_handles =
281 anjuta_plugin_manager_query (anjuta_shell_get_plugin_manager (shell, NULL),
282 NULL, NULL, NULL, NULL);
283 node = plugin_handles;
284 while (node)
286 gchar *label;
287 GtkWidget *item;
288 AnjutaPluginHandle *handle = (AnjutaPluginHandle *)node->data;
289 AnjutaPluginDescription *desc = anjuta_plugin_handle_get_description (handle);
290 if (anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
291 "Name", &label))
293 gchar *authors = NULL;
294 gchar *license = NULL;
295 if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
296 "Authors", &authors) ||
297 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
298 "License", &license))
300 item = gtk_menu_item_new_with_label (label);
301 gtk_widget_show (item);
303 g_object_set_data (G_OBJECT (item), "plugin-desc", desc);
304 g_signal_connect (G_OBJECT (item), "activate",
305 G_CALLBACK (on_about_plugin_activate),
306 shell);
307 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
308 g_free (authors);
309 g_free (license);
311 g_free (label);
313 node = g_list_next (node);
315 g_list_free (plugin_handles);