+ add_view (app, *client_site, server);
+ return server;
+}
+
+static void
+open_pdf (Application *app, const char *name)
+{
+ GnomeObjectClient *object;
+ GnomeStream *stream;
+ GNOME_PersistStream persist;
+
+ object = add_cmd (app, "bonobo-object:image-x-pdf", &image_client_site);
+ if (object == NULL) {
+ gnome_error_dialog (_("Could not launch bonobo object."));
+ return;
+ }
+
+ image_png_obj = object;
+
+ persist = GNOME_Unknown_query_interface (
+ gnome_object_corba_objref (GNOME_OBJECT (object)),
+ "IDL:GNOME/PersistStream:1.0", &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION ||
+ persist == CORBA_OBJECT_NIL) {
+ gnome_error_dialog ("Panic: component is well broken.");
+ return;
+ }
+
+ stream = gnome_stream_fs_open (name, GNOME_Storage_READ);
+
+ if (stream == NULL) {
+ char *err = g_strconcat (_("Could not open "), name, NULL);
+ gnome_error_dialog_parented (err, GTK_WINDOW(app->app));
+ g_free (err);
+ return;
+ }
+
+ GNOME_PersistStream_load (persist,
+ (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
+
+ GNOME_Unknown_unref (persist, &ev);
+ CORBA_Object_release (persist, &ev);
+ app->contains_pdf = TRUE;
+}
+
+static void
+set_ok (GtkWidget *widget, gboolean *dialog_result)
+{
+ *dialog_result = TRUE;
+ gtk_main_quit ();
+}
+
+static guint
+file_dialog_delete_event (GtkWidget *widget, GdkEventAny *event)
+{
+ gtk_main_quit ();
+ return TRUE;
+}
+
+static void
+file_open_cmd (GtkWidget *widget, Application *app)
+{
+ GtkFileSelection *fsel;
+ gboolean accepted = FALSE;
+
+ fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Load file")));
+ gtk_window_set_modal (GTK_WINDOW (fsel), TRUE);
+
+ gtk_window_set_transient_for (GTK_WINDOW (fsel),
+ GTK_WINDOW (app->app));
+
+ /* Connect the signals for Ok and Cancel */
+ gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked",
+ GTK_SIGNAL_FUNC (set_ok), &accepted);
+ gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked",
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+ gtk_window_set_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE);
+
+ /*
+ * Make sure that we quit the main loop if the window is destroyed
+ */
+ gtk_signal_connect (GTK_OBJECT (fsel), "delete_event",
+ GTK_SIGNAL_FUNC (file_dialog_delete_event), NULL);
+
+ /* Run the dialog */
+ gtk_widget_show (GTK_WIDGET (fsel));
+ gtk_grab_add (GTK_WIDGET (fsel));
+ gtk_main ();
+
+ if (accepted) {
+ char *name = gtk_file_selection_get_filename (fsel);
+
+ if (name [strlen (name)-1] != '/') {
+ if (app->contains_pdf)
+ app = application_new ();
+ char *fname = g_strdup (name);
+ open_pdf (app, fname);
+ g_free (fname);
+ } else {
+ GtkWidget *dialog;
+ dialog = gnome_message_box_new ("Can't open a directory",
+ GNOME_MESSAGE_BOX_ERROR,
+ GNOME_STOCK_BUTTON_OK, NULL);
+ gnome_dialog_set_parent (GNOME_DIALOG (dialog),
+ GTK_WINDOW (app->app));
+ gnome_dialog_run (GNOME_DIALOG (dialog));
+ }
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (fsel));
+}