[f-spot/icon-view-cleanup: 15/24] Create a file for each Gallery export class
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/icon-view-cleanup: 15/24] Create a file for each Gallery export class
- Date: Tue, 17 Aug 2010 19:21:19 +0000 (UTC)
commit c02a7dd2b4d123d0a5b597324ed31088414fdb9f
Author: Paul Lange <palango gmx de>
Date: Fri Aug 13 22:23:42 2010 +0200
Create a file for each Gallery export class
https://bugzilla.gnome.org/show_bug.cgi?id=626876
.../FSpot.Exporters.Gallery.csproj | 4 +
.../FSpot.Exporters.Gallery/AccountDialog.cs | 198 +++++++
.../FSpot.Exporters.Gallery/GalleryAccount.cs | 151 +++++
.../GalleryAccountManager.cs | 176 ++++++
.../FSpot.Exporters.Gallery/GalleryAddAlbum.cs | 141 +++++
.../FSpot.Exporters.Gallery/GalleryExport.cs | 595 +-------------------
.../Exporters/FSpot.Exporters.Gallery/Makefile.am | 4 +
7 files changed, 677 insertions(+), 592 deletions(-)
---
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery.csproj b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery.csproj
index da36280..e469458 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery.csproj
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery.csproj
@@ -35,6 +35,10 @@
<Compile Include="FSpot.Exporters.Gallery\FormClient.cs" />
<Compile Include="FSpot.Exporters.Gallery\GalleryExport.cs" />
<Compile Include="FSpot.Exporters.Gallery\GalleryRemote.cs" />
+ <Compile Include="FSpot.Exporters.Gallery\GalleryAccount.cs" />
+ <Compile Include="FSpot.Exporters.Gallery\GalleryAccountManager.cs" />
+ <Compile Include="FSpot.Exporters.Gallery\AccountDialog.cs" />
+ <Compile Include="FSpot.Exporters.Gallery\GalleryAddAlbum.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\GalleryExport.addin.xml">
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/AccountDialog.cs b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/AccountDialog.cs
new file mode 100644
index 0000000..0aba75c
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/AccountDialog.cs
@@ -0,0 +1,198 @@
+
+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 FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Utils;
+using FSpot.UI.Dialog;
+using FSpot.Extensions;
+using Hyena;
+using Hyena.Widgets;
+namespace FSpot.Exporters.Gallery
+{
+ public class AccountDialog {
+ public AccountDialog (Gtk.Window parent) : this (parent, null, false) {
+ add_dialog.Response += HandleAddResponse;
+ add_button.Sensitive = false;
+ }
+
+ public AccountDialog (Gtk.Window parent, GalleryAccount account, bool show_error)
+ {
+ Glade.XML xml = new Glade.XML (null, "GalleryExport.glade", "gallery_add_dialog", "f-spot");
+ xml.Autoconnect (this);
+ add_dialog = (Gtk.Dialog) xml.GetWidget ("gallery_add_dialog");
+ add_dialog.Modal = false;
+ add_dialog.TransientFor = parent;
+ add_dialog.DefaultResponse = Gtk.ResponseType.Ok;
+
+ this.account = account;
+
+ status_area.Visible = show_error;
+
+ if (account != null) {
+ gallery_entry.Text = account.Name;
+ url_entry.Text = account.Url;
+ password_entry.Text = account.Password;
+ username_entry.Text = account.Username;
+ add_button.Label = Gtk.Stock.Ok;
+ add_dialog.Response += HandleEditResponse;
+ }
+
+ if (remove_button != null)
+ remove_button.Visible = account != null;
+
+ add_dialog.Show ();
+
+ gallery_entry.Changed += HandleChanged;
+ url_entry.Changed += HandleChanged;
+ password_entry.Changed += HandleChanged;
+ username_entry.Changed += HandleChanged;
+ HandleChanged (null, null);
+ }
+
+ private void HandleChanged (object sender, System.EventArgs args)
+ {
+ name = gallery_entry.Text;
+ url = url_entry.Text;
+ password = password_entry.Text;
+ username = username_entry.Text;
+
+ if (name == String.Empty || url == String.Empty || password == String.Empty || username == 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) {
+ try {
+ Uri uri = new Uri (url);
+ if (uri.Scheme != Uri.UriSchemeHttp &&
+ uri.Scheme != Uri.UriSchemeHttps)
+ throw new System.UriFormatException ();
+
+ //Check for name uniqueness
+ foreach (GalleryAccount acc in GalleryAccountManager.GetInstance ().GetAccounts ())
+ if (acc.Name == name)
+ throw new ArgumentException ("name");
+ GalleryAccount created = new GalleryAccount (name,
+ url,
+ username,
+ password);
+
+ created.Connect ();
+ GalleryAccountManager.GetInstance ().AddAccount (created);
+ account = created;
+ } catch (System.UriFormatException) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Invalid URL"),
+ Catalog.GetString ("The gallery URL entry does not appear to be a valid URL"));
+ md.Run ();
+ md.Destroy ();
+ return;
+ } catch (GalleryException e) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Error while connecting to Gallery"),
+ String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), e.Message));
+ if (e.ResponseText != null) {
+ Log.Debug (e.Message);
+ Log.Debug (e.ResponseText);
+ }
+ md.Run ();
+ md.Destroy ();
+ return;
+ } catch (ArgumentException ae) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("A Gallery with this name already exists"),
+ String.Format (Catalog.GetString ("There is already a Gallery with the same name in your registered Galleries. Please choose a unique name.")));
+ Log.Exception (ae);
+ md.Run ();
+ md.Destroy ();
+ return;
+ } catch (System.Net.WebException we) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Error while connecting to Gallery"),
+ String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), we.Message));
+ md.Run ();
+ md.Destroy ();
+ return;
+ } catch (System.Exception se) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Error while connecting to Gallery"),
+ String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), se.Message));
+ Log.Exception (se);
+ md.Run ();
+ md.Destroy ();
+ return;
+ }
+ }
+ add_dialog.Destroy ();
+ }
+
+ protected void HandleEditResponse (object sender, Gtk.ResponseArgs args)
+ {
+ if (args.ResponseId == Gtk.ResponseType.Ok) {
+ account.Name = name;
+ account.Url = url;
+ account.Username = username;
+ account.Password = password;
+ GalleryAccountManager.GetInstance ().MarkChanged (true, account);
+ } else if (args.ResponseId == Gtk.ResponseType.Reject) {
+ // NOTE we are using Reject to signal the remove action.
+ GalleryAccountManager.GetInstance ().RemoveAccount (account);
+ }
+ add_dialog.Destroy ();
+ }
+
+ private GalleryAccount account;
+ private string name;
+ private string url;
+ private string password;
+ private string username;
+
+ // widgets
+ [Glade.Widget] Gtk.Dialog add_dialog;
+
+ [Glade.Widget] Gtk.Entry url_entry;
+ [Glade.Widget] Gtk.Entry password_entry;
+ [Glade.Widget] Gtk.Entry gallery_entry;
+ [Glade.Widget] Gtk.Entry username_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;
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccount.cs b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccount.cs
new file mode 100644
index 0000000..8377d4a
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccount.cs
@@ -0,0 +1,151 @@
+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 FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Utils;
+using FSpot.UI.Dialog;
+using FSpot.Extensions;
+using Hyena;
+using Hyena.Widgets;
+
+namespace FSpot.Exporters.Gallery
+{
+ public class GalleryAccount {
+ public GalleryAccount (string name, string url, string username, string password) : this (name, url, username, password, GalleryVersion.VersionUnknown) {}
+ public GalleryAccount (string name, string url, string username, string password, GalleryVersion version)
+ {
+ this.name = name;
+ this.username = username;
+ this.password = password;
+ this.Url = url;
+
+ if (version != GalleryVersion.VersionUnknown) {
+ this.version = version;
+ } else {
+ this.version = Gallery.DetectGalleryVersion(Url);
+ }
+ }
+
+ public const string EXPORT_SERVICE = "gallery/";
+ public const string LIGHTTPD_WORKAROUND_KEY = Preferences.APP_FSPOT_EXPORT + EXPORT_SERVICE + "lighttpd_workaround";
+
+ public Gallery Connect ()
+ {
+ //System.Console.WriteLine ("GalleryAccount.Connect()");
+ Gallery gal = null;
+
+ if (version == GalleryVersion.VersionUnknown)
+ this.version = Gallery.DetectGalleryVersion(Url);
+
+ if (version == GalleryVersion.Version1) {
+ gal = new Gallery1 (url, url);
+ } else if (version == GalleryVersion.Version2) {
+ gal = new Gallery2 (url, url);
+ } else {
+ throw new GalleryException (Catalog.GetString("Cannot connect to a Gallery for which the version is unknown.\nPlease check that you have Remote plugin 1.0.8 or later"));
+ }
+
+ Log.Debug ("Gallery created: " + gal);
+
+ gal.Login (username, password);
+
+ gallery = gal;
+ connected = true;
+
+ gallery.expect_continue = Preferences.Get<bool> (LIGHTTPD_WORKAROUND_KEY);
+
+ return gallery;
+ }
+
+ GalleryVersion version;
+ public GalleryVersion Version{
+ get {
+ return version;
+ }
+ }
+
+ private bool connected;
+ public bool Connected {
+ get {
+ bool retVal = false;
+ if(gallery != null) {
+ retVal = gallery.IsConnected ();
+ }
+ if (connected != retVal) {
+ Log.Warning ("Connected and retVal for IsConnected() don't agree");
+ }
+ return retVal;
+ }
+ }
+
+ public void MarkChanged ()
+ {
+ connected = false;
+ gallery = null;
+ }
+
+ Gallery gallery;
+ public Gallery Gallery {
+ get {
+ return gallery;
+ }
+ }
+
+ string name;
+ public string Name {
+ get {
+ return name;
+ }
+ set {
+ name = value;
+ }
+ }
+
+ string url;
+ public string Url {
+ get {
+ return url;
+ }
+ set {
+ if (url != value) {
+ url = value;
+ MarkChanged ();
+ }
+ }
+ }
+
+ string username;
+ public string Username {
+ get {
+ return username;
+ }
+ set {
+ if (username != value) {
+ username = value;
+ MarkChanged ();
+ }
+ }
+ }
+
+ string password;
+ public string Password {
+ get {
+ return password;
+ }
+ set {
+ if (password != value) {
+ password = value;
+ MarkChanged ();
+ }
+ }
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccountManager.cs b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccountManager.cs
new file mode 100644
index 0000000..b106c74
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAccountManager.cs
@@ -0,0 +1,176 @@
+
+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 FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Utils;
+using FSpot.UI.Dialog;
+using FSpot.Extensions;
+using Hyena;
+using Hyena.Widgets;
+namespace FSpot.Exporters.Gallery
+{
+ public class GalleryAccountManager
+ {
+ private static GalleryAccountManager instance;
+ string xml_path;
+ ArrayList accounts;
+
+ public delegate void AccountListChangedHandler (GalleryAccountManager manager, GalleryAccount changed_account);
+ public event AccountListChangedHandler AccountListChanged;
+
+ public static GalleryAccountManager GetInstance ()
+ {
+ if (instance == null) {
+ instance = new GalleryAccountManager ();
+ }
+
+ return instance;
+ }
+
+ private GalleryAccountManager ()
+ {
+ // FIXME this xml file path should be be retrieved from a central location not hard coded there
+ this.xml_path = System.IO.Path.Combine (FSpot.Core.Global.BaseDirectory, "Accounts.xml");
+
+ accounts = new ArrayList ();
+ ReadAccounts ();
+ }
+
+ public void MarkChanged ()
+ {
+ MarkChanged (true, null);
+ }
+
+ public void MarkChanged (bool write, GalleryAccount changed_account)
+ {
+ if (write)
+ WriteAccounts ();
+
+ if (AccountListChanged != null)
+ AccountListChanged (this, changed_account);
+ }
+
+ public ArrayList GetAccounts ()
+ {
+ return accounts;
+ }
+
+ public void AddAccount (GalleryAccount account)
+ {
+ AddAccount (account, true);
+ }
+
+ public void AddAccount (GalleryAccount account, bool write)
+ {
+ accounts.Add (account);
+ MarkChanged (write, account);
+ }
+
+ public void RemoveAccount (GalleryAccount account)
+ {
+ accounts.Remove (account);
+ MarkChanged ();
+ }
+
+ public void WriteAccounts ()
+ {
+ System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter (xml_path, System.Text.Encoding.Default);
+
+ writer.Formatting = System.Xml.Formatting.Indented;
+ writer.Indentation = 2;
+ writer.IndentChar = ' ';
+
+ writer.WriteStartDocument (true);
+
+ writer.WriteStartElement ("GalleryRemote");
+ foreach (GalleryAccount account in accounts) {
+ writer.WriteStartElement ("Account");
+ writer.WriteElementString ("Name", account.Name);
+
+ writer.WriteElementString ("Url", account.Url);
+ writer.WriteElementString ("Username", account.Username);
+ writer.WriteElementString ("Password", account.Password);
+ writer.WriteElementString ("Version", account.Version.ToString());
+ writer.WriteEndElement (); //Account
+ }
+ writer.WriteEndElement ();
+ writer.WriteEndDocument ();
+ writer.Close ();
+ }
+
+ private GalleryAccount ParseAccount (System.Xml.XmlNode node)
+ {
+ if (node.Name != "Account")
+
+ return null;
+
+ string name = null;
+ string url = null;
+ string username = null;
+ string password = null;
+ GalleryVersion version = GalleryVersion.VersionUnknown;
+
+ foreach (System.Xml.XmlNode child in node.ChildNodes) {
+ if (child.Name == "Name") {
+ name = child.ChildNodes [0].Value;
+
+ } else if (child.Name == "Url") {
+ url = child.ChildNodes [0].Value;
+ } else if (child.Name == "Password") {
+ password = child.ChildNodes [0].Value;
+ } else if (child.Name == "Username") {
+ username = child.ChildNodes [0].Value;
+ } else if (child.Name == "Version") {
+ string versionString = child.ChildNodes [0].Value;
+ if (versionString == "Version1")
+ version = GalleryVersion.Version1;
+ else if (versionString == "Version2")
+ version = GalleryVersion.Version2;
+ else
+ Log.Error ("Unexpected versions string: " + versionString);
+ }
+ }
+ return new GalleryAccount (name, url, username, password, version);
+ }
+
+ private void ReadAccounts ()
+ {
+
+ if (! File.Exists (xml_path)) {
+ MarkChanged ();
+ return;
+ }
+
+ try {
+ string query = "//GalleryRemote/Account";
+ System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
+
+ //System.Console.WriteLine ("xml_path: " + xml_path);
+ doc.Load (xml_path);
+ System.Xml.XmlNodeList nodes = doc.SelectNodes (query);
+
+ //System.Console.WriteLine ("selected {0} nodes match {1}", nodes.Count, query);
+ foreach (System.Xml.XmlNode node in nodes) {
+ GalleryAccount account = ParseAccount (node);
+ if (account != null)
+ AddAccount (account, false);
+
+ }
+ } catch (System.Exception e) {
+ // FIXME do something
+ Log.Exception ("Exception loading gallery accounts", e);
+ }
+
+ MarkChanged ();
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAddAlbum.cs b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAddAlbum.cs
new file mode 100644
index 0000000..2c0638e
--- /dev/null
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryAddAlbum.cs
@@ -0,0 +1,141 @@
+
+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 FSpot;
+using FSpot.Core;
+using FSpot.Filters;
+using FSpot.Widgets;
+using FSpot.Utils;
+using FSpot.UI.Dialog;
+using FSpot.Extensions;
+using Hyena;
+using Hyena.Widgets;
+namespace FSpot.Exporters.Gallery
+{
+ public class GalleryAddAlbum
+ {
+ [Glade.Widget] Gtk.Dialog add_album_dialog;
+ [Glade.Widget] Gtk.OptionMenu album_optionmenu;
+
+ [Glade.Widget] Gtk.Entry name_entry;
+ [Glade.Widget] Gtk.Entry description_entry;
+ [Glade.Widget] Gtk.Entry title_entry;
+
+ [Glade.Widget] Gtk.Button add_button;
+ [Glade.Widget] Gtk.Button cancel_button;
+
+ private GalleryExport export;
+ private Gallery gallery;
+ private string parent;
+ private string name;
+ private string description;
+ private string title;
+
+ public GalleryAddAlbum (GalleryExport export, Gallery gallery)
+ {
+ Glade.XML xml = new Glade.XML (null, "GalleryExport.glade", "gallery_add_album_dialog", "f-spot");
+ xml.Autoconnect (this);
+ add_album_dialog = (Gtk.Dialog) xml.GetWidget ("gallery_add_album_dialog");
+ add_album_dialog.Modal = true;
+ this.export = export;
+ this.gallery = gallery;
+ PopulateAlbums ();
+
+ add_album_dialog.Response += HandleAddResponse;
+
+ name_entry.Changed += HandleChanged;
+ description_entry.Changed += HandleChanged;
+ title_entry.Changed += HandleChanged;
+ HandleChanged (null, null);
+ }
+
+ private void PopulateAlbums ()
+ {
+ Gtk.Menu menu = new Gtk.Menu ();
+ if (gallery.Version == GalleryVersion.Version1) {
+ Gtk.MenuItem top_item = new Gtk.MenuItem (Catalog.GetString ("(TopLevel)"));
+ menu.Append (top_item);
+ }
+
+ foreach (Album album in gallery.Albums) {
+ System.Text.StringBuilder label_builder = new System.Text.StringBuilder ();
+
+ for (int i=0; i < album.Parents.Count; i++) {
+ label_builder.Append (" ");
+ }
+ label_builder.Append (album.Title);
+
+ Gtk.MenuItem item = new Gtk.MenuItem (label_builder.ToString ());
+ ((Gtk.Label)item.Child).UseUnderline = false;
+ menu.Append (item);
+
+ AlbumPermission create_sub = album.Perms & AlbumPermission.CreateSubAlbum;
+
+ if (create_sub == 0)
+ item.Sensitive = false;
+ }
+
+ album_optionmenu.Sensitive = true;
+ menu.ShowAll ();
+ album_optionmenu.Menu = menu;
+ }
+
+ private void HandleChanged (object sender, EventArgs args)
+ {
+ if (gallery.Version == GalleryVersion.Version1) {
+ if (gallery.Albums.Count == 0 || album_optionmenu.History <= 0) {
+ parent = String.Empty;
+ } else {
+ parent = ((Album) gallery.Albums [album_optionmenu.History-1]).Name;
+ }
+ } else {
+ if (gallery.Albums.Count == 0 || album_optionmenu.History < 0) {
+ parent = String.Empty;
+ } else {
+ parent = ((Album) gallery.Albums [album_optionmenu.History]).Name;
+ }
+ }
+ name = name_entry.Text;
+ description = description_entry.Text;
+ title = title_entry.Text;
+
+ if (name == String.Empty || 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) {
+ if (!System.Text.RegularExpressions.Regex.IsMatch (name, "^[A-Za-z0-9_-]+$")) {
+ HigMessageDialog md =
+ new HigMessageDialog (add_album_dialog,
+ Gtk.DialogFlags.Modal |
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
+ Catalog.GetString ("Invalid Gallery name"),
+ Catalog.GetString ("The gallery name contains invalid characters.\nOnly letters, numbers, - and _ are allowed"));
+ md.Run ();
+ md.Destroy ();
+ return;
+ }
+ try {
+ gallery.NewAlbum (parent, name, title, description);
+ export.HandleAlbumAdded (title);
+ } catch (GalleryCommandException e) {
+ gallery.PopupException(e, add_album_dialog);
+ return;
+ }
+ }
+ add_album_dialog.Destroy ();
+ }
+ }
+}
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryExport.cs b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryExport.cs
index 06cd07a..9108c3b 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryExport.cs
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/FSpot.Exporters.Gallery/GalleryExport.cs
@@ -18,599 +18,10 @@ using FSpot.Extensions;
using Hyena;
using Hyena.Widgets;
-namespace FSpot.Exporters.Gallery {
- public class GalleryAccount {
- public GalleryAccount (string name, string url, string username, string password) : this (name, url, username, password, GalleryVersion.VersionUnknown) {}
- public GalleryAccount (string name, string url, string username, string password, GalleryVersion version)
- {
- this.name = name;
- this.username = username;
- this.password = password;
- this.Url = url;
-
- if (version != GalleryVersion.VersionUnknown) {
- this.version = version;
- } else {
- this.version = Gallery.DetectGalleryVersion(Url);
- }
- }
-
- public const string EXPORT_SERVICE = "gallery/";
- public const string LIGHTTPD_WORKAROUND_KEY = Preferences.APP_FSPOT_EXPORT + EXPORT_SERVICE + "lighttpd_workaround";
-
- public Gallery Connect ()
- {
- //System.Console.WriteLine ("GalleryAccount.Connect()");
- Gallery gal = null;
-
- if (version == GalleryVersion.VersionUnknown)
- this.version = Gallery.DetectGalleryVersion(Url);
-
- if (version == GalleryVersion.Version1) {
- gal = new Gallery1 (url, url);
- } else if (version == GalleryVersion.Version2) {
- gal = new Gallery2 (url, url);
- } else {
- throw new GalleryException (Catalog.GetString("Cannot connect to a Gallery for which the version is unknown.\nPlease check that you have Remote plugin 1.0.8 or later"));
- }
-
- Log.Debug ("Gallery created: " + gal);
-
- gal.Login (username, password);
-
- gallery = gal;
- connected = true;
-
- gallery.expect_continue = Preferences.Get<bool> (LIGHTTPD_WORKAROUND_KEY);
-
- return gallery;
- }
-
- GalleryVersion version;
- public GalleryVersion Version{
- get {
- return version;
- }
- }
-
- private bool connected;
- public bool Connected {
- get {
- bool retVal = false;
- if(gallery != null) {
- retVal = gallery.IsConnected ();
- }
- if (connected != retVal) {
- Log.Warning ("Connected and retVal for IsConnected() don't agree");
- }
- return retVal;
- }
- }
-
- public void MarkChanged ()
- {
- connected = false;
- gallery = null;
- }
-
- Gallery gallery;
- public Gallery Gallery {
- get {
- return gallery;
- }
- }
-
- string name;
- public string Name {
- get {
- return name;
- }
- set {
- name = value;
- }
- }
-
- string url;
- public string Url {
- get {
- return url;
- }
- set {
- if (url != value) {
- url = value;
- MarkChanged ();
- }
- }
- }
-
- string username;
- public string Username {
- get {
- return username;
- }
- set {
- if (username != value) {
- username = value;
- MarkChanged ();
- }
- }
- }
-
- string password;
- public string Password {
- get {
- return password;
- }
- set {
- if (password != value) {
- password = value;
- MarkChanged ();
- }
- }
- }
- }
-
-
- public class GalleryAccountManager
- {
- private static GalleryAccountManager instance;
- string xml_path;
- ArrayList accounts;
-
- public delegate void AccountListChangedHandler (GalleryAccountManager manager, GalleryAccount changed_account);
- public event AccountListChangedHandler AccountListChanged;
-
- public static GalleryAccountManager GetInstance ()
- {
- if (instance == null) {
- instance = new GalleryAccountManager ();
- }
-
- return instance;
- }
-
- private GalleryAccountManager ()
- {
- // FIXME this xml file path should be be retrieved from a central location not hard coded there
- this.xml_path = System.IO.Path.Combine (FSpot.Core.Global.BaseDirectory, "Accounts.xml");
-
- accounts = new ArrayList ();
- ReadAccounts ();
- }
-
- public void MarkChanged ()
- {
- MarkChanged (true, null);
- }
-
- public void MarkChanged (bool write, GalleryAccount changed_account)
- {
- if (write)
- WriteAccounts ();
-
- if (AccountListChanged != null)
- AccountListChanged (this, changed_account);
- }
-
- public ArrayList GetAccounts ()
- {
- return accounts;
- }
-
- public void AddAccount (GalleryAccount account)
- {
- AddAccount (account, true);
- }
-
- public void AddAccount (GalleryAccount account, bool write)
- {
- accounts.Add (account);
- MarkChanged (write, account);
- }
-
- public void RemoveAccount (GalleryAccount account)
- {
- accounts.Remove (account);
- MarkChanged ();
- }
-
- public void WriteAccounts ()
- {
- System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter (xml_path, System.Text.Encoding.Default);
-
- writer.Formatting = System.Xml.Formatting.Indented;
- writer.Indentation = 2;
- writer.IndentChar = ' ';
-
- writer.WriteStartDocument (true);
-
- writer.WriteStartElement ("GalleryRemote");
- foreach (GalleryAccount account in accounts) {
- writer.WriteStartElement ("Account");
- writer.WriteElementString ("Name", account.Name);
-
- writer.WriteElementString ("Url", account.Url);
- writer.WriteElementString ("Username", account.Username);
- writer.WriteElementString ("Password", account.Password);
- writer.WriteElementString ("Version", account.Version.ToString());
- writer.WriteEndElement (); //Account
- }
- writer.WriteEndElement ();
- writer.WriteEndDocument ();
- writer.Close ();
- }
-
- private GalleryAccount ParseAccount (System.Xml.XmlNode node)
- {
- if (node.Name != "Account")
-
- return null;
-
- string name = null;
- string url = null;
- string username = null;
- string password = null;
- GalleryVersion version = GalleryVersion.VersionUnknown;
-
- foreach (System.Xml.XmlNode child in node.ChildNodes) {
- if (child.Name == "Name") {
- name = child.ChildNodes [0].Value;
-
- } else if (child.Name == "Url") {
- url = child.ChildNodes [0].Value;
- } else if (child.Name == "Password") {
- password = child.ChildNodes [0].Value;
- } else if (child.Name == "Username") {
- username = child.ChildNodes [0].Value;
- } else if (child.Name == "Version") {
- string versionString = child.ChildNodes [0].Value;
- if (versionString == "Version1")
- version = GalleryVersion.Version1;
- else if (versionString == "Version2")
- version = GalleryVersion.Version2;
- else
- Log.Error ("Unexpected versions string: " + versionString);
- }
- }
- return new GalleryAccount (name, url, username, password, version);
- }
-
- private void ReadAccounts ()
- {
-
- if (! File.Exists (xml_path)) {
- MarkChanged ();
- return;
- }
-
- try {
- string query = "//GalleryRemote/Account";
- System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
-
- //System.Console.WriteLine ("xml_path: " + xml_path);
- doc.Load (xml_path);
- System.Xml.XmlNodeList nodes = doc.SelectNodes (query);
-
- //System.Console.WriteLine ("selected {0} nodes match {1}", nodes.Count, query);
- foreach (System.Xml.XmlNode node in nodes) {
- GalleryAccount account = ParseAccount (node);
- if (account != null)
- AddAccount (account, false);
-
- }
- } catch (System.Exception e) {
- // FIXME do something
- Log.Exception ("Exception loading gallery accounts", e);
- }
-
- MarkChanged ();
- }
- }
-
- public class AccountDialog {
- public AccountDialog (Gtk.Window parent) : this (parent, null, false) {
- add_dialog.Response += HandleAddResponse;
- add_button.Sensitive = false;
- }
-
- public AccountDialog (Gtk.Window parent, GalleryAccount account, bool show_error)
- {
- Glade.XML xml = new Glade.XML (null, "GalleryExport.glade", "gallery_add_dialog", "f-spot");
- xml.Autoconnect (this);
- add_dialog = (Gtk.Dialog) xml.GetWidget ("gallery_add_dialog");
- add_dialog.Modal = false;
- add_dialog.TransientFor = parent;
- add_dialog.DefaultResponse = Gtk.ResponseType.Ok;
-
- this.account = account;
-
- status_area.Visible = show_error;
-
- if (account != null) {
- gallery_entry.Text = account.Name;
- url_entry.Text = account.Url;
- password_entry.Text = account.Password;
- username_entry.Text = account.Username;
- add_button.Label = Gtk.Stock.Ok;
- add_dialog.Response += HandleEditResponse;
- }
-
- if (remove_button != null)
- remove_button.Visible = account != null;
-
- add_dialog.Show ();
-
- gallery_entry.Changed += HandleChanged;
- url_entry.Changed += HandleChanged;
- password_entry.Changed += HandleChanged;
- username_entry.Changed += HandleChanged;
- HandleChanged (null, null);
- }
-
- private void HandleChanged (object sender, System.EventArgs args)
- {
- name = gallery_entry.Text;
- url = url_entry.Text;
- password = password_entry.Text;
- username = username_entry.Text;
-
- if (name == String.Empty || url == String.Empty || password == String.Empty || username == 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) {
- try {
- Uri uri = new Uri (url);
- if (uri.Scheme != Uri.UriSchemeHttp &&
- uri.Scheme != Uri.UriSchemeHttps)
- throw new System.UriFormatException ();
-
- //Check for name uniqueness
- foreach (GalleryAccount acc in GalleryAccountManager.GetInstance ().GetAccounts ())
- if (acc.Name == name)
- throw new ArgumentException ("name");
- GalleryAccount created = new GalleryAccount (name,
- url,
- username,
- password);
-
- created.Connect ();
- GalleryAccountManager.GetInstance ().AddAccount (created);
- account = created;
- } catch (System.UriFormatException) {
- HigMessageDialog md =
- new HigMessageDialog (add_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Invalid URL"),
- Catalog.GetString ("The gallery URL entry does not appear to be a valid URL"));
- md.Run ();
- md.Destroy ();
- return;
- } catch (GalleryException e) {
- HigMessageDialog md =
- new HigMessageDialog (add_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Error while connecting to Gallery"),
- String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), e.Message));
- if (e.ResponseText != null) {
- Log.Debug (e.Message);
- Log.Debug (e.ResponseText);
- }
- md.Run ();
- md.Destroy ();
- return;
- } catch (ArgumentException ae) {
- HigMessageDialog md =
- new HigMessageDialog (add_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("A Gallery with this name already exists"),
- String.Format (Catalog.GetString ("There is already a Gallery with the same name in your registered Galleries. Please choose a unique name.")));
- Log.Exception (ae);
- md.Run ();
- md.Destroy ();
- return;
- } catch (System.Net.WebException we) {
- HigMessageDialog md =
- new HigMessageDialog (add_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Error while connecting to Gallery"),
- String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), we.Message));
- md.Run ();
- md.Destroy ();
- return;
- } catch (System.Exception se) {
- HigMessageDialog md =
- new HigMessageDialog (add_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Error while connecting to Gallery"),
- String.Format (Catalog.GetString ("The following error was encountered while attempting to log in: {0}"), se.Message));
- Log.Exception (se);
- md.Run ();
- md.Destroy ();
- return;
- }
- }
- add_dialog.Destroy ();
- }
-
- protected void HandleEditResponse (object sender, Gtk.ResponseArgs args)
- {
- if (args.ResponseId == Gtk.ResponseType.Ok) {
- account.Name = name;
- account.Url = url;
- account.Username = username;
- account.Password = password;
- GalleryAccountManager.GetInstance ().MarkChanged (true, account);
- } else if (args.ResponseId == Gtk.ResponseType.Reject) {
- // NOTE we are using Reject to signal the remove action.
- GalleryAccountManager.GetInstance ().RemoveAccount (account);
- }
- add_dialog.Destroy ();
- }
-
- private GalleryAccount account;
- private string name;
- private string url;
- private string password;
- private string username;
-
- // widgets
- [Glade.Widget] Gtk.Dialog add_dialog;
-
- [Glade.Widget] Gtk.Entry url_entry;
- [Glade.Widget] Gtk.Entry password_entry;
- [Glade.Widget] Gtk.Entry gallery_entry;
- [Glade.Widget] Gtk.Entry username_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;
- }
-
- public class GalleryAddAlbum
- {
- [Glade.Widget] Gtk.Dialog add_album_dialog;
- [Glade.Widget] Gtk.OptionMenu album_optionmenu;
-
- [Glade.Widget] Gtk.Entry name_entry;
- [Glade.Widget] Gtk.Entry description_entry;
- [Glade.Widget] Gtk.Entry title_entry;
-
- [Glade.Widget] Gtk.Button add_button;
- [Glade.Widget] Gtk.Button cancel_button;
-
- private GalleryExport export;
- private Gallery gallery;
- private string parent;
- private string name;
- private string description;
- private string title;
-
- public GalleryAddAlbum (GalleryExport export, Gallery gallery)
- {
- Glade.XML xml = new Glade.XML (null, "GalleryExport.glade", "gallery_add_album_dialog", "f-spot");
- xml.Autoconnect (this);
- add_album_dialog = (Gtk.Dialog) xml.GetWidget ("gallery_add_album_dialog");
- add_album_dialog.Modal = true;
- this.export = export;
- this.gallery = gallery;
- PopulateAlbums ();
-
- add_album_dialog.Response += HandleAddResponse;
-
- name_entry.Changed += HandleChanged;
- description_entry.Changed += HandleChanged;
- title_entry.Changed += HandleChanged;
- HandleChanged (null, null);
- }
-
- private void PopulateAlbums ()
- {
- Gtk.Menu menu = new Gtk.Menu ();
- if (gallery.Version == GalleryVersion.Version1) {
- Gtk.MenuItem top_item = new Gtk.MenuItem (Catalog.GetString ("(TopLevel)"));
- menu.Append (top_item);
- }
-
- foreach (Album album in gallery.Albums) {
- System.Text.StringBuilder label_builder = new System.Text.StringBuilder ();
-
- for (int i=0; i < album.Parents.Count; i++) {
- label_builder.Append (" ");
- }
- label_builder.Append (album.Title);
-
- Gtk.MenuItem item = new Gtk.MenuItem (label_builder.ToString ());
- ((Gtk.Label)item.Child).UseUnderline = false;
- menu.Append (item);
-
- AlbumPermission create_sub = album.Perms & AlbumPermission.CreateSubAlbum;
-
- if (create_sub == 0)
- item.Sensitive = false;
- }
-
- album_optionmenu.Sensitive = true;
- menu.ShowAll ();
- album_optionmenu.Menu = menu;
- }
-
- private void HandleChanged (object sender, EventArgs args)
- {
- if (gallery.Version == GalleryVersion.Version1) {
- if (gallery.Albums.Count == 0 || album_optionmenu.History <= 0) {
- parent = String.Empty;
- } else {
- parent = ((Album) gallery.Albums [album_optionmenu.History-1]).Name;
- }
- } else {
- if (gallery.Albums.Count == 0 || album_optionmenu.History < 0) {
- parent = String.Empty;
- } else {
- parent = ((Album) gallery.Albums [album_optionmenu.History]).Name;
- }
- }
- name = name_entry.Text;
- description = description_entry.Text;
- title = title_entry.Text;
-
- if (name == String.Empty || 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) {
- if (!System.Text.RegularExpressions.Regex.IsMatch (name, "^[A-Za-z0-9_-]+$")) {
- HigMessageDialog md =
- new HigMessageDialog (add_album_dialog,
- Gtk.DialogFlags.Modal |
- Gtk.DialogFlags.DestroyWithParent,
- Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
- Catalog.GetString ("Invalid Gallery name"),
- Catalog.GetString ("The gallery name contains invalid characters.\nOnly letters, numbers, - and _ are allowed"));
- md.Run ();
- md.Destroy ();
- return;
- }
- try {
- gallery.NewAlbum (parent, name, title, description);
- export.HandleAlbumAdded (title);
- } catch (GalleryCommandException e) {
- gallery.PopupException(e, add_album_dialog);
- return;
- }
- }
- add_album_dialog.Destroy ();
- }
- }
-
-
+namespace FSpot.Exporters.Gallery
+{
public class GalleryExport : IExporter {
- public GalleryExport ()
- {
- }
+ public GalleryExport () { }
public void Run (IBrowsableCollection selection)
{
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Gallery/Makefile.am b/src/Extensions/Exporters/FSpot.Exporters.Gallery/Makefile.am
index 436b5ef..b3bbb60 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.Gallery/Makefile.am
+++ b/src/Extensions/Exporters/FSpot.Exporters.Gallery/Makefile.am
@@ -4,7 +4,11 @@ LINK = $(REF_FSPOT_EXTENSION_GALLERYEXPORT)
INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
SOURCES = \
+ FSpot.Exporters.Gallery/AccountDialog.cs \
FSpot.Exporters.Gallery/FormClient.cs \
+ FSpot.Exporters.Gallery/GalleryAccount.cs \
+ FSpot.Exporters.Gallery/GalleryAccountManager.cs \
+ FSpot.Exporters.Gallery/GalleryAddAlbum.cs \
FSpot.Exporters.Gallery/GalleryExport.cs \
FSpot.Exporters.Gallery/GalleryRemote.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]