private void TagsPanelOk_Click(object sender, EventArgs e)
 {
     List<string> items = new List<string>();
     if (this.mTagsChanged)
     {
         foreach (string tag in this.m_currentTags.Items)
         {
             if (tag != "")
             {
                 items.Add(tag);
             }
         }
     }
     PicasaWallpaperEventArgs ev = new PicasaWallpaperEventArgs(items);
     this.ev_EventFired(sender, ev, DialogResult.OK);
 }
        private void TagsPanelOk_Click(object sender, EventArgs e)
        {
            List <string> items = new List <string>();

            if (this.mTagsChanged)
            {
                foreach (string tag in this.m_currentTags.Items)
                {
                    if (tag != "")
                    {
                        items.Add(tag);
                    }
                }
            }
            PicasaWallpaperEventArgs ev = new PicasaWallpaperEventArgs(items);

            this.ev_EventFired(sender, ev, DialogResult.OK);
        }
        private void m_sourcePanelOk_Click(object sender, EventArgs e)
        {
            string password = string.Empty;
            string username = string.Empty;
            string usertoken = string.Empty;
            if (this.mPasswordChanged)
            {
                password = this.mPassword.Text;
            }
            if (this.mUserChanged)
            {
                username = this.mUserName.Text;
            }

            // login request
            WebRequest loginRequest = (WebRequest)HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE_OR_HOSTED&Email=" + this.mUserName.Text + "&Passwd=" + this.mPassword.Text + "&service=lh2&source=WallpaperChanger");
            loginRequest.Proxy = this.CreateProxy();
            HttpWebResponse loginResponse = null;
            StreamReader responseStreamReader = null;
            string result = string.Empty;

            try
            {
                // try the web request
                
                loginResponse = (HttpWebResponse)loginRequest.GetResponse();
            }
            catch (WebException wex)
            {
                
                // login validation failed, so find out why
                loginResponse = (HttpWebResponse)wex.Response;
                responseStreamReader = new StreamReader(loginResponse.GetResponseStream());
                // result contains the error.
                result = responseStreamReader.ReadToEnd();
                if (loginResponse.StatusCode == HttpStatusCode.MethodNotAllowed)
                {
                    this.m_sourcePanelOk_ClickNoProxy(sender, e);
                    return;
                }
                switch (result.Trim())
                {
                    case ("Error=BadAuthentication"):
                        MessageBox.Show("Username or Password error.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                       // break;
                    case ("NotVerified"):
                        MessageBox.Show("The account email address has not been verified.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    case ("TermsNotAgreed"):
                        MessageBox.Show("The user has not agreed to terms. The user will need to access their Google account directly to resolve the issue before logging in.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    case ("CaptchaRequired"):
                        //A CAPTCHA is required. (A response with this error code will also contain an image URL and a CAPTCHA token.) 
                        break;
                    case ("Unknown"):
                        MessageBox.Show("The error is unknown or unspecified; the request contained invalid input or was malformed.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    default:
                        MessageBox.Show("An error occurred: " + result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Your connection is down.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            responseStreamReader = new StreamReader(loginResponse.GetResponseStream());
            result = responseStreamReader.ReadToEnd();
            int start = result.IndexOf("Auth=");
            string token = result.Remove(0, start + 5);
            token = token.Trim();
            
            /* try
             {
                 Changer changer = new Changer(new string[0], password, username);
                
                 usertoken = changer.CheckLogin();
                 if(usertoken == string.Empty)
                 {

                 }
                 catch(
                 //CreateAlbumProxy();
                 this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
                 try
                 {
                 string token = this.m_albumService.QueryAuthenticationToken();
             }*/

            PicasaWallpaperEventArgs ev = new PicasaWallpaperEventArgs(username, password,token);
            this.ev_EventFired(sender, ev, DialogResult.OK);
        }
Beispiel #4
0
        private void m_sourcePanelOk_Click(object sender, EventArgs e)
        {
            string password  = string.Empty;
            string username  = string.Empty;
            string usertoken = string.Empty;

            if (this.mPasswordChanged)
            {
                password = this.mPassword.Text;
            }
            if (this.mUserChanged)
            {
                username = this.mUserName.Text;
            }

            // login request
            WebRequest loginRequest = (WebRequest)HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE_OR_HOSTED&Email=" + this.mUserName.Text + "&Passwd=" + this.mPassword.Text + "&service=lh2&source=WallpaperChanger");

            loginRequest.Proxy = this.CreateProxy();
            HttpWebResponse loginResponse        = null;
            StreamReader    responseStreamReader = null;
            string          result = string.Empty;

            try
            {
                // try the web request

                loginResponse = (HttpWebResponse)loginRequest.GetResponse();
            }
            catch (WebException wex)
            {
                // login validation failed, so find out why
                loginResponse        = (HttpWebResponse)wex.Response;
                responseStreamReader = new StreamReader(loginResponse.GetResponseStream());
                // result contains the error.
                result = responseStreamReader.ReadToEnd();
                if (loginResponse.StatusCode == HttpStatusCode.MethodNotAllowed)
                {
                    this.m_sourcePanelOk_ClickNoProxy(sender, e);
                    return;
                }
                switch (result.Trim())
                {
                case ("Error=BadAuthentication"):
                    MessageBox.Show("Username or Password error.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;

                // break;
                case ("NotVerified"):
                    MessageBox.Show("The account email address has not been verified.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;

                case ("TermsNotAgreed"):
                    MessageBox.Show("The user has not agreed to terms. The user will need to access their Google account directly to resolve the issue before logging in.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;

                case ("CaptchaRequired"):
                    //A CAPTCHA is required. (A response with this error code will also contain an image URL and a CAPTCHA token.)
                    break;

                case ("Unknown"):
                    MessageBox.Show("The error is unknown or unspecified; the request contained invalid input or was malformed.", "Bad Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;

                default:
                    MessageBox.Show("An error occurred: " + result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Your connection is down.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            responseStreamReader = new StreamReader(loginResponse.GetResponseStream());
            result = responseStreamReader.ReadToEnd();
            int    start = result.IndexOf("Auth=");
            string token = result.Remove(0, start + 5);

            token = token.Trim();

            /* try
             * {
             *   Changer changer = new Changer(new string[0], password, username);
             *
             *   usertoken = changer.CheckLogin();
             *   if(usertoken == string.Empty)
             *   {
             *
             *   }
             *   catch(
             *   //CreateAlbumProxy();
             *   this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
             *   try
             *   {
             *   string token = this.m_albumService.QueryAuthenticationToken();
             * }*/

            PicasaWallpaperEventArgs ev = new PicasaWallpaperEventArgs(username, password, token);

            this.ev_EventFired(sender, ev, DialogResult.OK);
        }
        /// <summary>
        /// Fired when the changer Panel OK button is clicked.
        /// </summary>
        /// <remarks>
        /// Once complete it will either return to the controls panel, or the next panel in the wizard sequence ( Controls)
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ChangerPanel_ev_EventFired(object sender, PicasaWallpaperEventArgs e, DialogResult result)
        {

            // ChangerPanel panel = this.mCurrentPanel.Controls[0] as ChangerPanel;
            if (result == DialogResult.OK)
            {

                this.mAutoRun = e.Autorun;

                if (!e.Autorun)
                {
                    if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Picasa Wallpaper Changer.lnk"))
                    {
                        System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Picasa Wallpaper Changer.lnk");
                    }
                }
                else
                {
                    if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Picasa Wallpaper Changer.lnk"))
                    {
                        WshShellClass shell = new WshShellClass();
                        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Picasa Wallpaper Changer.lnk");
                        shortcut.TargetPath = Application.ExecutablePath;
                        shortcut.Description = "Picasa Wallpaper Changer";
                        shortcut.IconLocation = Application.StartupPath + "\\pwcc.ico";
                        shortcut.Save();
                        shortcut = null;
                        shell = null;
                    }
                }

                if (e.StopNow)
                {
          

                    this.UpdateStatus("Currently idle");
                    this.mChangePhotoTimer.Stop();
                    this.mReindexTimer.Stop();
                  
                }
                if (e.StartNow)
                {
                    this.UpdateStatus("Currently waiting to change pictures");
                    this.mChangePhotoTimer.Start();
                    this.mReindexTimer.Start();
                  
                }
            }
            if (!this.mRunBefore)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReindexTagsHandler));
                this.mRunBefore = true;
            }
            BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Controls, AvailablePanels.Changer });
        }
 /// <summary>
 /// Fired when the size Panel OK button is clicked.
 /// </summary>
 /// <remarks>
 /// Once complete it will either return to the controls panel, or the next panel in the wizard sequence ( changer)
 /// </remarks>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void SizePanel_ev_EventFired(object sender, PicasaWallpaperEventArgs e, DialogResult result)
 {
     // SizePanel panel = this.mCurrentPanel.Controls[0] as SizePanel;
     if (result == DialogResult.OK)
     {
         this.mWallpaperSize = e.SizePercent;
     }
     if (this.mRunBefore)
     {
         BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Controls, AvailablePanels.Size });
     }
     else
     {
         BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Changer, AvailablePanels.Size });
     }
 }
        /// <summary>
        /// Fired when the tags Panel OK button is clicked.
        /// </summary>
        /// <remarks>
        /// Once complete it will either return to the controls panel, or the next panel in the wizard sequence ( Size)
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TagsPanel_ev_EventFired(object sender, PicasaWallpaperEventArgs e, DialogResult result)
        {
            // Tags okayed
            if (result == DialogResult.OK)
            {
                if (e.Items.Count > 0)
                {
                    this.mTags.Clear();

                    foreach (string s in e.Items)
                    {
                        this.mTags.Add(s);

                    }
                }
            }
            if (this.mRunBefore)
            {
                if (result == DialogResult.OK)
                {
                    // Reindex
                    if (e.Items.Count > 0)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(ReindexTagsHandler));
                    }
                }
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Controls, AvailablePanels.Tags });
            }
            else
            {
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Size, AvailablePanels.Tags });
            }
        }
        /// <summary>
        /// Fired when the timings Panel OK button is clicked.
        /// </summary>
        /// <remarks>
        /// Once complete it will either return to the controls panel, or the next panel in the wizard sequence ( Tags)
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TimingsPanel_ev_EventFired(object sender, PicasaWallpaperEventArgs e, DialogResult result)
        {
            // We have okayed the dialog
            if (result == DialogResult.OK)
            {
                this.mReindexTime = e.ReindexTime;
                this.mPictureChangeInterval = (int)e.ChangeInterval;
                // stop the times and recalculate the ticks before next firing
                this.mReindexTimer.Stop();
                this.mChangePhotoTimer.Stop();

                TimeSpan when = this.mReindexTime.TimeOfDay.Subtract(DateTime.Now.TimeOfDay);

                // workout the ticks for the reindex interval days, and sets the time accordingly.
                if (when.Ticks < 0)
                    when = when.Add(new TimeSpan(1, 0, 0, 0)); // we have missed the reindex time, so add a day
                this.mReindexTimer.Interval = (int)when.TotalMilliseconds;

                // set the photo changer time
                this.mChangePhotoTimer.Interval = ((int)e.ChangeInterval * 60) * 1000;
                this.mReindexTimer.Start();
                this.mChangePhotoTimer.Start();
            }
            if (this.mRunBefore)
            {
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Controls, AvailablePanels.Timings });
            }
            else
            {
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Tags, AvailablePanels.Timings });
            }
        }
        /// <summary>
        /// Fired when the Source Panel OK button is clicked.
        /// </summary>
        /// <remarks>
        /// Once complete it will either return to the controls panel, or the next panel in the wizard sequence ( Timings)
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SourcePanel_ev_EventFired(object sender, PicasaWallpaperEventArgs e, DialogResult result)
        {
            bool userChanged = false;
            // The user OKed the changes
            if (result == DialogResult.OK)
            {
                // And a new username was added.
                if (e.UserName != string.Empty)
                {
                    this.mUserName = e.UserName;
                }
                // if  a new password was added
                if (e.Password != string.Empty)
                {
                    // set the settings
                   // this.mEncryptedToken = AccountLogin.EncryptPassword(this.mUserName, e.Password, ref this.mPasswordKey, ref this.mPasswordIV);

                }
                // if a token was created
                if (e.Token != string.Empty)
                {
                    this.mEncryptedToken = AccountLogin.EncryptPassword(this.mUserName, e.Token, ref this.mPasswordKey, ref this.mPasswordIV);
                   // this.mToken = e.Token;
                }
                // only update anything if we have run before, and the user has changed
                if ((this.mRunBefore) && (userChanged == true))
                {
                    // reindex
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ReindexTagsHandler));
                }
            }
            if (this.mRunBefore)
            {
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Controls, AvailablePanels.Source });
            }
            else
            {
                BeginInvoke(new DisplayMe(DisplayMeHandler), new object[] { AvailablePanels.Timings, AvailablePanels.Source });
            }
        }