Example #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) {
                Log.DebugException(e);
            }

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

            if (AccountListChanged != null)
            {
                AccountListChanged(this, changed_account);
            }
        }
Example #4
0
        public GoogleAccountDialog(Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception)
        {
            builder = new GtkBeans.Builder(null, "google_add_dialog.ui", null);
            builder.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 = App.Instance.Container.Resolve <IImageFileFactory> ().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);
        }
Example #5
0
        public void HandleAlbumAdded(string title)
        {
            GoogleAccount account = (GoogleAccount)accounts [gallery_optionmenu.Active];

            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.Active = i;
                }
            }
        }
Example #6
0
        private void PopulateGoogleOptionMenu(GoogleAccountManager manager, GoogleAccount changed_account)
        {
            this.account = changed_account;
            int pos = -1;

            accounts = manager.GetAccounts();
            if (accounts == null || accounts.Count == 0)
            {
                if (accounts == null)
                {
                    Log.Debug("accounts == null");
                }
                else
                {
                    Log.Debug("accounts != null");
                }

                Log.DebugFormat("accounts.Count = {0}", accounts.Count);

                gallery_optionmenu.AppendText(Catalog.GetString("(No Gallery)"));
                gallery_optionmenu.Sensitive = false;
                edit_button.Sensitive        = false;

                pos = 0;
            }
            else
            {
                int i = 0;
                pos = 0;
                foreach (GoogleAccount account in accounts)
                {
                    if (account == changed_account)
                    {
                        pos = i;
                    }

                    gallery_optionmenu.AppendText(account.Username);
                    i++;
                }
                gallery_optionmenu.Sensitive = true;
                edit_button.Sensitive        = true;
            }

            Log.DebugFormat("Setting gallery_optionmenu.Active = {0}", pos);
            gallery_optionmenu.Active = pos;
        }
Example #7
0
        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();
        }
Example #8
0
        private void Connect(GoogleAccount selected, string token, string text)
        {
            try {
                if (accounts.Count != 0 && connect)
                {
                    if (selected == null)
                    {
                        account = (GoogleAccount)accounts [gallery_optionmenu.Active];
                    }
                    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(String.Format(Catalog.GetString("Available space: {0}, {1}% used out of {2}"),
                                            GLib.Format.SizeForDisplay(ql - qu),
                                            (100 * qu / ql),
                                            GLib.Format.SizeForDisplay(ql)));
                    sb.Append("</small>");
                    status_label.Text      = sb.ToString();
                    status_label.UseMarkup = true;

                    album_button.Sensitive = true;
                }
            } catch (CaptchaException exc) {
                Log.Debug("Your Google account is locked");
                if (selected != null)
                {
                    account = selected;
                }

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

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

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

                PopulateAlbumOptionMenu(account.Picasa);

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

                new GoogleAccountDialog(this.Dialog, account, true, null);
            }
        }
Example #9
0
 private void Connect(GoogleAccount selected)
 {
     Connect(selected, null, null);
 }
Example #10
0
 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 ();
 }
Example #11
0
 public void AddAccount(GoogleAccount account)
 {
     AddAccount(account, true);
 }
Example #12
0
 public void AddAccount(GoogleAccount account, bool write)
 {
     accounts.Add (account);
     MarkChanged (write, account);
 }
Example #13
0
 public void AddAccount(GoogleAccount account)
 {
     AddAccount (account, true);
 }
Example #14
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) {
                Log.DebugException (e);
            }

            MarkChanged ();
        }
Example #15
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 ();
 }
Example #16
0
 public void AddAccount(GoogleAccount account, bool write)
 {
     accounts.Add(account);
     MarkChanged(write, account);
 }
Example #17
0
        public GoogleAccountDialog(Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception)
        {
            builder = new GtkBeans.Builder (null, "google_add_dialog.ui", null);
            builder.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);
        }
Example #18
0
        public void MarkChanged(bool write, GoogleAccount changed_account)
        {
            if (write)
                WriteAccounts ();

            if (AccountListChanged != null)
                AccountListChanged (this, changed_account);
        }