libanjuta: bgo #696984 - Fix a signal name typo in documentation comments
[anjuta.git] / src / about.c
blobac8a4cb2c4ab296210491ad0c578e6ce7d5bdd27
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 LICENSE_FILE PACKAGE_DOC_DIR "/COPYING"
33 #define ANJUTA_PIXMAP_LOGO "anjuta_logo.png"
34 #define ABOUT_AUTHORS "AUTHORS"
35 #define MAX_CAR 256
36 #define MAX_CREDIT 500
38 static const gchar *authors[MAX_CREDIT];
39 static const gchar *documenters[MAX_CREDIT];
40 static gchar *translators;
43 static gchar*
44 about_read_line(FILE *fp)
46 static gchar tpn[MAX_CAR];
47 char *pt;
48 char c;
50 pt = tpn;
51 while( ((c=getc(fp))!='\n') && (c!=EOF) && ((pt-tpn)<MAX_CAR) )
52 *(pt++)=c;
53 *pt = '\0';
54 if ( c!=EOF)
55 return tpn;
56 else
57 return NULL;
60 static gchar*
61 about_read_developers(FILE *fp, gchar *line, gint *index, const gchar **tab)
65 if (*index < MAX_CREDIT)
66 tab[(*index)++] = g_strdup_printf("%s", line);
67 if ( !(line = about_read_line(fp)))
68 return NULL;
69 line = g_strchomp(line);
71 while (!g_str_has_suffix(line, ":") );
73 return line;
76 static gchar*
77 read_documenters(FILE *fp, gchar *line, gint *index, const gchar **tab)
81 if (*index < MAX_CREDIT)
82 tab[(*index)++] = g_strdup_printf("%s", line);
83 if ( !(line = about_read_line(fp)))
84 return NULL;
85 line = g_strchomp(line);
87 while ( !g_str_has_suffix(line, ":") );
89 return line;
92 static gchar*
93 read_translators(FILE *fp, gchar *line)
95 gboolean found = FALSE;
96 gchar *env_lang = getenv("LANG");
100 if ( !(line = about_read_line(fp)))
101 return NULL;
103 line = g_strchug(line);
104 if (!found && g_str_has_prefix(line, env_lang) )
106 found = TRUE;
107 gchar *tmp = g_strdup(line + strlen(env_lang));
108 tmp = g_strchug(tmp);
109 translators = g_strconcat("\n\n", tmp, NULL);
110 g_free(tmp);
112 line = g_strchomp(line);
114 while ( !g_str_has_suffix(line, ":") );
116 return line;
119 static void
120 about_read_file(void)
122 FILE *fp;
123 gchar *line;
124 gint i_auth = 0;
125 gint i_doc = 0;
127 fp = fopen(PACKAGE_DATA_DIR"/"ABOUT_AUTHORS, "r");
129 g_return_if_fail (fp != NULL);
130 line = about_read_line(fp);
133 line = g_strchomp(line);
134 if (g_str_has_suffix(line, "Developer:") ||
135 g_str_has_suffix(line, "Developers:") ||
136 g_str_has_suffix(line, "Contributors:") ||
137 g_str_has_suffix(line, "Note:"))
139 line = about_read_developers(fp, line, &i_auth, authors);
141 else if (g_str_has_suffix(line, "Website:") ||
142 g_str_has_suffix(line, "Documenters:") )
144 line = read_documenters(fp, line, &i_doc, documenters);
146 else if (g_str_has_suffix(line, "Translators:") )
148 line = read_translators(fp, line);
150 else
151 line = about_read_line(fp);
153 while (line);
154 fclose(fp);
157 static void
158 about_free_credit(void)
160 gint i = 0;
162 gchar** ptr = (gchar**) authors;
163 for(i=0; ptr[i]; i++)
164 g_free (ptr[i]);
165 ptr = (gchar**) documenters;
166 for(i=0; ptr[i]; i++)
167 g_free (ptr[i]);
169 g_free(translators);
172 GtkWidget *
173 about_box_new (GtkWindow *parent)
175 GtkWidget *dialog;
176 GdkPixbuf *pix;
177 gchar* license = NULL;
178 GError* error = NULL;
180 /* Parse AUTHORS file */
181 about_read_file();
184 if (!g_file_get_contents (LICENSE_FILE,
185 &license,
186 NULL,
187 &error))
189 g_warning ("Couldn't read license file %s: %s",
190 LICENSE_FILE,
191 error->message);
192 g_error_free (error);
195 pix = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"ANJUTA_PIXMAP_LOGO,
196 NULL);
198 dialog = gtk_about_dialog_new();
199 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
200 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
202 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), "Anjuta");
203 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
204 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
205 _("Copyright (c) Naba Kumar"));
206 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
207 _("Integrated Development Environment"));
208 gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(dialog),
209 license);
210 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://www.anjuta.org");
211 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pix);
213 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors);
214 gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(dialog), documenters);
215 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog), translators);
216 /* We should fill this!
217 gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), ???);*/
218 /* Free authors, documenters, translators */
219 about_free_credit();
220 g_object_unref (pix);
221 g_free (license);
222 return dialog;
225 static void
226 on_about_plugin_activate (GtkMenuItem *item, AnjutaShell *shell)
228 gchar *name = NULL;
229 gchar *authors = NULL;
230 gchar *license = NULL;
231 gchar **authors_v = NULL;
232 gchar *icon = NULL;
233 gchar *d = NULL;
234 GdkPixbuf *pix = NULL;
235 GtkWidget *dialog;
236 AnjutaPluginDescription *desc;
238 desc = g_object_get_data (G_OBJECT (item), "plugin-desc");
240 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
241 "Name", &name);
242 anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
243 "Description", &d);
244 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
245 "Icon", &icon);
246 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
247 "Authors", &authors);
248 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
249 "License", &license);
250 if (icon)
252 gchar *path = g_build_filename (PACKAGE_PIXMAPS_DIR, icon, NULL);
253 pix = gdk_pixbuf_new_from_file (path, NULL);
254 g_free (path);
256 if (authors)
258 authors_v = g_strsplit(authors, ",", -1);
260 dialog = gtk_about_dialog_new();
261 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(shell));
262 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
264 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), name);
265 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
266 if (license)
267 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
268 license);
269 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),d);
270 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pix);
272 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog),
273 (const gchar **)authors_v);
275 gtk_widget_show (dialog);
277 g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
279 g_object_unref (pix);
280 g_strfreev (authors_v);
281 g_free (name);
282 g_free (d);
283 g_free (authors);
284 g_free (icon);
285 g_free (license);
288 void
289 about_create_plugins_submenu (AnjutaShell *shell, GtkWidget *menuitem)
291 GtkWidget *submenu;
292 GList *plugin_descs, *node;
294 g_return_if_fail (ANJUTA_IS_SHELL (shell));
295 g_return_if_fail (GTK_IS_MENU_ITEM (menuitem));
297 submenu = gtk_menu_new ();
298 gtk_widget_show (submenu);
299 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
301 plugin_descs =
302 anjuta_plugin_manager_query (anjuta_shell_get_plugin_manager (shell, NULL),
303 NULL, NULL, NULL, NULL);
304 node = plugin_descs;
305 while (node)
307 gchar *label;
308 GtkWidget *item;
309 AnjutaPluginDescription *desc = node->data;
310 if (anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
311 "Name", &label))
313 gchar *authors = NULL;
314 gchar *license = NULL;
315 if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
316 "Authors", &authors) ||
317 anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
318 "License", &license))
320 item = gtk_menu_item_new_with_label (label);
321 gtk_widget_show (item);
323 g_object_set_data (G_OBJECT (item), "plugin-desc", desc);
324 g_signal_connect (G_OBJECT (item), "activate",
325 G_CALLBACK (on_about_plugin_activate),
326 shell);
327 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
328 g_free (authors);
329 g_free (license);
331 g_free (label);
333 node = g_list_next (node);