]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/gpdf.cc
Re-organise to get mime type right,
[evince.git] / pdf / xpdf / gpdf.cc
index ae4ca75f1282fbc70590576d512f85c09978b6ca..ea3d34078b5a3cccf2736ed8e73e3273a5d2a25d 100644 (file)
@@ -85,6 +85,7 @@ extern "C" {
   static void       container_open_cmd  (GtkWidget *widget, Container *container);
   static void       container_close_cmd (GtkWidget *widget, Container *container);
   static void       container_exit_cmd  (void);
+  static void       container_about_cmd (GtkWidget *widget, Container *container);
   static Component *container_activate_component (Container *container, char *component_goad_id);
   static void       zoom_in_cmd         (GtkWidget *widget, Container *container);
   static void       zoom_out_cmd        (GtkWidget *widget, Container *container);
@@ -113,9 +114,15 @@ static GnomeUIInfo container_menu_zoom [] = {
        GNOMEUIINFO_END
 };
 
+static GnomeUIInfo container_help_menu [] = {
+        GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL),
+       GNOMEUIINFO_END
+};
+
 static GnomeUIInfo container_main_menu [] = {
        GNOMEUIINFO_MENU_FILE_TREE (container_file_menu),
        { GNOME_APP_UI_SUBTREE, N_("_Zoom"), NULL, container_menu_zoom },
+       GNOMEUIINFO_MENU_HELP_TREE (container_help_menu),
        GNOMEUIINFO_END
 };
 
@@ -141,7 +148,7 @@ extern "C" {
     g_return_val_if_fail (container != NULL, FALSE);
     g_return_val_if_fail (container->view_widget == NULL, FALSE);
 
-    comp = container_activate_component (container, "bonobo-object:image-x-pdf");
+    comp = container_activate_component (container, "bonobo-object:application-x-pdf");
     if (!comp || !(object = comp->server)) {
       gnome_error_dialog (_("Could not launch bonobo object."));
       return FALSE;
@@ -170,8 +177,8 @@ extern "C" {
     GNOME_PersistStream_load (persist,
                              (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
 
-    
-    
+    zoom_set (container);
+        
     GNOME_Unknown_unref (persist, &ev);
     CORBA_Object_release (persist, &ev);
     CORBA_exception_free (&ev);
@@ -229,8 +236,10 @@ extern "C" {
        char *fname = g_strdup (name);
        if (container->view_widget) /* any sort of MDI sucks :-] */
          container = container_new (fname);
-       else
-         open_pdf (container, fname);
+       else {
+         if (!open_pdf (container, fname))
+           container_destroy (container);
+       }
        g_free (fname);
       } else {
        GtkWidget *dialog;
@@ -250,7 +259,11 @@ extern "C" {
   container_destroy (Container *cont)
   {
     containers = g_list_remove (containers, cont);
-    gtk_widget_destroy (cont->app);
+    if (cont->app)
+      gtk_widget_destroy (cont->app);
+    cont->app = NULL;
+    /* FIXME: Some serious resource freeing needs to be here */
+    
     g_free (cont);
     if (!containers)
       gtk_main_quit ();
@@ -269,6 +282,34 @@ extern "C" {
       container_destroy ((Container *)containers->data);
   }
 
+
+static void
+container_about_cmd (GtkWidget *widget, Container *container)
+{
+  GtkWidget *about;
+  int i;
+
+  const gchar *authors[] = {
+    N_("Michael Meeks, GNOME port maintainer."),
+    N_("Miguel de Icaza."),
+    N_("Nat Friedman."),
+    NULL
+  };
+  
+#ifdef ENABLE_NLS
+  for (i = 0; authors[i] != NULL; i++)
+    authors [i] = _(authors [i]);
+#endif
+  
+  about = gnome_about_new (_("GPDF"), VERSION,
+                          _("(C) 1996-1999 Derek B. Noonburg."),
+                          authors, NULL, NULL);
+  
+  gnome_dialog_set_parent (GNOME_DIALOG (about), GTK_WINDOW (container->app));
+  gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
+  gtk_widget_show (about);
+}
+
   /*
    * Enforces the containers zoom factor.
    */
@@ -301,75 +342,6 @@ extern "C" {
       zoom_set (container);
     }
   }
-  
-  static void
-  component_view_activated_cb (GnomeViewFrame *view_frame, gboolean activated, gpointer data)
-  {
-    Component *component = (Component *) data;
-    Container *container = component->container;
-    
-    if (activated) {
-      /*
-       * If the View is requesting to be activated, then we
-       * check whether or not there is already an active
-       * View.
-       */
-      if (container->active_view_frame != NULL) {
-       g_warning ("View requested to be activated but there is already "
-                  "an active View!\n");
-       return;
-      }
-      
-      /*
-       * Otherwise, uncover it so that it can receive
-       * events, and set it as the active View.
-       */
-      gnome_view_frame_set_covered (view_frame, FALSE);
-      container->active_view_frame = view_frame;
-    } else {
-      /*
-       * If the View is asking to be deactivated, always
-       * oblige.  We may have already deactivated it (see
-       * user_activation_request_cb), but there's no harm in
-       * doing it again.  There is always the possibility
-       * that a View will ask to be deactivated when we have
-       * not told it to deactivate itself, and that is
-       * why we cover the view here.
-       */
-      gnome_view_frame_set_covered (view_frame, TRUE);
-      
-      if (view_frame == container->active_view_frame)
-       container->active_view_frame = NULL;
-    }                                                                       
-  }
-  
-  static void
-  component_user_context_cb (GnomeViewFrame *view_frame, gpointer data)
-  {
-    Component *component = (Component *) data;
-    char *executed_verb;
-    GList *l;
-    
-    /*
-     * See if the remote GnomeEmbeddable supports any verbs at
-     * all.
-     */
-    l = gnome_client_site_get_verbs (component->client_site);
-    if (l == NULL)
-      return;
-    gnome_client_site_free_verbs (l);
-    
-    /*
-     * Popup the verb popup and execute the chosen verb.  This
-     * function saves us the work of creating the menu, connecting
-     * the callback, and executing the verb on the remove
-     * GnomeView.  We could implement all this functionality
-     * ourselves if we wanted.
-     */
-    executed_verb = gnome_view_frame_popup_verbs (view_frame);
-    
-    g_free (executed_verb);
-  }
 }
 
 static void
@@ -399,35 +371,13 @@ container_set_view (Container *container, Component *component)
        container->view_widget = view_widget;
        container->component   = component;
 
-       /*
-        * In-place activation of a component is a two-step process.
-        * After the user double clicks on the component, our signal
-        * callback (compoennt_user_activate_request_cb()) asks the
-        * component to activate itself (see
-        * gnome_view_frame_view_activate()).  The component can then
-        * choose to either accept or refuse activation.  When an
-        * embedded component notifies us of its decision to change
-        * its activation state, the "view_activated" signal is
-        * emitted from the view frame.  It is at that point that we
-        * actually remove the cover so that events can get through.
-        */
-       gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated",
-                           GTK_SIGNAL_FUNC (component_view_activated_cb), component);
-
-       /*
-        * The "user_context" signal is emitted when the user right
-        * clicks on the wrapper.  We use it to pop up a verb menu.
-        */
-       gtk_signal_connect (GTK_OBJECT (view_frame), "user_context",
-                           GTK_SIGNAL_FUNC (component_user_context_cb), component);
-
        /*
         * Show the component.
         */
        gtk_scrolled_window_add_with_viewport (container->scroll, view_widget);
 
        /*
-        * Activate it ( get it to merge menus etc.
+        * Activate it ( get it to merge menus etc. )
         */
        gnome_view_frame_view_activate (view_frame);
 
@@ -542,6 +492,35 @@ extern "C" {
 
     return component;
   }
+  
+  static void
+  filenames_dropped (GtkWidget * widget,
+                    GdkDragContext   *context,
+                    gint              x,
+                    gint              y,
+                    GtkSelectionData *selection_data,
+                    guint             info,
+                    guint             time,
+                    Container        *container)
+  {
+    GList *names, *tmp_list;
+    
+    names = gnome_uri_list_extract_filenames ((char *)selection_data->data);
+    tmp_list = names;
+    
+    while (tmp_list) {
+      const char *fname = (const char *)tmp_list->data;
+
+      if (fname) {
+       if (container->view_widget)
+         container = container_new (fname);
+       else
+         open_pdf (container, fname);
+      }
+
+      tmp_list = g_list_next (tmp_list);
+    }
+  }
 }
 
 static void
@@ -574,14 +553,28 @@ static Container *
 container_new (const char *fname)
 {
        Container *container;
-
+       static GtkTargetEntry drag_types[] =
+       {
+         { "text/uri-list", 0, 0 },
+       };
+       static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types [0]);
+       
        container = g_new0 (Container, 1);
 
        container->app  = gnome_app_new ("pdf-viewer",
                                         "GNOME PDF viewer");
        container->zoom = 86.0;
 
-       gtk_window_set_default_size (GTK_WINDOW (container->app), 400, 400);
+       gtk_drag_dest_set (container->app,
+                          GTK_DEST_DEFAULT_ALL,
+                          drag_types, n_drag_types,
+                          GDK_ACTION_COPY);
+
+       gtk_signal_connect (GTK_OBJECT(container->app),
+                           "drag_data_received",
+                           GTK_SIGNAL_FUNC(filenames_dropped), (gpointer)container);
+
+       gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600);
        gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE);
 
        container->container   = gnome_container_new ();
@@ -612,7 +605,6 @@ container_new (const char *fname)
          }
 
        containers = g_list_append (containers, container);
-       zoom_set (container);
 
        gtk_widget_show_all (container->app);
 
@@ -623,9 +615,10 @@ int
 main (int argc, char **argv)
 {
   CORBA_Environment ev;
-  CORBA_ORB orb;
-  char **view_files = NULL;
-  int    i;
+  CORBA_ORB         orb;
+  char            **view_files = NULL;
+  gboolean          loaded;
+  int               i;
   
   CORBA_exception_init (&ev);
   
@@ -646,11 +639,13 @@ main (int argc, char **argv)
 
   /* Load files */
   i = 0;
+  loaded = FALSE;
   if (view_files) {
     for (i = 0; view_files[i]; i++)
-      container_new (view_files[i]);
+      if (container_new (view_files[i]))
+       loaded = TRUE;
   }
-  if (i == 0)
+  if ((i == 0) || !loaded)
     container_new (NULL);
   
   poptFreeContext (ctx);