~noskcaj/ubuntu/wily/epiphany-browser/merge

« back to all changes in this revision

Viewing changes to embed/ephy-embed-shell.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-10-02 20:30:38 UTC
  • mto: (120.1.2 experimental) (1.10.1) (105.1.14 sid)
  • mto: This revision was merged to the branch mainline in revision 120.
  • Revision ID: package-import@ubuntu.com-20121002203038-q12kfjstt2ljy911
Tags: upstream-3.6.0
ImportĀ upstreamĀ versionĀ 3.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
1
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
2
/*
3
3
 *  Copyright Ā© 2000-2003 Marco Pesenti Gritti
4
4
 *  Copyright Ā© 2011 Igalia S.L.
20
20
 */
21
21
 
22
22
#include <config.h>
23
 
 
24
 
#include <glib.h>
25
 
 
26
 
#include <glib/gi18n.h>
27
 
#include <glib/gstdio.h>
28
 
#include <gtk/gtk.h>
 
23
#include "ephy-embed-shell.h"
29
24
 
30
25
#include "ephy-adblock-manager.h"
31
26
#include "ephy-debug.h"
32
27
#include "ephy-download.h"
33
 
#include "ephy-embed-shell.h"
 
28
#include "ephy-embed-private.h"
34
29
#include "ephy-embed-single.h"
35
30
#include "ephy-embed-type-builtins.h"
36
31
#include "ephy-encodings.h"
37
32
#include "ephy-file-helpers.h"
38
33
#include "ephy-history-service.h"
39
 
#include "ephy-print-utils.h"
40
 
 
41
 
#define PAGE_SETUP_FILENAME     "page-setup-gtk.ini"
42
 
#define PRINT_SETTINGS_FILENAME "print-settings.ini"
43
 
 
44
 
#define LEGACY_PAGE_SETUP_FILENAME      "page-setup.ini"
 
34
#include "ephy-snapshot-service.h"
 
35
 
 
36
#include <glib/gi18n.h>
 
37
#include <gtk/gtk.h>
 
38
#include <stdlib.h>
 
39
 
 
40
#define PAGE_SETUP_FILENAME "page-setup-gtk.ini"
 
41
#define PRINT_SETTINGS_FILENAME "print-settings.ini"
45
42
 
46
43
#define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate))
47
44
 
48
 
#define ENABLE_MIGRATION
49
 
 
50
45
struct _EphyEmbedShellPrivate
51
46
{
52
 
        EphyHistoryService *global_history_service;
53
 
        GList *downloads;
54
 
        EphyEmbedSingle *embed_single;
55
 
        EphyEncodings *encodings;
56
 
        EphyAdBlockManager *adblock_manager;
57
 
        GtkPageSetup *page_setup;
58
 
        GtkPrintSettings *print_settings;
59
 
        EphyEmbedShellMode mode;
60
 
        guint single_initialised : 1;
 
47
  EphyHistoryService *global_history_service;
 
48
  GList *downloads;
 
49
  EphyEmbedSingle *embed_single;
 
50
  EphyEncodings *encodings;
 
51
  EphyAdBlockManager *adblock_manager;
 
52
  GtkPageSetup *page_setup;
 
53
  GtkPrintSettings *print_settings;
 
54
  EphyEmbedShellMode mode;
 
55
  EphyFrecentStore *frecent_store;
 
56
  guint single_initialised : 1;
61
57
};
62
58
 
63
59
enum
64
60
{
65
 
        DOWNLOAD_ADDED,
66
 
        DOWNLOAD_REMOVED,
67
 
        PREPARE_CLOSE,
68
 
        LAST_SIGNAL
 
61
  DOWNLOAD_ADDED,
 
62
  DOWNLOAD_REMOVED,
 
63
  PREPARE_CLOSE,
 
64
  LAST_SIGNAL
69
65
};
70
66
 
71
67
static guint signals[LAST_SIGNAL];
72
68
 
73
69
enum
74
70
{
75
 
        PROP_0,
76
 
        PROP_MODE,
77
 
        N_PROPERTIES
 
71
  PROP_0,
 
72
  PROP_MODE,
 
73
  N_PROPERTIES
78
74
};
79
75
 
80
76
static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
81
77
 
82
 
static void ephy_embed_shell_class_init (EphyEmbedShellClass *klass);
83
 
static void ephy_embed_shell_init       (EphyEmbedShell *shell);
84
 
 
85
78
EphyEmbedShell *embed_shell = NULL;
86
79
 
87
80
G_DEFINE_TYPE (EphyEmbedShell, ephy_embed_shell, GTK_TYPE_APPLICATION)
89
82
static void
90
83
ephy_embed_shell_dispose (GObject *object)
91
84
{
92
 
        EphyEmbedShell *shell = EPHY_EMBED_SHELL (object);
93
 
        EphyEmbedShellPrivate *priv = shell->priv;
94
 
 
95
 
        if (priv->encodings != NULL)
96
 
        {
97
 
                LOG ("Unref encodings");
98
 
                g_object_unref (priv->encodings);
99
 
                priv->encodings = NULL;
100
 
        }
101
 
 
102
 
        if (priv->page_setup != NULL)
103
 
        {
104
 
                g_object_unref (priv->page_setup);
105
 
                priv->page_setup = NULL;
106
 
        }
107
 
 
108
 
        if (priv->print_settings != NULL)
109
 
        {
110
 
                g_object_unref (priv->print_settings);
111
 
                priv->print_settings = NULL;
112
 
        }
113
 
 
114
 
        G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
 
85
  EphyEmbedShellPrivate *priv = EPHY_EMBED_SHELL (object)->priv;
 
86
 
 
87
  g_clear_object (&priv->encodings);
 
88
  g_clear_object (&priv->page_setup);
 
89
  g_clear_object (&priv->print_settings);
 
90
  g_clear_object (&priv->frecent_store);
 
91
  g_clear_object (&priv->global_history_service);
 
92
  g_clear_object (&priv->embed_single);
 
93
  g_clear_object (&priv->adblock_manager);
 
94
 
 
95
  G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
115
96
}
116
97
 
117
98
static void
118
99
ephy_embed_shell_finalize (GObject *object)
119
100
{
120
 
        EphyEmbedShell *shell = EPHY_EMBED_SHELL (object);
121
 
 
122
 
        if (shell->priv->downloads != NULL)
123
 
        {
124
 
                LOG ("Destroying downloads list");
125
 
                g_list_foreach (shell->priv->downloads, (GFunc) g_object_unref, NULL);
126
 
                g_list_free (shell->priv->downloads);
127
 
                shell->priv->downloads = NULL;
128
 
        }
129
 
 
130
 
        if (shell->priv->global_history_service)
131
 
        {
132
 
                LOG ("Unref history service");
133
 
                g_object_unref (shell->priv->global_history_service);
134
 
        }
135
 
 
136
 
        if (shell->priv->embed_single)
137
 
        {
138
 
                LOG ("Unref embed single");
139
 
                g_object_unref (G_OBJECT (shell->priv->embed_single));
140
 
        }
141
 
 
142
 
        if (shell->priv->adblock_manager != NULL)
143
 
        {
144
 
                LOG ("Unref adblock manager");
145
 
                g_object_unref (shell->priv->adblock_manager);
146
 
                shell->priv->adblock_manager = NULL;
147
 
        }
148
 
 
149
 
        G_OBJECT_CLASS (ephy_embed_shell_parent_class)->finalize (object);
 
101
  EphyEmbedShellPrivate *priv = EPHY_EMBED_SHELL (object)->priv;
 
102
 
 
103
  if (priv->downloads != NULL) {
 
104
    LOG ("Destroying downloads list");
 
105
    g_list_foreach (priv->downloads, (GFunc)g_object_unref, NULL);
 
106
    g_list_free (priv->downloads);
 
107
    priv->downloads = NULL;
 
108
  }
 
109
 
 
110
  G_OBJECT_CLASS (ephy_embed_shell_parent_class)->finalize (object);
150
111
}
151
112
 
152
113
/**
158
119
GObject *
159
120
ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell)
160
121
{
161
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
162
 
 
163
 
        if (shell->priv->global_history_service == NULL)
164
 
        {
165
 
                char *filename;
166
 
 
167
 
                filename = g_build_filename (ephy_dot_dir (), "ephy-history.db", NULL);
168
 
                shell->priv->global_history_service = ephy_history_service_new (filename);
169
 
                g_free (filename);
170
 
                g_return_val_if_fail (shell->priv->global_history_service, NULL);
171
 
        }
172
 
 
173
 
        return G_OBJECT (shell->priv->global_history_service);
 
122
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
123
 
 
124
  if (shell->priv->global_history_service == NULL) {
 
125
    char *filename;
 
126
 
 
127
    filename = g_build_filename (ephy_dot_dir (), "ephy-history.db", NULL);
 
128
    shell->priv->global_history_service = ephy_history_service_new (filename);
 
129
    g_free (filename);
 
130
    g_return_val_if_fail (shell->priv->global_history_service, NULL);
 
131
  }
 
132
 
 
133
  return G_OBJECT (shell->priv->global_history_service);
 
134
}
 
135
 
 
136
static GdkPixbuf *
 
137
ephy_embed_shell_get_overview_icon (const char *icon_name)
 
138
{
 
139
  GError *error = NULL;
 
140
  GdkPixbuf *pixbuf;
 
141
  const char *filename;
 
142
 
 
143
  filename = ephy_file (icon_name);
 
144
  pixbuf = gdk_pixbuf_new_from_file (filename, &error);
 
145
 
 
146
  if (!pixbuf) {
 
147
    g_warning ("Couldn't load icon: %s", error->message);
 
148
    g_error_free (error);
 
149
  }
 
150
 
 
151
  return pixbuf;
 
152
}
 
153
 
 
154
/**
 
155
 * ephy_embed_shell_get_frecent_store:
 
156
 * @shell: a #EphyEmbedShell
 
157
 *
 
158
 * Gets the #EphyFrecentStore in the shell. This can be used
 
159
 * by EphyOverview implementors.
 
160
 *
 
161
 * Returns: (transfer none): a #EphyFrecentStore
 
162
 **/
 
163
EphyFrecentStore *
 
164
ephy_embed_shell_get_frecent_store (EphyEmbedShell *shell)
 
165
{
 
166
  GdkPixbuf *default_icon;
 
167
  GdkPixbuf *frame;
 
168
 
 
169
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
170
 
 
171
  if (shell->priv->frecent_store == NULL) {
 
172
    shell->priv->frecent_store = ephy_frecent_store_new ();
 
173
    default_icon = ephy_embed_shell_get_overview_icon ("missing-thumbnail.png");
 
174
    frame = ephy_embed_shell_get_overview_icon ("thumbnail-frame.png");
 
175
    g_object_set (shell->priv->frecent_store,
 
176
                  "history-service",
 
177
                  ephy_embed_shell_get_global_history_service (shell),
 
178
                  "history-length", 10,
 
179
                  "default-icon", default_icon,
 
180
                  "icon-frame", frame,
 
181
                  NULL);
 
182
    g_object_unref (default_icon);
 
183
    g_object_unref (frame);
 
184
  }
 
185
 
 
186
  return shell->priv->frecent_store;
174
187
}
175
188
 
176
189
static GObject *
177
190
impl_get_embed_single (EphyEmbedShell *shell)
178
191
{
179
 
        EphyEmbedShellPrivate *priv;
180
 
 
181
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
182
 
 
183
 
        priv = shell->priv;
184
 
 
185
 
        if (priv->embed_single != NULL &&
186
 
            !priv->single_initialised)
187
 
        {
188
 
                g_warning ("ephy_embed_shell_get_embed_single called while the single is being initialised!\n");
189
 
                return G_OBJECT (priv->embed_single);
190
 
        }
191
 
 
192
 
        if (priv->embed_single == NULL)
193
 
        {
194
 
                priv->embed_single = EPHY_EMBED_SINGLE
195
 
                  (g_object_new (EPHY_TYPE_EMBED_SINGLE, NULL));
196
 
                g_assert (priv->embed_single != NULL);
197
 
 
198
 
                if (!ephy_embed_single_initialize (priv->embed_single))
199
 
                {
200
 
                        GtkWidget *dialog;
201
 
 
202
 
                        dialog = gtk_message_dialog_new
203
 
                                        (NULL,
204
 
                                         GTK_DIALOG_MODAL,
205
 
                                         GTK_MESSAGE_ERROR,
206
 
                                         GTK_BUTTONS_CLOSE,
207
 
                                         _("Epiphany can't be used now. "
208
 
                                           "Initialization failed."));
209
 
                        gtk_dialog_run (GTK_DIALOG (dialog));
210
 
 
211
 
                        exit (0);
212
 
                }
213
 
 
214
 
                priv->single_initialised = TRUE;
215
 
        }
216
 
 
217
 
        return G_OBJECT (shell->priv->embed_single);
 
192
  EphyEmbedShellPrivate *priv;
 
193
 
 
194
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
195
 
 
196
  priv = shell->priv;
 
197
 
 
198
  if (priv->embed_single != NULL &&
 
199
      !priv->single_initialised) {
 
200
    g_warning ("ephy_embed_shell_get_embed_single called while the single is being initialised!\n");
 
201
    return G_OBJECT (priv->embed_single);
 
202
  }
 
203
 
 
204
  if (priv->embed_single == NULL) {
 
205
    priv->embed_single = EPHY_EMBED_SINGLE (g_object_new (EPHY_TYPE_EMBED_SINGLE, NULL));
 
206
    g_assert (priv->embed_single != NULL);
 
207
 
 
208
    if (!ephy_embed_single_initialize (priv->embed_single)) {
 
209
      GtkWidget *dialog;
 
210
 
 
211
      dialog = gtk_message_dialog_new (NULL,
 
212
                                       GTK_DIALOG_MODAL,
 
213
                                       GTK_MESSAGE_ERROR,
 
214
                                       GTK_BUTTONS_CLOSE,
 
215
                                       _("Epiphany can't be used now. "
 
216
                                         "Initialization failed."));
 
217
      gtk_dialog_run (GTK_DIALOG (dialog));
 
218
      
 
219
      exit (0);
 
220
    }
 
221
    
 
222
    priv->single_initialised = TRUE;
 
223
  }
 
224
 
 
225
  return G_OBJECT (shell->priv->embed_single);
218
226
}
219
227
 
220
228
/**
226
234
GObject *
227
235
ephy_embed_shell_get_embed_single (EphyEmbedShell *shell)
228
236
{
229
 
        EphyEmbedShellClass *klass = EPHY_EMBED_SHELL_GET_CLASS (shell);
 
237
  EphyEmbedShellClass *klass = EPHY_EMBED_SHELL_GET_CLASS (shell);
230
238
 
231
 
        return klass->get_embed_single (shell);
 
239
  return klass->get_embed_single (shell);
232
240
}
233
241
 
234
242
/**
240
248
GObject *
241
249
ephy_embed_shell_get_encodings (EphyEmbedShell *shell)
242
250
{
243
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
244
 
 
245
 
        if (shell->priv->encodings == NULL)
246
 
        {
247
 
                shell->priv->encodings = ephy_encodings_new ();
248
 
        }
249
 
 
250
 
        return G_OBJECT (shell->priv->encodings);
 
251
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
252
 
 
253
  if (shell->priv->encodings == NULL)
 
254
    shell->priv->encodings = ephy_encodings_new ();
 
255
 
 
256
  return G_OBJECT (shell->priv->encodings);
251
257
}
252
258
 
253
259
void
254
260
ephy_embed_shell_prepare_close (EphyEmbedShell *shell)
255
261
{
256
 
        g_signal_emit (shell, signals[PREPARE_CLOSE], 0);
 
262
  g_signal_emit (shell, signals[PREPARE_CLOSE], 0);
257
263
}
258
264
 
259
265
static void
260
266
ephy_embed_shell_set_property (GObject *object,
261
 
                               guint prop_id,
262
 
                               const GValue *value,
263
 
                               GParamSpec *pspec)
 
267
                               guint prop_id,
 
268
                               const GValue *value,
 
269
                               GParamSpec *pspec)
264
270
{
265
271
  EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object);
266
272
 
267
 
  switch (prop_id)
268
 
  {
 
273
  switch (prop_id) {
269
274
  case PROP_MODE:
270
 
          embed_shell->priv->mode = g_value_get_enum (value);
271
 
          break;
 
275
    embed_shell->priv->mode = g_value_get_enum (value);
 
276
    break;
272
277
  default:
273
 
          G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
278
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
274
279
  }
275
280
}
276
281
 
277
282
static void
278
283
ephy_embed_shell_get_property (GObject *object,
279
 
                               guint prop_id,
280
 
                               GValue *value,
281
 
                               GParamSpec *pspec)
 
284
                               guint prop_id,
 
285
                               GValue *value,
 
286
                               GParamSpec *pspec)
282
287
{
283
288
  EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object);
284
289
 
285
 
  switch (prop_id)
286
 
  {
 
290
  switch (prop_id) {
287
291
  case PROP_MODE:
288
 
          g_value_set_enum (value, embed_shell->priv->mode);
289
 
          break;
 
292
    g_value_set_enum (value, embed_shell->priv->mode);
 
293
    break;
290
294
  default:
291
 
          G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
295
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
292
296
  }
293
297
}
294
298
 
295
299
static void
296
300
ephy_embed_shell_init (EphyEmbedShell *shell)
297
301
{
298
 
        shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell);
299
 
 
300
 
        /* globally accessible singleton */
301
 
        g_assert (embed_shell == NULL);
302
 
        embed_shell = shell;
303
 
 
304
 
        shell->priv->downloads = NULL;
 
302
  shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell);
 
303
 
 
304
  /* globally accessible singleton */
 
305
  g_assert (embed_shell == NULL);
 
306
  embed_shell = shell;
 
307
 
 
308
  shell->priv->downloads = NULL;
305
309
}
306
310
 
307
311
static void
308
312
ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
309
313
{
310
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
311
 
 
312
 
        object_class->dispose = ephy_embed_shell_dispose;
313
 
        object_class->finalize = ephy_embed_shell_finalize;
314
 
        object_class->set_property = ephy_embed_shell_set_property;
315
 
        object_class->get_property = ephy_embed_shell_get_property;
316
 
 
317
 
        klass->get_embed_single = impl_get_embed_single;
318
 
 
319
 
        object_properties[PROP_MODE] =
320
 
                g_param_spec_enum ("mode",
321
 
                                   "Mode",
322
 
                                   "The  global mode for this instance of Epiphany .",
323
 
                                   EPHY_TYPE_EMBED_SHELL_MODE,
324
 
                                   EPHY_EMBED_SHELL_MODE_BROWSER,
325
 
                                   G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
326
 
                                   G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
327
 
        
328
 
        g_object_class_install_properties (object_class,
329
 
                                           N_PROPERTIES,
330
 
                                           object_properties);
331
 
 
 
314
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
315
 
 
316
  object_class->dispose = ephy_embed_shell_dispose;
 
317
  object_class->finalize = ephy_embed_shell_finalize;
 
318
  object_class->set_property = ephy_embed_shell_set_property;
 
319
  object_class->get_property = ephy_embed_shell_get_property;
 
320
 
 
321
  klass->get_embed_single = impl_get_embed_single;
 
322
 
 
323
  object_properties[PROP_MODE] =
 
324
    g_param_spec_enum ("mode",
 
325
                       "Mode",
 
326
                       "The  global mode f  or this instance of Epiphany .",
 
327
                       EPHY_TYPE_EMBED_SHELL_MODE,
 
328
                       EPHY_EMBED_SHELL_MODE_BROWSER,
 
329
                       G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
 
330
                       G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
 
331
  
 
332
  g_object_class_install_properties (object_class,
 
333
                                     N_PROPERTIES,
 
334
                                     object_properties);
 
335
  
332
336
/**
333
337
 * EphyEmbed::download-added:
334
338
 * @shell: the #EphyEmbedShell
337
341
 * Emitted when a #EphyDownload has been added to the global watch list of
338
342
 * @shell, via ephy_embed_shell_add_download.
339
343
 **/
340
 
        signals[DOWNLOAD_ADDED] =
341
 
                g_signal_new ("download-added",
342
 
                              EPHY_TYPE_EMBED_SHELL,
343
 
                              G_SIGNAL_RUN_LAST,
344
 
                              G_STRUCT_OFFSET (EphyEmbedShellClass, download_added),
345
 
                              NULL, NULL,
346
 
                              g_cclosure_marshal_VOID__OBJECT,
347
 
                              G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
348
 
 
 
344
  signals[DOWNLOAD_ADDED] =
 
345
    g_signal_new ("download-added",
 
346
                  EPHY_TYPE_EMBED_SHELL,
 
347
                  G_SIGNAL_RUN_LAST,
 
348
                  G_STRUCT_OFFSET (EphyEmbedShellClass, download_added),
 
349
                  NULL, NULL,
 
350
                  g_cclosure_marshal_VOID__OBJECT,
 
351
                  G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
 
352
  
349
353
/**
350
354
 * EphyEmbed::download-removed:
351
355
 * @shell: the #EphyEmbedShell
354
358
 * Emitted when a #EphyDownload has been removed from the global watch list of
355
359
 * @shell, via ephy_embed_shell_remove_download.
356
360
 **/
357
 
        signals[DOWNLOAD_REMOVED] =
358
 
                g_signal_new ("download-removed",
359
 
                              EPHY_TYPE_EMBED_SHELL,
360
 
                              G_SIGNAL_RUN_LAST,
361
 
                              G_STRUCT_OFFSET (EphyEmbedShellClass, download_removed),
362
 
                              NULL, NULL,
363
 
                              g_cclosure_marshal_VOID__OBJECT,
364
 
                              G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
 
361
  signals[DOWNLOAD_REMOVED] =
 
362
    g_signal_new ("download-removed",
 
363
                  EPHY_TYPE_EMBED_SHELL,
 
364
                  G_SIGNAL_RUN_LAST,
 
365
                  G_STRUCT_OFFSET (EphyEmbedShellClass, download_removed),
 
366
                  NULL, NULL,
 
367
                  g_cclosure_marshal_VOID__OBJECT,
 
368
                  G_TYPE_NONE, 1, EPHY_TYPE_DOWNLOAD);
365
369
 
366
370
/**
367
371
 * EphyEmbed::prepare-close:
371
375
 * quit on command from the session manager. You can use it when you need
372
376
 * to do something special (shut down a service, for example).
373
377
 **/
374
 
        signals[PREPARE_CLOSE] =
375
 
                g_signal_new ("prepare-close",
376
 
                              EPHY_TYPE_EMBED_SHELL,
377
 
                              G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
378
 
                              G_STRUCT_OFFSET (EphyEmbedShellClass, prepare_close),
379
 
                              NULL, NULL,
380
 
                              g_cclosure_marshal_VOID__VOID,
381
 
                              G_TYPE_NONE, 0);
 
378
  signals[PREPARE_CLOSE] =
 
379
    g_signal_new ("prepare-close",
 
380
                  EPHY_TYPE_EMBED_SHELL,
 
381
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
 
382
                  G_STRUCT_OFFSET (EphyEmbedShellClass, prepare_close),
 
383
                  NULL, NULL,
 
384
                  g_cclosure_marshal_VOID__VOID,
 
385
                  G_TYPE_NONE, 0);
382
386
 
383
 
        g_type_class_add_private (object_class, sizeof (EphyEmbedShellPrivate));
 
387
  g_type_class_add_private (object_class, sizeof (EphyEmbedShellPrivate));
384
388
}
385
389
 
386
390
/**
393
397
EphyEmbedShell *
394
398
ephy_embed_shell_get_default (void)
395
399
{
396
 
        return embed_shell;
 
400
  return embed_shell;
397
401
}
398
402
 
399
403
/**
407
411
GObject *
408
412
ephy_embed_shell_get_adblock_manager (EphyEmbedShell *shell)
409
413
{
410
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
411
 
 
412
 
        if (shell->priv->adblock_manager == NULL)
413
 
        {
414
 
                shell->priv->adblock_manager = g_object_new (EPHY_TYPE_ADBLOCK_MANAGER, NULL);
415
 
        }
416
 
 
417
 
        return G_OBJECT (shell->priv->adblock_manager);
 
414
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
415
 
 
416
  if (shell->priv->adblock_manager == NULL)
 
417
    shell->priv->adblock_manager = g_object_new (EPHY_TYPE_ADBLOCK_MANAGER, NULL);
 
418
 
 
419
  return G_OBJECT (shell->priv->adblock_manager);
418
420
}
419
421
 
420
422
void
421
 
ephy_embed_shell_set_page_setup (EphyEmbedShell *shell,
422
 
                                 GtkPageSetup *page_setup)
 
423
ephy_embed_shell_set_page_setup (EphyEmbedShell *shell,
 
424
                                 GtkPageSetup *page_setup)
423
425
{
424
 
        EphyEmbedShellPrivate *priv;
425
 
        char *path;
426
 
 
427
 
        g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
428
 
        priv = shell->priv;
429
 
 
430
 
        if (page_setup != NULL)
431
 
        {
432
 
                g_object_ref (page_setup);
433
 
        }
434
 
        else
435
 
        {
436
 
                page_setup = gtk_page_setup_new ();
437
 
        }
438
 
 
439
 
        if (priv->page_setup != NULL)
440
 
        {
441
 
                g_object_unref (priv->page_setup);
442
 
        }
443
 
 
444
 
        priv->page_setup = page_setup;
445
 
 
446
 
        path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
447
 
        gtk_page_setup_to_file (page_setup, path, NULL);
448
 
        g_free (path);
 
426
  EphyEmbedShellPrivate *priv;
 
427
  char *path;
 
428
 
 
429
  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
 
430
  priv = shell->priv;
 
431
 
 
432
  if (page_setup != NULL)
 
433
    g_object_ref (page_setup);
 
434
  else
 
435
    page_setup = gtk_page_setup_new ();
 
436
 
 
437
  if (priv->page_setup != NULL)
 
438
    g_object_unref (priv->page_setup);
 
439
 
 
440
  priv->page_setup = page_setup;
 
441
 
 
442
  path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
 
443
  gtk_page_setup_to_file (page_setup, path, NULL);
 
444
  g_free (path);
449
445
}
450
446
 
451
447
/**
454
450
 * Return value: (transfer none):
455
451
 **/
456
452
GtkPageSetup *
457
 
ephy_embed_shell_get_page_setup (EphyEmbedShell *shell)
 
453
ephy_embed_shell_get_page_setup (EphyEmbedShell *shell)
458
454
{
459
 
        EphyEmbedShellPrivate *priv;
460
 
 
461
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
462
 
        priv = shell->priv;
463
 
 
464
 
        if (priv->page_setup == NULL)
465
 
        {
466
 
                GError *error = NULL;
467
 
                char *path;
468
 
 
469
 
                path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
470
 
                priv->page_setup = gtk_page_setup_new_from_file (path, &error);
471
 
                g_free (path);
472
 
 
473
 
#ifdef ENABLE_MIGRATION
474
 
                /* If the file doesn't exist, try to fall back to the old format */
475
 
                if (error != NULL &&
476
 
                    error->domain == G_FILE_ERROR &&
477
 
                    error->code == G_FILE_ERROR_NOENT)
478
 
                {
479
 
                        path = g_build_filename (ephy_dot_dir (), LEGACY_PAGE_SETUP_FILENAME, NULL);
480
 
                        priv->page_setup = ephy_print_utils_page_setup_new_from_file (path, NULL);
481
 
                        if (priv->page_setup != NULL)
482
 
                        {
483
 
                                /* Delete the old file, so we don't migrate again */
484
 
                                g_unlink (path);
485
 
                        }
486
 
                        g_free (path);
487
 
                } else if (error != NULL)
488
 
                        g_warning ("error: %s\n", error->message);
489
 
#endif /* ENABLE_MIGRATION */
490
 
 
491
 
                if (error)
492
 
                {
493
 
                        g_error_free (error);
494
 
                }
495
 
 
496
 
                /* If that still didn't work, create a new, empty one */
497
 
                if (priv->page_setup == NULL)
498
 
                {
499
 
                        priv->page_setup = gtk_page_setup_new ();
500
 
                }
501
 
        }
502
 
 
503
 
        return priv->page_setup;
 
455
  EphyEmbedShellPrivate *priv;
 
456
 
 
457
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
458
  priv = shell->priv;
 
459
 
 
460
  if (priv->page_setup == NULL) {
 
461
    GError *error = NULL;
 
462
    char *path;
 
463
 
 
464
    path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
 
465
    priv->page_setup = gtk_page_setup_new_from_file (path, &error);
 
466
    g_free (path);
 
467
 
 
468
    if (error)
 
469
      g_error_free (error);
 
470
 
 
471
    /* If that still didn't work, create a new, empty one */
 
472
    if (priv->page_setup == NULL)
 
473
      priv->page_setup = gtk_page_setup_new ();
 
474
  }
 
475
 
 
476
  return priv->page_setup;
504
477
}
505
478
 
506
479
/**
513
486
 **/
514
487
void
515
488
ephy_embed_shell_set_print_settings (EphyEmbedShell *shell,
516
 
                                     GtkPrintSettings *settings)
 
489
                                     GtkPrintSettings *settings)
517
490
{
518
 
        EphyEmbedShellPrivate *priv;
519
 
        char *path;
520
 
 
521
 
        g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
522
 
        priv = shell->priv;
523
 
 
524
 
        if (settings != NULL)
525
 
        {
526
 
                g_object_ref (settings);
527
 
        }
528
 
 
529
 
        if (priv->print_settings != NULL)
530
 
        {
531
 
                g_object_unref (priv->print_settings);
532
 
        }
533
 
 
534
 
        priv->print_settings = settings ? settings : gtk_print_settings_new ();
535
 
 
536
 
        path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
537
 
        gtk_print_settings_to_file (settings, path, NULL);
538
 
        g_free (path);
 
491
  EphyEmbedShellPrivate *priv;
 
492
  char *path;
 
493
 
 
494
  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
 
495
  priv = shell->priv;
 
496
 
 
497
  if (settings != NULL)
 
498
    g_object_ref (settings);
 
499
 
 
500
  if (priv->print_settings != NULL)
 
501
    g_object_unref (priv->print_settings);
 
502
 
 
503
  priv->print_settings = settings ? settings : gtk_print_settings_new ();
 
504
 
 
505
  path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
 
506
  gtk_print_settings_to_file (settings, path, NULL);
 
507
  g_free (path);
539
508
}
540
509
 
541
510
/**
549
518
GtkPrintSettings *
550
519
ephy_embed_shell_get_print_settings (EphyEmbedShell *shell)
551
520
{
552
 
        EphyEmbedShellPrivate *priv;
553
 
 
554
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
555
 
        priv = shell->priv;
556
 
 
557
 
        if (priv->print_settings == NULL)
558
 
        {
559
 
                GError *error = NULL;
560
 
                char *path;
561
 
 
562
 
                path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
563
 
                priv->print_settings = gtk_print_settings_new_from_file (path, &error);
564
 
                g_free (path);
565
 
 
566
 
                /* Note: the gtk print settings file format is the same as our
567
 
                 * legacy one, so no need to migrate here.
568
 
                 */
569
 
 
570
 
                if (priv->print_settings == NULL)
571
 
                {
572
 
                        priv->print_settings = gtk_print_settings_new ();
573
 
                }
574
 
        }
575
 
 
576
 
        return priv->print_settings;
 
521
  EphyEmbedShellPrivate *priv;
 
522
 
 
523
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
524
  priv = shell->priv;
 
525
 
 
526
  if (priv->print_settings == NULL) {
 
527
    GError *error = NULL;
 
528
    char *path;
 
529
 
 
530
    path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
 
531
    priv->print_settings = gtk_print_settings_new_from_file (path, &error);
 
532
    g_free (path);
 
533
 
 
534
    /* Note: the gtk print settings file format is the same as our
 
535
     * legacy one, so no need to migrate here.
 
536
     */
 
537
 
 
538
    if (priv->print_settings == NULL)
 
539
      priv->print_settings = gtk_print_settings_new ();
 
540
  }
 
541
 
 
542
  return priv->print_settings;
577
543
}
578
544
 
579
545
/**
587
553
GList *
588
554
ephy_embed_shell_get_downloads (EphyEmbedShell *shell)
589
555
{
590
 
        EphyEmbedShellPrivate *priv;
591
 
 
592
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
593
 
        priv = shell->priv;
594
 
 
595
 
        return priv->downloads;
 
556
  EphyEmbedShellPrivate *priv;
 
557
 
 
558
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
 
559
  priv = shell->priv;
 
560
 
 
561
  return priv->downloads;
596
562
}
597
563
 
598
564
void
599
565
ephy_embed_shell_add_download (EphyEmbedShell *shell, EphyDownload *download)
600
566
{
601
 
        EphyEmbedShellPrivate *priv;
602
 
 
603
 
        g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
604
 
 
605
 
        priv = shell->priv;
606
 
        priv->downloads = g_list_prepend (priv->downloads, download);
607
 
 
608
 
        g_signal_emit_by_name (shell, "download-added", download, NULL);
 
567
  EphyEmbedShellPrivate *priv;
 
568
 
 
569
  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
 
570
 
 
571
  priv = shell->priv;
 
572
  priv->downloads = g_list_prepend (priv->downloads, download);
 
573
 
 
574
  g_signal_emit_by_name (shell, "download-added", download, NULL);
609
575
}
610
576
 
611
577
void
612
578
ephy_embed_shell_remove_download (EphyEmbedShell *shell, EphyDownload *download)
613
579
{
614
 
        EphyEmbedShellPrivate *priv;
615
 
 
616
 
        g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
617
 
 
618
 
        priv = shell->priv;
619
 
        priv->downloads = g_list_remove (priv->downloads, download);
620
 
 
621
 
        g_signal_emit_by_name (shell, "download-removed", download, NULL);
 
580
  EphyEmbedShellPrivate *priv;
 
581
 
 
582
  g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
 
583
 
 
584
  priv = shell->priv;
 
585
  priv->downloads = g_list_remove (priv->downloads, download);
 
586
 
 
587
  g_signal_emit_by_name (shell, "download-removed", download, NULL);
622
588
}
623
589
 
624
590
/**
630
596
EphyEmbedShellMode
631
597
ephy_embed_shell_get_mode (EphyEmbedShell *shell)
632
598
{
633
 
        g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), EPHY_EMBED_SHELL_MODE_BROWSER);
634
 
        
635
 
        return shell->priv->mode;
 
599
  g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), EPHY_EMBED_SHELL_MODE_BROWSER);
 
600
  
 
601
  return shell->priv->mode;
636
602
}