mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Changes for Box Plugin so it can re-use the OAuthLoginForm. Also fixed a startup issue with some plug-ins.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2143 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
dc8a160c7f
commit
69d29992a2
8 changed files with 74 additions and 54 deletions
|
@ -344,7 +344,7 @@ namespace Greenshot {
|
||||||
ProcessorHelper.GetAllProcessors();
|
ProcessorHelper.GetAllProcessors();
|
||||||
|
|
||||||
// Load all the plugins
|
// Load all the plugins
|
||||||
PluginHelper.Instance.LoadPlugins(this);
|
PluginHelper.Instance.LoadPlugins();
|
||||||
|
|
||||||
// Check destinations, remove all that don't exist
|
// Check destinations, remove all that don't exist
|
||||||
foreach(string destination in conf.OutputDestinations.ToArray()) {
|
foreach(string destination in conf.OutputDestinations.ToArray()) {
|
||||||
|
|
|
@ -50,11 +50,16 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PluginHelper() {
|
private PluginHelper() {
|
||||||
PluginUtils.Host = this;
|
PluginUtils.Host = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Form GreenshotForm {
|
||||||
|
get {
|
||||||
|
return MainForm.Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public NotifyIcon NotifyIcon {
|
public NotifyIcon NotifyIcon {
|
||||||
get {
|
get {
|
||||||
return MainForm.Instance.NotifyIcon;
|
return MainForm.Instance.NotifyIcon;
|
||||||
|
@ -105,7 +110,6 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Implementation of IGreenshotPluginHost
|
#region Implementation of IGreenshotPluginHost
|
||||||
private ContextMenuStrip mainMenu = null;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a Thumbnail
|
/// Create a Thumbnail
|
||||||
|
@ -125,7 +129,9 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextMenuStrip MainMenu {
|
public ContextMenuStrip MainMenu {
|
||||||
get { return mainMenu;}
|
get {
|
||||||
|
return MainForm.Instance.MainMenu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<PluginAttribute, IGreenshotPlugin> Plugins {
|
public IDictionary<PluginAttribute, IGreenshotPlugin> Plugins {
|
||||||
|
@ -202,10 +208,7 @@ namespace Greenshot.Helpers {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadPlugins(MainForm mainForm) {
|
public void LoadPlugins() {
|
||||||
// Copy ContextMenu
|
|
||||||
mainMenu = mainForm.MainMenu;
|
|
||||||
|
|
||||||
List<string> pluginFiles = new List<string>();
|
List<string> pluginFiles = new List<string>();
|
||||||
|
|
||||||
if (IniConfig.IsPortable && Directory.Exists(pafPath)) {
|
if (IniConfig.IsPortable && Directory.Exists(pafPath)) {
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
using System;
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: http://getgreenshot.org/
|
||||||
|
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 1 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace GreenshotImgurPlugin {
|
namespace GreenshotImgurPlugin {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -100,7 +100,7 @@ namespace GreenshotImgurPlugin {
|
||||||
private void CheckHistory() {
|
private void CheckHistory() {
|
||||||
try {
|
try {
|
||||||
ImgurUtils.LoadHistory();
|
ImgurUtils.LoadHistory();
|
||||||
host.MainMenu.BeginInvoke((MethodInvoker)delegate {
|
host.GreenshotForm.BeginInvoke((MethodInvoker)delegate {
|
||||||
if (config.ImgurUploadHistory.Count > 0) {
|
if (config.ImgurUploadHistory.Count > 0) {
|
||||||
historyMenuItem.Enabled = true;
|
historyMenuItem.Enabled = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -35,24 +35,20 @@ namespace GreenshotPlugin.Controls {
|
||||||
public partial class OAuthLoginForm : Form {
|
public partial class OAuthLoginForm : Form {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthLoginForm));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthLoginForm));
|
||||||
private string callbackUrl = null;
|
private string callbackUrl = null;
|
||||||
private String _token;
|
private IDictionary<string, string> callbackParameters = null;
|
||||||
private String _verifier;
|
|
||||||
|
|
||||||
public String Token {
|
public IDictionary<string, string> CallbackParameters {
|
||||||
|
get { return callbackParameters; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool isOk {
|
||||||
get {
|
get {
|
||||||
return _token;
|
return DialogResult == DialogResult.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String Verifier {
|
public OAuthLoginForm(string browserTitle, Size size, string authorizationLink, string callbackUrl) {
|
||||||
get {
|
|
||||||
return _verifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public OAuthLoginForm(OAuthSession o, string browserTitle, Size size, string authorizationLink, string callbackUrl) {
|
|
||||||
this.callbackUrl = callbackUrl;
|
this.callbackUrl = callbackUrl;
|
||||||
_token = null;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.ClientSize = size;
|
this.ClientSize = size;
|
||||||
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
||||||
|
@ -86,15 +82,9 @@ namespace GreenshotPlugin.Controls {
|
||||||
if (queryParams.Length > 0) {
|
if (queryParams.Length > 0) {
|
||||||
queryParams = NetworkHelper.UrlDecode(queryParams);
|
queryParams = NetworkHelper.UrlDecode(queryParams);
|
||||||
//Store the Token and Token Secret
|
//Store the Token and Token Secret
|
||||||
IDictionary<string, string> qs = NetworkHelper.ParseQueryString(queryParams);
|
callbackParameters = NetworkHelper.ParseQueryString(queryParams);
|
||||||
if (qs.ContainsKey("oauth_token") && qs["oauth_token"] != null) {
|
|
||||||
_token = qs["oauth_token"];
|
|
||||||
}
|
}
|
||||||
if (qs.ContainsKey("oauth_verifier") && qs["oauth_verifier"] != null) {
|
DialogResult = DialogResult.OK;
|
||||||
_verifier = qs["oauth_verifier"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,25 +49,16 @@ namespace GreenshotPlugin.Core {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Download a file as string
|
/// Download a url response as string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name=url">An Uri to specify the download location</param>
|
/// <param name=url">An Uri to specify the download location</param>
|
||||||
/// <param name=encoding">The encoding to use</param>
|
|
||||||
/// <returns>string with the file content</returns>
|
/// <returns>string with the file content</returns>
|
||||||
public static string DownloadFileAsString(Uri url, Encoding encoding) {
|
public static string GetAsString(Uri url) {
|
||||||
try {
|
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||||
HttpWebRequest request = (HttpWebRequest)CreateWebRequest(url);
|
webRequest.Method = "GET";
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
webRequest.KeepAlive = true;
|
||||||
if (request.HaveResponse) {
|
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||||
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) {
|
return GetResponse(webRequest);
|
||||||
return reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.Error("Problem downloading from: " + url.ToString(), e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -290,9 +281,11 @@ namespace GreenshotPlugin.Core {
|
||||||
public static string GetResponse(HttpWebRequest webRequest) {
|
public static string GetResponse(HttpWebRequest webRequest) {
|
||||||
string responseData;
|
string responseData;
|
||||||
try {
|
try {
|
||||||
using (StreamReader reader = new StreamReader(webRequest.GetResponse().GetResponseStream(), true)) {
|
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
|
||||||
|
using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
|
||||||
responseData = reader.ReadToEnd();
|
responseData = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
LOG.DebugFormat("Response status: {0}", response.StatusCode);
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
HttpWebResponse response = (HttpWebResponse)e.Response;
|
HttpWebResponse response = (HttpWebResponse)e.Response;
|
||||||
using (Stream responseStream = response.GetResponseStream()) {
|
using (Stream responseStream = response.GetResponseStream()) {
|
||||||
|
|
|
@ -295,11 +295,20 @@ namespace GreenshotPlugin.Core {
|
||||||
Exception e = new Exception("The request token is not set");
|
Exception e = new Exception("The request token is not set");
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
Token = null;
|
||||||
|
Verifier = null;
|
||||||
LOG.DebugFormat("Opening AuthorizationLink: {0}", authorizationLink);
|
LOG.DebugFormat("Opening AuthorizationLink: {0}", authorizationLink);
|
||||||
OAuthLoginForm oAuthLoginForm = new OAuthLoginForm(this, LoginTitle, BrowserSize, authorizationLink, CallbackUrl);
|
OAuthLoginForm oAuthLoginForm = new OAuthLoginForm(LoginTitle, BrowserSize, authorizationLink, CallbackUrl);
|
||||||
oAuthLoginForm.ShowDialog();
|
if (oAuthLoginForm.isOk) {
|
||||||
Token = oAuthLoginForm.Token;
|
if (oAuthLoginForm.CallbackParameters != null) {
|
||||||
Verifier = oAuthLoginForm.Verifier;
|
if (oAuthLoginForm.CallbackParameters.ContainsKey(OAUTH_TOKEN_KEY)) {
|
||||||
|
Token = oAuthLoginForm.CallbackParameters[OAUTH_TOKEN_KEY];
|
||||||
|
}
|
||||||
|
if (oAuthLoginForm.CallbackParameters.ContainsKey(OAUTH_VERIFIER_KEY)) {
|
||||||
|
Verifier = oAuthLoginForm.CallbackParameters[OAUTH_VERIFIER_KEY];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (CheckVerifier) {
|
if (CheckVerifier) {
|
||||||
if (!string.IsNullOrEmpty(Verifier)) {
|
if (!string.IsNullOrEmpty(Verifier)) {
|
||||||
return Token;
|
return Token;
|
||||||
|
|
|
@ -129,6 +129,11 @@ namespace Greenshot.Plugin {
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a reference to the MainForm, can be used for Invoking on the UI thread.
|
||||||
|
Form GreenshotForm {
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
NotifyIcon NotifyIcon {
|
NotifyIcon NotifyIcon {
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue