예제 #1
0
        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) {
                Console.Error.WriteLine(e);
            }

            MarkChanged();
        }
예제 #2
0
 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();
 }
예제 #3
0
        public void MarkChanged(bool write, GoogleAccount changed_account)
        {
            if (write)
            {
                WriteAccounts();
            }

            if (AccountListChanged != null)
            {
                AccountListChanged(this, changed_account);
            }
        }
예제 #4
0
        public GoogleAccountDialog(Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception) :  base("google_add_dialog")
        {
            this.Dialog.Modal           = false;
            this.Dialog.TransientFor    = parent;
            this.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  (ImageFile img = ImageFile.Create(new Uri(captcha_exception.CaptchaUrl))) {
                        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);
        }
예제 #5
0
        public void HandleAlbumAdded(string title)
        {
            GoogleAccount account = (GoogleAccount)accounts [gallery_optionmenu.History];

            PopulateAlbumOptionMenu(account.Picasa);

            // make the newly created album selected
            PicasaAlbumCollection albums = account.Picasa.GetAlbums();

            for (int i = 0; i < albums.Count; i++)
            {
                if (((PicasaAlbum)albums[i]).Title == title)
                {
                    album_optionmenu.SetHistory((uint)i);
                }
            }
        }
예제 #6
0
        public void RemoveAccount(GoogleAccount account)
        {
            string    keyring            = Ring.GetDefaultKeyring();
            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) {
                Console.WriteLine(e);
            }
            accounts.Remove(account);
            MarkChanged();
        }
예제 #7
0
        private void PopulateGoogleOptionMenu(GoogleAccountManager manager, GoogleAccount 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 (GoogleAccount account in accounts)
                {
                    if (account == changed_account)
                    {
                        pos = i;
                    }

                    Gtk.MenuItem item = new Gtk.MenuItem(account.Username);
                    menu.Append(item);
                    i++;
                }
                gallery_optionmenu.Sensitive = true;
                edit_button.Sensitive        = true;
            }

            menu.ShowAll();
            gallery_optionmenu.Menu = menu;
            gallery_optionmenu.SetHistory((uint)pos);
        }
		public void MarkChanged (bool write, GoogleAccount changed_account)
		{
			if (write)
				WriteAccounts ();

			if (AccountListChanged != null)
				AccountListChanged (this, changed_account);
		}
예제 #9
0
        private void Connect(GoogleAccount selected, string token, string text)
        {
            try {
                if (accounts.Count != 0 && connect)
                {
                    if (selected == null)
                    {
                        account = (GoogleAccount)accounts [gallery_optionmenu.History];
                    }
                    else
                    {
                        account = selected;
                    }

                    if (!account.Connected)
                    {
                        account.Connect();
                    }

                    PopulateAlbumOptionMenu(account.Picasa);

                    long qu = account.Picasa.QuotaUsed;
                    long ql = account.Picasa.QuotaLimit;

                    StringBuilder sb = new StringBuilder("<small>");
                    sb.Append(Catalog.GetString("Available space :"));
                    sb.Append(SizeUtil.ToHumanReadable(ql - qu));
                    sb.Append(" (");
                    sb.Append(100 * qu / ql);
                    sb.Append("% used out of ");
                    sb.Append(SizeUtil.ToHumanReadable(ql));
                    sb.Append(")");
                    sb.Append("</small>");

                    status_label.Text      = sb.ToString();
                    status_label.UseMarkup = true;

                    album_button.Sensitive = true;
                }
            } catch (CaptchaException exc) {
                System.Console.WriteLine("Your google account is locked");
                if (selected != null)
                {
                    account = selected;
                }

                PopulateAlbumOptionMenu(account.Picasa);
                album_button.Sensitive = false;

                new GoogleAccountDialog(this.Dialog, account, false, exc);

                System.Console.WriteLine("Your google account is locked, you can unlock it by visiting: {0}", CaptchaException.UnlockCaptchaURL);
            } catch (System.Exception) {
                System.Console.WriteLine("Can not connect to Picasa. Bad username ? password ? network connection ?");
                //System.Console.WriteLine ("{0}",ex);
                if (selected != null)
                {
                    account = selected;
                }

                PopulateAlbumOptionMenu(account.Picasa);

                status_label.Text      = String.Empty;
                album_button.Sensitive = false;

                new GoogleAccountDialog(this.Dialog, account, true, null);
            }
        }
예제 #10
0
 private void Connect(GoogleAccount selected)
 {
     Connect(selected, null, null);
 }
		public void AddAccount (GoogleAccount account, bool write)
		{
			accounts.Add (account);
			MarkChanged (write, account);
		}
		public void RemoveAccount (GoogleAccount account)
		{
			string keyring = Ring.GetDefaultKeyring();
			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) {
				Console.WriteLine(e);
			}
			accounts.Remove (account);
			MarkChanged ();
		}
		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) {
				Console.Error.WriteLine(e);
			}

			MarkChanged ();
		}
예제 #14
0
 public void AddAccount(GoogleAccount account, bool write)
 {
     accounts.Add(account);
     MarkChanged(write, account);
 }
		public void AddAccount (GoogleAccount account)
		{
			AddAccount (account, true);
		}
예제 #16
0
 public void AddAccount(GoogleAccount account)
 {
     AddAccount(account, true);
 }
		private void Connect (GoogleAccount selected, string token, string text)
		{
			try {
				if (accounts.Count != 0 && connect) {
					if (selected == null)
						account = (GoogleAccount) accounts [gallery_optionmenu.History];
					else
						account = selected;

					if (!account.Connected)
						account.Connect ();
					
					PopulateAlbumOptionMenu (account.Picasa);

					long qu = account.Picasa.QuotaUsed;
					long ql = account.Picasa.QuotaLimit;

					StringBuilder sb = new StringBuilder("<small>");
					sb.Append(Catalog.GetString("Available space :"));
					sb.Append(SizeUtil.ToHumanReadable (ql - qu));
					sb.Append(" (");
					sb.Append(100 * qu / ql);
					sb.Append("% used out of ");
					sb.Append(SizeUtil.ToHumanReadable (ql));
					sb.Append(")");
					sb.Append("</small>");

					status_label.Text = sb.ToString();
					status_label.UseMarkup = true;

					album_button.Sensitive = true;
				}
			} catch (CaptchaException exc){
				System.Console.WriteLine("Your google account is locked");
				if (selected != null)
					account = selected;

				PopulateAlbumOptionMenu (account.Picasa);
				album_button.Sensitive = false;

				new GoogleAccountDialog (this.Dialog, account, false, exc);
				
				System.Console.WriteLine ("Your google account is locked, you can unlock it by visiting: {0}", CaptchaException.UnlockCaptchaURL);

			} catch (System.Exception) {
				System.Console.WriteLine ("Can not connect to Picasa. Bad username ? password ? network connection ?");
				//System.Console.WriteLine ("{0}",ex);
				if (selected != null)
					account = selected;

				PopulateAlbumOptionMenu (account.Picasa);

				status_label.Text = String.Empty;
				album_button.Sensitive = false;
				
				new GoogleAccountDialog (this.Dialog, account, true, null);
			} 
		}
		private void Connect (GoogleAccount selected)
		{
			Connect (selected, null, null);
		}
		private void PopulateGoogleOptionMenu (GoogleAccountManager manager, GoogleAccount 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 (GoogleAccount account in accounts) {
					if (account == changed_account)
						pos = i;
					
					Gtk.MenuItem item = new Gtk.MenuItem (account.Username);
					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) {
				GoogleAccount account = new GoogleAccount (username, password);
				GoogleAccountManager.GetInstance ().AddAccount (account);
			}
			Dialog.Destroy ();
		}
		public GoogleAccountDialog (Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception) :  base ("google_add_dialog")
		{
			this.Dialog.Modal = false;
			this.Dialog.TransientFor = parent;
			this.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  (ImageFile img = ImageFile.Create(new Uri(captcha_exception.CaptchaUrl))) {
						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);
		}