static void
file_open_callback (GObject      *object,
		    GAsyncResult *res,
		    gpointer      user_data)
{
	FileOpenData *data = user_data;
	NemoImagePropertiesPage *page = data->page;
	GFile *file;
	GFileInputStream *stream;
	GError *error;
	char *uri;

	file = G_FILE (object);
	uri = g_file_get_uri (file);
	
	error = NULL;
	stream = g_file_read_finish (file, res, &error);
	if (stream) {
		char *mime_type;

		mime_type = nemo_file_info_get_mime_type (data->info);
		page->details->loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
		if (error != NULL) {
			g_warning ("Error creating loader for %s: %s", uri, error->message);
			g_clear_error (&error);
		}
		page->details->pixbuf_still_loading = TRUE;
		page->details->width = 0;
		page->details->height = 0;
#ifdef HAVE_EXIF
		page->details->exifldr = exif_loader_new ();
#endif /*HAVE_EXIF*/
		g_free (mime_type);

		g_signal_connect (page->details->loader,
				  "size_prepared",
				  G_CALLBACK (size_prepared_callback),
				  page);

		g_input_stream_read_async (G_INPUT_STREAM (stream),
					   page->details->buffer,
					   sizeof (page->details->buffer),
					   0,
					   page->details->cancellable,
					   file_read_callback,
					   page);

		g_object_unref (stream);
	} else {
		g_warning ("Error reading %s: %s", uri, error->message);
		g_clear_error (&error);
		load_finished (page);
	}

	g_free (uri);
	g_free (data);
}
Beispiel #2
0
void Portal::open( const QString& fname ) {
   dgd_scopef(trace_gui);

   dgd_echo(fname);

   QUrl url = QUrl::fromUserInput( fname );
   
   dgd_echo( QString(url.toEncoded()) );

   if( url.isValid() ) {
      Document *doc = new Document( url );

      QRect wsgeom = m_workspace->geometry();
      QRect mygeom;

      mygeom.setLeft( 10 );
      mygeom.setTop( 35 );
      mygeom.setWidth( (int)(wsgeom.width() * 0.7) );
      mygeom.setHeight( (int)(wsgeom.height() * 0.7) );

      doc->setGeometry( mygeom );

      connect( doc, SIGNAL(load_failed()), doc, SLOT(close()) );
      connect( doc, SIGNAL(load_finished()), 
	       m_history_mapper, SLOT(map()) );
      connect( doc, SIGNAL(load_finished()), 
	       m_properties_mapper, SLOT(map()) );

      m_history_mapper->setMapping( doc, QString(url.toEncoded()) );
      m_properties_mapper->setMapping( doc, doc );

      m_workspace->addWindow( doc );

      doc->show();
   }
}
static void
file_read_callback (GObject      *object,
                    GAsyncResult *res,
                    gpointer      data)
{
    CajaImagePropertiesPage *page;
    GInputStream *stream;
    gssize count_read;
    GError *error;
    int exif_still_loading;
    gboolean done_reading;

    page = CAJA_IMAGE_PROPERTIES_PAGE (data);
    stream = G_INPUT_STREAM (object);

    error = NULL;
    done_reading = FALSE;
    count_read = g_input_stream_read_finish (stream, res, &error);

    if (count_read > 0)
    {

        g_assert (count_read <= sizeof(page->details->buffer));

#ifdef HAVE_EXIF
        exif_still_loading = exif_loader_write (page->details->exifldr,
                                                page->details->buffer,
                                                count_read);
#else
        exif_still_loading = 0;
#endif /*HAVE_EXIF*/

        if (page->details->pixbuf_still_loading)
        {
            if (!gdk_pixbuf_loader_write (page->details->loader,
                                          page->details->buffer,
                                          count_read,
                                          NULL))
            {
                page->details->pixbuf_still_loading = FALSE;
            }
        }

        if (page->details->pixbuf_still_loading ||
                (exif_still_loading == 1))
        {
            g_input_stream_read_async (G_INPUT_STREAM (stream),
                                       page->details->buffer,
                                       sizeof (page->details->buffer),
                                       0,
                                       page->details->cancellable,
                                       file_read_callback,
                                       page);
        }
        else
        {
            done_reading = TRUE;
        }
    }
    else
    {
        /* either EOF, cancelled or an error occurred */
        done_reading = TRUE;
    }

    if (done_reading)
    {
        load_finished (page);
        g_input_stream_close_async (stream,
                                    0,
                                    page->details->cancellable,
                                    file_close_callback,
                                    page);
    }
}
static void
file_read_callback (GObject      *object,
		    GAsyncResult *res,
		    gpointer      data)
{
	NemoImagePropertiesPage *page;
	GInputStream *stream;
	gssize count_read;
	GError *error;
	int exif_still_loading;
	gboolean done_reading;

	page = NEMO_IMAGE_PROPERTIES_PAGE (data);
	stream = G_INPUT_STREAM (object);

	error = NULL;
	done_reading = FALSE;
	count_read = g_input_stream_read_finish (stream, res, &error);

	if (count_read > 0) {

		g_assert (count_read <= sizeof(page->details->buffer));

#ifdef HAVE_EXIF
		exif_still_loading = exif_loader_write (page->details->exifldr,
				  		        (guchar *) page->details->buffer,
				  			count_read);
#else
		exif_still_loading = 0;
#endif

		if (page->details->pixbuf_still_loading) {
			if (!gdk_pixbuf_loader_write (page->details->loader,
					      	      (const guchar *) page->details->buffer,
					      	      count_read,
					      	      NULL)) {
				page->details->pixbuf_still_loading = FALSE;
			}
		}

		if (page->details->pixbuf_still_loading ||
		    (exif_still_loading == 1)) {
			g_input_stream_read_async (G_INPUT_STREAM (stream),
						   page->details->buffer,
						   sizeof (page->details->buffer),
						   0,
						   page->details->cancellable,
						   file_read_callback,
						   page);
		}
		else {
			done_reading = TRUE;
		}
	}
	else {
		/* either EOF, cancelled or an error occurred */
		done_reading = TRUE;
	}

	if (error != NULL) {
		char *uri = g_file_get_uri (G_FILE (object));
		g_warning ("Error reading %s: %s", uri, error->message);
		g_free (uri);
		g_clear_error (&error);
	}

	if (done_reading) {
		load_finished (page);
		g_input_stream_close_async (stream,
					    0,
					    page->details->cancellable,
					    file_close_callback,
					    page);
	}
}
Beispiel #5
0
WebkitBrowser::WebkitBrowser(GtkWidget * parent_vbox)
{
  // Save and initialize variables.
  vbox = parent_vbox;
  last_focused_time = 0;

  toolbar = gtk_toolbar_new ();
  gtk_widget_show (toolbar);
  gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
  gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH);

  toolitem_back = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_back);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_back);

  button_back = gtk_button_new ();
  gtk_widget_show (button_back);
  gtk_container_add (GTK_CONTAINER (toolitem_back), button_back);

  image_back = gtk_image_new_from_stock ("gtk-go-back", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_back);
  gtk_container_add (GTK_CONTAINER (button_back), image_back);

  toolitem_forward = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_forward);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_forward);

  button_forward = gtk_button_new ();
  gtk_widget_show (button_forward);
  gtk_container_add (GTK_CONTAINER (toolitem_forward), button_forward);

  image_forward = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_forward);
  gtk_container_add (GTK_CONTAINER (button_forward), image_forward);

  toolitem_refresh = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_refresh);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_refresh);

  button_refresh = gtk_button_new ();
  gtk_widget_show (button_refresh);
  gtk_container_add (GTK_CONTAINER (toolitem_refresh), button_refresh);

  image_refresh = gtk_image_new_from_stock ("gtk-refresh", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_refresh);
  gtk_container_add (GTK_CONTAINER (button_refresh), image_refresh);

  toolitem_stop = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_stop);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_stop);

  button_stop = gtk_button_new ();
  gtk_widget_show (button_stop);
  gtk_container_add (GTK_CONTAINER (toolitem_stop), button_stop);

  image_stop = gtk_image_new_from_stock ("gtk-stop", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_stop);
  gtk_container_add (GTK_CONTAINER (button_stop), image_stop);

  toolitem_home = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_home);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_home);

  button_home = gtk_button_new ();
  gtk_widget_show (button_home);
  gtk_container_add (GTK_CONTAINER (toolitem_home), button_home);
  gtk_button_set_focus_on_click (GTK_BUTTON (button_home), FALSE);

  image_home = gtk_image_new_from_stock ("gtk-home", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_home);
  gtk_container_add (GTK_CONTAINER (button_home), image_home);

  toolitem_url = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_url);
  gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem_url), TRUE);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_url);

  entry_url = gtk_entry_new ();
  gtk_widget_show (entry_url);
  gtk_container_add (GTK_CONTAINER (toolitem_url), entry_url);
  gtk_entry_set_invisible_char (GTK_ENTRY (entry_url), 9679);

  toolitem_enter = (GtkWidget*) gtk_tool_item_new ();
  gtk_widget_show (toolitem_enter);
  gtk_container_add (GTK_CONTAINER (toolbar), toolitem_enter);

  button_enter = gtk_button_new ();
  gtk_widget_show (button_enter);
  gtk_container_add (GTK_CONTAINER (toolitem_enter), button_enter);

  image_enter = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image_enter);
  gtk_container_add (GTK_CONTAINER (button_enter), image_enter);

  scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolledwindow);
  gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);

  webview = webkit_web_view_new();
  gtk_widget_show(webview);
  gtk_container_add(GTK_CONTAINER(scrolledwindow), webview);

  notebook = gtk_notebook_new ();
  gtk_widget_show (notebook);
  gtk_box_pack_start (GTK_BOX (vbox), notebook, FALSE, FALSE, 0);
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
  gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);

  label_status = gtk_label_new ("");
  gtk_widget_show (label_status);
  gtk_container_add (GTK_CONTAINER (notebook), label_status);
  gtk_label_set_ellipsize (GTK_LABEL (label_status), PANGO_ELLIPSIZE_MIDDLE);

  progressbar = gtk_progress_bar_new ();
  gtk_widget_show (progressbar);
  gtk_container_add (GTK_CONTAINER (notebook), progressbar);
  gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (progressbar), PANGO_ELLIPSIZE_MIDDLE);

  // Set gui as if loading has finished, so that the sensitivitiy of buttons gets right.
  load_finished (NULL, NULL);

  // Signals.
  g_signal_connect ((gpointer) button_back, "clicked", G_CALLBACK (on_button_back_clicked), gpointer (this));
  g_signal_connect ((gpointer) button_forward, "clicked", G_CALLBACK (on_button_forward_clicked), gpointer (this));
  g_signal_connect ((gpointer) button_refresh, "clicked", G_CALLBACK (on_button_refresh_clicked), gpointer (this));
  g_signal_connect ((gpointer) button_stop, "clicked", G_CALLBACK (on_button_stop_clicked), gpointer (this));
  g_signal_connect ((gpointer) button_home, "clicked", G_CALLBACK (on_button_home_clicked), gpointer (this));
  g_signal_connect ((gpointer) entry_url, "activate", G_CALLBACK (on_entry_url_activate), gpointer (this));
  g_signal_connect ((gpointer) button_enter, "clicked", G_CALLBACK (on_button_enter_clicked), gpointer (this));
  g_signal_connect(G_OBJECT(webview), "grab_focus", G_CALLBACK(on_webview_grab_focus), gpointer(this));
  g_signal_connect (G_OBJECT (webview), "load-committed", G_CALLBACK (load_commit_cb), gpointer(this));
  g_signal_connect (G_OBJECT (webview), "load-started", G_CALLBACK (load_started_cb), gpointer(this));
  g_signal_connect (G_OBJECT (webview), "load-progress-changed", G_CALLBACK (progress_change_cb), gpointer(this));
  g_signal_connect (G_OBJECT (webview), "load-finished", G_CALLBACK (load_finished_cb), gpointer(this));
  g_signal_connect (G_OBJECT (webview), "hovering-over-link", G_CALLBACK (link_hover_cb), gpointer(this));
}
Beispiel #6
0
void WebkitBrowser::on_button_stop ()
{
  webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(webview));
  load_finished (NULL, NULL);
}