]> www.fi.muni.cz Git - evince.git/blob - shell/ev-properties-dialog.c
Plug a mem leak. HIG spacings.
[evince.git] / shell / ev-properties-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2005 Red Hat, Inc
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * 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.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-properties-view.h"
26 #include "ev-properties-fonts.h"
27 #include "ev-properties-dialog.h"
28 #include "ev-page-cache.h"
29 #include "ev-document-fonts.h"
30
31 #include <glib/gi18n.h>
32 #include <gtk/gtkdialog.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtknotebook.h>
35 #include <gtk/gtkstock.h>
36 #include <gtk/gtkbox.h>
37
38 struct _EvPropertiesDialog {
39         GtkDialog base_instance;
40
41         EvDocument *document;
42         GtkWidget *notebook;
43         GtkWidget *general_page;
44         GtkWidget *fonts_page;
45 };
46
47 struct _EvPropertiesDialogClass {
48         GtkDialogClass base_class;
49 };
50
51 G_DEFINE_TYPE (EvPropertiesDialog, ev_properties_dialog, GTK_TYPE_DIALOG)
52
53 static void
54 ev_properties_dialog_class_init (EvPropertiesDialogClass *properties_class)
55 {
56 }
57
58 static void
59 ev_properties_dialog_init (EvPropertiesDialog *properties)
60 {
61         gtk_window_set_title (GTK_WINDOW (properties), _("Properties"));
62         gtk_window_set_destroy_with_parent (GTK_WINDOW (properties), TRUE);
63         gtk_dialog_set_has_separator (GTK_DIALOG (properties), FALSE);
64         gtk_container_set_border_width (GTK_CONTAINER (properties), 5);
65         gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (properties)->vbox), 12);
66
67         gtk_dialog_add_button (GTK_DIALOG (properties), GTK_STOCK_CLOSE,
68                                GTK_RESPONSE_ACCEPT);
69
70         properties->notebook = gtk_notebook_new ();
71         gtk_container_set_border_width (GTK_CONTAINER (properties->notebook), 5);
72         gtk_box_pack_start (GTK_BOX (GTK_DIALOG (properties)->vbox),
73                             properties->notebook, TRUE, TRUE, 0);
74         gtk_widget_show (properties->notebook);
75
76         g_signal_connect (properties, "response",
77                           G_CALLBACK (gtk_widget_destroy), NULL);
78 }
79
80 void
81 ev_properties_dialog_set_document (EvPropertiesDialog *properties,
82                                    EvDocument         *document)
83 {
84         GtkWidget *label;
85         const EvDocumentInfo *info;
86
87         properties->document = document;
88
89         info = ev_page_cache_get_info (ev_page_cache_get (document));
90
91         if (properties->general_page == NULL) {
92                 label = gtk_label_new (_("General"));
93                 properties->general_page = ev_properties_view_new ();
94                 gtk_notebook_append_page (GTK_NOTEBOOK (properties->notebook),
95                                           properties->general_page, label);
96                 gtk_widget_show (properties->general_page);
97         }
98         ev_properties_view_set_info (EV_PROPERTIES_VIEW (properties->general_page), info);
99
100         if (EV_IS_DOCUMENT_FONTS (document)) {
101                 if (properties->fonts_page == NULL) {
102                         label = gtk_label_new (_("Fonts"));
103                         properties->fonts_page = ev_properties_fonts_new ();
104                         gtk_notebook_append_page (GTK_NOTEBOOK (properties->notebook),
105                                                   properties->fonts_page, label);
106                         gtk_widget_show (properties->fonts_page);
107                 }
108
109                 ev_properties_fonts_set_document (EV_PROPERTIES_FONTS (properties->fonts_page), document);
110         }
111 }
112
113 GtkWidget *
114 ev_properties_dialog_new ()
115 {
116         EvPropertiesDialog *properties;
117
118         properties = g_object_new (EV_TYPE_PROPERTIES_DIALOG, NULL);
119
120         return GTK_WIDGET (properties);
121 }