Пример #1
0
        public AccountDialog(Gtk.Window parent, GalleryAccount account, bool show_error) :  base("gallery_add_dialog")
        {
            this.Dialog.Modal           = false;
            this.Dialog.TransientFor    = parent;
            this.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;
                Dialog.Response    += HandleEditResponse;
            }

            if (remove_button != null)
            {
                remove_button.Visible = account != null;
            }

            this.Dialog.Show();

            gallery_entry.Changed  += HandleChanged;
            url_entry.Changed      += HandleChanged;
            password_entry.Changed += HandleChanged;
            username_entry.Changed += HandleChanged;
            HandleChanged(null, null);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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(this.Dialog, account, true);
            }
        }
Пример #4
0
        public void MarkChanged(bool write, GalleryAccount changed_account)
        {
            if (write)
            {
                WriteAccounts();
            }

            if (AccountListChanged != null)
            {
                AccountListChanged(this, changed_account);
            }
        }
Пример #5
0
        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);
                }
            }
        }
Пример #6
0
        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);
        }
		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 (this.Dialog, account, true);
			} 
		}
		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);
		}
		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 ();
					
					GalleryAccount created = new GalleryAccount (name, 
										     url, 
										     username,
										     password);
					
					created.Connect ();
					GalleryAccountManager.GetInstance ().AddAccount (created);
					account = created;
				} catch (System.UriFormatException) {
					
					HigMessageDialog md = 
						new HigMessageDialog (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 (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 (System.Net.WebException we) {
					HigMessageDialog md = 
						new HigMessageDialog (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;
				}
			}
			Dialog.Destroy ();
		}
		public AccountDialog (Gtk.Window parent, GalleryAccount account, bool show_error) :  base ("gallery_add_dialog")
		{
			this.Dialog.Modal = false;
			this.Dialog.TransientFor = parent;
			this.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;
				Dialog.Response += HandleEditResponse;
			}

			if (remove_button != null)
				remove_button.Visible = account != null;

			this.Dialog.Show ();

			gallery_entry.Changed += HandleChanged;
			url_entry.Changed += HandleChanged;
			password_entry.Changed += HandleChanged;
			username_entry.Changed += HandleChanged;
			HandleChanged (null, null);
		}
		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);
		}
		public void MarkChanged (bool write, GalleryAccount changed_account)
		{
			if (write)
				WriteAccounts ();

			if (AccountListChanged != null)
				AccountListChanged (this, changed_account);
		}
Пример #15
0
 public void AddAccount(GalleryAccount account)
 {
     AddAccount(account, true);
 }
Пример #16
0
 public void AddAccount(GalleryAccount account, bool write)
 {
     accounts.Add(account);
     MarkChanged(write, account);
 }
Пример #17
0
        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();
                    }

                    GalleryAccount created = new GalleryAccount(name,
                                                                url,
                                                                username,
                                                                password);

                    created.Connect();
                    GalleryAccountManager.GetInstance().AddAccount(created);
                    account = created;
                } catch (System.UriFormatException) {
                    HigMessageDialog md =
                        new HigMessageDialog(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(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 (System.Net.WebException we) {
                    HigMessageDialog md =
                        new HigMessageDialog(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;
                }
            }
            Dialog.Destroy();
        }
Пример #18
0
 public void RemoveAccount(GalleryAccount account)
 {
     accounts.Remove(account);
     MarkChanged();
 }