[f-spot/icon-view-cleanup: 20/24] Create a file for each Picasa exporter class
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/icon-view-cleanup: 20/24] Create a file for each Picasa exporter class
- Date: Tue, 17 Aug 2010 19:21:44 +0000 (UTC)
commit c349f5bd34035bc8b1682a77c910acec42d8a3c4
Author: Paul Lange <palango gmx de>
Date: Tue Aug 17 16:03:40 2010 +0200
Create a file for each Picasa exporter class
https://bugzilla.gnome.org/show_bug.cgi?id=627155
po/POTFILES.in | 4 +
.../FSpot.Exporters.PicasaWeb.csproj | 5 +-
.../FSpot.Exporters.PicasaWeb/GoogleAccount.cs | 123 ++++++
.../GoogleAccountDialog.cs | 142 +++++++
.../GoogleAccountManager.cs | 149 +++++++
.../FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs | 104 +++++
.../FSpot.Exporters.PicasaWeb/PicasaWebExport.cs | 436 +-------------------
.../FSpot.Exporters.PicasaWeb/Makefile.am | 7 +-
8 files changed, 533 insertions(+), 437 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 93e26cc..b85d917 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -112,6 +112,10 @@ src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/Gallery
[type: gettext/glade]src/Extensions/Exporters/FSpot.Exporters.Gallery/Resources/gallery_add_album_dialog.ui
[type: gettext/glade]src/Extensions/Exporters/FSpot.Exporters.Gallery/Resources/gallery_add_dialog.ui
[type: gettext/glade]src/Extensions/Exporters/FSpot.Exporters.Gallery/Resources/gallery_export_dialog.ui
+src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccount.cs
+src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountDialog.cs
+src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountManager.cs
+src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs
src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
[type: gettext/glade]src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/Resources/PicasaWebExport.glade
src/Extensions/Exporters/FSpot.Exporters.SmugMug/FSpot.Exporters.SmugMug/SmugMugExport.cs
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb.csproj b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb.csproj
index 62d42df..f3ead1a 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb.csproj
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb.csproj
@@ -33,6 +33,10 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="FSpot.Exporters.PicasaWeb\PicasaWebExport.cs" />
+ <Compile Include="FSpot.Exporters.PicasaWeb\GoogleAddAlbum.cs" />
+ <Compile Include="FSpot.Exporters.PicasaWeb\GoogleAccountDialog.cs" />
+ <Compile Include="FSpot.Exporters.PicasaWeb\GoogleAccountManager.cs" />
+ <Compile Include="FSpot.Exporters.PicasaWeb\GoogleAccount.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\PicasaWebExport.addin.xml">
@@ -65,7 +69,6 @@
<Reference Include="System" />
<Reference Include="Mono.Posix" />
<Reference Include="Gnome.Keyring, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1a73e1bde00c9b66">
- <Package>gnome-keyring-sharp-1.0</Package>
</Reference>
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccount.cs b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccount.cs
new file mode 100644
index 0000000..2db189e
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccount.cs
@@ -0,0 +1,123 @@
+using System;
+using System.Net;
+using System.IO;
+using System.Text;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web;
+using Mono.Unix;
+using Hyena;
+using Hyena.Widgets;
+using FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Imaging;
+using FSpot.UI.Dialog;
+using Gnome.Keyring;
+using Mono.Google;
+using Mono.Google.Picasa;
+
+namespace FSpot.Exporters.PicasaWeb
+{
+ public class GoogleAccount {
+
+ private string username;
+ private string password;
+ private string token;
+ private string unlock_captcha;
+ private GoogleConnection connection;
+ private Mono.Google.Picasa.PicasaWeb picasa;
+
+ public GoogleAccount (string username, string password)
+ {
+ this.username = username;
+ this.password = password;
+ }
+
+ public GoogleAccount (string username, string password, string token, string unlock_captcha)
+ {
+ this.username = username;
+ this.password = password;
+ this.token = token;
+ this.unlock_captcha = unlock_captcha;
+ }
+
+ public Mono.Google.Picasa.PicasaWeb Connect ()
+ {
+ Log.Debug ("GoogleAccount.Connect()");
+ GoogleConnection conn = new GoogleConnection (GoogleService.Picasa);
+ ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
+ if (unlock_captcha == null || token == null)
+ conn.Authenticate(username, password);
+ else {
+ conn.Authenticate(username, password, token, unlock_captcha);
+ token = null;
+ unlock_captcha = null;
+ }
+ connection = conn;
+ var picasa = new Mono.Google.Picasa.PicasaWeb(conn);
+ this.picasa = picasa;
+ return picasa;
+ }
+
+ private void MarkChanged()
+ {
+ connection = null;
+ }
+
+ public bool Connected {
+ get {
+ return (connection != null);
+ }
+ }
+
+ public string Username {
+ get {
+ return username;
+ }
+ set {
+ if (username != value) {
+ username = value;
+ MarkChanged ();
+ }
+ }
+ }
+
+ public string Password {
+ get {
+ return password;
+ }
+ set {
+ if (password != value) {
+ password = value;
+ MarkChanged ();
+ }
+ }
+ }
+
+ public string Token {
+ get {
+ return token;
+ }
+ set {
+ token = value;
+ }
+ }
+
+ public string UnlockCaptcha {
+ get {
+ return unlock_captcha;
+ }
+ set {
+ unlock_captcha = value;
+ }
+ }
+
+ public Mono.Google.Picasa.PicasaWeb Picasa {
+ get {
+ return picasa;
+ }
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountDialog.cs b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountDialog.cs
new file mode 100644
index 0000000..21be221
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountDialog.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Net;
+using System.IO;
+using System.Text;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web;
+using Mono.Unix;
+using Hyena;
+using Hyena.Widgets;
+using FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Imaging;
+using FSpot.UI.Dialog;
+using Gnome.Keyring;
+using Mono.Google;
+using Mono.Google.Picasa;
+
+namespace FSpot.Exporters.PicasaWeb
+{
+ public class GoogleAccountDialog {
+ public GoogleAccountDialog (Gtk.Window parent) : this (parent, null, false, null) {
+ Dialog.Response += HandleAddResponse;
+ add_button.Sensitive = false;
+ }
+
+ public GoogleAccountDialog (Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception)
+ {
+ xml = new Glade.XML (null, "PicasaWebExport.glade", dialog_name, "f-spot");
+ xml.Autoconnect (this);
+ Dialog.Modal = false;
+ Dialog.TransientFor = parent;
+ Dialog.DefaultResponse = Gtk.ResponseType.Ok;
+
+ this.account = account;
+
+ bool show_captcha = (captcha_exception != null);
+ status_area.Visible = show_error;
+ locked_area.Visible = show_captcha;
+ captcha_label.Visible = show_captcha;
+ captcha_entry.Visible = show_captcha;
+ captcha_image.Visible = show_captcha;
+
+ password_entry.ActivatesDefault = true;
+ username_entry.ActivatesDefault = true;
+
+ if (show_captcha) {
+ try {
+ using (var img = ImageFile.Create(new SafeUri(captcha_exception.CaptchaUrl, true))) {
+ captcha_image.Pixbuf = img.Load();
+ token = captcha_exception.Token;
+ }
+ } catch (Exception) {}
+ }
+
+ if (account != null) {
+ password_entry.Text = account.Password;
+ username_entry.Text = account.Username;
+ add_button.Label = Gtk.Stock.Ok;
+ Dialog.Response += HandleEditResponse;
+ }
+
+ if (remove_button != null)
+ remove_button.Visible = account != null;
+
+ this.Dialog.Show ();
+
+ password_entry.Changed += HandleChanged;
+ username_entry.Changed += HandleChanged;
+ HandleChanged (null, null);
+ }
+
+ private void HandleChanged (object sender, System.EventArgs args)
+ {
+ password = password_entry.Text;
+ username = username_entry.Text;
+
+ add_button.Sensitive = !(password == String.Empty || username == String.Empty);
+ }
+
+ [GLib.ConnectBefore]
+ protected void HandleAddResponse (object sender, Gtk.ResponseArgs args)
+ {
+ if (args.ResponseId == Gtk.ResponseType.Ok) {
+ GoogleAccount account = new GoogleAccount (username, password);
+ GoogleAccountManager.GetInstance ().AddAccount (account);
+ }
+ Dialog.Destroy ();
+ }
+
+ protected void HandleEditResponse (object sender, Gtk.ResponseArgs args)
+ {
+ if (args.ResponseId == Gtk.ResponseType.Ok) {
+ account.Username = username;
+ account.Password = password;
+ account.Token = token;
+ account.UnlockCaptcha = captcha_entry.Text;
+ GoogleAccountManager.GetInstance ().MarkChanged (true, account);
+ } else if (args.ResponseId == Gtk.ResponseType.Reject) {
+ // NOTE we are using Reject to signal the remove action.
+ GoogleAccountManager.GetInstance ().RemoveAccount (account);
+ }
+ Dialog.Destroy ();
+ }
+
+ private Gtk.Dialog Dialog {
+ get {
+ if (dialog == null)
+ dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
+
+ return dialog;
+ }
+ }
+
+ private GoogleAccount account;
+ private string password;
+ private string username;
+ private string token;
+
+ private Glade.XML xml;
+ private string dialog_name = "google_add_dialog";
+
+ // widgets
+ [Glade.Widget] Gtk.Dialog dialog;
+ [Glade.Widget] Gtk.Entry password_entry;
+ [Glade.Widget] Gtk.Entry username_entry;
+ [Glade.Widget] Gtk.Entry captcha_entry;
+
+ [Glade.Widget] Gtk.Button add_button;
+ [Glade.Widget] Gtk.Button remove_button;
+ [Glade.Widget] Gtk.Button cancel_button;
+
+ [Glade.Widget] Gtk.HBox status_area;
+ [Glade.Widget] Gtk.HBox locked_area;
+
+ [Glade.Widget] Gtk.Image captcha_image;
+ [Glade.Widget] Gtk.Label captcha_label;
+
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountManager.cs b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountManager.cs
new file mode 100644
index 0000000..17ace78
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAccountManager.cs
@@ -0,0 +1,149 @@
+using System;
+using System.Net;
+using System.IO;
+using System.Text;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web;
+using Mono.Unix;
+using Hyena;
+using Hyena.Widgets;
+using FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Imaging;
+using FSpot.UI.Dialog;
+using Gnome.Keyring;
+using Mono.Google;
+using Mono.Google.Picasa;
+
+namespace FSpot.Exporters.PicasaWeb
+{
+ public class GoogleAccountManager
+ {
+ private static GoogleAccountManager instance;
+ private const string keyring_item_name = "Google Account";
+ ArrayList accounts;
+
+ public delegate void AccountListChangedHandler (GoogleAccountManager manager, GoogleAccount changed_account);
+ public event AccountListChangedHandler AccountListChanged;
+
+ public static GoogleAccountManager GetInstance ()
+ {
+ if (instance == null) {
+ instance = new GoogleAccountManager ();
+ }
+
+ return instance;
+ }
+
+ private GoogleAccountManager ()
+ {
+ accounts = new ArrayList ();
+ ReadAccounts ();
+ }
+
+ public void MarkChanged ()
+ {
+ MarkChanged (true, null);
+ }
+
+ public void MarkChanged (bool write, GoogleAccount changed_account)
+ {
+ if (write)
+ WriteAccounts ();
+
+ if (AccountListChanged != null)
+ AccountListChanged (this, changed_account);
+ }
+
+ public ArrayList GetAccounts ()
+ {
+ return accounts;
+ }
+
+ public void AddAccount (GoogleAccount account)
+ {
+ AddAccount (account, true);
+ }
+
+ public void AddAccount (GoogleAccount account, bool write)
+ {
+ accounts.Add (account);
+ MarkChanged (write, account);
+ }
+
+ public void RemoveAccount (GoogleAccount account)
+ {
+ string keyring;
+ try {
+ keyring = Ring.GetDefaultKeyring();
+ } catch {
+ return;
+ }
+ Hashtable request_attributes = new Hashtable();
+ request_attributes["name"] = keyring_item_name;
+ request_attributes["username"] = account.Username;
+ try {
+ foreach(ItemData result in Ring.Find(ItemType.GenericSecret, request_attributes)) {
+ Ring.DeleteItem(keyring, result.ItemID);
+ }
+ } catch (Exception e) {
+ Log.DebugException (e);
+ }
+ accounts.Remove (account);
+ MarkChanged ();
+ }
+
+ public void WriteAccounts ()
+ {
+ string keyring;
+ try {
+ keyring = Ring.GetDefaultKeyring();
+ } catch {
+ return;
+ }
+ foreach (GoogleAccount account in accounts) {
+ Hashtable update_request_attributes = new Hashtable();
+ update_request_attributes["name"] = keyring_item_name;
+ update_request_attributes["username"] = account.Username;
+
+ try {
+ Ring.CreateItem(keyring, ItemType.GenericSecret, keyring_item_name, update_request_attributes, account.Password, true);
+ } catch {
+ continue;
+ }
+ }
+ }
+
+ private void ReadAccounts ()
+ {
+
+ Hashtable request_attributes = new Hashtable();
+ request_attributes["name"] = keyring_item_name;
+ try {
+ foreach(ItemData result in Ring.Find(ItemType.GenericSecret, request_attributes)) {
+ if(!result.Attributes.ContainsKey("name") || !result.Attributes.ContainsKey("username") ||
+ (result.Attributes["name"] as string) != keyring_item_name)
+ continue;
+
+ string username = (string)result.Attributes["username"];
+ string password = result.Secret;
+
+ if (username == null || username == String.Empty || password == null || password == String.Empty)
+ throw new ApplicationException ("Invalid username/password in keyring");
+
+ GoogleAccount account = new GoogleAccount(username, password);
+ if (account != null)
+ AddAccount (account, false);
+
+ }
+ } catch (Exception e) {
+ Log.DebugException (e);
+ }
+
+ MarkChanged ();
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs
new file mode 100644
index 0000000..e63874e
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Net;
+using System.IO;
+using System.Text;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web;
+using Mono.Unix;
+using Hyena;
+using Hyena.Widgets;
+using FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Imaging;
+using FSpot.UI.Dialog;
+using Gnome.Keyring;
+using Mono.Google;
+using Mono.Google.Picasa;
+
+namespace FSpot.Exporters.PicasaWeb
+{
+ public class GoogleAddAlbum {
+ [Glade.Widget] Gtk.Dialog dialog;
+ [Glade.Widget] Gtk.OptionMenu album_optionmenu;
+
+ [Glade.Widget] Gtk.Entry title_entry;
+ [Glade.Widget] Gtk.Entry description_entry;
+ [Glade.Widget] Gtk.CheckButton public_check;
+
+ [Glade.Widget] Gtk.Button add_button;
+ [Glade.Widget] Gtk.Button cancel_button;
+
+ private Glade.XML xml;
+ private string dialog_name = "google_add_album_dialog";
+
+ private GoogleExport export;
+ private Mono.Google.Picasa.PicasaWeb picasa;
+ private string description;
+ private string title;
+ private bool public_album;
+
+ public GoogleAddAlbum (GoogleExport export, Mono.Google.Picasa.PicasaWeb picasa)
+ {
+ xml = new Glade.XML (null, "PicasaWebExport.glade", dialog_name, "f-spot");
+ xml.Autoconnect (this);
+
+ this.export = export;
+ this.picasa = picasa;
+
+ Dialog.Response += HandleAddResponse;
+
+ description_entry.Changed += HandleChanged;
+ title_entry.Changed += HandleChanged;
+ HandleChanged (null, null);
+ }
+
+ private void HandleChanged (object sender, EventArgs args)
+ {
+ description = description_entry.Text;
+ title = title_entry.Text;
+ public_album = public_check.Active;
+
+ if (title == String.Empty)
+ add_button.Sensitive = false;
+ else
+ add_button.Sensitive = true;
+ }
+
+ [GLib.ConnectBefore]
+ protected void HandleAddResponse (object sender, Gtk.ResponseArgs args)
+ {
+ if (args.ResponseId == Gtk.ResponseType.Ok) {
+ public_album = public_check.Active;
+
+ try {
+ picasa.CreateAlbum (System.Web.HttpUtility.HtmlEncode (title), description, public_album ? AlbumAccess.Public : AlbumAccess.Private);
+ } catch (System.Exception e) {
+ HigMessageDialog md =
+ new HigMessageDialog (Dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Error while creating Album"),
+ String.Format (Catalog.GetString ("The following error was encountered while attempting to create an album: {0}"), e.Message));
+ md.Run ();
+ md.Destroy ();
+ return;
+ }
+ export.HandleAlbumAdded (title);
+ }
+ Dialog.Destroy ();
+ }
+
+ private Gtk.Dialog Dialog {
+ get {
+ if (dialog == null)
+ dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
+
+ return dialog;
+ }
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/PicasaWebExport.cs b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
index 718129f..bb426e9 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
@@ -31,442 +31,8 @@ using Mono.Google;
using Mono.Google.Picasa;
namespace FSpot.Exporters.PicasaWeb {
- public class GoogleAccount {
-
- private string username;
- private string password;
- private string token;
- private string unlock_captcha;
- private GoogleConnection connection;
- private Mono.Google.Picasa.PicasaWeb picasa;
-
- public GoogleAccount (string username, string password)
- {
- this.username = username;
- this.password = password;
- }
-
- public GoogleAccount (string username, string password, string token, string unlock_captcha)
- {
- this.username = username;
- this.password = password;
- this.token = token;
- this.unlock_captcha = unlock_captcha;
- }
-
- public Mono.Google.Picasa.PicasaWeb Connect ()
- {
- Log.Debug ("GoogleAccount.Connect()");
- GoogleConnection conn = new GoogleConnection (GoogleService.Picasa);
- ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
- if (unlock_captcha == null || token == null)
- conn.Authenticate(username, password);
- else {
- conn.Authenticate(username, password, token, unlock_captcha);
- token = null;
- unlock_captcha = null;
- }
- connection = conn;
- var picasa = new Mono.Google.Picasa.PicasaWeb(conn);
- this.picasa = picasa;
- return picasa;
- }
-
- private void MarkChanged()
- {
- connection = null;
- }
-
- public bool Connected {
- get {
- return (connection != null);
- }
- }
-
- public string Username {
- get {
- return username;
- }
- set {
- if (username != value) {
- username = value;
- MarkChanged ();
- }
- }
- }
-
- public string Password {
- get {
- return password;
- }
- set {
- if (password != value) {
- password = value;
- MarkChanged ();
- }
- }
- }
-
- public string Token {
- get {
- return token;
- }
- set {
- token = value;
- }
- }
-
- public string UnlockCaptcha {
- get {
- return unlock_captcha;
- }
- set {
- unlock_captcha = value;
- }
- }
-
- public Mono.Google.Picasa.PicasaWeb Picasa {
- get {
- return picasa;
- }
- }
- }
-
-
- public class GoogleAccountManager
- {
- private static GoogleAccountManager instance;
- private const string keyring_item_name = "Google Account";
- ArrayList accounts;
-
- public delegate void AccountListChangedHandler (GoogleAccountManager manager, GoogleAccount changed_account);
- public event AccountListChangedHandler AccountListChanged;
-
- public static GoogleAccountManager GetInstance ()
- {
- if (instance == null) {
- instance = new GoogleAccountManager ();
- }
-
- return instance;
- }
-
- private GoogleAccountManager ()
- {
- accounts = new ArrayList ();
- ReadAccounts ();
- }
-
- public void MarkChanged ()
- {
- MarkChanged (true, null);
- }
-
- public void MarkChanged (bool write, GoogleAccount changed_account)
- {
- if (write)
- WriteAccounts ();
-
- if (AccountListChanged != null)
- AccountListChanged (this, changed_account);
- }
-
- public ArrayList GetAccounts ()
- {
- return accounts;
- }
-
- public void AddAccount (GoogleAccount account)
- {
- AddAccount (account, true);
- }
-
- public void AddAccount (GoogleAccount account, bool write)
- {
- accounts.Add (account);
- MarkChanged (write, account);
- }
-
- public void RemoveAccount (GoogleAccount account)
- {
- string keyring;
- try {
- keyring = Ring.GetDefaultKeyring();
- } catch {
- return;
- }
- Hashtable request_attributes = new Hashtable();
- request_attributes["name"] = keyring_item_name;
- request_attributes["username"] = account.Username;
- try {
- foreach(ItemData result in Ring.Find(ItemType.GenericSecret, request_attributes)) {
- Ring.DeleteItem(keyring, result.ItemID);
- }
- } catch (Exception e) {
- Log.DebugException (e);
- }
- accounts.Remove (account);
- MarkChanged ();
- }
-
- public void WriteAccounts ()
- {
- string keyring;
- try {
- keyring = Ring.GetDefaultKeyring();
- } catch {
- return;
- }
- foreach (GoogleAccount account in accounts) {
- Hashtable update_request_attributes = new Hashtable();
- update_request_attributes["name"] = keyring_item_name;
- update_request_attributes["username"] = account.Username;
-
- try {
- Ring.CreateItem(keyring, ItemType.GenericSecret, keyring_item_name, update_request_attributes, account.Password, true);
- } catch {
- continue;
- }
- }
- }
-
- private void ReadAccounts ()
- {
-
- Hashtable request_attributes = new Hashtable();
- request_attributes["name"] = keyring_item_name;
- try {
- foreach(ItemData result in Ring.Find(ItemType.GenericSecret, request_attributes)) {
- if(!result.Attributes.ContainsKey("name") || !result.Attributes.ContainsKey("username") ||
- (result.Attributes["name"] as string) != keyring_item_name)
- continue;
-
- string username = (string)result.Attributes["username"];
- string password = result.Secret;
-
- if (username == null || username == String.Empty || password == null || password == String.Empty)
- throw new ApplicationException ("Invalid username/password in keyring");
-
- GoogleAccount account = new GoogleAccount(username, password);
- if (account != null)
- AddAccount (account, false);
-
- }
- } catch (Exception e) {
- Log.DebugException (e);
- }
-
- MarkChanged ();
- }
- }
-
- public class GoogleAccountDialog {
- public GoogleAccountDialog (Gtk.Window parent) : this (parent, null, false, null) {
- Dialog.Response += HandleAddResponse;
- add_button.Sensitive = false;
- }
-
- public GoogleAccountDialog (Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception)
- {
- xml = new Glade.XML (null, "PicasaWebExport.glade", dialog_name, "f-spot");
- xml.Autoconnect (this);
- Dialog.Modal = false;
- Dialog.TransientFor = parent;
- Dialog.DefaultResponse = Gtk.ResponseType.Ok;
-
- this.account = account;
-
- bool show_captcha = (captcha_exception != null);
- status_area.Visible = show_error;
- locked_area.Visible = show_captcha;
- captcha_label.Visible = show_captcha;
- captcha_entry.Visible = show_captcha;
- captcha_image.Visible = show_captcha;
-
- password_entry.ActivatesDefault = true;
- username_entry.ActivatesDefault = true;
-
- if (show_captcha) {
- try {
- using (var img = ImageFile.Create(new SafeUri(captcha_exception.CaptchaUrl, true))) {
- captcha_image.Pixbuf = img.Load();
- token = captcha_exception.Token;
- }
- } catch (Exception) {}
- }
-
- if (account != null) {
- password_entry.Text = account.Password;
- username_entry.Text = account.Username;
- add_button.Label = Gtk.Stock.Ok;
- Dialog.Response += HandleEditResponse;
- }
-
- if (remove_button != null)
- remove_button.Visible = account != null;
-
- this.Dialog.Show ();
-
- password_entry.Changed += HandleChanged;
- username_entry.Changed += HandleChanged;
- HandleChanged (null, null);
- }
-
- private void HandleChanged (object sender, System.EventArgs args)
- {
- password = password_entry.Text;
- username = username_entry.Text;
-
- add_button.Sensitive = !(password == String.Empty || username == String.Empty);
- }
-
- [GLib.ConnectBefore]
- protected void HandleAddResponse (object sender, Gtk.ResponseArgs args)
- {
- if (args.ResponseId == Gtk.ResponseType.Ok) {
- GoogleAccount account = new GoogleAccount (username, password);
- GoogleAccountManager.GetInstance ().AddAccount (account);
- }
- Dialog.Destroy ();
- }
-
- protected void HandleEditResponse (object sender, Gtk.ResponseArgs args)
- {
- if (args.ResponseId == Gtk.ResponseType.Ok) {
- account.Username = username;
- account.Password = password;
- account.Token = token;
- account.UnlockCaptcha = captcha_entry.Text;
- GoogleAccountManager.GetInstance ().MarkChanged (true, account);
- } else if (args.ResponseId == Gtk.ResponseType.Reject) {
- // NOTE we are using Reject to signal the remove action.
- GoogleAccountManager.GetInstance ().RemoveAccount (account);
- }
- Dialog.Destroy ();
- }
-
- private Gtk.Dialog Dialog {
- get {
- if (dialog == null)
- dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
-
- return dialog;
- }
- }
-
- private GoogleAccount account;
- private string password;
- private string username;
- private string token;
-
- private Glade.XML xml;
- private string dialog_name = "google_add_dialog";
-
- // widgets
- [Glade.Widget] Gtk.Dialog dialog;
- [Glade.Widget] Gtk.Entry password_entry;
- [Glade.Widget] Gtk.Entry username_entry;
- [Glade.Widget] Gtk.Entry captcha_entry;
-
- [Glade.Widget] Gtk.Button add_button;
- [Glade.Widget] Gtk.Button remove_button;
- [Glade.Widget] Gtk.Button cancel_button;
-
- [Glade.Widget] Gtk.HBox status_area;
- [Glade.Widget] Gtk.HBox locked_area;
-
- [Glade.Widget] Gtk.Image captcha_image;
- [Glade.Widget] Gtk.Label captcha_label;
-
- }
-
- public class GoogleAddAlbum {
- [Glade.Widget] Gtk.Dialog dialog;
- [Glade.Widget] Gtk.OptionMenu album_optionmenu;
-
- [Glade.Widget] Gtk.Entry title_entry;
- [Glade.Widget] Gtk.Entry description_entry;
- [Glade.Widget] Gtk.CheckButton public_check;
-
- [Glade.Widget] Gtk.Button add_button;
- [Glade.Widget] Gtk.Button cancel_button;
-
- private Glade.XML xml;
- private string dialog_name = "google_add_album_dialog";
-
- private GoogleExport export;
- private Mono.Google.Picasa.PicasaWeb picasa;
- private string description;
- private string title;
- private bool public_album;
-
- public GoogleAddAlbum (GoogleExport export, Mono.Google.Picasa.PicasaWeb picasa)
- {
- xml = new Glade.XML (null, "PicasaWebExport.glade", dialog_name, "f-spot");
- xml.Autoconnect (this);
-
- this.export = export;
- this.picasa = picasa;
-
- Dialog.Response += HandleAddResponse;
-
- description_entry.Changed += HandleChanged;
- title_entry.Changed += HandleChanged;
- HandleChanged (null, null);
- }
-
- private void HandleChanged (object sender, EventArgs args)
- {
- description = description_entry.Text;
- title = title_entry.Text;
- public_album = public_check.Active;
-
- if (title == String.Empty)
- add_button.Sensitive = false;
- else
- add_button.Sensitive = true;
- }
-
- [GLib.ConnectBefore]
- protected void HandleAddResponse (object sender, Gtk.ResponseArgs args)
- {
- if (args.ResponseId == Gtk.ResponseType.Ok) {
- public_album = public_check.Active;
-
- try {
- picasa.CreateAlbum (System.Web.HttpUtility.HtmlEncode (title), description, public_album ? AlbumAccess.Public : AlbumAccess.Private);
- } catch (System.Exception e) {
- HigMessageDialog md =
- new HigMessageDialog (Dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Error while creating Album"),
- String.Format (Catalog.GetString ("The following error was encountered while attempting to create an album: {0}"), e.Message));
- md.Run ();
- md.Destroy ();
- return;
- }
- export.HandleAlbumAdded (title);
- }
- Dialog.Destroy ();
- }
-
- private Gtk.Dialog Dialog {
- get {
- if (dialog == null)
- dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
-
- return dialog;
- }
- }
- }
-
-
public class GoogleExport : FSpot.Extensions.IExporter {
- public GoogleExport ()
- {
- }
+ public GoogleExport () {}
public void Run (IBrowsableCollection selection)
{
diff --git a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/Makefile.am b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/Makefile.am
index 8b53c91..be48085 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/Makefile.am
+++ b/src/Extensions/Exporters/FSpot.Exporters.PicasaWeb/Makefile.am
@@ -3,7 +3,12 @@ TARGET = library
LINK = $(REF_FSPOT_EXTENSION_PICASAWEBEXPORT)
INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
-SOURCES = FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
+SOURCES = \
+ FSpot.Exporters.PicasaWeb/GoogleAccount.cs \
+ FSpot.Exporters.PicasaWeb/GoogleAccountDialog.cs \
+ FSpot.Exporters.PicasaWeb/GoogleAccountManager.cs \
+ FSpot.Exporters.PicasaWeb/GoogleAddAlbum.cs \
+ FSpot.Exporters.PicasaWeb/PicasaWebExport.cs
RESOURCES = \
Resources/PicasaWebExport.addin.xml \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]