/**
 * xviewer_postasa_plugin_dispose:
 *
 * Cleans up the #XviewerPostasaPlugin object, unref'ing its #GDataPicasaWebService and #GCancellable.
 **/
static void
xviewer_postasa_plugin_dispose (GObject *_plugin)
{
	XviewerPostasaPlugin *plugin = XVIEWER_POSTASA_PLUGIN (_plugin);

	xviewer_debug_message (DEBUG_PLUGINS, "XviewerPostasaPlugin disposing");

#ifdef HAVE_LIBGDATA_0_9
	if (plugin->priv->authorizer) {
		g_object_unref (plugin->priv->authorizer);
		plugin->priv->authorizer = NULL;
	}
#endif

	if (plugin->priv->service) {
		g_object_unref (plugin->priv->service);
		plugin->priv->service = NULL;
	}
	if (plugin->priv->login_cancellable) {
		g_object_unref (plugin->priv->login_cancellable);
		plugin->priv->login_cancellable = NULL;
	}
	if (G_IS_OBJECT (plugin->priv->uploads_store)) {
		/* we check in case the upload window was never created */
		g_object_unref (plugin->priv->uploads_store);
		plugin->priv->uploads_store = NULL;
	}

	if (plugin->priv->xviewer_window) {
		g_object_unref (plugin->priv->xviewer_window);
		plugin->priv->xviewer_window = NULL;
	}

	G_OBJECT_CLASS (xviewer_postasa_plugin_parent_class)->dispose (_plugin);
}
Esempio n. 2
0
static XviewerJob *
xviewer_job_scheduler_dequeue_job (void)
{
	XviewerJob *job;
	gint    priority;

	/* initialization */
	job = NULL;

	while (!job) {
		/* --- enter critical section --- */
		g_mutex_lock (&job_queue_mutex);

		/* try to retrieve the next job from priority queue */
		for (priority = XVIEWER_JOB_PRIORITY_HIGH; priority < XVIEWER_JOB_N_PRIORITIES; priority++) {
			job = (XviewerJob *) g_queue_pop_head (job_queue[priority]);

			if (job)
				break;
		}

		/* show info for debugging */
		xviewer_debug_message (DEBUG_JOBS,
				   (job ? "DEQUEUED %s (%p)" : "No jobs in queue"),
				   XVIEWER_GET_TYPE_NAME (job),
				   job);

		/* if there is no job, wait for it */
		if (!job) {
			xviewer_debug_message (DEBUG_JOBS,
					   "Wating for jobs ...");

			g_cond_wait    (&job_queue_cond,
					&job_queue_mutex);
			g_mutex_unlock (&job_queue_mutex);
			continue;
		}

		/* --- leave critical section --- */
		g_mutex_unlock (&job_queue_mutex);
	}

	return job;
}
Esempio n. 3
0
static void
xviewer_reload_plugin_dispose (GObject *object)
{
	XviewerReloadPlugin *plugin = XVIEWER_RELOAD_PLUGIN (object);

	xviewer_debug_message (DEBUG_PLUGINS, "XviewerReloadPlugin disposing");

	if (plugin->window != NULL) {
		g_object_unref (plugin->window);
		plugin->window = NULL;
	}

	G_OBJECT_CLASS (xviewer_reload_plugin_parent_class)->dispose (object);
}
/**
 * xviewer_postasa_plugin_init:
 *
 * Object initialisation method.  Sets up the (unauthenticated)
 * PicasaWeb service, a #GCancellable for login, and sets the
 * uploads_pending flag to %FALSE.
 **/
static void
xviewer_postasa_plugin_init (XviewerPostasaPlugin *plugin)
{
	xviewer_debug_message (DEBUG_PLUGINS, "XviewerPostasaPlugin initializing");

	plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XVIEWER_TYPE_POSTASA_PLUGIN, XviewerPostasaPluginPrivate);

#ifdef HAVE_LIBGDATA_0_9
	plugin->priv->authorizer = gdata_client_login_authorizer_new ("XviewerPostasa", GDATA_TYPE_PICASAWEB_SERVICE);
	plugin->priv->service = gdata_picasaweb_service_new (GDATA_AUTHORIZER (plugin->priv->authorizer)); /* unref'd in xviewer_postasa_plugin_dispose() */
#else
	plugin->priv->service = gdata_picasaweb_service_new ("XviewerPostasa"); /* unref'd in xviewer_postasa_plugin_dispose() */
#endif
	plugin->priv->login_cancellable = g_cancellable_new (); /* unref'd in xviewer_postasa_plugin_dispose() */
	plugin->priv->uploads_pending = FALSE;
}
Esempio n. 5
0
static void
xviewer_job_process (XviewerJob *job)
{
	g_return_if_fail (XVIEWER_IS_JOB (job));

	/* nothing to do if job was cancelled */
	if (xviewer_job_is_cancelled (job))
		return;

	/* show info for debugging */
	xviewer_debug_message (DEBUG_JOBS,
			   "PROCESSING a %s (%p)",
			   XVIEWER_GET_TYPE_NAME (job),
			   job);

	/* process the current job */
	xviewer_job_run (job);
}
Esempio n. 6
0
static void
xviewer_job_scheduler_enqueue_job (XviewerJob         *job,
			       XviewerJobPriority  priority)
{
	/* show info for debugging */
	xviewer_debug_message (DEBUG_JOBS,
			   "ENQUEUED %s (%p) with priority %d",
			   XVIEWER_GET_TYPE_NAME (job),
			   job,
			   priority);

	/* --- enter critical section --- */
	g_mutex_lock (&job_queue_mutex);

	g_queue_push_tail (job_queue[priority], job);
	g_cond_broadcast  (&job_queue_cond);

	/* --- leave critical section --- */
	g_mutex_unlock (&job_queue_mutex);
}
Esempio n. 7
0
static void
xviewer_print_draw_page (GtkPrintOperation *operation,
                         GtkPrintContext   *context,
                         gint               page_nr,
                         gpointer           user_data)
{
    cairo_t *cr;
    gdouble dpi_x, dpi_y;
    gdouble x0, y0;
    gdouble scale_factor;
    gdouble p_width, p_height;
    gint width, height;
    XviewerPrintData *data;
    GtkPageSetup *page_setup;

    xviewer_debug (DEBUG_PRINTING);

    data = (XviewerPrintData *) user_data;

    scale_factor = data->scale_factor/100;

    dpi_x = gtk_print_context_get_dpi_x (context);
    dpi_y = gtk_print_context_get_dpi_y (context);

    switch (data->unit) {
    case GTK_UNIT_INCH:
        x0 = data->left_margin * dpi_x;
        y0 = data->top_margin  * dpi_y;
        break;
    case GTK_UNIT_MM:
        x0 = data->left_margin * dpi_x/25.4;
        y0 = data->top_margin  * dpi_y/25.4;
        break;
    default:
        g_assert_not_reached ();
    }

    cr = gtk_print_context_get_cairo_context (context);

    cairo_translate (cr, x0, y0);

    page_setup = gtk_print_context_get_page_setup (context);
    p_width =  gtk_page_setup_get_page_width (page_setup, GTK_UNIT_POINTS);
    p_height = gtk_page_setup_get_page_height (page_setup, GTK_UNIT_POINTS);

    xviewer_image_get_size (data->image, &width, &height);

    /* this is both a workaround for a bug in cairo's PDF backend, and
       a way to ensure we are not printing outside the page margins */
    cairo_rectangle (cr, 0, 0, MIN (width*scale_factor, p_width), MIN (height*scale_factor, p_height));
    cairo_clip (cr);

    cairo_scale (cr, scale_factor, scale_factor);

#ifdef HAVE_RSVG
    if (xviewer_image_is_svg (data->image))
    {
        RsvgHandle *svg = xviewer_image_get_svg (data->image);

        rsvg_handle_render_cairo (svg, cr);
        return;
    } else
#endif
        /* JPEGs can be attached to the cairo surface which simply embeds the JPEG file into the
         * destination PDF skipping (PNG-)recompression. This should reduce PDF sizes enormously. */
        if (xviewer_image_is_jpeg (data->image) && _cairo_ctx_supports_jpg_metadata (cr))
        {
            GFile *file;
            char *img_data;
            gsize data_len;
            cairo_surface_t *surface = NULL;

            xviewer_debug_message (DEBUG_PRINTING, "Attaching image to cairo surface");

            file = xviewer_image_get_file (data->image);
            if (g_file_load_contents (file, NULL, &img_data, &data_len, NULL, NULL))
            {
                XviewerTransform *tf = xviewer_image_get_transform (data->image);
                XviewerTransform *auto_tf = xviewer_image_get_autorotate_transform (data->image);
                cairo_matrix_t mx, mx2;

                if (!tf && auto_tf) {
                    /* If only autorotation data present,
                     * make it the normal rotation. */
                    tf = auto_tf;
                    auto_tf = NULL;
                }

                /* Care must be taken with height and width values. They are not the original
                 * values but were affected by the transformation. As the surface needs to be
                 * generated using the original dimensions they might need to be flipped. */
                if (tf) {
                    if (auto_tf) {
                        /* If we have an autorotation apply
                         * it before the others */
                        tf = xviewer_transform_compose (auto_tf, tf);
                    }

                    switch (xviewer_transform_get_transform_type (tf)) {
                    case XVIEWER_TRANSFORM_ROT_90:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, height, width);
                        cairo_rotate (cr, 90.0 * (G_PI/180.0));
                        cairo_translate (cr, 0.0, -width);
                        break;
                    case XVIEWER_TRANSFORM_ROT_180:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, width, height);
                        cairo_rotate (cr, 180.0 * (G_PI/180.0));
                        cairo_translate (cr, -width, -height);
                        break;
                    case XVIEWER_TRANSFORM_ROT_270:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, height, width);
                        cairo_rotate (cr, 270.0 * (G_PI/180.0));
                        cairo_translate (cr, -height, 0.0);
                        break;
                    case XVIEWER_TRANSFORM_FLIP_HORIZONTAL:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, width, height);
                        cairo_matrix_init_identity (&mx);
                        _xviewer_cairo_matrix_flip (&mx2, &mx, TRUE, FALSE);
                        cairo_transform (cr, &mx2);
                        cairo_translate (cr, -width, 0.0);
                        break;
                    case XVIEWER_TRANSFORM_FLIP_VERTICAL:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, width, height);
                        cairo_matrix_init_identity (&mx);
                        _xviewer_cairo_matrix_flip (&mx2, &mx, FALSE, TRUE);
                        cairo_transform (cr, &mx2);
                        cairo_translate (cr, 0.0, -height);
                        break;
                    case XVIEWER_TRANSFORM_TRANSPOSE:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, height, width);
                        cairo_matrix_init_rotate (&mx, 90.0 * (G_PI/180.0));
                        cairo_matrix_init_identity (&mx2);
                        _xviewer_cairo_matrix_flip (&mx2, &mx2, TRUE, FALSE);
                        cairo_matrix_multiply (&mx2, &mx, &mx2);
                        cairo_transform (cr, &mx2);
                        break;
                    case XVIEWER_TRANSFORM_TRANSVERSE:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, height, width);
                        cairo_matrix_init_rotate (&mx, 90.0 * (G_PI/180.0));
                        cairo_matrix_init_identity (&mx2);
                        _xviewer_cairo_matrix_flip (&mx2, &mx2, FALSE, TRUE);
                        cairo_matrix_multiply (&mx2, &mx, &mx2);
                        cairo_transform (cr, &mx2);
                        cairo_translate (cr, -height , -width);
                        break;
                    case XVIEWER_TRANSFORM_NONE:
                    default:
                        surface = cairo_image_surface_create (
                                      CAIRO_FORMAT_RGB24, width, height);
                        break;
                    }
                }

                if (!surface)
                    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
                                                          width, height);
                cairo_surface_set_mime_data (surface,
                                             CAIRO_MIME_TYPE_JPEG,
                                             (unsigned char*)img_data, data_len,
                                             g_free, img_data);
                cairo_set_source_surface (cr, surface, 0, 0);
                cairo_paint (cr);
                cairo_surface_destroy (surface);
                g_object_unref (file);
                return;
            }
            g_object_unref (file);

        }

    {
        GdkPixbuf *pixbuf;

        pixbuf = xviewer_image_get_pixbuf (data->image);
        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
        cairo_paint (cr);
        g_object_unref (pixbuf);
    }
}
Esempio n. 8
0
static void
xviewer_reload_plugin_init (XviewerReloadPlugin *plugin)
{
	xviewer_debug_message (DEBUG_PLUGINS, "XviewerReloadPlugin initializing");
}