private void Connect(GalleryAccount selected) { try { if (accounts.Count != 0 && connect) { if (selected == null) { account = (GalleryAccount)accounts [gallery_optionmenu.History]; } else { account = selected; } if (!account.Connected) { account.Connect(); } PopulateAlbumOptionMenu(account.Gallery); album_button.Sensitive = true; } } catch (System.Exception ex) { if (selected != null) { account = selected; } System.Console.WriteLine("{0}", ex); PopulateAlbumOptionMenu(account.Gallery); album_button.Sensitive = false; new AccountDialog(export_dialog, account, true); } }
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 System.Console.WriteLine("Exception loading gallery accounts"); System.Console.WriteLine(e); } MarkChanged(); }
public void MarkChanged(bool write, GalleryAccount changed_account) { if (write) { WriteAccounts(); } if (AccountListChanged != null) { AccountListChanged(this, changed_account); } }
public void HandleAlbumAdded(string title) { GalleryAccount account = (GalleryAccount)accounts [gallery_optionmenu.History]; PopulateAlbumOptionMenu(account.Gallery); // make the newly created album selected ArrayList albums = account.Gallery.Albums; for (int i = 0; i < albums.Count; i++) { if (((Album)albums[i]).Title == title) { album_optionmenu.SetHistory((uint)i); } } }
private void PopulateGalleryOptionMenu(GalleryAccountManager manager, GalleryAccount changed_account) { Gtk.Menu menu = new Gtk.Menu(); this.account = changed_account; int pos = -1; accounts = manager.GetAccounts(); if (accounts == null || accounts.Count == 0) { Gtk.MenuItem item = new Gtk.MenuItem(Catalog.GetString("(No Gallery)")); menu.Append(item); gallery_optionmenu.Sensitive = false; edit_button.Sensitive = false; } else { int i = 0; foreach (GalleryAccount account in accounts) { if (account == changed_account) { pos = i; } Gtk.MenuItem item = new Gtk.MenuItem(account.Name); menu.Append(item); i++; } gallery_optionmenu.Sensitive = true; edit_button.Sensitive = true; } menu.ShowAll(); gallery_optionmenu.Menu = menu; gallery_optionmenu.SetHistory((uint)pos); }
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); }
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 (GalleryRemote.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) { System.Console.WriteLine(e.Message); System.Console.WriteLine(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."))); System.Console.WriteLine(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)); Console.WriteLine(se); md.Run(); md.Destroy(); return; } } add_dialog.Destroy(); }
public void RemoveAccount(GalleryAccount account) { accounts.Remove(account); MarkChanged(); }
public void AddAccount(GalleryAccount account, bool write) { accounts.Add(account); MarkChanged(write, account); }
public void AddAccount(GalleryAccount account) { AddAccount(account, true); }