Make it an object, cleanup the code, api to show it as transient and to
authorMarco Pesenti Gritti <mpg@redhat.com>
Wed, 15 Jun 2005 00:11:33 +0000 (00:11 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Wed, 15 Jun 2005 00:11:33 +0000 (00:11 +0000)
2005-06-15  Marco Pesenti Gritti <mpg@redhat.com>

        * shell/ev-properties.c: (ev_properties_dispose),
        (ev_properties_class_init), (dialog_destroy_cb),
        (ev_properties_init), (job_fonts_finished_cb), (setup_fonts_view),
        (ev_properties_set_document), (ev_properties_new),
        (ev_properties_show):
        * shell/ev-properties.h:

        Make it an object, cleanup the code, api to show it as transient
        and to set the document.

        * shell/ev-window.c: (ev_window_setup_document),
        (ev_window_cmd_file_properties):

        Adapt to EvProperties changes, do not show multiple
        times, update it when document changes.

ChangeLog
shell/ev-properties.c
shell/ev-properties.h
shell/ev-window.c

index d7fdf661edf28e2213ff8d2472d67b4f15377731..794db778a1b23287127d61171447c2e8cae099ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2005-06-15  Marco Pesenti Gritti <mpg@redhat.com>
+
+       * shell/ev-properties.c: (ev_properties_dispose),
+       (ev_properties_class_init), (dialog_destroy_cb),
+       (ev_properties_init), (job_fonts_finished_cb), (setup_fonts_view),
+       (ev_properties_set_document), (ev_properties_new),
+       (ev_properties_show):
+       * shell/ev-properties.h:
+
+       Make it an object, cleanup the code, api to show it as transient
+       and to set the document.
+
+       * shell/ev-window.c: (ev_window_setup_document),
+       (ev_window_cmd_file_properties):
+
+       Adapt to EvProperties changes, do not show multiple
+       times, update it when document changes.
+
 2005-06-14  Marco Pesenti Gritti <mpg@redhat.com>
 
        * ps/gstypes.h:
index 295194f47888c5dc295c3834fb8ffd985bf78160..b7c0bcc7f8f007ebb041edd4fddfcac27a7b5671 100644 (file)
@@ -26,6 +26,7 @@
 #include "ev-document-fonts.h"
 #include "ev-jobs.h"
 #include "ev-job-queue.h"
+#include "ev-page-cache.h"
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
@@ -76,6 +77,82 @@ static const PropertyInfo properties_info[] = {
        { SECURITY_PROPERTY, "security" }
 };
 
+struct _EvProperties {
+       GObject base_instance;
+
+       GladeXML *xml;
+
+       GtkWidget *dialog;
+       GtkWidget *fonts_treeview;
+       GtkWidget *fonts_progress_label;
+       GtkWidget *font_page;
+
+       EvDocument *document;
+};
+
+struct _EvPropertiesClass {
+       GObjectClass base_class;
+};
+
+G_DEFINE_TYPE (EvProperties, ev_properties, G_TYPE_OBJECT)
+
+static void
+ev_properties_dispose (GObject *object)
+{
+       EvProperties *properties = EV_PROPERTIES (object);
+
+       if (properties->xml) {
+               g_object_unref (properties->xml);
+               properties->xml = NULL;
+       }
+}
+
+static void
+ev_properties_class_init (EvPropertiesClass *properties_class)
+{
+       GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
+
+       g_object_class->dispose = ev_properties_dispose;
+}
+
+static void
+dialog_destroy_cb (GtkWidget *dialog, EvProperties *properties)
+{
+       g_object_unref (properties);
+}
+
+static void
+ev_properties_init (EvProperties *properties)
+{
+       GladeXML *xml;
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *column;
+
+       /* Create a new GladeXML object from XML file glade_file */
+       xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL);
+       properties->xml = xml;
+       g_assert (xml != NULL);
+
+       properties->dialog = glade_xml_get_widget (xml, "properties_dialog");
+       properties->fonts_treeview = glade_xml_get_widget (xml, "fonts_treeview");
+       properties->fonts_progress_label = glade_xml_get_widget (xml, "font_progress_label");
+       properties->font_page = glade_xml_get_widget (xml, "fonts_page");
+
+       column = gtk_tree_view_column_new ();
+       gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
+       gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Name"));
+       gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
+                                            "text", EV_DOCUMENT_FONTS_COLUMN_NAME,
+                                            NULL);
+
+        g_signal_connect (properties->dialog, "destroy",
+                          G_CALLBACK (dialog_destroy_cb), properties);
+}
+
 /* Returns a locale specific date and time representation */
 static char *
 ev_properties_format_date (GTime utime)
@@ -120,24 +197,24 @@ update_progress_label (GtkWidget *label, double progress)
 }
 
 static void
-job_fonts_finished_cb (EvJob *job, GtkTreeView *tree_view)
-{
+job_fonts_finished_cb (EvJob *job, EvProperties *properties)
+{      
        EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document);
-       GtkWidget *progress_label;
        double progress;
 
-       progress_label = g_object_get_data (G_OBJECT (tree_view), "progress_label");
        progress = ev_document_fonts_get_progress (document_fonts);
-       update_progress_label (progress_label, progress);
+       update_progress_label (properties->fonts_progress_label, progress);
 
        if (EV_JOB_FONTS (job)->scan_completed) {
                g_signal_handlers_disconnect_by_func
-                               (job, job_fonts_finished_cb, tree_view);
+                               (job, job_fonts_finished_cb, properties);
        } else {
+               GtkTreeModel *model;
                EvJob *new_job;
 
-               ev_document_fonts_fill_model (document_fonts,
-                                             gtk_tree_view_get_model (tree_view));
+               model = gtk_tree_view_get_model
+                               (GTK_TREE_VIEW (properties->fonts_treeview));
+               ev_document_fonts_fill_model (document_fonts, model);
                new_job = ev_job_fonts_new (job->document);
                ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
                g_object_unref (new_job);
@@ -145,57 +222,37 @@ job_fonts_finished_cb (EvJob *job, GtkTreeView *tree_view)
 }
 
 static void
-setup_fonts_view (GladeXML *xml, EvDocument *document)
+setup_fonts_view (EvProperties *properties)
 {
-       GtkCellRenderer *renderer;
-       GtkTreeViewColumn *column;
+       GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
        GtkListStore *list_store;
        EvJob *job;
-       GtkWidget *tree_view;
-       GtkWidget *progress_label;
-
-       tree_view = glade_xml_get_widget (xml, "fonts_treeview");
-       progress_label = glade_xml_get_widget (xml, "font_progress_label");
-
-       column = gtk_tree_view_column_new ();
-       gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
-       gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
-
-       renderer = gtk_cell_renderer_text_new ();
-       gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
-       gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Name"));
-       gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
-                                            "text", EV_DOCUMENT_FONTS_COLUMN_NAME,
-                                            NULL);
 
        list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING);
-       gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view),
-                                GTK_TREE_MODEL (list_store));
+       gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
 
-       job = ev_job_fonts_new (document);
-       g_object_set_data (G_OBJECT (tree_view), "progress_label",
-                          progress_label);
+       job = ev_job_fonts_new (properties->document);
        g_signal_connect_object (job, "finished",
                                 G_CALLBACK (job_fonts_finished_cb),
-                                tree_view, 0);
+                                properties, 0);
        ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
        g_object_unref (job);
 }
 
-GtkDialog *
-ev_properties_new (EvDocument *document, const EvDocumentInfo *info)
+void
+ev_properties_set_document (EvProperties *properties,
+                           EvDocument   *document)
 {
-       GladeXML *xml;
-       GtkWidget *dialog;
+       EvPageCache *page_cache;
+       GladeXML *xml = properties->xml;
+       const EvDocumentInfo *info;
        char *text;
-       
-       /* Create a new GladeXML object from XML file glade_file */
-       xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL);
-       g_return_val_if_fail (xml != NULL, NULL);
 
-       dialog = glade_xml_get_widget (xml, "properties_dialog");
-       g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
-                                       
+       properties->document = document;
+
+       page_cache = ev_page_cache_get (document);
+       info = ev_page_cache_get_info (page_cache);
+
        if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
                set_property (xml, TITLE_PROPERTY, info->title);
        }
@@ -246,10 +303,29 @@ ev_properties_new (EvDocument *document, const EvDocumentInfo *info)
        }
 
        if (EV_IS_DOCUMENT_FONTS (document)) {
-               setup_fonts_view (xml, document);
+               gtk_widget_show (properties->font_page);
+               setup_fonts_view (properties);
        } else {
-               gtk_widget_hide (glade_xml_get_widget (xml, "fonts_page"));
+               gtk_widget_hide (properties->font_page);
        }
+}
+
+EvProperties *
+ev_properties_new ()
+{
+       EvProperties *properties;
 
-       return GTK_DIALOG (dialog); 
+       properties = g_object_new (EV_TYPE_PROPERTIES, NULL);
+
+       return properties;
+}
+
+void
+ev_properties_show (EvProperties *properties, GtkWidget *parent)
+{
+       gtk_window_set_transient_for (GTK_WINDOW (properties->dialog),
+                                     GTK_WINDOW (parent));
+       g_signal_connect (properties->dialog, "response",
+                         G_CALLBACK (gtk_widget_destroy), NULL);
+       gtk_widget_show (properties->dialog);
 }
index f17e9639b87d09e012b2baa77b4994e2145ee495..410ed1a966b501912693417e262ac42028441687 100644 (file)
 
 #include "ev-document.h"
 
-#include <gtk/gtkdialog.h>
-#include <gtk/gtktreemodel.h>
+#include <gtk/gtkwidget.h>
 
 G_BEGIN_DECLS
 
-GtkDialog *ev_properties_new (EvDocument *document, const EvDocumentInfo *info);
+typedef struct _EvProperties EvProperties;
+typedef struct _EvPropertiesClass EvPropertiesClass;
+typedef struct _EvPropertiesPrivate EvPropertiesPrivate;
+
+#define EV_TYPE_PROPERTIES             (ev_properties_get_type())
+#define EV_PROPERTIES(object)          (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PROPERTIES, EvProperties))
+#define EV_PROPERTIES_CLASS(klass)     (G_TYPE_CHACK_CLASS_CAST((klass), EV_TYPE_PROPERTIES, EvPropertiesClass))
+#define EV_IS_PROPERTIES(object)       (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PROPERTIES))
+#define EV_IS_PROPERTIES_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PROPERTIES))
+#define EV_PROPERTIES_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PROPERTIES, EvPropertiesClass))
+
+GType        ev_properties_get_type     (void);
+EvProperties *ev_properties_new          (void);
+void         ev_properties_set_document (EvProperties *properties,
+                                         EvDocument   *document);
+void         ev_properties_show         (EvProperties *properties,
+                                         GtkWidget    *parent);
 
 G_END_DECLS
 
index 12fa3d86d68888cf522a6dfa33236638b63eeef6..1bb82bae017c332698181b6379d0f13dc59ae101 100644 (file)
@@ -100,6 +100,9 @@ struct _EvWindowPrivate {
        GtkWidget *password_view;
        GtkWidget *statusbar;
 
+       /* Dialogs */
+       EvProperties *properties;
+
        /* UI Builders */
        GtkActionGroup *action_group;
        GtkUIManager *ui_manager;
@@ -640,6 +643,11 @@ ev_window_setup_document (EvWindow *ev_window)
 
        info = ev_page_cache_get_info (ev_window->priv->page_cache);
        update_document_mode (ev_window, info->mode);
+
+       if (ev_window->priv->properties) {
+               ev_properties_set_document (ev_window->priv->properties,
+                                           ev_window->priv->document);
+       }
 }
 
 static void
@@ -1246,15 +1254,15 @@ ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
 {
-       EvDocument *document = ev_window->priv->document;
-       const EvDocumentInfo *info;
-       GtkDialog *dialog;
+       if (ev_window->priv->properties == NULL) {
+               ev_window->priv->properties = ev_properties_new ();
+               ev_properties_set_document (ev_window->priv->properties,
+                                           ev_window->priv->document);
+               g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
+                                          (gpointer *) &(ev_window->priv->properties));
+       }
 
-       info = ev_page_cache_get_info (ev_window->priv->page_cache);
-       dialog = ev_properties_new (document, info);
-       gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ev_window));
-       gtk_dialog_run (dialog);
-       gtk_widget_destroy (GTK_WIDGET (dialog));
+       ev_properties_show (ev_window->priv->properties, GTK_WIDGET (ev_window));
 }
                                        
 static void