~ubuntu-branches/ubuntu/precise/evince/precise-updates

« back to all changes in this revision

Viewing changes to shell/ev-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-06-02 10:30:12 UTC
  • mfrom: (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602103012-liwypsthciko6ae9
Tags: 2.27.1-0ubuntu1
* New upstream version:
  New Features and UI Improvements:
  - Use GtkPrintOperation when printing for the backends that
    support rendering into a cairo context 
  - Recover previous session when running evince after a crash
  - Preliminary annotations support
  - Rename Print Setup menu entry as Page Setup for consistency with
    the GTK+ dialog title 
  - Added F3 as a find-next accelerator key 
  - Support the free Gna! unrar tool in comics backend
  - Add evince-previewer as a separate applicaton that implements
    the printing preview 
  Bug fixes:
  - Fix handling of the tmp folder 
  - Abort dnd operations originated in the same Evince window  
  - Disable bouncing during scrolling 
  - Fix build without gconftool-2 
  - Fix documentation build 
  - Fix error handling of broken documents 
  - Fix several memory leaks in comics backend 
  - Escape URIs for display 
  - Resync with libegg to remove deprecated GTK+ symbols
  - Correct check for exit status of commands in comics backend
  - Add -no-undefined flag for Cygwin build 
  - Use g_file_make_symbolic_link to create symlinks 
  - Delete the temp symlink created when opening a copy
  - Don't redraw again when zoom is set more than once to the same
    scale factor 
  - Fix print preview of empty selection 
  - Don't prevent unmounting in case the initial cwd is on an external device 
  - Create and load the document based on the mime-type provided by
    nautilus instead of using our own documents factory.
  - Fix endianess issues in dvi and tiff backends 
  - Fix memory leak in tiff backend 
  - Fix path where accels file is saved 
  - Fix fading animations 
  - Translate the categories in the nautilus properties tab
* debian/control.in:
  - updated libpoppler and gtk requirements
* debian/patches/01_launchpad.patch:
  - new version update

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <glib/gi18n.h>
39
39
#include <gio/gio.h>
40
40
#include <gtk/gtk.h>
41
 
#if GTK_CHECK_VERSION (2, 14, 0)
42
41
#include <gtk/gtkunixprint.h>
43
 
#else
44
 
#include <gtk/gtkprintunixdialog.h>
45
 
#endif
 
42
 
46
43
#ifdef WITH_GCONF
47
44
#include <gconf/gconf-client.h>
48
45
#endif
73
70
#include "ev-jobs.h"
74
71
#include "ev-message-area.h"
75
72
#include "ev-metadata-manager.h"
76
 
#include "ev-mount-operation.h"
77
73
#include "ev-navigation-action.h"
78
74
#include "ev-open-recent-action.h"
79
75
#include "ev-page-action.h"
115
111
        EV_CHROME_RAISE_TOOLBAR = 1 << 3,
116
112
        EV_CHROME_FULLSCREEN_TOOLBAR    = 1 << 4,
117
113
        EV_CHROME_SIDEBAR       = 1 << 5,
118
 
        EV_CHROME_PREVIEW_TOOLBAR       = 1 << 6,
119
114
        EV_CHROME_NORMAL        = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR
120
115
} EvChrome;
121
116
 
168
163
        /* Presentation mode */
169
164
        guint      presentation_timeout_id;
170
165
 
171
 
        /* Preview mode */
172
 
        GtkWidget *preview_toolbar;
173
 
        gchar     *print_settings_file;
174
 
 
175
166
        /* Popup view */
176
167
        GtkWidget *view_popup;
177
168
        EvLink    *link;
185
176
        char *uri;
186
177
        glong uri_mtime;
187
178
        char *local_uri;
188
 
        gboolean unlink_temp_file;
189
179
        gboolean in_reload;
190
180
        EvFileMonitor *monitor;
191
181
        guint setup_document_idle;
279
269
                                                         gboolean          unfullscreen_window);
280
270
static void     ev_window_cmd_view_presentation         (GtkAction        *action,
281
271
                                                         EvWindow         *window);
282
 
static void     ev_window_run_preview                   (EvWindow         *window);
283
272
static void     ev_view_popup_cmd_open_link             (GtkAction        *action,
284
273
                                                         EvWindow         *window);
285
274
static void     ev_view_popup_cmd_open_link_new_window  (GtkAction        *action,
307
296
static void     find_bar_search_changed_cb              (EggFindBar       *find_bar,
308
297
                                                         GParamSpec       *param,
309
298
                                                         EvWindow         *ev_window);
310
 
static void     ev_window_do_preview_print              (EvWindow         *window);
311
299
static void     ev_window_load_file_remote              (EvWindow         *ev_window,
312
300
                                                         GFile            *source_file);
313
301
static void     ev_window_media_player_key_pressed      (EvWindow         *window,
396
384
        /* File menu */
397
385
        ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document);
398
386
        ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
399
 
        ev_window_set_action_sensitive (ev_window, "FilePrintSetup", has_pages && ok_to_print);
 
387
        ev_window_set_action_sensitive (ev_window, "FilePageSetup", has_pages && ok_to_print);
400
388
        ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
401
389
        ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties);
402
390
 
419
407
        ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
420
408
        ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION,  has_pages);
421
409
        ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION,  FALSE);
422
 
        ev_window_set_action_sensitive (ev_window, "PreviewPrint", has_pages && ok_to_print);
423
410
 
424
411
        ev_window_update_actions (ev_window);
425
412
}
449
436
                                        has_pages && can_find_in_page);
450
437
        ev_window_set_action_sensitive (ev_window, "EditFindPrevious",
451
438
                                        has_pages && can_find_in_page);
 
439
        ev_window_set_action_sensitive (ev_window, "F3",
 
440
                                        has_pages && can_find_in_page);
452
441
 
453
442
        presentation_mode = ev_view_get_presentation (view);
454
443
        
536
525
        EvWindowPrivate *priv = window->priv;
537
526
        gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
538
527
        gboolean fullscreen_mode, presentation, fullscreen;
539
 
        gboolean preview_toolbar;
540
528
 
541
529
        presentation = ev_view_get_presentation (EV_VIEW (priv->view));
542
530
        fullscreen = ev_view_get_fullscreen (EV_VIEW (priv->view));
549
537
                              (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen;
550
538
        findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
551
539
        sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !presentation;
552
 
        preview_toolbar = (priv->chrome& EV_CHROME_PREVIEW_TOOLBAR);
553
540
 
554
541
        set_widget_visibility (priv->menubar, menubar); 
555
542
        set_widget_visibility (priv->toolbar, toolbar);
556
543
        set_widget_visibility (priv->find_bar, findbar);
557
544
        set_widget_visibility (priv->sidebar, sidebar);
558
545
        
559
 
        if (priv->preview_toolbar)
560
 
                set_widget_visibility (priv->preview_toolbar, preview_toolbar);
561
 
 
562
546
        ev_window_set_action_sensitive (window, "EditToolbar", toolbar);
563
547
        gtk_widget_set_sensitive (priv->menubar, menubar);
564
548
 
1008
992
                        request_width = MIN (request_width, gdk_screen_get_width (screen));
1009
993
                        request_height = MIN (request_width, gdk_screen_get_height (screen));
1010
994
                }
1011
 
                                
1012
 
                gtk_window_resize (GTK_WINDOW (window),
1013
 
                                   request_width,
1014
 
                                   request_height);
 
995
                
 
996
                if (request_width > 0 && request_height > 0) {
 
997
                        gtk_window_resize (GTK_WINDOW (window),
 
998
                                           request_width,
 
999
                                           request_height);
 
1000
                }
1015
1001
                g_value_unset (&width_ratio);
1016
1002
                g_value_unset (&height_ratio);
1017
1003
        }
1173
1159
        EvDocument *document = ev_window->priv->document;
1174
1160
        
1175
1161
        if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
1176
 
            ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
 
1162
            ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0 ||
 
1163
            ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
1177
1164
                return;
1178
1165
        }
1179
1166
        
1260
1247
                ev_window->priv->dest = NULL;
1261
1248
        }
1262
1249
 
1263
 
        if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
 
1250
        if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
 
1251
                ev_window_warning_message (ev_window, "%s",
 
1252
                                           _("The document contains no pages"));
 
1253
        } else if (ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
 
1254
                ev_window_warning_message (ev_window, "%s",
 
1255
                                           _("The document contains only empty pages"));
 
1256
        } else {
1264
1257
                ev_view_set_document (view, document);
1265
 
        } else {
1266
 
                ev_window_warning_message (ev_window, "%s",
1267
 
                                           _("The document contains no pages"));
1268
1258
        }
1269
1259
 
1270
1260
        if (ev_window->priv->setup_document_idle > 0)
1271
1261
                g_source_remove (ev_window->priv->setup_document_idle);
 
1262
 
1272
1263
        ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
1273
1264
}
1274
1265
 
1328
1319
}
1329
1320
 
1330
1321
static void
1331
 
ev_window_clear_print_settings_file (EvWindow *ev_window)
1332
 
{
1333
 
        if (ev_window->priv->print_settings_file) {
1334
 
                g_unlink (ev_window->priv->print_settings_file);
1335
 
                g_free (ev_window->priv->print_settings_file);
1336
 
                ev_window->priv->print_settings_file = NULL;
1337
 
        }
1338
 
}
1339
 
 
1340
 
static void
1341
 
ev_window_clear_temp_file (EvWindow *ev_window)
 
1322
ev_window_clear_temp_symlink (EvWindow *ev_window)
1342
1323
{
1343
1324
        GFile *file, *tempdir;
1344
1325
 
1346
1327
                return;
1347
1328
 
1348
1329
        file = g_file_new_for_uri (ev_window->priv->uri);
1349
 
        tempdir = g_file_new_for_path (g_get_tmp_dir ());
 
1330
        tempdir = g_file_new_for_path (ev_tmp_dir ());
1350
1331
 
1351
1332
        if (g_file_has_prefix (file, tempdir)) {
1352
 
                g_file_delete (file, NULL, NULL);
 
1333
                GFileInfo *file_info;
 
1334
                GError    *error = NULL;
 
1335
 
 
1336
                file_info = g_file_query_info (file,
 
1337
                                               G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK,
 
1338
                                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
1339
                                               NULL, &error);
 
1340
                if (file_info) {
 
1341
                        if (g_file_info_get_is_symlink (file_info))
 
1342
                                g_file_delete (file, NULL, NULL);
 
1343
                        g_object_unref (file_info);
 
1344
                } else {
 
1345
                        g_warning ("Error deleting temp symlink: %s\n", error->message);
 
1346
                        g_error_free (error);
 
1347
                }
1353
1348
        }
1354
1349
 
1355
1350
        g_object_unref (file);
1381
1376
                ev_window_set_document (ev_window, document);
1382
1377
 
1383
1378
                setup_document_from_metadata (ev_window);
1384
 
                
1385
 
                if (ev_window->priv->window_mode != EV_WINDOW_MODE_PREVIEW) {
1386
 
                        setup_view_from_metadata (ev_window);
1387
 
                }
 
1379
                setup_view_from_metadata (ev_window);
1388
1380
 
1389
 
                if (!ev_window->priv->unlink_temp_file) {
1390
 
                        ev_window_add_recent (ev_window, ev_window->priv->uri);
1391
 
                }
 
1381
                ev_window_add_recent (ev_window, ev_window->priv->uri);
1392
1382
 
1393
1383
                ev_window_title_set_type (ev_window->priv->title,
1394
1384
                                          EV_WINDOW_TITLE_DOCUMENT);
1425
1415
                        case EV_WINDOW_MODE_PRESENTATION:
1426
1416
                                ev_window_run_presentation (ev_window);
1427
1417
                                break;
1428
 
                        case EV_WINDOW_MODE_PREVIEW:
1429
 
                                ev_window_run_preview (ev_window);
1430
 
                                break;
1431
1418
                        default:
1432
1419
                                break;
1433
1420
                }
1606
1593
{
1607
1594
        GtkWidget *area;
1608
1595
        gchar     *text;
 
1596
        gchar     *display_name;
1609
1597
        
1610
1598
        if (ev_window->priv->message_area)
1611
1599
                return FALSE;
1612
 
        
1613
 
        text = g_strdup_printf (_("Loading document from %s"),
1614
 
                                ev_window->priv->uri);
 
1600
 
 
1601
        display_name = escape_uri_for_display (ev_window->priv->uri);
 
1602
        text = g_strdup_printf (_("Loading document from “%s”"),
 
1603
                                display_name);
 
1604
 
1615
1605
        area = ev_progress_message_area_new (GTK_STOCK_OPEN,
1616
1606
                                             text,
1617
1607
                                             GTK_STOCK_CLOSE,
1624
1614
                          ev_window);
1625
1615
        gtk_widget_show (area);
1626
1616
        ev_window_set_message_area (ev_window, area);
 
1617
 
1627
1618
        g_free (text);
 
1619
        g_free (display_name);
1628
1620
 
1629
1621
        return FALSE;
1630
1622
}
1707
1699
                return;
1708
1700
        }
1709
1701
 
1710
 
        if (error->domain == G_IO_ERROR &&
1711
 
            error->code == G_IO_ERROR_NOT_MOUNTED) {
 
1702
        if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
1712
1703
                GMountOperation *operation;
1713
1704
 
1714
 
                operation = ev_mount_operation_new (GTK_WINDOW (ev_window));
 
1705
                operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
1715
1706
                g_file_mount_enclosing_volume (source,
1716
1707
                                               G_MOUNT_MOUNT_NONE,
1717
1708
                                               operation, NULL,
1718
1709
                                               (GAsyncReadyCallback)mount_volume_ready_cb,
1719
1710
                                               ev_window);
1720
1711
                g_object_unref (operation);
1721
 
        } else if (error->domain == G_IO_ERROR &&
1722
 
                   error->code == G_IO_ERROR_CANCELLED) {
 
1712
        } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1723
1713
                ev_window_clear_load_job (ev_window);
1724
1714
                ev_window_clear_local_uri (ev_window);
1725
 
                ev_window_clear_print_settings_file (ev_window);
1726
1715
                g_free (ev_window->priv->uri);
1727
1716
                ev_window->priv->uri = NULL;
1728
1717
                g_object_unref (source);
1802
1791
                    const char     *uri,
1803
1792
                    EvLinkDest     *dest,
1804
1793
                    EvWindowRunMode mode,
1805
 
                    const gchar    *search_string, 
1806
 
                    gboolean        unlink_temp_file,
1807
 
                    const gchar    *print_settings)
 
1794
                    const gchar    *search_string)
1808
1795
{
1809
1796
        GFile *source_file;
1810
1797
 
1824
1811
        ev_window_close_dialogs (ev_window);
1825
1812
        ev_window_clear_load_job (ev_window);
1826
1813
        ev_window_clear_local_uri (ev_window);
1827
 
        ev_window_clear_print_settings_file (ev_window);
1828
1814
        ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
1829
1815
 
1830
 
        ev_window->priv->unlink_temp_file = unlink_temp_file;
1831
1816
        ev_window->priv->window_mode = mode;
1832
1817
 
1833
 
        if (mode == EV_WINDOW_MODE_PREVIEW) {
1834
 
                ev_window->priv->print_settings_file = print_settings ? 
1835
 
                        g_strdup (print_settings) : NULL;
1836
 
        }
1837
 
 
1838
1818
        if (ev_window->priv->uri)
1839
1819
                g_free (ev_window->priv->uri);
1840
1820
        ev_window->priv->uri = g_strdup (uri);
1917
1897
        
1918
1898
        g_file_copy_finish (remote, async_result, &error);
1919
1899
        if (error) {
1920
 
                if (error->domain != G_IO_ERROR ||
1921
 
                    error->code != G_IO_ERROR_CANCELLED)
 
1900
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
1922
1901
                        ev_window_error_message (ev_window, error,
1923
1902
                                                 "%s", _("Failed to reload document."));
1924
1903
                g_error_free (error);
2104
2083
static gchar *
2105
2084
ev_window_create_tmp_symlink (const gchar *filename, GError **error)
2106
2085
{
2107
 
        gchar *tmp_filename = NULL;
2108
 
        gchar *name;
2109
 
        gint   res;
2110
 
        guint  i = 0;
 
2086
        gchar  *tmp_filename = NULL;
 
2087
        gchar  *name;
 
2088
        guint   i = 0;
 
2089
        GError *link_error = NULL;
 
2090
        GFile  *tmp_file = NULL;
2111
2091
 
2112
2092
        name = g_path_get_basename (filename);
2113
2093
        
2116
2096
 
2117
2097
                if (tmp_filename)
2118
2098
                        g_free (tmp_filename);
 
2099
                if (tmp_file)
 
2100
                        g_object_unref (tmp_file);
 
2101
                g_clear_error (&link_error);
2119
2102
 
2120
2103
                basename = g_strdup_printf ("%s-%d", name, i++);
2121
2104
                tmp_filename = g_build_filename (ev_tmp_dir (),
2122
2105
                                                 basename, NULL);
2123
2106
                
2124
2107
                g_free (basename);
2125
 
        } while ((res = symlink (filename, tmp_filename)) != 0 && errno == EEXIST);
2126
 
 
 
2108
                tmp_file = g_file_new_for_path (tmp_filename);
 
2109
        } while (!g_file_make_symbolic_link (tmp_file, filename, NULL, &link_error) &&
 
2110
                 g_error_matches (link_error, G_IO_ERROR, G_IO_ERROR_EXISTS));
 
2111
        
2127
2112
        g_free (name);
2128
 
        
2129
 
        if (res != 0 && errno != EEXIST) {
2130
 
                if (error) {
2131
 
                        *error = g_error_new (G_FILE_ERROR,
2132
 
                                              g_file_error_from_errno (errno),
2133
 
                                              _("Couldn't create symlink “%s”: %s"),
2134
 
                                              tmp_filename, strerror (errno));
2135
 
                }
 
2113
        g_object_unref (tmp_file);
2136
2114
 
 
2115
        if (link_error) {
 
2116
                g_propagate_prefixed_error (error, 
 
2117
                                            link_error,
 
2118
                                            _("Couldn't create symlink “%s”: "),
 
2119
                                            tmp_filename);
2137
2120
                g_free (tmp_filename);
2138
 
 
 
2121
                
2139
2122
                return NULL;
2140
2123
        }
2141
 
        
 
2124
 
2142
2125
        return tmp_filename;
2143
2126
}
2144
2127
 
2178
2161
                                         dest,
2179
2162
                                         0,
2180
2163
                                         NULL, 
2181
 
                                         TRUE,
2182
 
                                         NULL,
2183
2164
                                         GDK_CURRENT_TIME);
2184
2165
        g_free (symlink_uri);
2185
2166
}
2213
2194
        
2214
2195
        ev_application_open_uri_at_dest (EV_APP, uri,
2215
2196
                                         gtk_window_get_screen (GTK_WINDOW (window)),
2216
 
                                         NULL, 0, NULL, FALSE, NULL, 
2217
 
                                         GDK_CURRENT_TIME);
 
2197
                                         NULL, 0, NULL, GDK_CURRENT_TIME);
2218
2198
}
2219
2199
 
2220
2200
static void
2224
2204
{
2225
2205
        ev_application_open_uri_at_dest (EV_APP, uri,
2226
2206
                                         gtk_window_get_screen (GTK_WINDOW (window)),
2227
 
                                         NULL, 0, NULL, FALSE, NULL, 
2228
 
                                         GDK_CURRENT_TIME);
 
2207
                                         NULL, 0, NULL, GDK_CURRENT_TIME);
2229
2208
}
2230
2209
 
2231
2210
static void
2444
2423
                return;
2445
2424
        }
2446
2425
 
2447
 
        if (error->domain != G_IO_ERROR ||
2448
 
            error->code != G_IO_ERROR_CANCELLED) {
 
2426
        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
2449
2427
                gchar *name;
2450
2428
                
2451
2429
                name = g_file_get_basename (dst);
3599
3577
}
3600
3578
 
3601
3579
static void
3602
 
ev_window_run_preview (EvWindow *window)
3603
 
{
3604
 
        GtkAction *action;
3605
 
        
3606
 
        if (!window->priv->preview_toolbar) {
3607
 
                window->priv->preview_toolbar =
3608
 
                        gtk_ui_manager_get_widget (window->priv->ui_manager,
3609
 
                                                   "/PreviewToolbar");
3610
 
 
3611
 
                gtk_box_pack_start (GTK_BOX (window->priv->main_box),
3612
 
                                    window->priv->preview_toolbar,
3613
 
                                    FALSE, FALSE, 0);
3614
 
                gtk_box_reorder_child (GTK_BOX (window->priv->main_box),
3615
 
                                       window->priv->preview_toolbar, 1);
3616
 
        }
3617
 
        
3618
 
        ev_view_set_continuous (EV_VIEW (window->priv->view), FALSE); 
3619
 
        
3620
 
        update_chrome_flag (window, EV_CHROME_TOOLBAR, FALSE);
3621
 
        update_chrome_flag (window, EV_CHROME_MENUBAR, FALSE);
3622
 
        update_chrome_flag (window, EV_CHROME_SIDEBAR, FALSE);
3623
 
 
3624
 
        update_chrome_flag (window, EV_CHROME_PREVIEW_TOOLBAR, TRUE);
3625
 
        
3626
 
        action = gtk_action_group_get_action (window->priv->action_group,
3627
 
                                              "PreviewPrint");
3628
 
        gtk_action_set_visible (action, TRUE);
3629
 
 
3630
 
        update_chrome_visibility (window);
3631
 
}
3632
 
 
3633
 
static void
3634
3580
ev_window_screen_changed (GtkWidget *widget,
3635
3581
                          GdkScreen *old_screen)
3636
3582
{
3861
3807
        ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
3862
3808
}
3863
3809
 
3864
 
#if GTK_CHECK_VERSION (2, 14, 0)
3865
3810
static void
3866
3811
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
3867
3812
{
3877
3822
                g_error_free (error);
3878
3823
        }
3879
3824
}
3880
 
#else /* !GTK_CHECK_VERSION (2, 14, 0) */
3881
 
static void
3882
 
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
3883
 
{
3884
 
        GError *error = NULL;
3885
 
        GdkScreen *screen;
3886
 
        char *command;
3887
 
        const char *lang;
3888
 
        char *uri = NULL;
3889
 
 
3890
 
        int i;
3891
 
 
3892
 
        const char * const * langs = g_get_language_names ();
3893
 
 
3894
 
        for (i = 0; langs[i]; i++) {
3895
 
                lang = langs[i];
3896
 
                if (strchr (lang, '.')) {
3897
 
                        continue;
3898
 
                }
3899
 
 
3900
 
                uri = g_build_filename(GNOMEDATADIR,
3901
 
                                       "/gnome/help/" PACKAGE,
3902
 
                                       lang,
3903
 
                                       "/evince.xml",
3904
 
                                       NULL);
3905
 
                                        
3906
 
                if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
3907
 
                        break;
3908
 
                }
3909
 
                g_free (uri);
3910
 
                uri = NULL;
3911
 
        }
3912
 
 
3913
 
        if (uri == NULL) {
3914
 
                g_warning ("Cannot find help");
3915
 
                return;
3916
 
        }
3917
 
        
3918
 
        command = g_strconcat ("gnome-help ghelp://", uri,  NULL);
3919
 
        g_free (uri);
3920
 
        
3921
 
        screen = gtk_widget_get_screen (GTK_WIDGET (ev_window));
3922
 
        gdk_spawn_command_line_on_screen (screen, command, &error);
3923
 
        if (error != NULL) {
3924
 
                g_warning ("%s", error->message);
3925
 
                g_error_free (error);
3926
 
        }
3927
 
        g_free (command);
3928
 
}
3929
 
#endif /* GTK_CHECK_VERSION (2, 14, 0) */
3930
3825
 
3931
3826
static void
3932
3827
ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
3940
3835
        ev_window_run_presentation (window);
3941
3836
}
3942
3837
 
3943
 
static gboolean
3944
 
ev_window_enumerate_printer_cb (GtkPrinter *printer,
3945
 
                                EvWindow   *window)
3946
 
{
3947
 
        EvWindowPrivate *priv = window->priv;
3948
 
        const gchar *printer_name;
3949
 
 
3950
 
        printer_name = gtk_print_settings_get_printer (priv->print_settings);
3951
 
        if ((printer_name
3952
 
             && strcmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
3953
 
            (!printer_name && gtk_printer_is_default (printer))) {
3954
 
                if (priv->printer)
3955
 
                        g_object_unref (priv->printer);
3956
 
                priv->printer = g_object_ref (printer);
3957
 
 
3958
 
                /* Now that we have the printer, we'll start the print */
3959
 
                ev_window_do_preview_print (window);
3960
 
 
3961
 
                return TRUE; /* we're done */
3962
 
        }
3963
 
 
3964
 
        return FALSE; /* continue the enumeration */
3965
 
}
3966
 
 
3967
 
static void
3968
 
ev_window_preview_print_finished (GtkPrintJob *print_job,
3969
 
                                  EvWindow    *window,
3970
 
                                  GError      *error)
3971
 
{
3972
 
        if (error) {
3973
 
                ev_window_error_message (window, error,
3974
 
                                         "%s", _("Failed to print document"));
3975
 
        }
3976
 
 
3977
 
        g_object_unref (print_job);
3978
 
        gtk_widget_destroy (GTK_WIDGET (window));
3979
 
}
3980
 
 
3981
 
static void
3982
 
ev_window_do_preview_print (EvWindow *window)
3983
 
{
3984
 
        EvWindowPrivate  *priv = window->priv;
3985
 
        GtkPrintJob      *job;
3986
 
        gchar            *filename;
3987
 
        GError           *error = NULL;
3988
 
 
3989
 
        g_assert (priv->print_settings != NULL);
3990
 
        g_assert (priv->printer != NULL);
3991
 
 
3992
 
        job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (window)),
3993
 
                                 priv->printer,
3994
 
                                 priv->print_settings,
3995
 
                                 priv->print_page_setup);
3996
 
 
3997
 
        g_object_unref (priv->print_settings);
3998
 
        priv->print_settings = NULL;
3999
 
        g_object_unref (priv->print_page_setup);
4000
 
        priv->print_page_setup = NULL;
4001
 
        g_object_unref (priv->printer);
4002
 
        priv->printer = NULL;
4003
 
 
4004
 
        filename = g_filename_from_uri (priv->local_uri ?
4005
 
                                        priv->local_uri : priv->uri,
4006
 
                                        NULL, NULL);
4007
 
 
4008
 
        if (gtk_print_job_set_source_file (job, filename, &error)) {
4009
 
                gtk_print_job_send (job,
4010
 
                                    (GtkPrintJobCompleteFunc)ev_window_preview_print_finished,
4011
 
                                    window, NULL);
4012
 
        } else {
4013
 
                g_warning ("%s", error->message);
4014
 
                g_error_free (error);
4015
 
        }
4016
 
 
4017
 
        g_free (filename);
4018
 
 
4019
 
        gtk_widget_hide (GTK_WIDGET (window));
4020
 
}
4021
 
 
4022
 
static void
4023
 
ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
4024
 
{
4025
 
        EvWindowPrivate  *priv = window->priv;
4026
 
        GtkPrintSettings *print_settings;
4027
 
        GtkPageSetup     *page_setup;
4028
 
        const gchar      *print_settings_file = priv->print_settings_file;
4029
 
 
4030
 
        if (print_settings_file && g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
4031
 
                GKeyFile *key_file;
4032
 
                GError   *error = NULL;
4033
 
 
4034
 
                key_file = g_key_file_new ();
4035
 
                g_key_file_load_from_file (key_file,
4036
 
                                           print_settings_file,
4037
 
                                           G_KEY_FILE_KEEP_COMMENTS |
4038
 
                                           G_KEY_FILE_KEEP_TRANSLATIONS,
4039
 
                                           &error);
4040
 
                if (!error) {
4041
 
                        print_settings =
4042
 
                                gtk_print_settings_new_from_key_file (key_file,
4043
 
                                                                      "Print Settings",
4044
 
                                                                      NULL);
4045
 
                        print_settings = print_settings ? print_settings : gtk_print_settings_new ();
4046
 
                        
4047
 
                        page_setup = gtk_page_setup_new_from_key_file (key_file,
4048
 
                                                                       "Page Setup",
4049
 
                                                                       NULL);
4050
 
                        page_setup = page_setup ? page_setup : gtk_page_setup_new ();
4051
 
                } else {
4052
 
                        print_settings = gtk_print_settings_new ();
4053
 
                        page_setup = gtk_page_setup_new ();
4054
 
                        g_error_free (error);
4055
 
                }
4056
 
 
4057
 
                g_key_file_free (key_file);
4058
 
        } else {
4059
 
                print_settings = gtk_print_settings_new ();
4060
 
                page_setup = gtk_page_setup_new ();
4061
 
        }
4062
 
        
4063
 
        if (priv->print_settings)
4064
 
                g_object_unref (priv->print_settings);
4065
 
        priv->print_settings = print_settings;
4066
 
        if (priv->print_page_setup)
4067
 
                g_object_unref (priv->print_page_setup);
4068
 
        priv->print_page_setup = page_setup;
4069
 
 
4070
 
        gtk_enumerate_printers ((GtkPrinterFunc) ev_window_enumerate_printer_cb,
4071
 
                                window, NULL, FALSE);
4072
 
}
4073
 
 
4074
3838
static void
4075
3839
ev_window_cmd_escape (GtkAction *action, EvWindow *window)
4076
3840
{
4120
3884
                                                enum_value->value_nick);
4121
3885
}
4122
3886
 
 
3887
static void
 
3888
ev_window_set_view_size (EvWindow *window)
 
3889
{
 
3890
        gint width, height;
 
3891
        GtkRequisition vsb_requisition;
 
3892
        GtkRequisition hsb_requisition;
 
3893
        gint scrollbar_spacing;
 
3894
        GtkWidget *scrolled_window = window->priv->scrolled_window;
 
3895
 
 
3896
        if (!window->priv->view)
 
3897
                return;
 
3898
 
 
3899
        /* Calculate the width available for the content */
 
3900
        width  = scrolled_window->allocation.width;
 
3901
        height = scrolled_window->allocation.height;
 
3902
 
 
3903
        if (gtk_scrolled_window_get_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window)) == GTK_SHADOW_IN) {
 
3904
                width -=  2 * window->priv->view->style->xthickness;
 
3905
                height -= 2 * window->priv->view->style->ythickness;
 
3906
        }
 
3907
 
 
3908
        gtk_widget_size_request (GTK_SCROLLED_WINDOW (scrolled_window)->vscrollbar,
 
3909
                                 &vsb_requisition);
 
3910
        gtk_widget_size_request (GTK_SCROLLED_WINDOW (scrolled_window)->hscrollbar,
 
3911
                                 &hsb_requisition);
 
3912
        gtk_widget_style_get (scrolled_window,
 
3913
                              "scrollbar_spacing",
 
3914
                              &scrollbar_spacing,
 
3915
                              NULL);
 
3916
 
 
3917
        ev_view_set_zoom_for_size (EV_VIEW (window->priv->view),
 
3918
                                   MAX (1, width),
 
3919
                                   MAX (1, height),
 
3920
                                   vsb_requisition.width + scrollbar_spacing,
 
3921
                                   hsb_requisition.height + scrollbar_spacing);
 
3922
}
 
3923
 
4123
3924
static void     
4124
3925
ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec,
4125
3926
                                  EvWindow   *ev_window)
4126
3927
{
4127
 
        GtkWidget *scrolled_window;
4128
3928
        EvSizingMode sizing_mode;
4129
3929
 
4130
3930
        g_object_get (ev_window->priv->view,
4131
3931
                      "sizing-mode", &sizing_mode,
4132
3932
                      NULL);
4133
3933
 
4134
 
        scrolled_window = ev_window->priv->scrolled_window;
4135
 
 
4136
 
        g_signal_handlers_disconnect_by_func (ev_window->priv->view, ev_view_update_view_size, scrolled_window);
4137
 
 
4138
 
        if (sizing_mode != EV_SIZING_FREE)
4139
 
                ev_view_update_view_size (EV_VIEW (ev_window->priv->view),
4140
 
                                          GTK_SCROLLED_WINDOW (scrolled_window));
4141
 
 
4142
 
        switch (sizing_mode) {
4143
 
                case EV_SIZING_BEST_FIT:
4144
 
                        g_object_set (G_OBJECT (scrolled_window),
4145
 
                                      "hscrollbar-policy", GTK_POLICY_NEVER,
4146
 
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4147
 
                                      NULL);
4148
 
                        g_signal_connect (ev_window->priv->view, "zoom_invalid",
4149
 
                                          G_CALLBACK (ev_view_update_view_size),
4150
 
                                          scrolled_window);
4151
 
                        break;
4152
 
                case EV_SIZING_FIT_WIDTH:
4153
 
                        g_object_set (G_OBJECT (scrolled_window),
4154
 
                                      "hscrollbar-policy", GTK_POLICY_NEVER,
4155
 
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4156
 
                                      NULL);
4157
 
                        g_signal_connect (ev_window->priv->view, "zoom_invalid",
4158
 
                                          G_CALLBACK (ev_view_update_view_size),
4159
 
                                          scrolled_window);
4160
 
                        break;
4161
 
                case EV_SIZING_FREE:
4162
 
                        g_object_set (G_OBJECT (scrolled_window),
4163
 
                                      "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
4164
 
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
4165
 
                                      NULL);
4166
 
                        break;
4167
 
        }
 
3934
        g_object_set (ev_window->priv->scrolled_window,
 
3935
                      "hscrollbar-policy",
 
3936
                      sizing_mode == EV_SIZING_FREE ?
 
3937
                      GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
 
3938
                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
 
3939
                      NULL);
4168
3940
 
4169
3941
        update_sizing_buttons (ev_window);
4170
3942
        save_sizing_mode (ev_window);
4727
4499
        } else {
4728
4500
                mode = EV_SIZING_FREE;
4729
4501
        }
4730
 
        
 
4502
 
4731
4503
        ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), mode);
4732
4504
        
4733
4505
        if (mode == EV_SIZING_FREE) {
4747
4519
                              guint             time)
4748
4520
 
4749
4521
{
4750
 
        EvWindow *window = EV_WINDOW (widget);
4751
 
        gchar   **uris;
4752
 
        gint      i = 0;
4753
 
        GSList   *uri_list = NULL;
 
4522
        EvWindow  *window = EV_WINDOW (widget);
 
4523
        gchar    **uris;
 
4524
        gint       i = 0;
 
4525
        GSList    *uri_list = NULL;
 
4526
        GtkWidget *source;
 
4527
 
 
4528
        source = gtk_drag_get_source_widget (context);
 
4529
        if (source && widget == gtk_widget_get_toplevel (source)) {
 
4530
                gtk_drag_finish (context, FALSE, FALSE, time);
 
4531
                return;
 
4532
        }
4754
4533
 
4755
4534
        uris = gtk_selection_data_get_uris (selection_data);
4756
4535
        if (!uris) {
4942
4721
        }
4943
4722
 
4944
4723
        if (priv->uri) {
4945
 
                if (priv->unlink_temp_file)
4946
 
                        ev_window_clear_temp_file (window);
 
4724
                /* Delete the uri if it's a temp symlink (open a copy) */
 
4725
                ev_window_clear_temp_symlink (window);
4947
4726
                g_free (priv->uri);
4948
4727
                priv->uri = NULL;
4949
4728
        }
4963
4742
                priv->history = NULL;
4964
4743
        }
4965
4744
 
4966
 
        if (priv->print_settings_file) {
4967
 
                ev_window_clear_print_settings_file (window);
4968
 
                priv->print_settings_file = NULL;
4969
 
        }
4970
 
 
4971
4745
        if (priv->presentation_timeout_id > 0) {
4972
4746
                g_source_remove (priv->presentation_timeout_id);
4973
4747
                priv->presentation_timeout_id = 0;
4981
4755
        G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
4982
4756
}
4983
4757
 
 
4758
static gboolean
 
4759
ev_window_key_press_event (GtkWidget   *widget,
 
4760
                           GdkEventKey *event)
 
4761
{
 
4762
        EvWindow *ev_window = EV_WINDOW (widget);
 
4763
        gboolean  handled = FALSE;
 
4764
 
 
4765
        /* Propagate the event to the view first
 
4766
         * It's needed to be able to type in
 
4767
         * annot popups windows
 
4768
         */
 
4769
        if (ev_window->priv->view) {
 
4770
                g_object_ref (ev_window->priv->view);
 
4771
                if (GTK_WIDGET_IS_SENSITIVE (ev_window->priv->view))
 
4772
                        handled = gtk_widget_event (ev_window->priv->view, (GdkEvent*) event);
 
4773
                g_object_unref (ev_window->priv->view);
 
4774
        }
 
4775
 
 
4776
        if (!handled)
 
4777
                handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
 
4778
 
 
4779
        return handled;
 
4780
}
 
4781
 
4984
4782
static void
4985
4783
ev_window_class_init (EvWindowClass *ev_window_class)
4986
4784
{
4990
4788
        g_object_class->dispose = ev_window_dispose;
4991
4789
        g_object_class->finalize = ev_window_finalize;
4992
4790
 
 
4791
        widget_class->key_press_event = ev_window_key_press_event;
4993
4792
        widget_class->screen_changed = ev_window_screen_changed;
4994
4793
        widget_class->window_state_event = ev_window_state_event;
4995
4794
        widget_class->drag_data_received = ev_window_drag_data_received;
5015
4814
        { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), "<control>S",
5016
4815
          N_("Save a copy of the current document"),
5017
4816
          G_CALLBACK (ev_window_cmd_save_as) },
5018
 
        { "FilePrintSetup", NULL, N_("Print Set_up..."), NULL,
 
4817
        { "FilePageSetup", GTK_STOCK_PAGE_SETUP, N_("Page Set_up..."), NULL,
5019
4818
          N_("Setup the page settings for printing"),
5020
4819
          G_CALLBACK (ev_window_cmd_file_print_setup) },
5021
4820
        { "FilePrint", GTK_STOCK_PRINT, N_("_Print..."), "<control>P",
5040
4839
          G_CALLBACK (ev_window_cmd_edit_find_previous) },
5041
4840
        { "EditToolbar", NULL, N_("T_oolbar"), NULL, NULL,
5042
4841
          G_CALLBACK (ev_window_cmd_edit_toolbar) },
5043
 
        { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<alt>Left", NULL,
 
4842
        { "EditRotateLeft", EV_STOCK_ROTATE_LEFT, N_("Rotate _Left"), "<control>Left", NULL,
5044
4843
          G_CALLBACK (ev_window_cmd_edit_rotate_left) },
5045
 
        { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<alt>Right", NULL,
 
4844
        { "EditRotateRight", EV_STOCK_ROTATE_RIGHT, N_("Rotate _Right"), "<control>Right", NULL,
5046
4845
          G_CALLBACK (ev_window_cmd_edit_rotate_right) },
5047
4846
 
5048
4847
        /* View menu */
5087
4886
        { "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
5088
4887
          N_("Start a presentation"),
5089
4888
          G_CALLBACK (ev_window_cmd_start_presentation) },
5090
 
        { "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
5091
 
          N_("Print this document"),
5092
 
          G_CALLBACK (ev_window_cmd_preview_print) },
5093
4889
 
5094
4890
        /* Accellerators */
5095
4891
        { "Escape", NULL, "", "Escape", "",
5096
4892
          G_CALLBACK (ev_window_cmd_escape) },
5097
4893
        { "Slash", GTK_STOCK_FIND, NULL, "slash", NULL,
5098
4894
          G_CALLBACK (ev_window_cmd_edit_find) },
 
4895
        { "F3", NULL, "", "F3", NULL,
 
4896
          G_CALLBACK (ev_window_cmd_edit_find_next) },
5099
4897
        { "PageDown", NULL, "", "Page_Down", NULL,
5100
4898
          G_CALLBACK (ev_window_cmd_scroll_forward) },
5101
4899
        { "PageUp", NULL, "", "Page_Up", NULL,
5449
5247
        GAppInfo *app_info;
5450
5248
        GFile *file;
5451
5249
        GList file_list = {NULL};
5452
 
        GAppLaunchContext *context = NULL;
 
5250
        GAppLaunchContext *context;
5453
5251
        GError *error = NULL;
5454
5252
 
5455
5253
        if (filename == NULL)
5480
5278
                return;
5481
5279
        }
5482
5280
 
5483
 
#if GTK_CHECK_VERSION (2, 14, 0)
5484
5281
        context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
5485
5282
        gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
5486
5283
                                           gtk_window_get_screen (GTK_WINDOW (window)));
5487
5284
        gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context), GDK_CURRENT_TIME);
5488
 
#endif
5489
5285
        
5490
5286
        file_list.data = file;
5491
5287
        if (!g_app_info_launch (app_info, &file_list, context, &error)) {
5508
5304
        const gchar *uri = ev_link_action_get_uri (action);
5509
5305
        GError *error = NULL;
5510
5306
        gboolean ret;
5511
 
#if GTK_CHECK_VERSION (2, 14, 0)
5512
 
        GAppLaunchContext *context = NULL;
5513
 
#endif
 
5307
        GAppLaunchContext *context;
5514
5308
 
5515
 
#if GTK_CHECK_VERSION (2, 14, 0)
5516
5309
        context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
5517
5310
        gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
5518
5311
                                           gtk_window_get_screen (GTK_WINDOW (window)));
5519
5312
        gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
5520
5313
                                              GDK_CURRENT_TIME);
5521
 
#endif
5522
5314
 
5523
5315
        if (!g_strstr_len (uri, strlen (uri), "://") &&
5524
5316
            !g_str_has_prefix (uri, "mailto:")) {
5556
5348
                                         ev_link_action_get_dest (action),
5557
5349
                                         0,
5558
5350
                                         NULL, 
5559
 
                                         FALSE,
5560
 
                                         NULL,
5561
5351
                                         GDK_CURRENT_TIME);
5562
5352
 
5563
5353
        g_free (uri);
5582
5372
                ev_window_cmd_edit_find (NULL, window);
5583
5373
        } else if (g_ascii_strcasecmp (name, "Close") == 0) {
5584
5374
                ev_window_cmd_file_close_window (NULL, window);
 
5375
        } else if (g_ascii_strcasecmp (name, "Print") == 0) {
 
5376
                ev_window_cmd_file_print (NULL, window);
5585
5377
        } else {
5586
5378
                g_warning ("Unimplemented named action: %s, please post a "
5587
5379
                           "bug report in Evince bugzilla "
6178
5970
        g_signal_connect_object (ev_window->priv->view, "handle-link",
6179
5971
                                 G_CALLBACK (view_handle_link_cb),
6180
5972
                                 ev_window, 0);
6181
 
 
 
5973
        g_signal_connect_swapped (ev_window->priv->view, "zoom_invalid",
 
5974
                                 G_CALLBACK (ev_window_set_view_size),
 
5975
                                 ev_window);
6182
5976
        g_signal_connect_object (ev_window->priv->view,
6183
5977
                                 "popup",
6184
5978
                                 G_CALLBACK (view_menu_popup_cb),