1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
27 #include <libanjuta/anjuta-plugin-manager.h>
31 #define LICENSE_FILE PACKAGE_DOC_DIR "/COPYING"
33 #define ANJUTA_PIXMAP_LOGO "anjuta_logo.png"
34 #define ABOUT_AUTHORS "AUTHORS"
36 #define MAX_CREDIT 500
38 static const gchar
*authors
[MAX_CREDIT
];
39 static const gchar
*documenters
[MAX_CREDIT
];
40 static gchar
*translators
;
44 about_read_line(FILE *fp
)
46 static gchar tpn
[MAX_CAR
];
51 while( ((c
=getc(fp
))!='\n') && (c
!=EOF
) && ((pt
-tpn
)<MAX_CAR
) )
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
)))
69 line
= g_strchomp(line
);
71 while (!g_str_has_suffix(line
, ":") );
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
)))
85 line
= g_strchomp(line
);
87 while ( !g_str_has_suffix(line
, ":") );
93 read_translators(FILE *fp
, gchar
*line
)
95 gboolean found
= FALSE
;
96 gchar
*env_lang
= getenv("LANG");
100 if ( !(line
= about_read_line(fp
)))
103 line
= g_strchug(line
);
104 if (!found
&& g_str_has_prefix(line
, env_lang
) )
107 gchar
*tmp
= g_strdup(line
+ strlen(env_lang
));
108 tmp
= g_strchug(tmp
);
109 translators
= g_strconcat("\n\n", tmp
, NULL
);
112 line
= g_strchomp(line
);
114 while ( !g_str_has_suffix(line
, ":") );
120 about_read_file(void)
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
);
151 line
= about_read_line(fp
);
158 about_free_credit(void)
162 gchar
** ptr
= (gchar
**) authors
;
163 for(i
=0; ptr
[i
]; i
++)
165 ptr
= (gchar
**) documenters
;
166 for(i
=0; ptr
[i
]; i
++)
173 about_box_new (GtkWindow
*parent
)
177 gchar
* license
= NULL
;
178 GError
* error
= NULL
;
180 /* Parse AUTHORS file */
184 if (!g_file_get_contents (LICENSE_FILE
,
189 g_warning ("Couldn't read license file %s: %s",
192 g_error_free (error
);
195 pix
= gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR
"/"ANJUTA_PIXMAP_LOGO
,
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
),
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 */
220 g_object_unref (pix
);
226 on_about_plugin_activate (GtkMenuItem
*item
, AnjutaShell
*shell
)
229 gchar
*authors
= NULL
;
230 gchar
*license
= NULL
;
231 gchar
**authors_v
= NULL
;
234 GdkPixbuf
*pix
= NULL
;
236 AnjutaPluginDescription
*desc
;
238 desc
= g_object_get_data (G_OBJECT (item
), "plugin-desc");
240 anjuta_plugin_description_get_locale_string (desc
, "Anjuta Plugin",
242 anjuta_plugin_description_get_locale_string (desc
, "Anjuta Plugin",
244 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
246 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
247 "Authors", &authors
);
248 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
249 "License", &license
);
252 gchar
*path
= g_build_filename (PACKAGE_PIXMAPS_DIR
, icon
, NULL
);
253 pix
= gdk_pixbuf_new_from_file (path
, NULL
);
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
);
267 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog
),
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
);
289 about_create_plugins_submenu (AnjutaShell
*shell
, GtkWidget
*menuitem
)
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
);
302 anjuta_plugin_manager_query (anjuta_shell_get_plugin_manager (shell
, NULL
),
303 NULL
, NULL
, NULL
, NULL
);
309 AnjutaPluginDescription
*desc
= node
->data
;
310 if (anjuta_plugin_description_get_locale_string (desc
, "Anjuta Plugin",
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
),
327 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), item
);
333 node
= g_list_next (node
);