Some oAuth fixes for Imgur & Photobucket. Still having problems with Photobucket...

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2026 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-12 12:43:02 +00:00
commit f447fb8b72
11 changed files with 165 additions and 118 deletions

View file

@ -44,52 +44,49 @@ namespace GreenshotPlugin.Controls {
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.browser = new System.Windows.Forms.WebBrowser();
this.addressTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// browser
//
this.browser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.browser.Location = new System.Drawing.Point(0, 26);
this.browser.MinimumSize = new System.Drawing.Size(20, 20);
this.browser.Name = "browser";
this.browser.Size = new System.Drawing.Size(864, 561);
this.browser.TabIndex = 0;
this.browser.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.webBrowser1_Navigating);
this.browser.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.browser_Navigated);
//
// addressTextBox
//
this.addressTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.addressTextBox.Location = new System.Drawing.Point(7, 2);
this.addressTextBox.Name = "addressTextBox";
this.addressTextBox.Size = new System.Drawing.Size(840, 20);
this.addressTextBox.TabIndex = 1;
this.addressTextBox.TabStop = false;
this.addressTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.addressTextBox_KeyPress);
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(864, 587);
this.Controls.Add(this.addressTextBox);
this.Controls.Add(this.browser);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
this.ShowInTaskbar = false;
this.ResumeLayout(false);
this.PerformLayout();
this.addressTextBox = new System.Windows.Forms.TextBox();
this.browser = new System.Windows.Forms.WebBrowser();
this.SuspendLayout();
//
// addressTextBox
//
this.addressTextBox.Cursor = System.Windows.Forms.Cursors.Arrow;
this.addressTextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.addressTextBox.Enabled = false;
this.addressTextBox.Location = new System.Drawing.Point(0, 0);
this.addressTextBox.Name = "addressTextBox";
this.addressTextBox.Size = new System.Drawing.Size(595, 20);
this.addressTextBox.TabIndex = 3;
this.addressTextBox.TabStop = false;
//
// browser
//
this.browser.Dock = System.Windows.Forms.DockStyle.Fill;
this.browser.Location = new System.Drawing.Point(0, 20);
this.browser.MinimumSize = new System.Drawing.Size(100, 100);
this.browser.Name = "browser";
this.browser.Size = new System.Drawing.Size(595, 295);
this.browser.TabIndex = 4;
//
// OAuthLoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(595, 315);
this.Controls.Add(this.browser);
this.Controls.Add(this.addressTextBox);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "OAuthLoginForm";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.WebBrowser browser;
private System.Windows.Forms.TextBox addressTextBox;
private System.Windows.Forms.TextBox addressTextBox;
private System.Windows.Forms.WebBrowser browser;
}
}

View file

@ -33,6 +33,7 @@ namespace GreenshotPlugin.Controls {
/// The OAuthLoginForm is used to allow the user to authorize Greenshot with an "Oauth" application
/// </summary>
public partial class OAuthLoginForm : Form {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthLoginForm));
private OAuthHelper _oauth;
private String _token;
private String _verifier;
@ -56,25 +57,39 @@ namespace GreenshotPlugin.Controls {
}
}
public OAuthLoginForm(OAuthHelper o, string browserTitle) {
public OAuthLoginForm(OAuthHelper o, string browserTitle, int width, int height) {
_oauth = o;
_token = null;
InitializeComponent();
this.ClientSize = new System.Drawing.Size(width, height);
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
this.Text = browserTitle;
this.addressTextBox.Text = o.AuthorizationLink;
_token = _oauth.Token;
_tokenSecret = _oauth.TokenSecret;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate(new Uri(_oauth.AuthorizationLink));
WindowDetails.ToForeground(this.Handle);
}
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
LOG.DebugFormat("document completed with url: {0}", browser.Url);
checkUrl();
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
LOG.DebugFormat("Navigating to url: {0}", browser.Url);
this.addressTextBox.Text = e.Url.ToString();
}
private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
if (browser.Url.ToString().Contains(_oauth.CallbackUrl)) {
string queryParams = e.Url.Query;
LOG.DebugFormat("Navigated to url: {0}", browser.Url);
checkUrl();
}
private void checkUrl() {
if (browser.Url.ToString().Contains(_oauth.CallbackUrl)) {
string queryParams = browser.Url.Query;
if (queryParams.Length > 0) {
//Store the Token and Token Secret
NameValueCollection qs = NetworkHelper.ParseQueryString(queryParams);

View file

@ -91,7 +91,6 @@ namespace GreenshotPlugin.Controls {
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Greenshot";
this.TopMost = true;
this.UseWaitCursor = true;
this.ResumeLayout(false);
this.PerformLayout();