mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
Reused new OAuth 2 code for the Box plug-in, this was possible by adding the embedded browser. Also refactored code to be more readable, and have more reuse. Fixed problems with Picasa upload and pressing cancel on the PleaseWaitForm. [skip ci]
This commit is contained in:
parent
9d7299e5ea
commit
1f80d56b10
16 changed files with 408 additions and 277 deletions
|
@ -87,7 +87,7 @@ namespace GreenshotPlugin.Controls {
|
|||
/// <summary>
|
||||
/// When this is set, the form will be brought to the foreground as soon as it is shown.
|
||||
/// </summary>
|
||||
protected bool BringToFront {
|
||||
protected bool ToFront {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ namespace GreenshotPlugin.Controls {
|
|||
/// <param name="e">EventArgs</param>
|
||||
protected override void OnShown(EventArgs e) {
|
||||
base.OnShown(e);
|
||||
if (BringToFront) {
|
||||
if (ToFront) {
|
||||
WindowDetails.ToForeground(Handle);
|
||||
}
|
||||
}
|
||||
|
|
44
GreenshotPlugin/Controls/OAuthLoginForm.Designer.cs
generated
44
GreenshotPlugin/Controls/OAuthLoginForm.Designer.cs
generated
|
@ -44,37 +44,37 @@ namespace GreenshotPlugin.Controls {
|
|||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
this.addressTextBox = new System.Windows.Forms.TextBox();
|
||||
this.browser = new ExtendedWebBrowser();
|
||||
this._addressTextBox = new System.Windows.Forms.TextBox();
|
||||
this._browser = new ExtendedWebBrowser();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// addressTextBox
|
||||
// _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;
|
||||
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
|
||||
// _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;
|
||||
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.Controls.Add(this._browser);
|
||||
this.Controls.Add(this._addressTextBox);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "OAuthLoginForm";
|
||||
|
@ -85,8 +85,8 @@ namespace GreenshotPlugin.Controls {
|
|||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox addressTextBox;
|
||||
private ExtendedWebBrowser browser;
|
||||
private System.Windows.Forms.TextBox _addressTextBox;
|
||||
private ExtendedWebBrowser _browser;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,31 +35,33 @@ namespace GreenshotPlugin.Controls {
|
|||
/// </summary>
|
||||
public partial class OAuthLoginForm : Form {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(OAuthLoginForm));
|
||||
private string callbackUrl = null;
|
||||
private IDictionary<string, string> callbackParameters = null;
|
||||
private string _callbackUrl = null;
|
||||
private IDictionary<string, string> _callbackParameters = null;
|
||||
|
||||
public IDictionary<string, string> CallbackParameters {
|
||||
get { return callbackParameters; }
|
||||
get {
|
||||
return _callbackParameters;
|
||||
}
|
||||
}
|
||||
|
||||
public bool isOk {
|
||||
public bool IsOk {
|
||||
get {
|
||||
return DialogResult == DialogResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
public OAuthLoginForm(string browserTitle, Size size, string authorizationLink, string callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
_callbackUrl = callbackUrl;
|
||||
InitializeComponent();
|
||||
ClientSize = size;
|
||||
Icon = GreenshotResources.getGreenshotIcon();
|
||||
Text = browserTitle;
|
||||
addressTextBox.Text = authorizationLink;
|
||||
_addressTextBox.Text = authorizationLink;
|
||||
|
||||
// The script errors are suppressed by using the ExtendedWebBrowser
|
||||
browser.ScriptErrorsSuppressed = false;
|
||||
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
|
||||
browser.Navigate(new Uri(authorizationLink));
|
||||
_browser.ScriptErrorsSuppressed = false;
|
||||
_browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
|
||||
_browser.Navigate(new Uri(authorizationLink));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,33 +73,24 @@ namespace GreenshotPlugin.Controls {
|
|||
WindowDetails.ToForeground(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);
|
||||
addressTextBox.Text = e.Url.ToString();
|
||||
private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
|
||||
LOG.DebugFormat("document completed with url: {0}", _browser.Url);
|
||||
CheckUrl();
|
||||
}
|
||||
|
||||
private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
|
||||
LOG.DebugFormat("Navigated to url: {0}", browser.Url);
|
||||
checkUrl();
|
||||
}
|
||||
|
||||
private void checkUrl() {
|
||||
if (browser.Url.ToString().StartsWith(callbackUrl)) {
|
||||
string queryParams = browser.Url.Query;
|
||||
private void CheckUrl() {
|
||||
if (_browser.Url.ToString().StartsWith(_callbackUrl)) {
|
||||
string queryParams = _browser.Url.Query;
|
||||
if (queryParams.Length > 0) {
|
||||
queryParams = NetworkHelper.UrlDecode(queryParams);
|
||||
//Store the Token and Token Secret
|
||||
callbackParameters = NetworkHelper.ParseQueryString(queryParams);
|
||||
_callbackParameters = NetworkHelper.ParseQueryString(queryParams);
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
private void addressTextBox_KeyPress(object sender, KeyPressEventArgs e) {
|
||||
private void AddressTextBox_KeyPress(object sender, KeyPressEventArgs e) {
|
||||
//Cancel the key press so the user can't enter a new url
|
||||
e.Handled = true;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace GreenshotPlugin.Controls {
|
|||
trackBarJpegQuality.Value = Settings.JPGQuality;
|
||||
textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||
textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
|
||||
BringToFront = true;
|
||||
ToFront = true;
|
||||
}
|
||||
|
||||
void Button_okClick(object sender, EventArgs e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue