333
328
this.favorite = cursor.get_boolean(Query.QueryColumns.FAVORITE);
335
330
let mtime = cursor.get_string(Query.QueryColumns.MTIME)[0];
336
let timeVal = Gd.time_val_from_iso8601(mtime)[1];
337
this.mtime = timeVal.tv_sec;
332
let timeVal = GLib.time_val_from_iso8601(mtime)[1];
333
this.mtime = timeVal.tv_sec;
335
this.mtime = Math.floor(GLib.get_real_time() / 1000000);
339
338
this.mimeType = cursor.get_string(Query.QueryColumns.MIMETYPE)[0];
340
339
this.rdfType = cursor.get_string(Query.QueryColumns.RDFTYPE)[0];
603
605
retval = '{ ?urn nie:isPartOf <' + this.id + '> }';
610
_finishLoad: function(document, callback, exception) {
613
Global.errorHandler.addLoadError(this, exception);
615
docModel = EvView.DocumentModel.new_with_document(document);
618
callback(this, docModel, exception);
608
621
Signals.addSignalMethods(DocCommon.prototype);
610
function LocalDocument(cursor) {
614
LocalDocument.prototype = {
615
__proto__: DocCommon.prototype,
623
const LocalDocument = new Lang.Class({
624
Name: 'LocalDocument',
617
627
_init: function(cursor) {
618
628
this._failedThumbnailing = false;
619
629
this._triedThumbnailing = false;
621
DocCommon.prototype._init.call(this, cursor);
623
633
this.sourceName = _("Local");
662
672
const _GOOGLE_DOCS_SCHEME_LABELS = "http://schemas.google.com/g/2005/labels";
663
673
const _GOOGLE_DOCS_TERM_STARRED = "http://schemas.google.com/g/2005/labels#starred";
665
function GoogleDocument(cursor) {
669
GoogleDocument.prototype = {
670
__proto__: DocCommon.prototype,
675
const GoogleDocument = new Lang.Class({
676
Name: 'GoogleDocument',
672
679
_init: function(cursor) {
673
680
this._triedThumbnailing = true;
674
681
this._failedThumbnailing = true;
676
DocCommon.prototype._init.call(this, cursor);
679
686
this.defaultAppName = _("Google Docs");
686
693
let authorizer = new Gd.GDataGoaAuthorizer({ goa_object: source.object });
687
694
let service = new GData.DocumentsService({ authorizer: authorizer });
689
// HACK: GJS doesn't support introspecting GTypes, so we need to use
690
// GObject.type_from_name(); but for that to work, we need at least one
691
// instance of the GType in question to have ever been created. Ensure that
692
let temp = new GData.DocumentsText();
693
696
service.query_single_entry_async
694
697
(service.get_primary_authorization_domain(),
695
698
this.identifier, null,
696
GObject.type_from_name('GDataDocumentsText'),
697
700
cancellable, Lang.bind(this,
698
701
function(object, res) {
699
702
let entry = null;
718
721
function(source, res) {
720
723
let document = Gd.pdf_loader_load_uri_finish(res);
721
callback(this, document, null);
724
this._finishLoad(document, callback, null);
723
726
// report the outmost error only
724
callback(this, null, exception);
727
this._finishLoad(null, callback, exception);
732
Gd.pdf_loader_load_entry_async
734
Gd.pdf_loader_load_gdata_entry_async
733
735
(entry, service, cancellable, Lang.bind(this,
734
736
function(source, res) {
736
let document = Gd.pdf_loader_load_entry_finish(res);
737
callback(this, document, null);
738
let document = Gd.pdf_loader_load_uri_finish(res);
739
this._finishLoad(document, callback, null);
739
callback(this, null, e);
741
this._finishLoad(null, callback, e);
760
762
populateFromCursor: function(cursor) {
761
763
this.shared = cursor.get_boolean(Query.QueryColumns.SHARED);
763
DocCommon.prototype.populateFromCursor.call(this, cursor);
766
768
setFavorite: function(favorite) {
767
DocCommon.prototype.setFavorite.call(this, favorite);
769
this.parent(favorite);
769
771
this._createGDataEntry(null, Lang.bind(this,
770
772
function(entry, service, exception) {
806
808
canTrash: function() {
811
function DocumentManager() {
815
DocumentManager.prototype = {
816
__proto__: Manager.BaseManager.prototype,
813
const SkydriveDocument = new Lang.Class({
814
Name: 'SkydriveDocument',
817
_init: function(cursor) {
818
this._triedThumbnailing = true;
819
this._failedThumbnailing = true;
824
this.defaultAppName = _("Skydrive");
825
this.sourceName = _("Skydrive");
828
_createZpjEntry: function(cancellable, callback) {
829
let source = Global.sourceManager.getItemById(this.resourceUrn);
831
let authorizer = new Zpj.GoaAuthorizer({ goa_object: source.object });
832
let service = new Zpj.Skydrive({ authorizer: authorizer });
834
const zpj_prefix = "windows-live:skydrive:";
835
let zpj_id = this.identifier.substring(zpj_prefix.length);
837
service.query_info_from_id_async
838
(zpj_id, cancellable,
840
function(object, res) {
842
let exception = null;
845
entry = object.query_info_from_id_finish(res);
850
callback(entry, service, exception);
854
load: function(cancellable, callback) {
855
this._createZpjEntry(cancellable, Lang.bind(this,
856
function(entry, service, exception) {
858
// try loading from the most recent cache, if any
859
Gd.pdf_loader_load_uri_async(this.identifier, cancellable, Lang.bind(this,
860
function(source, res) {
862
let document = Gd.pdf_loader_load_uri_finish(res);
863
this._finishLoad(document, callback, null);
865
// report the outmost error only
866
this._finishLoad(null, callback, exception);
873
Gd.pdf_loader_load_zpj_entry_async
874
(entry, service, cancellable, Lang.bind(this,
875
function(source, res) {
877
let document = Gd.pdf_loader_load_zpj_entry_finish(res);
878
this._finishLoad(document, callback, null);
880
this._finishLoad(null, callback, e);
886
updateTypeDescription: function() {
889
if (this.rdfType.indexOf('nfo#Spreadsheet') != -1)
890
description = _("Spreadsheet");
891
else if (this.rdfType.indexOf('nfo#Presentation') != -1)
892
description = _("Presentation");
893
else if (this.rdfType.indexOf('nfo#DataContainer') != -1)
894
description = _("Collection");
896
description = _("Document");
898
this.typeDescription = description;
901
setFavorite: function(favorite) {
904
canTrash: function() {
909
const DocumentManager = new Lang.Class({
910
Name: 'DocumentManager',
911
Extends: Manager.BaseManager,
818
913
_init: function() {
819
Manager.BaseManager.prototype._init.call(this);
821
916
this._model = new DocumentModel();
867
962
(identifier.indexOf('https://docs.google.com') != -1));
965
_identifierIsSkydrive: function(identifier) {
966
return (identifier &&
967
(identifier.indexOf('windows-live:skydrive:') != -1));
870
970
createDocumentFromCursor: function(cursor) {
871
971
let identifier = cursor.get_string(Query.QueryColumns.IDENTIFIER)[0];
874
974
if (this._identifierIsGoogle(identifier))
875
975
doc = new GoogleDocument(cursor);
976
else if (this._identifierIsSkydrive(identifier))
977
doc = new SkydriveDocument(cursor);
877
979
doc = new LocalDocument(cursor);
896
998
items[idx].destroy();
899
Manager.BaseManager.prototype.clear.call(this);
900
1002
this._model.clear();
903
1005
setActiveItem: function(doc) {
904
if (Manager.BaseManager.prototype.setActiveItem.call(this, doc)) {
906
if (doc && !doc.collection) {
907
let recentManager = Gtk.RecentManager.get_default();
908
recentManager.add_item(doc.uri);
1006
if (!this.parent(doc))
1012
if (doc.collection) {
1013
Global.collectionManager.setActiveItem(doc);
1017
let recentManager = Gtk.RecentManager.get_default();
1018
recentManager.add_item(doc.uri);
913
1021
getModel: function() {
914
1022
return this._model;
918
function DocumentModel() {
922
DocumentModel.prototype = {
1026
const DocumentModel = new Lang.Class({
1027
Name: 'DocumentModel',
923
1029
_init: function() {
924
this.model = Gd.create_list_store();
1030
this.model = Gtk.ListStore.new(
1031
[ GObject.TYPE_STRING,
1032
GObject.TYPE_STRING,
1033
GObject.TYPE_STRING,
1034
GObject.TYPE_STRING,
1037
GObject.TYPE_BOOLEAN ]);
925
1038
this.model.set_sort_column_id(Gd.MainColumns.MTIME,
926
1039
Gtk.SortType.DESCENDING);
933
1046
documentAdded: function(doc) {
934
1047
let iter = this.model.append();
936
Gd.store_set(this.model, iter,
938
doc.name, doc.author,
939
doc.pixbuf, doc.mtime);
1048
this.model.set(iter,
1049
[ 0, 1, 2, 3, 4, 5 ],
1050
[ doc.id, doc.uri, doc.name,
1051
doc.author, doc.pixbuf, doc.mtime ]);
941
1053
let treePath = this.model.get_path(iter);
942
1054
let treeRowRef = Gtk.TreeRowReference.new(this.model, treePath);