diff options
author | Alessio Treglia <alessio@debian.org> | 2011-08-27 10:54:21 +0200 |
---|---|---|
committer | Alessio Treglia <alessio@debian.org> | 2011-08-27 10:54:21 +0200 |
commit | 87ebc2af1f0417b3bc38a233e28ff673eff4fa51 (patch) | |
tree | 747dd400400bf7593642d0ab321a4e37df2ee188 /src/simple-scan.c | |
parent | 0898b615a2ea01bd65aa1d560350b48bd036b5b6 (diff) |
Imported Upstream version 3.1.5upstream/3.1.5
Diffstat (limited to 'src/simple-scan.c')
-rw-r--r-- | src/simple-scan.c | 2006 |
1 files changed, 1454 insertions, 552 deletions
diff --git a/src/simple-scan.c b/src/simple-scan.c index bb7e036..1f1f599 100644 --- a/src/simple-scan.c +++ b/src/simple-scan.c @@ -1,7 +1,10 @@ +/* simple-scan.c generated by valac 0.13.1, the Vala compiler + * generated from simple-scan.vala, do not modify */ + /* - * Copyright (C) 2009 Canonical Ltd. + * Copyright (C) 2009-2011 Canonical Ltd. * Author: Robert Ancell <robert.ancell@canonical.com> - * + * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later @@ -9,608 +12,1507 @@ * license. */ -#include <stdlib.h> +#include <glib.h> +#include <glib-object.h> +#include <gudev/gudev.h> #include <stdio.h> -#include <glib/gi18n.h> -#include <gtk/gtk.h> +#include <stdlib.h> +#include <string.h> +#include <float.h> +#include <math.h> +#include <sane/sane.h> +#include <glib/gi18n-lib.h> +#include <glib/gstdio.h> #include <unistd.h> -#include <gudev/gudev.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> +#include <gtk/gtk.h> +#include <locale.h> +#include <config.h> +#include <gobject/gvaluecollector.h> + + +#define TYPE_APPLICATION (application_get_type ()) +#define APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APPLICATION, Application)) +#define APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION, ApplicationClass)) +#define IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APPLICATION)) +#define IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION)) +#define APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION, ApplicationClass)) + +typedef struct _Application Application; +typedef struct _ApplicationClass ApplicationClass; +typedef struct _ApplicationPrivate ApplicationPrivate; + +#define TYPE_SCAN_DEVICE (scan_device_get_type ()) +#define SCAN_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCAN_DEVICE, ScanDevice)) +#define SCAN_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCAN_DEVICE, ScanDeviceClass)) +#define IS_SCAN_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCAN_DEVICE)) +#define IS_SCAN_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCAN_DEVICE)) +#define SCAN_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCAN_DEVICE, ScanDeviceClass)) + +typedef struct _ScanDevice ScanDevice; +typedef struct _ScanDeviceClass ScanDeviceClass; + +#define TYPE_SIMPLE_SCAN (simple_scan_get_type ()) +#define SIMPLE_SCAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SIMPLE_SCAN, SimpleScan)) +#define SIMPLE_SCAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SIMPLE_SCAN, SimpleScanClass)) +#define IS_SIMPLE_SCAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SIMPLE_SCAN)) +#define IS_SIMPLE_SCAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SIMPLE_SCAN)) +#define SIMPLE_SCAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SIMPLE_SCAN, SimpleScanClass)) + +typedef struct _SimpleScan SimpleScan; +typedef struct _SimpleScanClass SimpleScanClass; + +#define TYPE_SCANNER (scanner_get_type ()) +#define SCANNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCANNER, Scanner)) +#define SCANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCANNER, ScannerClass)) +#define IS_SCANNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCANNER)) +#define IS_SCANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCANNER)) +#define SCANNER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCANNER, ScannerClass)) + +typedef struct _Scanner Scanner; +typedef struct _ScannerClass ScannerClass; + +#define TYPE_BOOK (book_get_type ()) +#define BOOK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BOOK, Book)) +#define BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BOOK, BookClass)) +#define IS_BOOK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BOOK)) +#define IS_BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BOOK)) +#define BOOK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BOOK, BookClass)) + +typedef struct _Book Book; +typedef struct _BookClass BookClass; +#define _scan_device_unref0(var) ((var == NULL) ? NULL : (var = (scan_device_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _simple_scan_unref0(var) ((var == NULL) ? NULL : (var = (simple_scan_unref (var), NULL))) +#define _scanner_unref0(var) ((var == NULL) ? NULL : (var = (scanner_unref (var), NULL))) +#define _book_unref0(var) ((var == NULL) ? NULL : (var = (book_unref (var), NULL))) + +#define TYPE_SCAN_OPTIONS (scan_options_get_type ()) +#define SCAN_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCAN_OPTIONS, ScanOptions)) +#define SCAN_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCAN_OPTIONS, ScanOptionsClass)) +#define IS_SCAN_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCAN_OPTIONS)) +#define IS_SCAN_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCAN_OPTIONS)) +#define SCAN_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCAN_OPTIONS, ScanOptionsClass)) + +typedef struct _ScanOptions ScanOptions; +typedef struct _ScanOptionsClass ScanOptionsClass; + +#define TYPE_SCAN_PAGE_INFO (scan_page_info_get_type ()) +#define SCAN_PAGE_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCAN_PAGE_INFO, ScanPageInfo)) +#define SCAN_PAGE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCAN_PAGE_INFO, ScanPageInfoClass)) +#define IS_SCAN_PAGE_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCAN_PAGE_INFO)) +#define IS_SCAN_PAGE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCAN_PAGE_INFO)) +#define SCAN_PAGE_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCAN_PAGE_INFO, ScanPageInfoClass)) + +typedef struct _ScanPageInfo ScanPageInfo; +typedef struct _ScanPageInfoClass ScanPageInfoClass; + +#define TYPE_SCAN_LINE (scan_line_get_type ()) +#define SCAN_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCAN_LINE, ScanLine)) +#define SCAN_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCAN_LINE, ScanLineClass)) +#define IS_SCAN_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCAN_LINE)) +#define IS_SCAN_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCAN_LINE)) +#define SCAN_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCAN_LINE, ScanLineClass)) + +typedef struct _ScanLine ScanLine; +typedef struct _ScanLineClass ScanLineClass; +typedef struct _ScanDevicePrivate ScanDevicePrivate; +#define __g_list_free__scan_device_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__scan_device_unref0_ (var), NULL))) +#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL))) +#define _g_free0(var) (var = (g_free (var), NULL)) + +#define TYPE_PAGE (page_get_type ()) +#define PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PAGE, Page)) +#define PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PAGE, PageClass)) +#define IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PAGE)) +#define IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PAGE)) +#define PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PAGE, PageClass)) + +typedef struct _Page Page; +typedef struct _PageClass PageClass; + +#define TYPE_SCAN_DIRECTION (scan_direction_get_type ()) +#define _page_unref0(var) ((var == NULL) ? NULL : (var = (page_unref (var), NULL))) +typedef struct _ScanPageInfoPrivate ScanPageInfoPrivate; +typedef struct _ScanOptionsPrivate ScanOptionsPrivate; + +#define TYPE_SCAN_MODE (scan_mode_get_type ()) + +#define TYPE_SCAN_TYPE (scan_type_get_type ()) +#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL))) +#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL))) +#define _g_timer_destroy0(var) ((var == NULL) ? NULL : (var = (g_timer_destroy (var), NULL))) +#define _fclose0(var) ((var == NULL) ? NULL : (var = (fclose (var), NULL))) +#define _application_unref0(var) ((var == NULL) ? NULL : (var = (application_unref (var), NULL))) +typedef struct _ParamSpecApplication ParamSpecApplication; + +struct _Application { + GTypeInstance parent_instance; + volatile int ref_count; + ApplicationPrivate * priv; +}; + +struct _ApplicationClass { + GTypeClass parent_class; + void (*finalize) (Application *self); +}; + +struct _ApplicationPrivate { + ScanDevice* default_device; + gboolean have_devices; + GUdevClient* udev_client; + SimpleScan* ui; + Scanner* scanner; + Book* book; +}; + +struct _ScanDevice { + GTypeInstance parent_instance; + volatile int ref_count; + ScanDevicePrivate * priv; + gchar* name; + gchar* label; +}; + +struct _ScanDeviceClass { + GTypeClass parent_class; + void (*finalize) (ScanDevice *self); +}; + +typedef enum { + SCAN_DIRECTION_TOP_TO_BOTTOM, + SCAN_DIRECTION_LEFT_TO_RIGHT, + SCAN_DIRECTION_BOTTOM_TO_TOP, + SCAN_DIRECTION_RIGHT_TO_LEFT +} ScanDirection; + +struct _ScanPageInfo { + GTypeInstance parent_instance; + volatile int ref_count; + ScanPageInfoPrivate * priv; + gint width; + gint height; + gint depth; + gint n_channels; + gdouble dpi; + gchar* device; +}; + +struct _ScanPageInfoClass { + GTypeClass parent_class; + void (*finalize) (ScanPageInfo *self); +}; + +typedef enum { + SCAN_MODE_DEFAULT, + SCAN_MODE_COLOR, + SCAN_MODE_GRAY, + SCAN_MODE_LINEART +} ScanMode; + +typedef enum { + SCAN_TYPE_SINGLE, + SCAN_TYPE_ADF_FRONT, + SCAN_TYPE_ADF_BACK, + SCAN_TYPE_ADF_BOTH +} ScanType; + +struct _ScanOptions { + GTypeInstance parent_instance; + volatile int ref_count; + ScanOptionsPrivate * priv; + gint dpi; + ScanMode scan_mode; + gint depth; + ScanType type; + gint paper_width; + gint paper_height; +}; + +struct _ScanOptionsClass { + GTypeClass parent_class; + void (*finalize) (ScanOptions *self); +}; + +struct _ParamSpecApplication { + GParamSpec parent_instance; +}; + + +static gpointer application_parent_class = NULL; +static gboolean application_show_version; +static gboolean application_show_version = FALSE; +static gboolean application_debug_enabled; +static gboolean application_debug_enabled = FALSE; +static GTimer* application_log_timer; +static GTimer* application_log_timer = NULL; +static FILE* application_log_file; +static FILE* application_log_file = NULL; + +gpointer application_ref (gpointer instance); +void application_unref (gpointer instance); +GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_application (GValue* value, gpointer v_object); +void value_take_application (GValue* value, gpointer v_object); +gpointer value_get_application (const GValue* value); +GType application_get_type (void) G_GNUC_CONST; +gpointer scan_device_ref (gpointer instance); +void scan_device_unref (gpointer instance); +GParamSpec* param_spec_scan_device (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_scan_device (GValue* value, gpointer v_object); +void value_take_scan_device (GValue* value, gpointer v_object); +gpointer value_get_scan_device (const GValue* value); +GType scan_device_get_type (void) G_GNUC_CONST; +gpointer simple_scan_ref (gpointer instance); +void simple_scan_unref (gpointer instance); +GParamSpec* param_spec_simple_scan (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_simple_scan (GValue* value, gpointer v_object); +void value_take_simple_scan (GValue* value, gpointer v_object); +gpointer value_get_simple_scan (const GValue* value); +GType simple_scan_get_type (void) G_GNUC_CONST; +gpointer scanner_ref (gpointer instance); +void scanner_unref (gpointer instance); +GParamSpec* param_spec_scanner (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_scanner (GValue* value, gpointer v_object); +void value_take_scanner (GValue* value, gpointer v_object); +gpointer value_get_scanner (const GValue* value); +GType scanner_get_type (void) G_GNUC_CONST; +gpointer book_ref (gpointer instance); +void book_unref (gpointer instance); +GParamSpec* param_spec_book (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_book (GValue* value, gpointer v_object); +void value_take_book (GValue* value, gpointer v_object); +gpointer value_get_book (const GValue* value); +GType book_get_type (void) G_GNUC_CONST; +#define APPLICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_APPLICATION, ApplicationPrivate)) +enum { + APPLICATION_DUMMY_PROPERTY +}; +Application* application_new (ScanDevice* device); +Application* application_construct (GType object_type, ScanDevice* device); +SimpleScan* simple_scan_new (void); +SimpleScan* simple_scan_construct (GType object_type); +Book* simple_scan_get_book (SimpleScan* self); +gpointer scan_options_ref (gpointer instance); +void scan_options_unref (gpointer instance); +GParamSpec* param_spec_scan_options (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_scan_options (GValue* value, gpointer v_object); +void value_take_scan_options (GValue* value, gpointer v_object); +gpointer value_get_scan_options (const GValue* value); +GType scan_options_get_type (void) G_GNUC_CONST; +static void application_scan_cb (Application* self, SimpleScan* ui, const gchar* device, ScanOptions* options); +static void _application_scan_cb_simple_scan_start_scan (SimpleScan* _sender, const gchar* device, ScanOptions* options, gpointer self); +static void application_cancel_cb (Application* self, SimpleScan* ui); +static void _application_cancel_cb_simple_scan_stop_scan (SimpleScan* _sender, gpointer self); +static void application_email_cb (Application* self, SimpleScan* ui, const gchar* profile); +static void _application_email_cb_simple_scan_email (SimpleScan* _sender, const gchar* profile, gpointer self); +static void application_quit_cb (Application* self, SimpleScan* ui); +static void _application_quit_cb_simple_scan_quit (SimpleScan* _sender, gpointer self); +Scanner* scanner_get_instance (void); +static void application_update_scan_devices_cb (Application* self, Scanner* scanner, GList* devices); +static void _application_update_scan_devices_cb_scanner_update_devices (Scanner* _sender, GList* devices, gpointer self); +static void application_authorize_cb (Application* self, Scanner* scanner, const gchar* resource); +static void _application_authorize_cb_scanner_request_authorization (Scanner* _sender, const gchar* resource, gpointer self); +static void application_scanner_new_page_cb (Application* self, Scanner* scanner); +static void _application_scanner_new_page_cb_scanner_expect_page (Scanner* _sender, gpointer self); +gpointer scan_page_info_ref (gpointer instance); +void scan_page_info_unref (gpointer instance); +GParamSpec* param_spec_scan_page_info (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_scan_page_info (GValue* value, gpointer v_object); +void value_take_scan_page_info (GValue* value, gpointer v_object); +gpointer value_get_scan_page_info (const GValue* value); +GType scan_page_info_get_type (void) G_GNUC_CONST; +static void application_scanner_page_info_cb (Application* self, Scanner* scanner, ScanPageInfo* info); +static void _application_scanner_page_info_cb_scanner_got_page_info (Scanner* _sender, ScanPageInfo* info, gpointer self); +gpointer scan_line_ref (gpointer instance); +void scan_line_unref (gpointer instance); +GParamSpec* param_spec_scan_line (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_scan_line (GValue* value, gpointer v_object); +void value_take_scan_line (GValue* value, gpointer v_object); +gpointer value_get_scan_line (const GValue* value); +GType scan_line_get_type (void) G_GNUC_CONST; +static void application_scanner_line_cb (Application* self, Scanner* scanner, ScanLine* line); +static void _application_scanner_line_cb_scanner_got_line (Scanner* _sender, ScanLine* line, gpointer self); +static void application_scanner_page_done_cb (Application* self, Scanner* scanner); +static void _application_scanner_page_done_cb_scanner_page_done (Scanner* _sender, gpointer self); +static void application_scanner_document_done_cb (Application* self, Scanner* scanner); +static void _application_scanner_document_done_cb_scanner_document_done (Scanner* _sender, gpointer self); +static void application_scanner_failed_cb (Application* self, Scanner* scanner, gint error_code, const gchar* error_string); +static void _application_scanner_failed_cb_scanner_scan_failed (Scanner* _sender, gint error_code, const gchar* error_string, gpointer self); +static void application_scanner_scanning_changed_cb (Application* self, Scanner* scanner); +static void _application_scanner_scanning_changed_cb_scanner_scanning_changed (Scanner* _sender, gpointer self); +static void application_on_uevent (Application* self, GUdevClient* client, const gchar* action, GUdevDevice* device); +static void _application_on_uevent_g_udev_client_uevent (GUdevClient* _sender, const gchar* action, GUdevDevice* device, gpointer self); +void simple_scan_set_scan_devices (SimpleScan* self, GList* devices); +void simple_scan_set_selected_device (SimpleScan* self, const gchar* device); +static void _scan_device_unref0_ (gpointer var); +static void _g_list_free__scan_device_unref0_ (GList* self); +void application_start (Application* self); +void simple_scan_start (SimpleScan* self); +void scanner_start (Scanner* self); +void simple_scan_authorize (SimpleScan* self, const gchar* resource, gchar** username, gchar** password); +void scanner_authorize (Scanner* self, const gchar* username, const gchar* password); +gpointer page_ref (gpointer instance); +void page_unref (gpointer instance); +GParamSpec* param_spec_page (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags); +void value_set_page (GValue* value, gpointer v_object); +void value_take_page (GValue* value, gpointer v_object); +gpointer value_get_page (const GValue* value); +GType page_get_type (void) G_GNUC_CONST; +static Page* application_append_page (Application* self); +Page* book_get_page (Book* self, gint page_number); +gboolean page_has_data (Page* self); +void simple_scan_set_selected_page (SimpleScan* self, Page* page); +void page_start (Page* self); +GType scan_direction_get_type (void) G_GNUC_CONST; +ScanDirection page_get_scan_direction (Page* self); +gint page_get_width (Page* self); +gint page_get_height (Page* self); +gint page_get_dpi (Page* self); +gboolean page_has_crop (Page* self); +gchar* page_get_named_crop (Page* self); +void page_get_crop (Page* self, gint* x, gint* y, gint* width, gint* height); +Page* book_append_page (Book* self, gint width, gint height, gint dpi, ScanDirection scan_direction); +void page_set_named_crop (Page* self, const gchar* name); +void page_set_custom_crop (Page* self, gint width, gint height); +void page_move_crop (Page* self, gint x, gint y); +static gchar* application_get_profile_for_device (Application* self, const gchar* device_name); +void page_set_page_info (Page* self, ScanPageInfo* info); +void page_set_color_profile (Page* self, const gchar* color_profile); +guint book_get_n_pages (Book* self); +void page_parse_scan_line (Page* self, ScanLine* line); +void page_finish (Page* self); +static void application_remove_empty_page (Application* self); +void book_delete_page (Book* self, Page* page); +void simple_scan_show_error (SimpleScan* self, const gchar* error_title, const gchar* error_text, gboolean change_scanner_hint); +void simple_scan_set_scanning (SimpleScan* self, gboolean scanning); +gboolean scanner_is_scanning (Scanner* self); +GType scan_mode_get_type (void) G_GNUC_CONST; +GType scan_type_get_type (void) G_GNUC_CONST; +void simple_scan_set_default_file_name (SimpleScan* self, const gchar* default_file_name); +void scanner_scan (Scanner* self, const gchar* device, ScanOptions* options); +void scanner_cancel (Scanner* self); +static gchar* application_get_temporary_filename (Application* self, const gchar* prefix, const gchar* extension); +void book_save (Book* self, const gchar* type, GFile* file, GError** error); +void page_save (Page* self, const gchar* type, GFile* file, GError** error); +void scanner_free (Scanner* self); +static void application_log_cb (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message); +void scanner_redetect (Scanner* self); +gint application_main (gchar** args, int args_length1); +ScanDevice* scan_device_new (void); +ScanDevice* scan_device_construct (GType object_type); +static void _application_log_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self); +static void application_finalize (Application* obj); +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func); + +const GOptionEntry APPLICATION_options[3] = {{"version", 'v', 0, G_OPTION_ARG_NONE, &application_show_version, "Show release version", NULL}, {"debug", 'd', 0, G_OPTION_ARG_NONE, &application_debug_enabled, "Print debugging messages", NULL}, {NULL}}; + +static gpointer _scan_device_ref0 (gpointer self) { + return self ? scan_device_ref (self) : NULL; +} + + +static void _application_scan_cb_simple_scan_start_scan (SimpleScan* _sender, const gchar* device, ScanOptions* options, gpointer self) { + application_scan_cb (self, _sender, device, options); +} + + +static void _application_cancel_cb_simple_scan_stop_scan (SimpleScan* _sender, gpointer self) { + application_cancel_cb (self, _sender); +} + + +static void _application_email_cb_simple_scan_email (SimpleScan* _sender, const gchar* profile, gpointer self) { + application_email_cb (self, _sender, profile); +} + + +static void _application_quit_cb_simple_scan_quit (SimpleScan* _sender, gpointer self) { + application_quit_cb (self, _sender); +} + + +static void _application_update_scan_devices_cb_scanner_update_devices (Scanner* _sender, GList* devices, gpointer self) { + application_update_scan_devices_cb (self, _sender, devices); +} + + +static void _application_authorize_cb_scanner_request_authorization (Scanner* _sender, const gchar* resource, gpointer self) { + application_authorize_cb (self, _sender, resource); +} + + +static void _application_scanner_new_page_cb_scanner_expect_page (Scanner* _sender, gpointer self) { + application_scanner_new_page_cb (self, _sender); +} + + +static void _application_scanner_page_info_cb_scanner_got_page_info (Scanner* _sender, ScanPageInfo* info, gpointer self) { + application_scanner_page_info_cb (self, _sender, info); +} + + +static void _application_scanner_line_cb_scanner_got_line (Scanner* _sender, ScanLine* line, gpointer self) { + application_scanner_line_cb (self, _sender, line); +} + + +static void _application_scanner_page_done_cb_scanner_page_done (Scanner* _sender, gpointer self) { + application_scanner_page_done_cb (self, _sender); +} + + +static void _application_scanner_document_done_cb_scanner_document_done (Scanner* _sender, gpointer self) { + application_scanner_document_done_cb (self, _sender); +} + + +static void _application_scanner_failed_cb_scanner_scan_failed (Scanner* _sender, gint error_code, const gchar* error_string, gpointer self) { + application_scanner_failed_cb (self, _sender, error_code, error_string); +} + + +static void _application_scanner_scanning_changed_cb_scanner_scanning_changed (Scanner* _sender, gpointer self) { + application_scanner_scanning_changed_cb (self, _sender); +} + + +static void _application_on_uevent_g_udev_client_uevent (GUdevClient* _sender, const gchar* action, GUdevDevice* device, gpointer self) { + application_on_uevent (self, _sender, action, device); +} + -#include <sane/sane.h> // For SANE_STATUS_CANCELLED +static void _scan_device_unref0_ (gpointer var) { + (var == NULL) ? NULL : (var = (scan_device_unref (var), NULL)); +} -#include "ui.h" -#include "scanner.h" -#include "book.h" - - -static ScanDevice *default_device = NULL; - -static gboolean have_devices = FALSE; - -static GUdevClient *udev_client; -static SimpleScan *ui; +static void _g_list_free__scan_device_unref0_ (GList* self) { + g_list_foreach (self, (GFunc) _scan_device_unref0_, NULL); + g_list_free (self); +} -static Scanner *scanner; -static Book *book; +Application* application_construct (GType object_type, ScanDevice* device) { + Application* self = NULL; + ScanDevice* _tmp0_; + SimpleScan* _tmp1_ = NULL; + Book* _tmp2_ = NULL; + Scanner* _tmp3_ = NULL; + gchar* _tmp4_; + gchar** _tmp5_ = NULL; + gchar** subsystems; + gint subsystems_length1; + gint _subsystems_size_; + GUdevClient* _tmp6_ = NULL; + self = (Application*) g_type_create_instance (object_type); + _tmp0_ = _scan_device_ref0 (device); + _scan_device_unref0 (self->priv->default_device); + self->priv->default_device = _tmp0_; + _tmp1_ = simple_scan_new (); + _simple_scan_unref0 (self->priv->ui); + self->priv->ui = _tmp1_; + _tmp2_ = simple_scan_get_book (self->priv->ui); + _book_unref0 (self->priv->book); + self->priv->book = _tmp2_; + g_signal_connect (self->priv->ui, "start-scan", (GCallback) _application_scan_cb_simple_scan_start_scan, self); + g_signal_connect (self->priv->ui, "stop-scan", (GCallback) _application_cancel_cb_simple_scan_stop_scan, self); + g_signal_connect (self->priv->ui, "email", (GCallback) _application_email_cb_simple_scan_email, self); + g_signal_connect (self->priv->ui, "quit", (GCallback) _application_quit_cb_simple_scan_quit, self); + _tmp3_ = scanner_get_instance (); + _scanner_unref0 (self->priv->scanner); + self->priv->scanner = _tmp3_; + g_signal_connect (self->priv->scanner, "update-devices", (GCallback) _application_update_scan_devices_cb_scanner_update_devices, self); + g_signal_connect (self->priv->scanner, "request-authorization", (GCallback) _application_authorize_cb_scanner_request_authorization, self); + g_signal_connect (self->priv->scanner, "expect-page", (GCallback) _application_scanner_new_page_cb_scanner_expect_page, self); + g_signal_connect (self->priv->scanner, "got-page-info", (GCallback) _application_scanner_page_info_cb_scanner_got_page_info, self); + g_signal_connect (self->priv->scanner, "got-line", (GCallback) _application_scanner_line_cb_scanner_got_line, self); + g_signal_connect (self->priv->scanner, "page-done", (GCallback) _application_scanner_page_done_cb_scanner_page_done, self); + g_signal_connect (self->priv->scanner, "document-done", (GCallback) _application_scanner_document_done_cb_scanner_document_done, self); + g_signal_connect (self->priv->scanner, "scan-failed", (GCallback) _application_scanner_failed_cb_scanner_scan_failed, self); + g_signal_connect (self->priv->scanner, "scanning-changed", (GCallback) _application_scanner_scanning_changed_cb_scanner_scanning_changed, self); + _tmp4_ = g_strdup ("usb"); + _tmp5_ = g_new0 (gchar*, 2 + 1); + _tmp5_[0] = _tmp4_; + _tmp5_[1] = NULL; + subsystems = _tmp5_; + subsystems_length1 = 2; + _subsystems_size_ = subsystems_length1; + _tmp6_ = g_udev_client_new (subsystems); + _g_object_unref0 (self->priv->udev_client); + self->priv->udev_client = _tmp6_; + g_signal_connect (self->priv->udev_client, "uevent", (GCallback) _application_on_uevent_g_udev_client_uevent, self); + if (self->priv->default_device != NULL) { + GList* device_list; + ScanDevice* _tmp7_; + device_list = NULL; + _tmp7_ = _scan_device_ref0 (self->priv->default_device); + device_list = g_list_append (device_list, _tmp7_); + simple_scan_set_scan_devices (self->priv->ui, device_list); + simple_scan_set_selected_device (self->priv->ui, self->priv->default_device->name); + __g_list_free__scan_device_unref0_0 (device_list); + } + subsystems = (_vala_array_free (subsystems, subsystems_length1, (GDestroyNotify) g_free), NULL); + return self; +} -static GTimer *log_timer; -static FILE *log_file; +Application* application_new (ScanDevice* device) { + return application_construct (TYPE_APPLICATION, device); +} -static gboolean debug = FALSE; +void application_start (Application* self) { + g_return_if_fail (self != NULL); + simple_scan_start (self->priv->ui); + scanner_start (self->priv->scanner); +} -static void -update_scan_devices_cb (Scanner *scanner, GList *devices) -{ - GList *devices_copy; - - devices_copy = g_list_copy (devices); - - /* If the default device is not detected add it to the list */ - if (default_device) { - GList *i; - - for (i = devices_copy; i; i = i->next) { - ScanDevice *device = i->data; - if (strcmp (device->name, default_device->name) == 0) - break; - } - - if (!i) - devices_copy = g_list_prepend (devices_copy, default_device); - } - - have_devices = devices_copy != NULL; - ui_set_scan_devices (ui, devices_copy); - - g_list_free (devices_copy); -} - - -static void -authorize_cb (Scanner *scanner, const gchar *resource) -{ - gchar *username = NULL, *password = NULL; - ui_authorize (ui, resource, &username, &password); - scanner_authorize (scanner, username, password); - g_free (username); - g_free (password); -} - - -static Page * -append_page () -{ - Page *page; - ScanDirection scan_direction = TOP_TO_BOTTOM; - gboolean do_crop = FALSE; - gchar *named_crop = NULL; - gint width = 100, height = 100, dpi = 100, cx, cy, cw, ch; - - /* Use current page if not used */ - page = book_get_page (book, -1); - if (page && !page_has_data (page)) { - ui_set_selected_page (ui, page); - page_start (page); - return page; - } - - /* Copy info from previous page */ - if (page) { - scan_direction = page_get_scan_direction (page); - width = page_get_width (page); - height = page_get_height (page); - dpi = page_get_dpi (page); - - do_crop = page_has_crop (page); - if (do_crop) { - named_crop = page_get_named_crop (page); - page_get_crop (page, &cx, &cy, &cw, &ch); - } - } - - page = book_append_page (book, width, height, dpi, scan_direction); - if (do_crop) { - if (named_crop) { - page_set_named_crop (page, named_crop); - g_free (named_crop); - } - else - page_set_custom_crop (page, cw, ch); - page_move_crop (page, cx, cy); - } - ui_set_selected_page (ui, page); - page_start (page); - - return page; -} - - -static void -scanner_new_page_cb (Scanner *scanner) -{ - append_page (); -} - - -static gchar * -get_profile_for_device (const gchar *current_device) -{ - gboolean ret; - DBusGConnection *connection; - DBusGProxy *proxy; - GError *error = NULL; - GType custom_g_type_string_string; - GPtrArray *profile_data_array = NULL; - gchar *device_id = NULL; - gchar *icc_profile = NULL; - - /* Connect to the color manager on the session bus */ - connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); - proxy = dbus_g_proxy_new_for_name (connection, - "org.gnome.ColorManager", - "/org/gnome/ColorManager", - "org.gnome.ColorManager"); - - /* Get color profile */ - device_id = g_strdup_printf ("sane:%s", current_device); - custom_g_type_string_string = dbus_g_type_get_collection ("GPtrArray", - dbus_g_type_get_struct("GValueArray", - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_INVALID)); - ret = dbus_g_proxy_call (proxy, "GetProfilesForDevice", &error, - G_TYPE_STRING, device_id, - G_TYPE_STRING, "", - G_TYPE_INVALID, - custom_g_type_string_string, &profile_data_array, - G_TYPE_INVALID); - g_object_unref (proxy); - g_free (device_id); - if (!ret) { - g_debug ("The request failed: %s", error->message); - g_error_free (error); - return NULL; - } - - if (profile_data_array->len > 0) { - GValueArray *gva; - GValue *gv = NULL; - - /* Just use the preferred profile filename */ - gva = (GValueArray *) g_ptr_array_index (profile_data_array, 0); - gv = g_value_array_get_nth (gva, 1); - icc_profile = g_value_dup_string (gv); - g_value_unset (gv); - } - else - g_debug ("There are no ICC profiles for the device sane:%s", current_device); - g_ptr_array_free (profile_data_array, TRUE); - - return icc_profile; -} - - -static void -scanner_page_info_cb (Scanner *scanner, ScanPageInfo *info) -{ - Page *page; - - g_debug ("Page is %d pixels wide, %d pixels high, %d bits per pixel", - info->width, info->height, info->depth); - /* Add a new page */ - page = append_page (); - page_set_page_info (page, info); +static void application_update_scan_devices_cb (Application* self, Scanner* scanner, GList* devices) { + GList* _tmp0_ = NULL; + GList* devices_copy; + guint _tmp1_; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + _tmp0_ = g_list_copy (devices); + devices_copy = _tmp0_; + if (self->priv->default_device != NULL) { + gboolean default_in_list; + default_in_list = FALSE; + { + GList* device_collection = NULL; + GList* device_it = NULL; + device_collection = devices_copy; + for (device_it = device_collection; device_it != NULL; device_it = device_it->next) { + ScanDevice* device = NULL; + device = (ScanDevice*) device_it->data; + { + if (g_strcmp0 (device->name, self->priv->default_device->name) == 0) { + default_in_list = TRUE; + break; + } + } + } + } + if (!default_in_list) { + devices_copy = g_list_prepend (devices_copy, self->priv->default_device); + } + } + _tmp1_ = g_list_length (devices_copy); + self->priv->have_devices = _tmp1_ > ((guint) 0); + simple_scan_set_scan_devices (self->priv->ui, devices_copy); + _g_list_free0 (devices_copy); +} + - /* Get ICC color profile */ - /* FIXME: The ICC profile could change */ - /* FIXME: Don't do a D-bus call for each page, cache color profiles */ - page_set_color_profile (page, get_profile_for_device (info->device)); +static void application_authorize_cb (Application* self, Scanner* scanner, const gchar* resource) { + gchar* username = NULL; + gchar* password = NULL; + gchar* _tmp0_ = NULL; + gchar* _tmp1_ = NULL; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + g_return_if_fail (resource != NULL); + simple_scan_authorize (self->priv->ui, resource, &_tmp0_, &_tmp1_); + _g_free0 (username); + username = _tmp0_; + _g_free0 (password); + password = _tmp1_; + scanner_authorize (scanner, username, password); + _g_free0 (password); + _g_free0 (username); } -static void -scanner_line_cb (Scanner *scanner, ScanLine *line) -{ - Page *page; +static Page* application_append_page (Application* self) { + Page* result = NULL; + Page* _tmp0_ = NULL; + Page* page; + gboolean _tmp1_ = FALSE; + ScanDirection scan_direction; + gboolean do_crop; + gchar* named_crop; + gint width; + gint height; + gint dpi; + gint cx; + gint cy; + gint cw; + gint ch; + Page* _tmp13_ = NULL; + g_return_val_if_fail (self != NULL, NULL); + _tmp0_ = book_get_page (self->priv->book, -1); + page = _tmp0_; + if (page != NULL) { + gboolean _tmp2_; + _tmp2_ = page_has_data (page); + _tmp1_ = !_tmp2_; + } else { + _tmp1_ = FALSE; + } + if (_tmp1_) { + simple_scan_set_selected_page (self->priv->ui, page); + page_start (page); + result = page; + return result; + } + scan_direction = SCAN_DIRECTION_TOP_TO_BOTTOM; + do_crop = FALSE; + named_crop = NULL; + width = 100; + height = 100; + dpi = 100; + cx = 0; + cy = 0; + cw = 0; + ch = 0; + if (page != NULL) { + ScanDirection _tmp3_; + gint _tmp4_; + gint _tmp5_; + gint _tmp6_; + gboolean _tmp7_; + _tmp3_ = page_get_scan_direction (page); + scan_direction = _tmp3_; + _tmp4_ = page_get_width (page); + width = _tmp4_; + _tmp5_ = page_get_height (page); + height = _tmp5_; + _tmp6_ = page_get_dpi (page); + dpi = _tmp6_; + _tmp7_ = page_has_crop (page); + do_crop = _tmp7_; + if (do_crop) { + gchar* _tmp8_ = NULL; + gint _tmp9_; + gint _tmp10_; + gint _tmp11_; + gint _tmp12_; + _tmp8_ = page_get_named_crop (page); + _g_free0 (named_crop); + named_crop = _tmp8_; + page_get_crop (page, &_tmp9_, &_tmp10_, &_tmp11_, &_tmp12_); + cx = _tmp9_; + cy = _tmp10_; + cw = _tmp11_; + ch = _tmp12_; + } + } + _tmp13_ = book_append_page (self->priv->book, width, height, dpi, scan_direction); + _page_unref0 (page); + page = _tmp13_; + if (do_crop) { + if (named_crop != NULL) { + page_set_named_crop (page, named_crop); + } else { + page_set_custom_crop (page, cw, ch); + } + page_move_crop (page, cx, cy); + } + simple_scan_set_selected_page (self->priv->ui, page); + page_start (page); + result = page; + _g_free0 (named_crop); + return result; +} + - page = book_get_page (book, book_get_n_pages (book) - 1); - page_parse_scan_line (page, line); +static void application_scanner_new_page_cb (Application* self, Scanner* scanner) { + Page* _tmp0_ = NULL; + Page* _tmp1_; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + _tmp0_ = application_append_page (self); + _tmp1_ = _tmp0_; + _page_unref0 (_tmp1_); } -static void -scanner_page_done_cb (Scanner *scanner) -{ - Page *page; - page = book_get_page (book, book_get_n_pages (book) - 1); - page_finish (page); +static gchar* application_get_profile_for_device (Application* self, const gchar* device_name) { + gchar* result = NULL; + g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (device_name != NULL, NULL); + result = NULL; + return result; } -static void -remove_empty_page () -{ - Page *page; +static void application_scanner_page_info_cb (Application* self, Scanner* scanner, ScanPageInfo* info) { + Page* _tmp0_ = NULL; + Page* page; + gchar* _tmp1_ = NULL; + gchar* _tmp2_; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + g_return_if_fail (info != NULL); + g_debug ("simple-scan.vala:233: Page is %d pixels wide, %d pixels high, %d bits " \ +"per pixel", info->width, info->height, info->depth); + _tmp0_ = application_append_page (self); + page = _tmp0_; + page_set_page_info (page, info); + _tmp1_ = application_get_profile_for_device (self, info->device); + _tmp2_ = _tmp1_; + page_set_color_profile (page, _tmp2_); + _g_free0 (_tmp2_); + _page_unref0 (page); +} - page = book_get_page (book, book_get_n_pages (book) - 1); - /* Remove a failed page */ - if (page_has_data (page)) - page_finish (page); - else - book_delete_page (book, page); +static void application_scanner_line_cb (Application* self, Scanner* scanner, ScanLine* line) { + guint _tmp0_; + Page* _tmp1_ = NULL; + Page* page; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + g_return_if_fail (line != NULL); + _tmp0_ = book_get_n_pages (self->priv->book); + _tmp1_ = book_get_page (self->priv->book, ((gint) _tmp0_) - 1); + page = _tmp1_; + page_parse_scan_line (page, line); + _page_unref0 (page); } -static void -scanner_document_done_cb (Scanner *scanner) -{ - remove_empty_page (); +static void application_scanner_page_done_cb (Application* self, Scanner* scanner) { + guint _tmp0_; + Page* _tmp1_ = NULL; + Page* page; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + _tmp0_ = book_get_n_pages (self->priv->book); + _tmp1_ = book_get_page (self->priv->book, ((gint) _tmp0_) - 1); + page = _tmp1_; + page_finish (page); + _page_unref0 (page); } -static void -scanner_failed_cb (Scanner *scanner, GError *error) -{ - remove_empty_page (); - if (!g_error_matches (error, SCANNER_TYPE, SANE_STATUS_CANCELLED)) { - ui_show_error (ui, - /* Title of error dialog when scan failed */ - _("Failed to scan"), - error->message, - have_devices); - } +static void application_remove_empty_page (Application* self) { + guint _tmp0_; + Page* _tmp1_ = NULL; + Page* page; + gboolean _tmp2_; + g_return_if_fail (self != NULL); + _tmp0_ = book_get_n_pages (self->priv->book); + _tmp1_ = book_get_page (self->priv->book, ((gint) _tmp0_) - 1); + page = _tmp1_; + _tmp2_ = page_has_data (page); + if (_tmp2_) { + page_finish (page); + } else { + book_delete_page (self->priv->book, page); + } + _page_unref0 (page); } -static void -scanner_scanning_changed_cb (Scanner *scanner) -{ - ui_set_scanning (ui, scanner_is_scanning (scanner)); +static void application_scanner_document_done_cb (Application* self, Scanner* scanner) { + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + application_remove_empty_page (self); } -static void -scan_cb (SimpleScan *ui, const gchar *device, ScanOptions *options) -{ - /* Default filename to use when saving document (and extension will be added, e.g. .jpg) */ - const gchar *filename_prefix = _("Scanned Document"); - const gchar *extension; - gchar *filename; +static void application_scanner_failed_cb (Application* self, Scanner* scanner, gint error_code, const gchar* error_string) { + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + g_return_if_fail (error_string != NULL); + application_remove_empty_page (self); + if (error_code != ((gint) SANE_STATUS_CANCELLED)) { + const gchar* _tmp0_ = NULL; + _tmp0_ = _ ("Failed to scan"); + simple_scan_show_error (self->priv->ui, _tmp0_, error_string, self->priv->have_devices); + } +} - if (options->scan_mode == SCAN_MODE_COLOR) - extension = "jpg"; - else - extension = "pdf"; - g_debug ("Requesting scan at %d dpi from device '%s'", options->dpi, device); +static void application_scanner_scanning_changed_cb (Application* self, Scanner* scanner) { + gboolean _tmp0_; + g_return_if_fail (self != NULL); + g_return_if_fail (scanner != NULL); + _tmp0_ = scanner_is_scanning (scanner); + simple_scan_set_scanning (self->priv->ui, _tmp0_); +} - if (!scanner_is_scanning (scanner)) - append_page (); - filename = g_strdup_printf ("%s.%s", filename_prefix, extension); - ui_set_default_file_name (ui, filename); - g_free (filename); - scanner_scan (scanner, device, options); +static void application_scan_cb (Application* self, SimpleScan* ui, const gchar* device, ScanOptions* options) { + gboolean _tmp0_; + const gchar* _tmp3_ = NULL; + gchar* _tmp4_; + gchar* filename_prefix; + gchar* extension = NULL; + gchar* _tmp7_ = NULL; + gchar* filename; + g_return_if_fail (self != NULL); + g_return_if_fail (ui != NULL); + g_return_if_fail (options != NULL); + g_debug ("simple-scan.vala:293: Requesting scan at %d dpi from device '%s'", options->dpi, device); + _tmp0_ = scanner_is_scanning (self->priv->scanner); + if (!_tmp0_) { + Page* _tmp1_ = NULL; + Page* _tmp2_; + _tmp1_ = application_append_page (self); + _tmp2_ = _tmp1_; + _page_unref0 (_tmp2_); + } + _tmp3_ = _ ("Scanned Document"); + _tmp4_ = g_strdup (_tmp3_); + filename_prefix = _tmp4_; + if (options->scan_mode == SCAN_MODE_COLOR) { + gchar* _tmp5_; + _tmp5_ = g_strdup ("jpg"); + _g_free0 (extension); + extension = _tmp5_; + } else { + gchar* _tmp6_; + _tmp6_ = g_strdup ("pdf"); + _g_free0 (extension); + extension = _tmp6_; + } + _tmp7_ = g_strdup_printf ("%s.%s", filename_prefix, extension); + filename = _tmp7_; + simple_scan_set_default_file_name (ui, filename); + scanner_scan (self->priv->scanner, device, options); + _g_free0 (filename); + _g_free0 (extension); + _g_free0 (filename_prefix); } -static void -cancel_cb (SimpleScan *ui) -{ - scanner_cancel (scanner); +static void application_cancel_cb (Application* self, SimpleScan* ui) { + g_return_if_fail (self != NULL); + g_return_if_fail (ui != NULL); + scanner_cancel (self->priv->scanner); } -static gchar * -get_temporary_filename (const gchar *prefix, const gchar *extension) -{ - gint fd; - gchar *filename, *path; - GError *error = NULL; +static gchar* application_get_temporary_filename (Application* self, const gchar* prefix, const gchar* extension) { + gchar* result = NULL; + gchar* _tmp0_ = NULL; + gchar* filename; + gchar* path = NULL; + GError * _inner_error_ = NULL; + g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (prefix != NULL, NULL); + g_return_val_if_fail (extension != NULL, NULL); + _tmp0_ = g_strdup_printf ("%sXXXXXX.%s", prefix, extension); + filename = _tmp0_; + { + gchar* _tmp1_ = NULL; + gint _tmp2_; + gint fd; + _tmp2_ = g_file_open_tmp (filename, &_tmp1_, &_inner_error_); + _g_free0 (path); + path = _tmp1_; + fd = _tmp2_; + if (_inner_error_ != NULL) { + goto __catch3_g_error; + } + close (fd); + } + goto __finally3; + __catch3_g_error: + { + GError* e = NULL; + e = _inner_error_; + _inner_error_ = NULL; + g_warning ("simple-scan.vala:329: Error saving email attachment: %s", e->message); + result = NULL; + _g_error_free0 (e); + _g_free0 (path); + _g_free0 (filename); + return result; + } + __finally3: + if (_inner_error_ != NULL) { + _g_free0 (path); + _g_free0 (filename); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return NULL; + } + result = path; + _g_free0 (filename); + return result; +} + - /* NOTE: I'm not sure if this is a 100% safe strategy to use g_file_open_tmp(), close and - * use the filename but it appears to work in practise */ +static void application_email_cb (Application* self, SimpleScan* ui, const gchar* profile) { + gboolean saved; + gchar* _tmp0_; + gchar* command_line; + GError * _inner_error_ = NULL; + g_return_if_fail (self != NULL); + g_return_if_fail (ui != NULL); + g_return_if_fail (profile != NULL); + saved = FALSE; + _tmp0_ = g_strdup ("xdg-email"); + command_line = _tmp0_; + if (g_strcmp0 (profile, "text") == 0) { + gchar* _tmp1_ = NULL; + gchar* path; + _tmp1_ = application_get_temporary_filename (self, "scan", "pdf"); + path = _tmp1_; + if (path != NULL) { + GFile* _tmp2_ = NULL; + GFile* file; + gchar* _tmp3_ = NULL; + gchar* _tmp4_; + gchar* _tmp5_; + _tmp2_ = g_file_new_for_path (path); + file = _tmp2_; + { + book_save (self->priv->book, "pdf", file, &_inner_error_); + if (_inner_error_ != NULL) { + goto __catch4_g_error; + } + } + goto __finally4; + __catch4_g_error: + { + GError* e = NULL; + e = _inner_error_; + _inner_error_ = NULL; + g_warning ("simple-scan.vala:355: Unable to save email file: %s", e->message); + _g_error_free0 (e); + _g_object_unref0 (file); + _g_free0 (path); + _g_free0 (command_line); + return; + } + __finally4: + if (_inner_error_ != NULL) { + _g_object_unref0 (file); + _g_free0 (path); + _g_free0 (command_line); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return; + } + _tmp3_ = g_strdup_printf (" --attach %s", path); + _tmp4_ = _tmp3_; + _tmp5_ = g_strconcat (command_line, _tmp4_, NULL); + _g_free0 (command_line); + command_line = _tmp5_; + _g_free0 (_tmp4_); + _g_object_unref0 (file); + } + _g_free0 (path); + } else { + { + gint i; + i = 0; + { + gboolean _tmp6_; + _tmp6_ = TRUE; + while (TRUE) { + guint _tmp7_; + gchar* _tmp8_ = NULL; + gchar* path; + GFile* _tmp9_ = NULL; + GFile* file; + gchar* _tmp12_ = NULL; + gchar* _tmp13_; + gchar* _tmp14_; + if (!_tmp6_) { + i++; + } + _tmp6_ = FALSE; + _tmp7_ = book_get_n_pages (self->priv->book); + if (!(((guint) i) < _tmp7_)) { + break; + } + _tmp8_ = application_get_temporary_filename (self, "scan", "jpg"); + path = _tmp8_; + if (path == NULL) { + saved = FALSE; + _g_free0 (path); + break; + } + _tmp9_ = g_file_new_for_path (path); + file = _tmp9_; + { + Page* _tmp10_ = NULL; + Page* _tmp11_; + _tmp10_ = book_get_page (self->priv->book, i); + _tmp11_ = _tmp10_; + page_save (_tmp11_, "jpeg", file, &_inner_error_); + _page_unref0 (_tmp11_); + if (_inner_error_ != NULL) { + goto __catch5_g_error; + } + } + goto __finally5; + __catch5_g_error: + { + GError* e = NULL; + e = _inner_error_; + _inner_error_ = NULL; + g_warning ("simple-scan.vala:379: Unable to save email file: %s", e->message); + _g_error_free0 (e); + _g_object_unref0 (file); + _g_free0 (path); + _g_free0 (command_line); + return; + } + __finally5: + if (_inner_error_ != NULL) { + _g_object_unref0 (file); + _g_free0 (path); + _g_free0 (command_line); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return; + } + _tmp12_ = g_strdup_printf (" --attach %s", path); + _tmp13_ = _tmp12_; + _tmp14_ = g_strconcat (command_line, _tmp13_, NULL); + _g_free0 (command_line); + command_line = _tmp14_; + _g_free0 (_tmp13_); + if (!saved) { + _g_object_unref0 (file); + _g_free0 (path); + break; + } + _g_object_unref0 (file); + _g_free0 (path); + } + } + } + } + g_debug ("simple-scan.vala:389: Launching email client: %s", command_line); + { + g_spawn_command_line_async (command_line, &_inner_error_); + if (_inner_error_ != NULL) { + goto __catch6_g_error; + } + } + goto __finally6; + __catch6_g_error: + { + GError* e = NULL; + e = _inner_error_; + _inner_error_ = NULL; + g_warning ("simple-scan.vala:396: Unable to start email: %s", e->message); + _g_error_free0 (e); + } + __finally6: + if (_inner_error_ != NULL) { + _g_free0 (command_line); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return; + } + _g_free0 (command_line); +} - filename = g_strdup_printf ("%sXXXXXX.%s", prefix, extension); - fd = g_file_open_tmp (filename, &path, &error); - g_free (filename); - if (fd < 0) { - g_warning ("Error saving email attachment: %s", error->message); - g_clear_error (&error); - return NULL; - } - close (fd); - return path; +static void application_quit_cb (Application* self, SimpleScan* ui) { + g_return_if_fail (self != NULL); + g_return_if_fail (ui != NULL); + _book_unref0 (self->priv->book); + self->priv->book = NULL; + ui = NULL; + _g_object_unref0 (self->priv->udev_client); + self->priv->udev_client = NULL; + scanner_free (self->priv->scanner); + gtk_main_quit (); } -static void -email_cb (SimpleScan *ui, const gchar *profile) -{ - gboolean saved = FALSE; - GError *error = NULL; - GString *command_line; - - command_line = g_string_new ("xdg-email"); - - /* Save text files as PDFs */ - if (strcmp (profile, "text") == 0) { - gchar *path; - - /* Open a temporary file */ - path = get_temporary_filename ("scan", "pdf"); - if (path) { - GFile *file; - - file = g_file_new_for_path (path); - saved = book_save (book, "pdf", file, &error); - g_string_append_printf (command_line, " --attach %s", path); - g_free (path); - g_object_unref (file); - } - } - else { - gint i; - - for (i = 0; i < book_get_n_pages (book); i++) { - gchar *path; - GFile *file; - - path = get_temporary_filename ("scan", "jpg"); - if (!path) { - saved = FALSE; - break; - } - - file = g_file_new_for_path (path); - saved = page_save (book_get_page (book, i), "jpeg", file, &error); - g_string_append_printf (command_line, " --attach %s", path); - g_free (path); - g_object_unref (file); - - if (!saved) - break; - } - } - - if (saved) { - g_debug ("Launchind email client: %s", command_line->str); - g_spawn_command_line_async (command_line->str, &error); - - if (error) { - g_warning ("Unable to start email: %s", error->message); - g_clear_error (&error); - } - } - else { - g_warning ("Unable to save email file: %s", error->message); - g_clear_error (&error); - } - - g_string_free (command_line, TRUE); -} - - -static void -quit_cb (SimpleScan *ui) -{ - g_object_unref (book); - g_object_unref (ui); - g_object_unref (udev_client); - scanner_free (scanner); - gtk_main_quit (); -} - - -static void -version() -{ - /* NOTE: Is not translated so can be easily parsed */ - fprintf(stderr, "%1$s %2$s\n", SIMPLE_SCAN_BINARY, VERSION); -} - - -static void -usage(int show_gtk) -{ - fprintf(stderr, - /* Description on how to use simple-scan displayed on command-line */ - _("Usage:\n" - " %s [DEVICE...] - Scanning utility"), SIMPLE_SCAN_BINARY); - - fprintf(stderr, - "\n\n"); - - fprintf(stderr, - /* Description on how to use simple-scan displayed on command-line */ - _("Help Options:\n" - " -d, --debug Print debugging messages\n" - " -v, --version Show release version\n" - " -h, --help Show help options\n" - " --help-all Show all help options\n" - " --help-gtk Show GTK+ options")); - fprintf(stderr, - "\n\n"); - - if (show_gtk) { - fprintf(stderr, - /* Description on simple-scan command-line GTK+ options displayed on command-line */ - _("GTK+ Options:\n" - " --class=CLASS Program class as used by the window manager\n" - " --name=NAME Program name as used by the window manager\n" - " --screen=SCREEN X screen to use\n" - " --sync Make X calls synchronous\n" - " --gtk-module=MODULES Load additional GTK+ modules\n" - " --g-fatal-warnings Make all warnings fatal")); - fprintf(stderr, - "\n\n"); - } -} - - -static void -log_cb (const gchar *log_domain, GLogLevelFlags log_level, - const gchar *message, gpointer data) -{ - /* Log everything to a file */ - if (log_file) { - const gchar *prefix; - - switch (log_level & G_LOG_LEVEL_MASK) { - case G_LOG_LEVEL_ERROR: - prefix = "ERROR:"; - break; - case G_LOG_LEVEL_CRITICAL: - prefix = "CRITICAL:"; - break; - case G_LOG_LEVEL_WARNING: - prefix = "WARNING:"; - break; - case G_LOG_LEVEL_MESSAGE: - prefix = "MESSAGE:"; - break; - case G_LOG_LEVEL_INFO: - prefix = "INFO:"; - break; - case G_LOG_LEVEL_DEBUG: - prefix = "DEBUG:"; - break; - default: - prefix = "LOG:"; - break; - } - - fprintf (log_file, "[%+.2fs] %s %s\n", g_timer_elapsed (log_timer, NULL), prefix, message); - } - - /* Only show debug if requested */ - if (log_level & G_LOG_LEVEL_DEBUG) { - if (debug) - g_log_default_handler (log_domain, log_level, message, data); - } - else - g_log_default_handler (log_domain, log_level, message, data); -} - - -static void -get_options (int argc, char **argv) -{ - int i; - - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (strcmp (arg, "-d") == 0 || - strcmp (arg, "--debug") == 0) { - debug = TRUE; - } - else if (strcmp (arg, "-v") == 0 || - strcmp (arg, "--version") == 0) { - version (); - exit (0); - } - else if (strcmp (arg, "-h") == 0 || - strcmp (arg, "--help") == 0) { - usage (FALSE); - exit (0); - } - else if (strcmp (arg, "--help-all") == 0 || - strcmp (arg, "--help-gtk") == 0) { - usage (TRUE); - exit (0); - } - else { - if (default_device) { - fprintf (stderr, "Unknown argument: '%s'\n", arg); - exit (1); - } - default_device = g_malloc0 (sizeof (ScanDevice)); - default_device->name = g_strdup (arg); - default_device->label = g_strdup (arg); - } - } -} - - -static void -on_uevent (GUdevClient *client, const gchar *action, GUdevDevice *device) -{ - scanner_redetect (scanner); -} - - -int -main (int argc, char **argv) -{ - const char *udev_subsystems[] = { "usb", NULL }; - gchar *path; - - g_thread_init (NULL); - - /* Log to a file */ - log_timer = g_timer_new (); - path = g_build_filename (g_get_user_cache_dir (), "simple-scan", NULL); - g_mkdir_with_parents (path, 0700); - g_free (path); - path = g_build_filename (g_get_user_cache_dir (), "simple-scan", "simple-scan.log", NULL); - log_file = fopen (path, "w"); - g_free (path); - g_log_set_default_handler (log_cb, NULL); - - bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - gtk_init (&argc, &argv); - - get_options (argc, argv); - - g_debug ("Starting Simple Scan %s, PID=%i", VERSION, getpid ()); - - ui = ui_new (); - book = ui_get_book (ui); - g_signal_connect (ui, "start-scan", G_CALLBACK (scan_cb), NULL); - g_signal_connect (ui, "stop-scan", G_CALLBACK (cancel_cb), NULL); - g_signal_connect (ui, "email", G_CALLBACK (email_cb), NULL); - g_signal_connect (ui, "quit", G_CALLBACK (quit_cb), NULL); - - scanner = scanner_new (); - g_signal_connect (G_OBJECT (scanner), "update-devices", G_CALLBACK (update_scan_devices_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "authorize", G_CALLBACK (authorize_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "expect-page", G_CALLBACK (scanner_new_page_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "got-page-info", G_CALLBACK (scanner_page_info_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "got-line", G_CALLBACK (scanner_line_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "page-done", G_CALLBACK (scanner_page_done_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "document-done", G_CALLBACK (scanner_document_done_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "scan-failed", G_CALLBACK (scanner_failed_cb), NULL); - g_signal_connect (G_OBJECT (scanner), "scanning-changed", G_CALLBACK (scanner_scanning_changed_cb), NULL); - - udev_client = g_udev_client_new (udev_subsystems); - g_signal_connect (udev_client, "uevent", G_CALLBACK (on_uevent), NULL); - - if (default_device) { - GList device_list; - - device_list.data = default_device; - device_list.next = NULL; - device_list.prev = NULL; - ui_set_scan_devices (ui, &device_list); - ui_set_selected_device (ui, default_device->name); - } - - ui_start (ui); - scanner_start (scanner); - - gtk_main (); - - return 0; +static void application_log_cb (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message) { + g_return_if_fail (message != NULL); + if (application_log_file != NULL) { + gchar* prefix = NULL; + gdouble _tmp7_; + switch (log_level & G_LOG_LEVEL_MASK) { + case G_LOG_LEVEL_ERROR: + { + gchar* _tmp0_; + _tmp0_ = g_strdup ("ERROR:"); + _g_free0 (prefix); + prefix = _tmp0_; + break; + } + case G_LOG_LEVEL_CRITICAL: + { + gchar* _tmp1_; + _tmp1_ = g_strdup ("CRITICAL:"); + _g_free0 (prefix); + prefix = _tmp1_; + break; + } + case G_LOG_LEVEL_WARNING: + { + gchar* _tmp2_; + _tmp2_ = g_strdup ("WARNING:"); + _g_free0 (prefix); + prefix = _tmp2_; + break; + } + case G_LOG_LEVEL_MESSAGE: + { + gchar* _tmp3_; + _tmp3_ = g_strdup ("MESSAGE:"); + _g_free0 (prefix); + prefix = _tmp3_; + break; + } + case G_LOG_LEVEL_INFO: + { + gchar* _tmp4_; + _tmp4_ = g_strdup ("INFO:"); + _g_free0 (prefix); + prefix = _tmp4_; + break; + } + case G_LOG_LEVEL_DEBUG: + { + gchar* _tmp5_; + _tmp5_ = g_strdup ("DEBUG:"); + _g_free0 (prefix); + prefix = _tmp5_; + break; + } + default: + { + gchar* _tmp6_; + _tmp6_ = g_strdup ("LOG:"); + _g_free0 (prefix); + prefix = _tmp6_; + break; + } + } + _tmp7_ = g_timer_elapsed (application_log_timer, NULL); + fprintf (application_log_file, "[%+.2fs] %s %s\n", _tmp7_, prefix, message); + _g_free0 (prefix); + } + if ((log_level & G_LOG_LEVEL_DEBUG) != 0) { + if (application_debug_enabled) { + g_log_default_handler (log_domain, log_level, message, NULL); + } + } else { + g_log_default_handler (log_domain, log_level, message, NULL); + } } + + +static void application_on_uevent (Application* self, GUdevClient* client, const gchar* action, GUdevDevice* device) { + g_return_if_fail (self != NULL); + g_return_if_fail (client != NULL); + g_return_if_fail (action != NULL); + g_return_if_fail (device != NULL); + scanner_redetect (self->priv->scanner); +} + + +static void _application_log_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self) { + application_log_cb (log_domain, log_levels, message); +} + + +gint application_main (gchar** args, int args_length1) { + gint result = 0; + const gchar* _tmp0_ = NULL; + GOptionContext* _tmp1_ = NULL; + GOptionContext* c; + GOptionGroup* _tmp2_ = NULL; + ScanDevice* device; + GTimer* _tmp7_ = NULL; + const gchar* _tmp8_ = NULL; + gchar* _tmp9_ = NULL; + gchar* path; + const gchar* _tmp10_ = NULL; + gchar* _tmp11_ = NULL; + FILE* _tmp12_ = NULL; + pid_t _tmp13_; + Application* _tmp14_ = NULL; + Application* app; + GError * _inner_error_ = NULL; + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + gtk_init (&args_length1, &args); + _tmp0_ = _ ("[DEVICE...] - Scanning utility"); + _tmp1_ = g_option_context_new (_tmp0_); + c = _tmp1_; + g_option_context_add_main_entries (c, APPLICATION_options, GETTEXT_PACKAGE); + _tmp2_ = gtk_get_option_group (TRUE); + g_option_context_add_group (c, _tmp2_); + { + g_option_context_parse (c, &args_length1, &args, &_inner_error_); + if (_inner_error_ != NULL) { + goto __catch7_g_error; + } + } + goto __finally7; + __catch7_g_error: + { + GError* e = NULL; + const gchar* _tmp3_ = NULL; + e = _inner_error_; + _inner_error_ = NULL; + fprintf (stderr, "%s\n", e->message); + _tmp3_ = _ ("Run '%s --help' to see a full list of available command line options."); + fprintf (stderr, _tmp3_, args[0]); + fprintf (stderr, "\n"); + result = EXIT_FAILURE; + _g_error_free0 (e); + _g_option_context_free0 (c); + return result; + } + __finally7: + if (_inner_error_ != NULL) { + _g_option_context_free0 (c); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return 0; + } + if (application_show_version) { + fprintf (stderr, "simple-scan %s\n", VERSION); + result = EXIT_SUCCESS; + _g_option_context_free0 (c); + return result; + } + device = NULL; + if (args_length1 > 1) { + ScanDevice* _tmp4_ = NULL; + gchar* _tmp5_; + gchar* _tmp6_; + _tmp4_ = scan_device_new (); + _scan_device_unref0 (device); + device = _tmp4_; + _tmp5_ = g_strdup (args[1]); + _g_free0 (device->name); + device->name = _tmp5_; + _tmp6_ = g_strdup (args[1]); + _g_free0 (device->label); + device->label = _tmp6_; + } + _tmp7_ = g_timer_new (); + _g_timer_destroy0 (application_log_timer); + application_log_timer = _tmp7_; + _tmp8_ = g_get_user_cache_dir (); + _tmp9_ = g_build_filename (_tmp8_, "simple-scan", NULL, NULL); + path = _tmp9_; + g_mkdir_with_parents (path, 0700); + _tmp10_ = g_get_user_cache_dir (); + _tmp11_ = g_build_filename (_tmp10_, "simple-scan", "simple-scan.log", NULL, NULL); + _g_free0 (path); + path = _tmp11_; + _tmp12_ = fopen (path, "w"); + _fclose0 (application_log_file); + application_log_file = _tmp12_; + g_log_set_default_handler (_application_log_cb_glog_func, NULL); + _tmp13_ = getpid (); + g_debug ("simple-scan.vala:507: Starting Simple Scan %s, PID=%i", VERSION, (gint) _tmp13_); + _tmp14_ = application_new (device); + app = _tmp14_; + application_start (app); + gtk_main (); + result = EXIT_SUCCESS; + _application_unref0 (app); + _g_free0 (path); + _scan_device_unref0 (device); + _g_option_context_free0 (c); + return result; +} + + +int main (int argc, char ** argv) { + g_type_init (); + return application_main (argv, argc); +} + + +static void value_application_init (GValue* value) { + value->data[0].v_pointer = NULL; +} + + +static void value_application_free_value (GValue* value) { + if (value->data[0].v_pointer) { + application_unref (value->data[0].v_pointer); + } +} + + +static void value_application_copy_value (const GValue* src_value, GValue* dest_value) { + if (src_value->data[0].v_pointer) { + dest_value->data[0].v_pointer = application_ref (src_value->data[0].v_pointer); + } else { + dest_value->data[0].v_pointer = NULL; + } +} + + +static gpointer value_application_peek_pointer (const GValue* value) { + return value->data[0].v_pointer; +} + + +static gchar* value_application_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) { + if (collect_values[0].v_pointer) { + Application* object; + object = collect_values[0].v_pointer; + if (object->parent_instance.g_class == NULL) { + return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL); + } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) { + return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL); + } + value->data[0].v_pointer = application_ref (object); + } else { + value->data[0].v_pointer = NULL; + } + return NULL; +} + + +static gchar* value_application_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) { + Application** object_p; + object_p = collect_values[0].v_pointer; + if (!object_p) { + return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value)); + } + if (!value->data[0].v_pointer) { + *object_p = NULL; + } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) { + *object_p = value->data[0].v_pointer; + } else { + *object_p = application_ref (value->data[0].v_pointer); + } + return NULL; +} + + +GParamSpec* param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) { + ParamSpecApplication* spec; + g_return_val_if_fail (g_type_is_a (object_type, TYPE_APPLICATION), NULL); + spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags); + G_PARAM_SPEC (spec)->value_type = object_type; + return G_PARAM_SPEC (spec); +} + + +gpointer value_get_application (const GValue* value) { + g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION), NULL); + return value->data[0].v_pointer; +} + + +void value_set_application (GValue* value, gpointer v_object) { + Application* old; + g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION)); + old = value->data[0].v_pointer; + if (v_object) { + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION)); + g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value))); + value->data[0].v_pointer = v_object; + application_ref (value->data[0].v_pointer); + } else { + value->data[0].v_pointer = NULL; + } + if (old) { + application_unref (old); + } +} + + +void value_take_application (GValue* value, gpointer v_object) { + Application* old; + g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_APPLICATION)); + old = value->data[0].v_pointer; + if (v_object) { + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_APPLICATION)); + g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value))); + value->data[0].v_pointer = v_object; + } else { + value->data[0].v_pointer = NULL; + } + if (old) { + application_unref (old); + } +} + + +static void application_class_init (ApplicationClass * klass) { + application_parent_class = g_type_class_peek_parent (klass); + APPLICATION_CLASS (klass)->finalize = application_finalize; + g_type_class_add_private (klass, sizeof (ApplicationPrivate)); +} + + +static void application_instance_init (Application * self) { + self->priv = APPLICATION_GET_PRIVATE (self); + self->priv->default_device = NULL; + self->priv->have_devices = FALSE; + self->ref_count = 1; +} + + +static void application_finalize (Application* obj) { + Application * self; + self = APPLICATION (obj); + _scan_device_unref0 (self->priv->default_device); + _g_object_unref0 (self->priv->udev_client); + _simple_scan_unref0 (self->priv->ui); + _scanner_unref0 (self->priv->scanner); + _book_unref0 (self->priv->book); +} + + +GType application_get_type (void) { + static volatile gsize application_type_id__volatile = 0; + if (g_once_init_enter (&application_type_id__volatile)) { + static const GTypeValueTable g_define_type_value_table = { value_application_init, value_application_free_value, value_application_copy_value, value_application_peek_pointer, "p", value_application_collect_value, "p", value_application_lcopy_value }; + static const GTypeInfo g_define_type_info = { sizeof (ApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Application), 0, (GInstanceInitFunc) application_instance_init, &g_define_type_value_table }; + static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) }; + GType application_type_id; + application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Application", &g_define_type_info, &g_define_type_fundamental_info, 0); + g_once_init_leave (&application_type_id__volatile, application_type_id); + } + return application_type_id__volatile; +} + + +gpointer application_ref (gpointer instance) { + Application* self; + self = instance; + g_atomic_int_inc (&self->ref_count); + return instance; +} + + +void application_unref (gpointer instance) { + Application* self; + self = instance; + if (g_atomic_int_dec_and_test (&self->ref_count)) { + APPLICATION_GET_CLASS (self)->finalize (self); + g_type_free_instance ((GTypeInstance *) self); + } +} + + +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) { + if ((array != NULL) && (destroy_func != NULL)) { + int i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + + +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) { + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + + + |