3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
using System.Threading;
26
using System.Collections.Generic;
29
using Google.GData.Client;
30
using Google.GData.Documents;
31
using Google.GData.Extensions;
36
public static class GDocs {
37
private static DocumentsService service;
38
private static List<IItem> docs;
39
private static object docs_lock;
41
const string FeedUri = "http://docs.google.com/feeds/documents/private/full";
42
private static string gAppName = "pengDeng-gnomeDoGDocsPlugin-1.0";
46
string username, password;
47
//Google works over SSL, we need accept the cert.
48
System.Net.ServicePointManager.CertificatePolicy = new CertHandler ();
50
docs = new List<IItem> ();
51
docs_lock = new object ();
53
Configuration.GetAccountData (out username, out password,
54
typeof (Configuration));
55
Connect (username, password);
58
public static string GAppName {
59
get { return gAppName; }
62
public static bool Connect (string username, string password)
65
service = new DocumentsService (gAppName);
66
service.setUserCredentials (username, password);
67
} catch (Exception e) {
68
Console.Error.WriteLine (e.Message);
74
public static List<IItem> Docs {
78
public static void UpdateDocs ()
80
DocumentsFeed docsFeed;
81
DocumentsListQuery query = new DocumentsListQuery ();
82
query.Uri = new Uri (FeedUri);
85
docsFeed = service.Query (query);
86
} catch (Exception e) {
88
Console.Error.WriteLine (e.Message);
94
foreach (DocumentEntry doc in docsFeed.Entries) {
95
string doc_url = doc.AlternateUri.Content;
96
string doc_title = doc.Title.Text;
99
docs.Add (new GDocsDocumentItem (doc_title, doc_url));
100
else if (doc.IsSpreadsheet)
101
docs.Add (new GDocsSpreadsheetItem (doc_title, doc_url));
102
else if (doc.IsPresentation)
103
docs.Add (new GDocsPresentationItem (doc_title, doc_url));
105
docs.Add (new GDocsPDFItem (doc_title, doc_url));
110
public static IItem UploadDocument (string fileName, string documentName)
112
DocumentEntry newDoc;
113
GDocsItem newDocItem;
116
newDoc = service.UploadDocument (fileName, documentName);
117
} catch (Exception e) {
119
Console.Error.WriteLine (e.Message);
120
Do.Addins.NotificationBridge.ShowMessage (Catalog.GetString ("Uploading failed."),
121
Catalog.GetString ("An error occurred when uploading file to Google Docs."));
126
string doc_url = newDoc.AlternateUri.Content;
127
string doc_title = newDoc.Title.Text;
129
if (newDoc.IsDocument)
130
newDocItem = new GDocsDocumentItem (doc_title, doc_url);
131
else if (newDoc.IsSpreadsheet)
132
newDocItem = new GDocsSpreadsheetItem (doc_title, doc_url);
133
else if (newDoc.IsPresentation)
134
newDocItem = new GDocsPresentationItem (doc_title, doc_url);
135
else if (newDoc.IsPDF)
136
newDocItem = new GDocsPDFItem (doc_title, doc_url);
141
docs.Add (newDocItem);
146
public static void TrashDocument (GDocsItem docItem)
148
string doc_title = docItem.Name;
149
string doc_url = docItem.URL;
151
// Search for document(s) having exactly the title,
152
// Delete the one with matching AlternateUri
153
DocumentsListQuery query = new DocumentsListQuery ();
154
query.Title = doc_title;
155
query.TitleExact = true;
156
DocumentsFeed docFeed = service.Query (query);
158
if (docFeed.Entries.Count >= 1) {
159
foreach (DocumentEntry docEntry in docFeed.Entries) {
160
if (docEntry.AlternateUri == doc_url) {
163
} catch (Exception e) {
164
Console.Error.WriteLine (e.Message);
165
Do.Addins.NotificationBridge.ShowMessage (Catalog.GetString ("Deleting failed"),
166
Catalog.GetString ("An error occurred when deleting the document at Google Docs."));
170
Do.Addins.NotificationBridge.ShowMessage (Catalog.GetString ("Document deleted."),
171
Catalog.GetString (String.Format ("The document '{0}' has been successfully moved into Trash at Google Docs.",
174
docs.Remove (docItem);
b'\\ No newline at end of file'