/* -*- mode: c; style: linux -*- */ /* capplet-dir-view-html.c * Copyright (C) 2000 Helix Code, Inc. * * Written by Jacob Berkman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include #include #include #include #include #include #include "capplet-dir-view.h" static void html_clear (CappletDirView *view) { g_return_if_fail (GTK_IS_HTML (view->view)); gtk_html_load_empty (GTK_HTML (view->view)); } static void html_clean (CappletDirView *view) { g_return_if_fail (GTK_IS_HTML (view->view)); gtk_object_destroy (GTK_OBJECT (view->view)); } #define BUFLEN 4096 static void handle_url_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *stream, CappletDirView *view) { char buf[BUFLEN]; int fd; ssize_t s; fd = open (url, O_RDONLY); if (fd == -1) goto loading_error; while (1) { s = read (fd, buf, BUFLEN); switch (s) { case -1: if (! (errno == EINTR || errno == EAGAIN) ) goto loading_error; break; case 0: gtk_html_end (html, stream, GTK_HTML_STREAM_OK); return; default: gtk_html_write (html, stream, buf, s); break; } } return; loading_error: gtk_html_end (html, stream, GTK_HTML_STREAM_ERROR); } #undef BUFLEN static void handle_link_cb (GtkHTML *html, const gchar *url, CappletDirView *view) { CappletDirEntry *entry; g_print ("activating: %s\n", url); entry = capplet_lookup (url); if (entry) capplet_dir_entry_activate (entry, view); } static void write_parent_html (CappletDir *dir, GtkHTML *html, GtkHTMLStream *stream) { char *s; if (!dir) return; g_return_if_fail (html != NULL); g_return_if_fail (stream != NULL); write_parent_html (dir->entry.dir, html, stream); s = g_strdup_printf ("%s %s", dir->entry.dir ? " |" : "", dir->entry.path, dir->entry.label); gtk_html_write (html, stream, s, strlen (s)); g_free (s); } static void html_populate (CappletDirView *view) { GtkHTMLStream *stream; CappletDirEntry *entry; GSList *item; int i; char *s; g_return_if_fail (GTK_IS_HTML (view->view)); stream = gtk_html_begin (GTK_HTML (view->view)); s = "\n" "\n" " \n" " GNOME Control Center\n" " \n" " \n" #if 0 " \n" " \n" " \n" " \n" " \n" "
\n" " \n" " %s\n" "
\n" #endif " \n" " \n" " \n" " <\tr>\n" " \n" " \n"; gtk_html_write (GTK_HTML (view->view), stream, s, strlen (s)); } entry = CAPPLET_DIR_ENTRY (item->data); s = g_strdup_printf ( " \n" " \n" , entry->path, entry->icon, entry->path, entry->label, entry->entry->comment); gtk_html_write (GTK_HTML (view->view), stream, s, strlen (s)); g_free (s); if (i%2 || !item->next) { s = " \n"; gtk_html_write (GTK_HTML (view->view), stream, s, strlen (s)); } } s = "
\n" " Select something you want to customize.\n" "
\n" "  \n"; gtk_html_write (GTK_HTML (view->view), stream, s, strlen (s)); write_parent_html (view->capplet_dir->entry.dir, GTK_HTML (view->view), stream); for (i = 0, item = view->capplet_dir->entries; item; item = item->next, i++) { if (!(i%2)) { s = "
\n" " \n" " %s
\n" " %s\n" "
\n" " \n" "\n"; gtk_html_write (GTK_HTML (view->view), stream, s, strlen (s)); gtk_html_end (GTK_HTML (view->view), stream, GTK_HTML_STREAM_OK); } static GtkWidget * html_create (CappletDirView *view) { GtkWidget *w = gtk_html_new (); gtk_signal_connect (GTK_OBJECT (w), "url_requested", GTK_SIGNAL_FUNC (handle_url_cb), view); gtk_signal_connect (GTK_OBJECT (w), "link_clicked", GTK_SIGNAL_FUNC (handle_link_cb), view); return w; } CappletDirViewImpl capplet_dir_view_html = { html_clear, html_clean, html_populate, html_create };