2
* Copyright (c) 2013 Red Hat, Inc.
4
* Gnome Documents is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
9
* Gnome Documents is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* You should have received a copy of the GNU General Public License along
15
* with Gnome Documents; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
const WebKit = imports.gi.WebKit;
21
const Soup = imports.gi.Soup;
22
const Gd = imports.gi.Gd;
23
const GdPrivate = imports.gi.GdPrivate;
24
const Gdk = imports.gi.Gdk;
25
const Gio = imports.gi.Gio;
26
const GLib = imports.gi.GLib;
27
const Gtk = imports.gi.Gtk;
28
const _ = imports.gettext.gettext;
30
const Lang = imports.lang;
31
const Mainloop = imports.mainloop;
32
const Signals = imports.signals;
34
const Application = imports.application;
35
const MainToolbar = imports.mainToolbar;
36
const Searchbar = imports.searchbar;
37
const Utils = imports.utils;
38
const View = imports.view;
39
const WindowMode = imports.windowMode;
40
const Documents = imports.documents;
42
const _BLANK_URI = "about:blank";
44
const EditView = new Lang.Class({
50
this.widget = new Gtk.Overlay();
52
this._scrolledWindow = new Gtk.ScrolledWindow({ hexpand: true,
54
this.widget.get_style_context().add_class('documents-scrolledwin');
55
this.widget.add(this._scrolledWindow);
57
this._session = WebKit.get_default_session ();
58
Soup.Session.prototype.add_feature.call(this._session, new Soup.ProxyResolverDefault());
59
Soup.Session.prototype.remove_feature.call(this._session, new Soup.CookieJar());
60
let jarfile = GLib.build_filenamev([GLib.get_user_cache_dir(), 'gnome-documents', 'cookies.sqlite']);
61
this._cookieJar = new Soup.CookieJarDB({ filename: jarfile, read_only: false });
62
Soup.Session.prototype.add_feature.call(this._session, this._cookieJar);
64
this._progressBar = new Gtk.ProgressBar({ halign: Gtk.Align.FILL,
65
valign: Gtk.Align.START });
66
this._progressBar.get_style_context().add_class('osd');
67
this.widget.add_overlay(this._progressBar);
71
this.widget.show_all();
73
this._editAction = Application.application.lookup_action('edit-current');
74
this._editAction.enabled = false;
75
this._editAction.connect('activate', Lang.bind(this,
77
let doc = Application.documentManager.getActiveItem();
80
Application.modeController.setWindowMode(WindowMode.WindowMode.EDIT);
81
this.setUri (doc.uri);
84
this._viewAction = Application.application.lookup_action('view-current');
85
this._viewAction.enabled = false;
86
this._viewAction.connect('activate', Lang.bind(this,
88
Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW);
91
Application.documentManager.connect('load-started',
92
Lang.bind(this, this._onLoadStarted));
93
Application.documentManager.connect('load-finished',
94
Lang.bind(this, this._onLoadFinished));
98
_onLoadStarted: function() {
99
this._editAction.enabled = false;
100
this._viewAction.enabled = false;
103
_onLoadFinished: function(manager, doc, docModel) {
105
if (doc instanceof Documents.GoogleDocument)
106
this._editAction.enabled = true;
107
this._viewAction.enabled = true;
111
_createView: function() {
112
this.view = new WebKit.WebView();
113
this._scrolledWindow.add(this.view);
115
this.view.connect('notify::progress', Lang.bind(this, this._onProgressChanged));
118
_isLoading: function() {
119
let status = this.view.load_status;
120
if ((status == WebKit.LoadStatus.finished
121
|| status == WebKit.LoadStatus.failed)
122
&& status != WebKit.LoadStatus.provisional)
125
return status != WebKit.LoadStatus.finished
126
&& status != WebKit.LoadStatus.failed;
129
_onProgressChanged: function() {
130
if (!this.view.uri || this.view.uri == _BLANK_URI)
133
let progress = this.view.progress;
134
let loading = this._isLoading();
136
if (progress == 1.0 || !loading) {
137
if (!this._timeoutId)
138
this._timeoutId = Mainloop.timeout_add(500, Lang.bind(this, this._onTimeoutExpired));
140
if (this._timeoutId) {
141
Mainloop.source_remove(this._timeoutId);
144
this._progressBar.show();
147
if (loading || progress == 1.0)
149
this._progressBar.fraction = value;
152
_onTimeoutExpired: function() {
154
this._progressBar.hide();
158
setUri: function(uri) {
159
if (this._uri == uri)
166
this.view.load_uri (uri);
173
Signals.addSignalMethods(EditView.prototype);
175
const EditToolbar = new Lang.Class({
177
Extends: MainToolbar.MainToolbar,
179
_init: function(editView) {
180
this._editView = editView;
184
// back button, on the left of the toolbar
185
let backButton = this.addBackButton();
186
backButton.connect('clicked', Lang.bind(this,
188
Application.documentManager.setActiveItem(null);
191
let viewButton = new Gd.HeaderSimpleButton({ label: _("View"),
192
action_name: 'app.view-current' });
193
viewButton.get_style_context().add_class('suggested-action');
194
this.toolbar.pack_end(viewButton);
196
this._setToolbarTitle();
197
this.widget.show_all();
200
createSearchbar: function() {
203
handleEvent: function(event) {
207
_setToolbarTitle: function() {
209
let doc = Application.documentManager.getActiveItem();
214
this.toolbar.set_title(primary);