[gedit/wip/improve-printing: 1/2] PrintJob: small code improvements
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/improve-printing: 1/2] PrintJob: small code improvements
- Date: Fri, 20 Feb 2015 11:22:02 +0000 (UTC)
commit a1a323a24f8463083a23b1f814ef59764811322f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Feb 20 10:56:58 2015 +0100
PrintJob: small code improvements
- in the header, remove dead code and remove comments for standard
GObject code.
- use g_signal_connect_object()
- better order the functions: dispose before finalize and init after
class_init.
- various other things (space out more the code, etc)
gedit/gedit-print-job.c | 95 +++++++++++++++++++++++------------------------
gedit/gedit-print-job.h | 31 ++-------------
2 files changed, 51 insertions(+), 75 deletions(-)
---
diff --git a/gedit/gedit-print-job.c b/gedit/gedit-print-job.c
index a19ef65..22a63b9 100644
--- a/gedit/gedit-print-job.c
+++ b/gedit/gedit-print-job.c
@@ -1,5 +1,5 @@
/*
- * gedit-print.c
+ * gedit-print-job.c
* This file is part of gedit
*
* Copyright (C) 2000-2001 Chema Celorio, Paolo Maggi
@@ -93,16 +93,9 @@ static guint print_job_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_PRIVATE (GeditPrintJob, gedit_print_job, G_TYPE_OBJECT)
-static void end_print_cb (GtkPrintOperation *operation,
- GtkPrintContext *context,
- GeditPrintJob *job);
-
-static void done_cb (GtkPrintOperation *operation,
- GtkPrintOperationResult result,
- GeditPrintJob *job);
-
static void
-set_view (GeditPrintJob *job, GeditView *view)
+set_view (GeditPrintJob *job,
+ GeditView *view)
{
job->priv->view = view;
job->priv->doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
@@ -121,6 +114,7 @@ gedit_print_job_get_property (GObject *object,
case PROP_VIEW:
g_value_set_object (value, job->priv->view);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -140,6 +134,7 @@ gedit_print_job_set_property (GObject *object,
case PROP_VIEW:
set_view (job, g_value_get_object (value));
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -147,34 +142,25 @@ gedit_print_job_set_property (GObject *object,
}
static void
-gedit_print_job_finalize (GObject *object)
+gedit_print_job_dispose (GObject *object)
{
GeditPrintJob *job = GEDIT_PRINT_JOB (object);
- g_free (job->priv->status_string);
+ g_clear_object (&job->priv->print_settings);
+ g_clear_object (&job->priv->compositor);
+ g_clear_object (&job->priv->operation);
- G_OBJECT_CLASS (gedit_print_job_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gedit_print_job_parent_class)->dispose (object);
}
static void
-gedit_print_job_dispose (GObject *object)
+gedit_print_job_finalize (GObject *object)
{
GeditPrintJob *job = GEDIT_PRINT_JOB (object);
- g_clear_object (&job->priv->print_settings);
- g_clear_object (&job->priv->compositor);
-
- if (job->priv->operation != NULL)
- {
- g_signal_handlers_disconnect_by_func (job->priv->operation,
- end_print_cb, job);
- g_signal_handlers_disconnect_by_func (job->priv->operation,
- done_cb, job);
- g_object_unref (job->priv->operation);
- job->priv->operation = NULL;
- }
+ g_free (job->priv->status_string);
- G_OBJECT_CLASS (gedit_print_job_parent_class)->dispose (object);
+ G_OBJECT_CLASS (gedit_print_job_parent_class)->finalize (object);
}
static void
@@ -186,8 +172,8 @@ gedit_print_job_class_init (GeditPrintJobClass *klass)
object_class->get_property = gedit_print_job_get_property;
object_class->set_property = gedit_print_job_set_property;
- object_class->finalize = gedit_print_job_finalize;
object_class->dispose = gedit_print_job_dispose;
+ object_class->finalize = gedit_print_job_finalize;
g_object_class_install_property (object_class,
PROP_VIEW,
@@ -235,6 +221,18 @@ gedit_print_job_class_init (GeditPrintJobClass *klass)
}
static void
+gedit_print_job_init (GeditPrintJob *job)
+{
+ job->priv = gedit_print_job_get_instance_private (job);
+
+ job->priv->print_settings = g_settings_new ("org.gnome.gedit.preferences.print");
+
+ job->priv->status = GEDIT_PRINT_JOB_STATUS_INIT;
+
+ job->priv->status_string = g_strdup (_("Preparing..."));
+}
+
+static void
line_numbers_checkbutton_toggled (GtkToggleButton *button,
GeditPrintJob *job)
{
@@ -735,7 +733,9 @@ done_cb (GtkPrintOperation *operation,
g_object_unref (job);
}
-/* Note that gedit_print_job_print can can only be called once on a given GeditPrintJob */
+/* Note that gedit_print_job_print() can only be called once on a given
+ * GeditPrintJob.
+ */
GtkPrintOperationResult
gedit_print_job_print (GeditPrintJob *job,
GtkPrintOperationAction action,
@@ -780,34 +780,43 @@ gedit_print_job_print (GeditPrintJob *job,
"create-custom-widget",
G_CALLBACK (create_custom_widget_cb),
job);
+
g_signal_connect (priv->operation,
"custom-widget-apply",
G_CALLBACK (custom_widget_apply_cb),
job);
+
g_signal_connect (priv->operation,
"begin-print",
G_CALLBACK (begin_print_cb),
job);
+
g_signal_connect (priv->operation,
"preview",
G_CALLBACK (preview_cb),
job);
+
g_signal_connect (priv->operation,
"paginate",
G_CALLBACK (paginate_cb),
job);
+
g_signal_connect (priv->operation,
"draw-page",
G_CALLBACK (draw_page_cb),
job);
- g_signal_connect (priv->operation,
- "end-print",
- G_CALLBACK (end_print_cb),
- job);
- g_signal_connect (priv->operation,
- "done",
- G_CALLBACK (done_cb),
- job);
+
+ g_signal_connect_object (priv->operation,
+ "end-print",
+ G_CALLBACK (end_print_cb),
+ job,
+ 0);
+
+ g_signal_connect_object (priv->operation,
+ "done",
+ G_CALLBACK (done_cb),
+ job,
+ 0);
return gtk_print_operation_run (priv->operation,
action,
@@ -815,18 +824,6 @@ gedit_print_job_print (GeditPrintJob *job,
error);
}
-static void
-gedit_print_job_init (GeditPrintJob *job)
-{
- job->priv = gedit_print_job_get_instance_private (job);
-
- job->priv->print_settings = g_settings_new ("org.gnome.gedit.preferences.print");
-
- job->priv->status = GEDIT_PRINT_JOB_STATUS_INIT;
-
- job->priv->status_string = g_strdup (_("Preparing..."));
-}
-
GeditPrintJob *
gedit_print_job_new (GeditView *view)
{
diff --git a/gedit/gedit-print-job.h b/gedit/gedit-print-job.h
index 7291629..58bf260 100644
--- a/gedit/gedit-print-job.h
+++ b/gedit/gedit-print-job.h
@@ -27,9 +27,6 @@
G_BEGIN_DECLS
-/*
- * Type checking and casting macros
- */
#define GEDIT_TYPE_PRINT_JOB (gedit_print_job_get_type())
#define GEDIT_PRINT_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_PRINT_JOB,
GeditPrintJob))
#define GEDIT_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_PRINT_JOB,
GeditPrintJobClass))
@@ -37,13 +34,15 @@ G_BEGIN_DECLS
#define GEDIT_IS_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PRINT_JOB))
#define GEDIT_PRINT_JOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_PRINT_JOB,
GeditPrintJobClass))
+typedef struct _GeditPrintJob GeditPrintJob;
+typedef struct _GeditPrintJobClass GeditPrintJobClass;
+typedef struct _GeditPrintJobPrivate GeditPrintJobPrivate;
typedef enum
{
GEDIT_PRINT_JOB_STATUS_INIT,
GEDIT_PRINT_JOB_STATUS_PAGINATING,
- GEDIT_PRINT_JOB_STATUS_DRAWING,
- GEDIT_PRINT_JOB_STATUS_DONE
+ GEDIT_PRINT_JOB_STATUS_DRAWING
} GeditPrintJobStatus;
typedef enum
@@ -53,15 +52,6 @@ typedef enum
GEDIT_PRINT_JOB_RESULT_ERROR
} GeditPrintJobResult;
-/* Private structure type */
-typedef struct _GeditPrintJobPrivate GeditPrintJobPrivate;
-
-/*
- * Main object structure
- */
-typedef struct _GeditPrintJob GeditPrintJob;
-
-
struct _GeditPrintJob
{
GObject parent;
@@ -70,11 +60,6 @@ struct _GeditPrintJob
GeditPrintJobPrivate *priv;
};
-/*
- * Class definition
- */
-typedef struct _GeditPrintJobClass GeditPrintJobClass;
-
struct _GeditPrintJobClass
{
GObjectClass parent_class;
@@ -86,21 +71,15 @@ struct _GeditPrintJobClass
void (* show_preview) (GeditPrintJob *job,
GtkWidget *preview);
- void (*done) (GeditPrintJob *job,
+ void (* done) (GeditPrintJob *job,
GeditPrintJobResult result,
const GError *error);
};
-/*
- * Public methods
- */
GType gedit_print_job_get_type (void) G_GNUC_CONST;
GeditPrintJob *gedit_print_job_new (GeditView *view);
-void gedit_print_job_set_export_filename (GeditPrintJob *job,
- const gchar *filename);
-
GtkPrintOperationResult gedit_print_job_print (GeditPrintJob *job,
GtkPrintOperationAction action,
GtkPageSetup *page_setup,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]