mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Refactorings for the new IniConfig
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@853 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
232fd4e33d
commit
14b0863bcd
34 changed files with 338 additions and 499 deletions
|
@ -163,7 +163,7 @@ namespace GreenshotOCR {
|
||||||
if (eventArgs.Capture.Image == null) {
|
if (eventArgs.Capture.Image == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string file = host.GetFilename("bmp", eventArgs.Capture.CaptureDetails);
|
string file = host.GetFilename(OutputFormat.Bmp, eventArgs.Capture.CaptureDetails);
|
||||||
string filePath = Path.Combine(Path.GetTempPath(),file);
|
string filePath = Path.Combine(Path.GetTempPath(),file);
|
||||||
|
|
||||||
using (FileStream stream = File.Create(filePath)) {
|
using (FileStream stream = File.Create(filePath)) {
|
||||||
|
@ -177,10 +177,10 @@ namespace GreenshotOCR {
|
||||||
graphics.Clear(Color.White);
|
graphics.Clear(Color.White);
|
||||||
graphics.DrawImage(capturedImage, Point.Empty);
|
graphics.DrawImage(capturedImage, Point.Empty);
|
||||||
}
|
}
|
||||||
host.SaveToStream(tmpImage, stream, "bmp", 100);
|
host.SaveToStream(tmpImage, stream, OutputFormat.Bmp, 100);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
host.SaveToStream(capturedImage, stream, "bmp", 100);
|
host.SaveToStream(capturedImage, stream, OutputFormat.Bmp, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace Greenshot.Forms {
|
||||||
private bool mouseDown = false;
|
private bool mouseDown = false;
|
||||||
private Rectangle captureRect = Rectangle.Empty;
|
private Rectangle captureRect = Rectangle.Empty;
|
||||||
private ICapture capture = null;
|
private ICapture capture = null;
|
||||||
private AppConfig conf = AppConfig.GetInstance();
|
private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
private ILanguage lang = Language.GetInstance();
|
private ILanguage lang = Language.GetInstance();
|
||||||
|
|
||||||
public CaptureForm() {
|
public CaptureForm() {
|
||||||
|
@ -70,10 +70,10 @@ namespace Greenshot.Forms {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoCaptureFeedback() {
|
void DoCaptureFeedback() {
|
||||||
if((bool)conf.Ui_Effects_CameraSound) {
|
if(conf.PlayCameraSound) {
|
||||||
SoundHelper.Play();
|
SoundHelper.Play();
|
||||||
}
|
}
|
||||||
if((bool)conf.Ui_Effects_Flashlight) {
|
if(conf.ShowFlash) {
|
||||||
FlashlightForm flashlightForm = new FlashlightForm();
|
FlashlightForm flashlightForm = new FlashlightForm();
|
||||||
flashlightForm.Bounds = capture.ScreenBounds;
|
flashlightForm.Bounds = capture.ScreenBounds;
|
||||||
flashlightForm.FadeIn();
|
flashlightForm.FadeIn();
|
||||||
|
@ -153,14 +153,14 @@ namespace Greenshot.Forms {
|
||||||
capture.CaptureDetails.CaptureMode = mode;
|
capture.CaptureDetails.CaptureMode = mode;
|
||||||
|
|
||||||
// Delay for the Context menu
|
// Delay for the Context menu
|
||||||
System.Threading.Thread.Sleep(conf.Capture_Wait_Time);
|
System.Threading.Thread.Sleep(conf.CaptureDelay);
|
||||||
|
|
||||||
// Allways capture Mousecursor, only show when needed
|
// Allways capture Mousecursor, only show when needed
|
||||||
capture = WindowCapture.CaptureCursor(capture);
|
capture = WindowCapture.CaptureCursor(capture);
|
||||||
capture.CursorVisible = false;
|
capture.CursorVisible = false;
|
||||||
// Check if needed
|
// Check if needed
|
||||||
if (captureMouseCursor && mode != CaptureMode.Clipboard && mode != CaptureMode.File) {
|
if (captureMouseCursor && mode != CaptureMode.Clipboard && mode != CaptureMode.File) {
|
||||||
capture.CursorVisible = (conf.Capture_Mousepointer.HasValue && conf.Capture_Mousepointer.Value);
|
capture.CursorVisible = conf.CaptureMousepointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
|
@ -240,27 +240,27 @@ namespace Greenshot.Forms {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICapture AddConfiguredDestination(ICapture capture) {
|
private ICapture AddConfiguredDestination(ICapture capture) {
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault) {
|
if (conf.OutputDestinations.Contains(Destination.FileDefault)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.File);
|
capture.CaptureDetails.AddDestination(CaptureDestination.File);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog) {
|
if (conf.OutputDestinations.Contains(Destination.FileWithDialog)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.FileWithDialog);
|
capture.CaptureDetails.AddDestination(CaptureDestination.FileWithDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard) {
|
if (conf.OutputDestinations.Contains(Destination.Clipboard)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.Clipboard);
|
capture.CaptureDetails.AddDestination(CaptureDestination.Clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer) {
|
if (conf.OutputDestinations.Contains(Destination.Printer)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.Printer);
|
capture.CaptureDetails.AddDestination(CaptureDestination.Printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor) {
|
if (conf.OutputDestinations.Contains(Destination.Editor)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.Editor);
|
capture.CaptureDetails.AddDestination(CaptureDestination.Editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf.Output_Destinations & ScreenshotDestinations.EMail) == ScreenshotDestinations.EMail) {
|
if (conf.OutputDestinations.Contains(Destination.EMail)) {
|
||||||
capture.CaptureDetails.AddDestination(CaptureDestination.EMail);
|
capture.CaptureDetails.AddDestination(CaptureDestination.EMail);
|
||||||
}
|
}
|
||||||
return capture;
|
return capture;
|
||||||
|
@ -334,7 +334,7 @@ namespace Greenshot.Forms {
|
||||||
// or use the file that was written
|
// or use the file that was written
|
||||||
bool fileWritten = false;
|
bool fileWritten = false;
|
||||||
if (captureDestinations.Contains(CaptureDestination.File)) {
|
if (captureDestinations.Contains(CaptureDestination.File)) {
|
||||||
string filename = FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, conf.Output_File_Format, captureDetails);
|
string filename = FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, conf.OutputFileFormat, captureDetails);
|
||||||
fullPath = Path.Combine(conf.Output_File_Path,filename);
|
fullPath = Path.Combine(conf.Output_File_Path,filename);
|
||||||
|
|
||||||
// Catching any exception to prevent that the user can't write in the directory.
|
// Catching any exception to prevent that the user can't write in the directory.
|
||||||
|
@ -405,8 +405,6 @@ namespace Greenshot.Forms {
|
||||||
* Finishing the whole Capture with Feedback flow, passing the result on to the HandleCapture
|
* Finishing the whole Capture with Feedback flow, passing the result on to the HandleCapture
|
||||||
*/
|
*/
|
||||||
private void finishCapture() {
|
private void finishCapture() {
|
||||||
bool fromWindow = (conf.Capture_Complete_Window.HasValue && conf.Capture_Complete_Window.Value);
|
|
||||||
|
|
||||||
// Get title
|
// Get title
|
||||||
if (selectedCaptureWindow != null) {
|
if (selectedCaptureWindow != null) {
|
||||||
if (capture == null) {
|
if (capture == null) {
|
||||||
|
@ -418,7 +416,7 @@ namespace Greenshot.Forms {
|
||||||
if ( (captureMode == CaptureMode.Window || captureMode == CaptureMode.ActiveWindow) && selectedCaptureWindow != null) {
|
if ( (captureMode == CaptureMode.Window || captureMode == CaptureMode.ActiveWindow) && selectedCaptureWindow != null) {
|
||||||
Image capturedWindowImage = null;
|
Image capturedWindowImage = null;
|
||||||
// What type of capturing? (From Screen or from window)
|
// What type of capturing? (From Screen or from window)
|
||||||
if (fromWindow) {
|
if (conf.CaptureCompleteWindow) {
|
||||||
// "Capture" the windows content
|
// "Capture" the windows content
|
||||||
capturedWindowImage = selectedCaptureWindow.Image;
|
capturedWindowImage = selectedCaptureWindow.Image;
|
||||||
if (capturedWindowImage != null) {
|
if (capturedWindowImage != null) {
|
||||||
|
@ -510,7 +508,7 @@ namespace Greenshot.Forms {
|
||||||
capture = WindowCapture.CaptureScreen(capture);
|
capture = WindowCapture.CaptureScreen(capture);
|
||||||
selectedCaptureWindow = new WindowDetails(hWnd);
|
selectedCaptureWindow = new WindowDetails(hWnd);
|
||||||
// Content only
|
// Content only
|
||||||
if ((conf.Capture_Window_Content.HasValue && conf.Capture_Window_Content.Value)) {
|
if (conf.CaptureWindowContent) {
|
||||||
// Print Tree for debugging
|
// Print Tree for debugging
|
||||||
selectedCaptureWindow.PrintTree("");
|
selectedCaptureWindow.PrintTree("");
|
||||||
WindowDetails contentWindow = selectedCaptureWindow.GetContent();
|
WindowDetails contentWindow = selectedCaptureWindow.GetContent();
|
||||||
|
@ -553,7 +551,7 @@ namespace Greenshot.Forms {
|
||||||
if (windowRectangle.Contains(Cursor.Position)) {
|
if (windowRectangle.Contains(Cursor.Position)) {
|
||||||
WindowDetails selectedChild = null;
|
WindowDetails selectedChild = null;
|
||||||
// Content only
|
// Content only
|
||||||
if ((conf.Capture_Window_Content.HasValue && conf.Capture_Window_Content.Value)) {
|
if (conf.CaptureWindowContent) {
|
||||||
WindowDetails childWindow = window.GetContent();
|
WindowDetails childWindow = window.GetContent();
|
||||||
if (childWindow != null && childWindow.Rectangle.Contains(Cursor.Position)) {
|
if (childWindow != null && childWindow.Rectangle.Contains(Cursor.Position)) {
|
||||||
return childWindow;
|
return childWindow;
|
||||||
|
|
|
@ -137,14 +137,6 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
StringBuilder helpOutput = new StringBuilder();
|
StringBuilder helpOutput = new StringBuilder();
|
||||||
helpOutput.AppendLine();
|
helpOutput.AppendLine();
|
||||||
if (argumentNr + 1 < args.Length && args[argumentNr + 1].ToLower().Equals("configure")) {
|
|
||||||
helpOutput.AppendLine("Available configuration settings:");
|
|
||||||
|
|
||||||
Properties properties = AppConfig.GetAvailableProperties();
|
|
||||||
foreach(string key in properties.Keys) {
|
|
||||||
helpOutput.AppendLine("\t\t" + key + "=" + properties.GetProperty(key));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
helpOutput.AppendLine("Greenshot commandline options:");
|
helpOutput.AppendLine("Greenshot commandline options:");
|
||||||
helpOutput.AppendLine();
|
helpOutput.AppendLine();
|
||||||
helpOutput.AppendLine();
|
helpOutput.AppendLine();
|
||||||
|
@ -174,7 +166,6 @@ namespace Greenshot {
|
||||||
helpOutput.AppendLine("\t\tCan be used if someone only wants to change the configuration.");
|
helpOutput.AppendLine("\t\tCan be used if someone only wants to change the configuration.");
|
||||||
helpOutput.AppendLine("\t\tAs soon as this option is found Greenshot exits if not and there is no running instance it will stay running.");
|
helpOutput.AppendLine("\t\tAs soon as this option is found Greenshot exits if not and there is no running instance it will stay running.");
|
||||||
helpOutput.AppendLine("\t\tExample: greenshot.exe /configure Output_File_Path=\"C:\\Documents and Settings\\\" --exit");
|
helpOutput.AppendLine("\t\tExample: greenshot.exe /configure Output_File_Path=\"C:\\Documents and Settings\\\" --exit");
|
||||||
}
|
|
||||||
Console.WriteLine(helpOutput.ToString());
|
Console.WriteLine(helpOutput.ToString());
|
||||||
|
|
||||||
// If attach didn't work, wait for key otherwise the console will close to quickly
|
// If attach didn't work, wait for key otherwise the console will close to quickly
|
||||||
|
@ -371,7 +362,7 @@ namespace Greenshot {
|
||||||
exit();
|
exit();
|
||||||
break;
|
break;
|
||||||
case CommandEnum.ReloadConfig:
|
case CommandEnum.ReloadConfig:
|
||||||
AppConfig.Reload();
|
// TODO: Reload the configuration
|
||||||
// Even update language when needed
|
// Even update language when needed
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Greenshot.Forms;
|
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
|
using Greenshot.Forms;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Greenshot.Test
|
namespace Greenshot.Test
|
||||||
{
|
{
|
||||||
|
@ -62,12 +62,12 @@ namespace Greenshot.Test
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SuggestBasicFileNameTest() {
|
public void SuggestBasicFileNameTest() {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
//conf.Output_FileAs_Fullpath = @"c:\path\to\greenshot_testdir\gstest_28.jpg";
|
//conf.Output_FileAs_Fullpath = @"c:\path\to\greenshot_testdir\gstest_28.jpg";
|
||||||
conf.Output_File_Path = @"c:\path\to\greenshot_testdir\";
|
conf.Output_File_Path = @"c:\path\to\greenshot_testdir\";
|
||||||
conf.Output_File_FilenamePattern = "gstest_%NUM%";
|
conf.OutputFileFilenamePattern = "gstest_%NUM%";
|
||||||
conf.Output_File_Format = "Jpeg";
|
conf.OutputFileFormat = OutputFormat.Jpeg;
|
||||||
conf.Output_File_IncrementingNumber = 28;
|
conf.OutputFileIncrementingNumber = 28;
|
||||||
SaveImageFileDialog sifd = new SaveImageFileDialog();
|
SaveImageFileDialog sifd = new SaveImageFileDialog();
|
||||||
|
|
||||||
Assert.AreEqual(sifd.InitialDirectory, @"c:\path\to\greenshot_testdir");
|
Assert.AreEqual(sifd.InitialDirectory, @"c:\path\to\greenshot_testdir");
|
||||||
|
|
|
@ -33,6 +33,7 @@ using Greenshot.Core;
|
||||||
/// See: http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification
|
/// See: http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification
|
||||||
/// </summary>
|
/// </summary>
|
||||||
namespace Confluence {
|
namespace Confluence {
|
||||||
|
#region transport classes
|
||||||
public class Page {
|
public class Page {
|
||||||
public Page(RemotePage page) {
|
public Page(RemotePage page) {
|
||||||
id = page.id;
|
id = page.id;
|
||||||
|
@ -42,101 +43,43 @@ namespace Confluence {
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public class ConfluenceConnector {
|
public class ConfluenceConnector {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
||||||
private const string CONFLUENCE_URL_PROPERTY = "url";
|
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
|
||||||
private const string CONFLUENCE_USER_PROPERTY = "user";
|
|
||||||
private const string CONFLUENCE_PASSWORD_PROPERTY = "password";
|
|
||||||
private const int DEFAULT_TIMEOUT = 29;
|
|
||||||
public const string CONFIG_FILENAME = "confluence.properties";
|
|
||||||
private const string DEFAULT_CONFLUENCE_URL = "http://confluence/rpc/soap-axis/confluenceservice-v1?wsdl";
|
|
||||||
private string configurationPath = null;
|
|
||||||
private string credentials = null;
|
private string credentials = null;
|
||||||
private DateTime loggedInTime = DateTime.Now;
|
private DateTime loggedInTime = DateTime.Now;
|
||||||
private bool loggedIn = false;
|
private bool loggedIn = false;
|
||||||
private string tmpPassword = null;
|
private ConfluenceConfiguration config;
|
||||||
private Properties config;
|
|
||||||
private ConfluenceSoapServiceService confluence;
|
private ConfluenceSoapServiceService confluence;
|
||||||
private Dictionary<string, string> userMap = new Dictionary<string, string>();
|
private Dictionary<string, string> userMap = new Dictionary<string, string>();
|
||||||
|
|
||||||
public ConfluenceConnector(string configurationPath) {
|
public ConfluenceConnector(string configurationPath) {
|
||||||
this.configurationPath = configurationPath;
|
this.config = IniConfig.GetIniSection<ConfluenceConfiguration>();
|
||||||
this.config = LoadConfig();
|
|
||||||
confluence = new ConfluenceSoapServiceService();
|
confluence = new ConfluenceSoapServiceService();
|
||||||
confluence.Url = config.GetProperty(CONFLUENCE_URL_PROPERTY);
|
confluence.Url = config.Url;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ConfluenceConnector() {
|
~ConfluenceConnector() {
|
||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasPassword() {
|
|
||||||
return config.ContainsKey(CONFLUENCE_PASSWORD_PROPERTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetTmpPassword(string password) {
|
|
||||||
tmpPassword = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties LoadConfig() {
|
|
||||||
Properties config = null;
|
|
||||||
string filename = Path.Combine(configurationPath, CONFIG_FILENAME);
|
|
||||||
if (File.Exists(filename)) {
|
|
||||||
LOG.Debug("Loading configuration from: " + filename);
|
|
||||||
config = Properties.read(filename);
|
|
||||||
}
|
|
||||||
bool changed = false;
|
|
||||||
if (config == null) {
|
|
||||||
config = new Properties();
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
if (!config.ContainsKey(CONFLUENCE_URL_PROPERTY)) {
|
|
||||||
config.AddProperty(CONFLUENCE_URL_PROPERTY, DEFAULT_CONFLUENCE_URL);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
if (!config.ContainsKey(CONFLUENCE_USER_PROPERTY)) {
|
|
||||||
config.AddProperty(CONFLUENCE_USER_PROPERTY, Environment.UserName);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
if (changed) {
|
|
||||||
SaveConfig(config);
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveConfig(Properties config) {
|
|
||||||
string filename = Path.Combine(configurationPath, CONFIG_FILENAME);
|
|
||||||
LOG.Debug("Saving configuration to: " + filename);
|
|
||||||
StringBuilder comment = new StringBuilder();
|
|
||||||
comment.AppendLine("# The configuration file for the Confluence Plugin");
|
|
||||||
comment.AppendLine("#");
|
|
||||||
comment.AppendLine("# Example settings:");
|
|
||||||
comment.AppendLine("# " + CONFLUENCE_URL_PROPERTY + "=" + DEFAULT_CONFLUENCE_URL);
|
|
||||||
comment.AppendLine("# " + CONFLUENCE_USER_PROPERTY + "=Username");
|
|
||||||
config.write(filename, comment.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void login() {
|
public void login() {
|
||||||
logout();
|
logout();
|
||||||
try {
|
try {
|
||||||
if (HasPassword()) {
|
if (config.HasPassword()) {
|
||||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), config.GetProperty(CONFLUENCE_PASSWORD_PROPERTY));
|
this.credentials = confluence.login(config.User, config.Password);
|
||||||
} else if (tmpPassword != null) {
|
} else if (config.HasTmpPassword()) {
|
||||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), tmpPassword);
|
this.credentials = confluence.login(config.User, config.TmpPassword);
|
||||||
} else {
|
} else {
|
||||||
LoginForm pwForm = new LoginForm();
|
if (config.ShowConfigDialog()) {
|
||||||
pwForm.User = config.GetProperty(CONFLUENCE_USER_PROPERTY);
|
if (config.HasPassword()) {
|
||||||
pwForm.Url = config.GetProperty(CONFLUENCE_URL_PROPERTY);
|
this.credentials = confluence.login(config.User, config.Password);
|
||||||
DialogResult result = pwForm.ShowDialog();
|
} else if (config.HasTmpPassword()) {
|
||||||
if (result == DialogResult.OK) {
|
this.credentials = confluence.login(config.User, config.TmpPassword);
|
||||||
tmpPassword = pwForm.Password;
|
|
||||||
if (!pwForm.User.Equals(config.GetProperty(CONFLUENCE_USER_PROPERTY)) ||!pwForm.Url.Equals(config.GetProperty(CONFLUENCE_URL_PROPERTY))) {
|
|
||||||
config.ChangeProperty(CONFLUENCE_USER_PROPERTY, pwForm.User);
|
|
||||||
config.ChangeProperty(CONFLUENCE_URL_PROPERTY, pwForm.Url);
|
|
||||||
confluence.Url = config.GetProperty(CONFLUENCE_URL_PROPERTY);
|
|
||||||
SaveConfig(config);
|
|
||||||
}
|
}
|
||||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), tmpPassword);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("User pressed cancel!");
|
throw new Exception("User pressed cancel!");
|
||||||
}
|
}
|
||||||
|
@ -146,12 +89,13 @@ namespace Confluence {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
this.credentials = null;
|
this.credentials = null;
|
||||||
e.Data.Add("user",config.GetProperty(CONFLUENCE_USER_PROPERTY));
|
e.Data.Add("user",config.User);
|
||||||
e.Data.Add("url",config.GetProperty(CONFLUENCE_URL_PROPERTY));
|
e.Data.Add("url",config.Url);
|
||||||
if (e.Message.Contains("com.atlassian.confluence.rpc.AuthenticationFailedException")) {
|
if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
|
||||||
// Login failed due to wrong user or password, password should be removed!
|
// Login failed due to wrong user or password, password should be removed!
|
||||||
this.tmpPassword = null;
|
config.Password = null;
|
||||||
throw new Exception(e.Message.Replace("com.atlassian.confluence.rpc.AuthenticationFailedException: ",""));
|
config.TmpPassword = null;
|
||||||
|
throw new Exception(e.Message.Replace(AUTH_FAILED_EXCEPTION_NAME+ ": ",""));
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +111,7 @@ namespace Confluence {
|
||||||
|
|
||||||
private void checkCredentials() {
|
private void checkCredentials() {
|
||||||
if (loggedIn) {
|
if (loggedIn) {
|
||||||
if (loggedInTime.AddMinutes(DEFAULT_TIMEOUT).CompareTo(DateTime.Now) < 0) {
|
if (loggedInTime.AddMinutes(config.Timeout-1).CompareTo(DateTime.Now) < 0) {
|
||||||
logout();
|
logout();
|
||||||
login();
|
login();
|
||||||
}
|
}
|
||||||
|
|
84
GreenshotConfluencePlugin/ConfluenceConfiguration.cs
Normal file
84
GreenshotConfluencePlugin/ConfluenceConfiguration.cs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2010 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
using Greenshot.Core;
|
||||||
|
|
||||||
|
namespace GreenshotConfluencePlugin {
|
||||||
|
/// <summary>
|
||||||
|
/// Description of ConfluenceConfiguration.
|
||||||
|
/// </summary>
|
||||||
|
[IniSection("Confluence", Description="Greenshot Confluence Plugin configuration")]
|
||||||
|
public class ConfluenceConfiguration : IniSection {
|
||||||
|
[IniProperty("Url", Description="Url to Confluence system, including wsdl.", DefaultValue="http://confluence/rpc/soap-axis/confluenceservice-v1?wsdl")]
|
||||||
|
public string Url;
|
||||||
|
[IniProperty("Timeout", Description="Session timeout in minutes", DefaultValue="30")]
|
||||||
|
public int Timeout;
|
||||||
|
[IniProperty("User", Description="User for the Confluence System")]
|
||||||
|
public string User;
|
||||||
|
[IniProperty("Password", Description="Password for the Confluence System, belonging to user.")]
|
||||||
|
public string Password;
|
||||||
|
|
||||||
|
// This will not be stored
|
||||||
|
public string TmpPassword;
|
||||||
|
|
||||||
|
public bool HasPassword() {
|
||||||
|
return (Password != null && Password.Length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasTmpPassword() {
|
||||||
|
return (TmpPassword != null && TmpPassword.Length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A form for username/password
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>bool true if OK was pressed, false if cancel</returns>
|
||||||
|
public bool ShowConfigDialog() {
|
||||||
|
LoginForm pwForm = new LoginForm();
|
||||||
|
if (User == null || User.Length == 0) {
|
||||||
|
User = Environment.UserName;
|
||||||
|
}
|
||||||
|
pwForm.User = User;
|
||||||
|
pwForm.Url = Url;
|
||||||
|
DialogResult result = pwForm.ShowDialog();
|
||||||
|
if (result == DialogResult.OK) {
|
||||||
|
if (pwForm.DoNotStorePassword) {
|
||||||
|
TmpPassword = pwForm.Password;
|
||||||
|
Password = null;
|
||||||
|
} else {
|
||||||
|
Password = pwForm.Password;
|
||||||
|
TmpPassword = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pwForm.User.Equals(User) ||!pwForm.Url.Equals(Url)) {
|
||||||
|
User = pwForm.User;
|
||||||
|
Url = pwForm.Url;
|
||||||
|
}
|
||||||
|
IniConfig.Save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,10 +72,7 @@ namespace GreenshotConfluencePlugin {
|
||||||
/// Implementation of the IPlugin.Configure
|
/// Implementation of the IPlugin.Configure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Configure() {
|
public virtual void Configure() {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
IniConfig.GetIniSection<ConfluenceConfiguration>().ShowConfigDialog();
|
||||||
stringBuilder.AppendLine("This plugin doesn't have a configuration screen.");
|
|
||||||
stringBuilder.AppendLine("Configuration is stored at: " + Path.Combine(host.ConfigurationPath, ConfluenceConnector.CONFIG_FILENAME));
|
|
||||||
MessageBox.Show(stringBuilder.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -110,21 +107,21 @@ namespace GreenshotConfluencePlugin {
|
||||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||||
|
|
||||||
ConfluenceForm confluenceForm = new ConfluenceForm(confluenceConnector);
|
ConfluenceForm confluenceForm = new ConfluenceForm(confluenceConnector);
|
||||||
confluenceForm.setFilename(host.GetFilename("png", imageEditor.CaptureDetails));
|
confluenceForm.setFilename(host.GetFilename(OutputFormat.Png, imageEditor.CaptureDetails));
|
||||||
DialogResult result = confluenceForm.ShowDialog();
|
DialogResult result = confluenceForm.ShowDialog();
|
||||||
if (result == DialogResult.OK) {
|
if (result == DialogResult.OK) {
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||||
byte [] buffer = stream.GetBuffer();
|
byte [] buffer = stream.GetBuffer();
|
||||||
try {
|
try {
|
||||||
confluenceForm.upload(buffer);
|
confluenceForm.upload(buffer);
|
||||||
|
LOG.Debug("Uploaded to Confluence.");
|
||||||
MessageBox.Show(lang.GetString(LangKey.upload_success));
|
MessageBox.Show(lang.GetString(LangKey.upload_success));
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.Message);
|
MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.Debug("Uploaded to Confluence.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,16 @@ namespace GreenshotConfluencePlugin {
|
||||||
this.textBoxUser = new System.Windows.Forms.TextBox();
|
this.textBoxUser = new System.Windows.Forms.TextBox();
|
||||||
this.label_url = new System.Windows.Forms.Label();
|
this.label_url = new System.Windows.Forms.Label();
|
||||||
this.textBoxUrl = new System.Windows.Forms.TextBox();
|
this.textBoxUrl = new System.Windows.Forms.TextBox();
|
||||||
|
this.checkBoxDoNotStorePassword = new System.Windows.Forms.CheckBox();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// textBoxPassword
|
// textBoxPassword
|
||||||
//
|
//
|
||||||
this.textBoxPassword.Location = new System.Drawing.Point(118, 73);
|
this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.textBoxPassword.Location = new System.Drawing.Point(102, 73);
|
||||||
this.textBoxPassword.Name = "textBoxPassword";
|
this.textBoxPassword.Name = "textBoxPassword";
|
||||||
this.textBoxPassword.PasswordChar = '*';
|
this.textBoxPassword.PasswordChar = '*';
|
||||||
this.textBoxPassword.Size = new System.Drawing.Size(190, 20);
|
this.textBoxPassword.Size = new System.Drawing.Size(276, 20);
|
||||||
this.textBoxPassword.TabIndex = 0;
|
this.textBoxPassword.TabIndex = 0;
|
||||||
this.textBoxPassword.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBoxPasswordKeyUp);
|
this.textBoxPassword.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBoxPasswordKeyUp);
|
||||||
//
|
//
|
||||||
|
@ -69,13 +71,14 @@ namespace GreenshotConfluencePlugin {
|
||||||
//
|
//
|
||||||
this.label_password.Location = new System.Drawing.Point(12, 73);
|
this.label_password.Location = new System.Drawing.Point(12, 73);
|
||||||
this.label_password.Name = "label_password";
|
this.label_password.Name = "label_password";
|
||||||
this.label_password.Size = new System.Drawing.Size(100, 20);
|
this.label_password.Size = new System.Drawing.Size(84, 20);
|
||||||
this.label_password.TabIndex = 1;
|
this.label_password.TabIndex = 1;
|
||||||
this.label_password.Text = "Password";
|
this.label_password.Text = "Password";
|
||||||
//
|
//
|
||||||
// buttonOK
|
// buttonOK
|
||||||
//
|
//
|
||||||
this.buttonOK.Location = new System.Drawing.Point(152, 102);
|
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonOK.Location = new System.Drawing.Point(222, 139);
|
||||||
this.buttonOK.Name = "buttonOK";
|
this.buttonOK.Name = "buttonOK";
|
||||||
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
||||||
this.buttonOK.TabIndex = 2;
|
this.buttonOK.TabIndex = 2;
|
||||||
|
@ -85,7 +88,8 @@ namespace GreenshotConfluencePlugin {
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(233, 102);
|
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(303, 139);
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
this.buttonCancel.TabIndex = 3;
|
this.buttonCancel.TabIndex = 3;
|
||||||
|
@ -97,37 +101,50 @@ namespace GreenshotConfluencePlugin {
|
||||||
//
|
//
|
||||||
this.label_user.Location = new System.Drawing.Point(12, 47);
|
this.label_user.Location = new System.Drawing.Point(12, 47);
|
||||||
this.label_user.Name = "label_user";
|
this.label_user.Name = "label_user";
|
||||||
this.label_user.Size = new System.Drawing.Size(100, 20);
|
this.label_user.Size = new System.Drawing.Size(84, 20);
|
||||||
this.label_user.TabIndex = 5;
|
this.label_user.TabIndex = 5;
|
||||||
this.label_user.Text = "User";
|
this.label_user.Text = "User";
|
||||||
//
|
//
|
||||||
// textBoxUser
|
// textBoxUser
|
||||||
//
|
//
|
||||||
this.textBoxUser.Location = new System.Drawing.Point(118, 47);
|
this.textBoxUser.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.textBoxUser.Location = new System.Drawing.Point(102, 47);
|
||||||
this.textBoxUser.Name = "textBoxUser";
|
this.textBoxUser.Name = "textBoxUser";
|
||||||
this.textBoxUser.Size = new System.Drawing.Size(190, 20);
|
this.textBoxUser.Size = new System.Drawing.Size(276, 20);
|
||||||
this.textBoxUser.TabIndex = 4;
|
this.textBoxUser.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// label_url
|
// label_url
|
||||||
//
|
//
|
||||||
this.label_url.Location = new System.Drawing.Point(12, 21);
|
this.label_url.Location = new System.Drawing.Point(12, 21);
|
||||||
this.label_url.Name = "label_url";
|
this.label_url.Name = "label_url";
|
||||||
this.label_url.Size = new System.Drawing.Size(100, 20);
|
this.label_url.Size = new System.Drawing.Size(84, 20);
|
||||||
this.label_url.TabIndex = 7;
|
this.label_url.TabIndex = 7;
|
||||||
this.label_url.Text = "Url";
|
this.label_url.Text = "Url";
|
||||||
//
|
//
|
||||||
// textBoxUrl
|
// textBoxUrl
|
||||||
//
|
//
|
||||||
this.textBoxUrl.Location = new System.Drawing.Point(118, 21);
|
this.textBoxUrl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.textBoxUrl.Location = new System.Drawing.Point(102, 21);
|
||||||
this.textBoxUrl.Name = "textBoxUrl";
|
this.textBoxUrl.Name = "textBoxUrl";
|
||||||
this.textBoxUrl.Size = new System.Drawing.Size(190, 20);
|
this.textBoxUrl.Size = new System.Drawing.Size(276, 20);
|
||||||
this.textBoxUrl.TabIndex = 6;
|
this.textBoxUrl.TabIndex = 6;
|
||||||
//
|
//
|
||||||
|
// checkBoxDoNotStorePassword
|
||||||
|
//
|
||||||
|
this.checkBoxDoNotStorePassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.checkBoxDoNotStorePassword.Location = new System.Drawing.Point(102, 99);
|
||||||
|
this.checkBoxDoNotStorePassword.Name = "checkBoxDoNotStorePassword";
|
||||||
|
this.checkBoxDoNotStorePassword.Size = new System.Drawing.Size(276, 24);
|
||||||
|
this.checkBoxDoNotStorePassword.TabIndex = 8;
|
||||||
|
this.checkBoxDoNotStorePassword.Text = "Do not store the password";
|
||||||
|
this.checkBoxDoNotStorePassword.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// LoginForm
|
// LoginForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(320, 139);
|
this.ClientSize = new System.Drawing.Size(387, 174);
|
||||||
|
this.Controls.Add(this.checkBoxDoNotStorePassword);
|
||||||
this.Controls.Add(this.label_url);
|
this.Controls.Add(this.label_url);
|
||||||
this.Controls.Add(this.textBoxUrl);
|
this.Controls.Add(this.textBoxUrl);
|
||||||
this.Controls.Add(this.label_user);
|
this.Controls.Add(this.label_user);
|
||||||
|
@ -137,10 +154,11 @@ namespace GreenshotConfluencePlugin {
|
||||||
this.Controls.Add(this.label_password);
|
this.Controls.Add(this.label_password);
|
||||||
this.Controls.Add(this.textBoxPassword);
|
this.Controls.Add(this.textBoxPassword);
|
||||||
this.Name = "LoginForm";
|
this.Name = "LoginForm";
|
||||||
this.Text = "Please enter your Confluence password";
|
this.Text = "Please enter your Confluence data";
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
}
|
}
|
||||||
|
private System.Windows.Forms.CheckBox checkBoxDoNotStorePassword;
|
||||||
private System.Windows.Forms.TextBox textBoxUrl;
|
private System.Windows.Forms.TextBox textBoxUrl;
|
||||||
private System.Windows.Forms.Label label_url;
|
private System.Windows.Forms.Label label_url;
|
||||||
private System.Windows.Forms.TextBox textBoxUser;
|
private System.Windows.Forms.TextBox textBoxUser;
|
||||||
|
@ -149,6 +167,5 @@ namespace GreenshotConfluencePlugin {
|
||||||
private System.Windows.Forms.TextBox textBoxPassword;
|
private System.Windows.Forms.TextBox textBoxPassword;
|
||||||
private System.Windows.Forms.Button buttonCancel;
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
private System.Windows.Forms.Button buttonOK;
|
private System.Windows.Forms.Button buttonOK;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ using Greenshot.Core;
|
||||||
|
|
||||||
namespace GreenshotConfluencePlugin {
|
namespace GreenshotConfluencePlugin {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of LoginForm.
|
/// Description of PasswordRequestForm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class LoginForm : Form {
|
public partial class LoginForm : Form {
|
||||||
private ILanguage lang = Language.GetInstance();
|
private ILanguage lang = Language.GetInstance();
|
||||||
|
@ -45,6 +45,7 @@ namespace GreenshotConfluencePlugin {
|
||||||
this.label_password.Text = lang.GetString(LangKey.label_password);
|
this.label_password.Text = lang.GetString(LangKey.label_password);
|
||||||
this.buttonOK.Text = lang.GetString(LangKey.OK);
|
this.buttonOK.Text = lang.GetString(LangKey.OK);
|
||||||
this.buttonCancel.Text = lang.GetString(LangKey.CANCEL);
|
this.buttonCancel.Text = lang.GetString(LangKey.CANCEL);
|
||||||
|
this.checkBoxDoNotStorePassword.Text = lang.GetString(LangKey.label_no_password_store);
|
||||||
this.Text = lang.GetString(LangKey.login_title);
|
this.Text = lang.GetString(LangKey.login_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +64,11 @@ namespace GreenshotConfluencePlugin {
|
||||||
set {textBoxPassword.Text = value;}
|
set {textBoxPassword.Text = value;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DoNotStorePassword {
|
||||||
|
get {return checkBoxDoNotStorePassword.Checked;}
|
||||||
|
set {checkBoxDoNotStorePassword.Checked = value;}
|
||||||
|
}
|
||||||
|
|
||||||
void ButtonOKClick(object sender, EventArgs e) {
|
void ButtonOKClick(object sender, EventArgs e) {
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ConfluenceConfiguration.cs" />
|
||||||
<Compile Include="ConfluencePluginBase.cs" />
|
<Compile Include="ConfluencePluginBase.cs" />
|
||||||
<Compile Include="Forms\ConfluenceForm.cs" />
|
<Compile Include="Forms\ConfluenceForm.cs" />
|
||||||
<Compile Include="Forms\ConfluenceForm.Designer.cs">
|
<Compile Include="Forms\ConfluenceForm.Designer.cs">
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace GreenshotConfluencePlugin {
|
||||||
label_url,
|
label_url,
|
||||||
label_user,
|
label_user,
|
||||||
label_password,
|
label_password,
|
||||||
|
label_no_password_store,
|
||||||
OK,
|
OK,
|
||||||
CANCEL,
|
CANCEL,
|
||||||
upload_success,
|
upload_success,
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
<resource name="label_password">
|
<resource name="label_password">
|
||||||
Password
|
Password
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource name="label_no_password_store">
|
||||||
|
Kennwort nicht speichern
|
||||||
|
</resource>
|
||||||
<resource name="OK">
|
<resource name="OK">
|
||||||
OK
|
OK
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
<resource name="label_password">
|
<resource name="label_password">
|
||||||
Password
|
Password
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource name="label_no_password_store">
|
||||||
|
Do not store the password
|
||||||
|
</resource>
|
||||||
<resource name="login_title">
|
<resource name="login_title">
|
||||||
Please enter your Confluence login data
|
Please enter your Confluence login data
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
<resource name="label_password">
|
<resource name="label_password">
|
||||||
Password
|
Password
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource name="label_no_password_store">
|
||||||
|
Het wachtwoord niet opslaan
|
||||||
|
</resource>
|
||||||
<resource name="login_title">
|
<resource name="login_title">
|
||||||
Geef uw Confluence login data
|
Geef uw Confluence login data
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -36,8 +36,6 @@ using Greenshot.Drawing;
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
|
|
||||||
namespace Greenshot.Configuration {
|
namespace Greenshot.Configuration {
|
||||||
public enum ScreenshotDestinations {Editor=1, FileDefault=2, FileWithDialog=4, Clipboard=8, Printer=16, EMail=32}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AppConfig is used for loading and saving the configuration. All public fields
|
/// AppConfig is used for loading and saving the configuration. All public fields
|
||||||
/// in this class are serialized with the BinaryFormatter and then saved to the
|
/// in this class are serialized with the BinaryFormatter and then saved to the
|
||||||
|
@ -48,68 +46,10 @@ namespace Greenshot.Configuration {
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AppConfig));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AppConfig));
|
||||||
|
|
||||||
//private static string loc = Assembly.GetExecutingAssembly().Location;
|
|
||||||
//private static string oldFilename = Path.Combine(loc.Substring(0,loc.LastIndexOf(@"\")),"config.dat");
|
|
||||||
private const string CONFIG_FILE_NAME = "config.dat";
|
|
||||||
private static string configfilepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"Greenshot\");
|
|
||||||
private static AppConfig instance = null;
|
private static AppConfig instance = null;
|
||||||
|
|
||||||
public Dictionary<string, object> LastUsedFieldValues = new Dictionary<string, object>();
|
public Dictionary<string, object> LastUsedFieldValues = new Dictionary<string, object>();
|
||||||
|
|
||||||
// the configuration part - all public vars are stored in the config file
|
|
||||||
// don't use "null" and "0" as default value!
|
|
||||||
|
|
||||||
#region general application config
|
|
||||||
public bool? General_RegisterHotkeys = true;
|
|
||||||
public bool? General_IsFirstLaunch = true;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region capture config
|
|
||||||
public bool? Capture_Mousepointer = true;
|
|
||||||
public bool? Capture_Windows_Interactive = false;
|
|
||||||
public int Capture_Wait_Time = 100;
|
|
||||||
public bool? Capture_Complete_Window = false;
|
|
||||||
public bool? Capture_Window_Content = false;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region user interface config
|
|
||||||
public string Ui_Language = "";
|
|
||||||
public bool? Ui_Effects_Flashlight = false;
|
|
||||||
public bool? Ui_Effects_CameraSound = true;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region output config
|
|
||||||
public ScreenshotDestinations Output_Destinations = ScreenshotDestinations.Editor;
|
|
||||||
|
|
||||||
|
|
||||||
public string Output_File_Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
||||||
public string Output_File_FilenamePattern = "%title%_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%";
|
|
||||||
public string Output_File_Format = ImageFormat.Png.ToString();
|
|
||||||
public bool? Output_File_CopyPathToClipboard = false;
|
|
||||||
public int Output_File_JpegQuality = 80;
|
|
||||||
public bool? Output_File_PromptJpegQuality = false;
|
|
||||||
public int Output_File_IncrementingNumber = 1;
|
|
||||||
|
|
||||||
public string Output_FileAs_Fullpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
|
|
||||||
|
|
||||||
public bool? Output_Print_PromptOptions = true;
|
|
||||||
public bool? Output_Print_AllowRotate = true;
|
|
||||||
public bool? Output_Print_AllowEnlarge = true;
|
|
||||||
public bool? Output_Print_AllowShrink = true;
|
|
||||||
public bool? Output_Print_Center = true;
|
|
||||||
public bool? Output_Print_Timestamp = true;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region editor config
|
|
||||||
public Size Editor_WindowSize = new Size(540, 380);
|
|
||||||
public Point Editor_WindowLocation = new Point(100, 100);
|
|
||||||
public String Editor_WindowState = "Normal";
|
|
||||||
public Rectangle Editor_Previous_Screenbounds = Rectangle.Empty;
|
|
||||||
public Color[] Editor_RecentColors = new Color[12];
|
|
||||||
public Font Editor_Font = null;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a private constructor because this is a singleton
|
/// a private constructor because this is a singleton
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -122,170 +62,11 @@ namespace Greenshot.Configuration {
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static AppConfig GetInstance() {
|
public static AppConfig GetInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = Load();
|
instance = new AppConfig();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Reload() {
|
|
||||||
AppConfig newInstance = Load();
|
|
||||||
instance.Copy(newInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// loads the configuration from the config file
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>an instance of AppConfig with all values set from the config file</returns>
|
|
||||||
private static AppConfig Load() {
|
|
||||||
AppConfig conf;
|
|
||||||
CheckConfigFile();
|
|
||||||
string configfilename = Path.Combine(configfilepath, CONFIG_FILE_NAME);
|
|
||||||
try {
|
|
||||||
LOG.Debug("Loading configuration from: " + configfilename);
|
|
||||||
using (FileStream fileStream = File.Open(configfilename, FileMode.Open, FileAccess.Read)) {
|
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
|
||||||
conf = (AppConfig) binaryFormatter.Deserialize(fileStream);
|
|
||||||
}
|
|
||||||
conf.SetDefaults();
|
|
||||||
return conf;
|
|
||||||
} catch (SerializationException e) {
|
|
||||||
LOG.Error("Problem loading configuration from: " + configfilename, e);
|
|
||||||
AppConfig config = new AppConfig();
|
|
||||||
config.Store();
|
|
||||||
return config;
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.Error("Problem loading configuration from: " + configfilename, e);
|
|
||||||
MessageBox.Show(String.Format("Could not load Greenshot's configuration file. Please check access permissions for '{0}'.\n",configfilename),"Error");
|
|
||||||
Process.GetCurrentProcess().Kill();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks for the existence of a configuration file.
|
|
||||||
/// First in greenshot's Applicationdata folder (where it is stored since 0.6),
|
|
||||||
/// then (if it cannot be found there) in greenshot's program directory (where older
|
|
||||||
/// versions might have stored it).
|
|
||||||
/// If the latter is the case, the file is moved to the new location, so that a user does not lose
|
|
||||||
/// their configuration after upgrading.
|
|
||||||
/// If there is no file in both locations, a virgin config file is created.
|
|
||||||
/// </summary>
|
|
||||||
private static void CheckConfigFile() {
|
|
||||||
// check if file is in the same location as started from, if this is the case
|
|
||||||
// we will use this file instead of the Applicationdate folder
|
|
||||||
// Done for Feature Request #2741508
|
|
||||||
if (File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME))) {
|
|
||||||
configfilepath = Application.StartupPath;
|
|
||||||
} else if (!File.Exists(Path.Combine(configfilepath, CONFIG_FILE_NAME))) {
|
|
||||||
Directory.CreateDirectory(configfilepath);
|
|
||||||
new AppConfig().Store();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// saves the configuration values to the supplied config file
|
|
||||||
/// </summary>
|
|
||||||
public void Store() {
|
|
||||||
Store(configfilepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// saves the configuration values to the config path
|
|
||||||
/// </summary>
|
|
||||||
public void Store(string configpath) {
|
|
||||||
string configfilename = Path.Combine(configpath, CONFIG_FILE_NAME);
|
|
||||||
try {
|
|
||||||
LOG.Debug("Saving configuration to: " + configfilename);
|
|
||||||
using (FileStream fileStream = File.Open(configfilename, FileMode.Create)) {
|
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
|
||||||
formatter.Serialize(fileStream, this);
|
|
||||||
}
|
|
||||||
} catch (UnauthorizedAccessException e) {
|
|
||||||
LOG.Error("Problem saving configuration to: " + configfilename, e);
|
|
||||||
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.config_unauthorizedaccess_write,configfilename),Language.GetInstance().GetString(LangKey.error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// when new fields are added to this class, they are instanced
|
|
||||||
/// with null by default. this method iterates over all public
|
|
||||||
/// fields and uses reflection to set them to the proper default value.
|
|
||||||
/// </summary>
|
|
||||||
public void SetDefaults() {
|
|
||||||
Type type = this.GetType();
|
|
||||||
FieldInfo[] fieldInfos = type.GetFields();
|
|
||||||
foreach (FieldInfo fi in fieldInfos) {
|
|
||||||
object o = fi.GetValue(this);
|
|
||||||
int i;
|
|
||||||
if (o == null || (int.TryParse(o.ToString(), out i) && i == 0)) {
|
|
||||||
// found field with value null. setting to default.
|
|
||||||
AppConfig tmpConf = new AppConfig();
|
|
||||||
Type tmpType = tmpConf.GetType();
|
|
||||||
FieldInfo defaultField = tmpType.GetField(fi.Name);
|
|
||||||
fi.SetValue(this, defaultField.GetValue(tmpConf));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Copy(AppConfig newConfig) {
|
|
||||||
Type type = this.GetType();
|
|
||||||
|
|
||||||
// Copy fields
|
|
||||||
FieldInfo[] fieldInfos = type.GetFields();
|
|
||||||
foreach (FieldInfo fi in fieldInfos) {
|
|
||||||
object newValue = fi.GetValue(newConfig);
|
|
||||||
fi.SetValue(this, newValue);
|
|
||||||
}
|
|
||||||
// Update language
|
|
||||||
if (newConfig.Ui_Language != null && !newConfig.Ui_Language.Equals(Language.GetInstance().CurrentLanguage)) {
|
|
||||||
string newLang = Language.GetInstance().SetLanguage(newConfig.Ui_Language);
|
|
||||||
// check if the language was not wat was supplied (near match)
|
|
||||||
if (newConfig.Ui_Language.Equals(newLang)) {
|
|
||||||
// Store change
|
|
||||||
this.Store();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Properties GetAvailableProperties() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
Type type = typeof(AppConfig);
|
|
||||||
FieldInfo[] fieldInfos = type.GetFields();
|
|
||||||
foreach (FieldInfo fi in fieldInfos) {
|
|
||||||
Type fieldType = fi.FieldType;
|
|
||||||
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) {
|
|
||||||
// We are dealing with a generic type that is nullable
|
|
||||||
fieldType = Nullable.GetUnderlyingType(fieldType);
|
|
||||||
}
|
|
||||||
if (fieldType == typeof(string) || fieldType == typeof(bool) || fieldType == typeof(int)) {
|
|
||||||
properties.AddProperty(fi.Name, fieldType.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetProperties(Properties properties) {
|
|
||||||
Type type = this.GetType();
|
|
||||||
FieldInfo[] fieldInfos = type.GetFields();
|
|
||||||
foreach(string key in properties.Keys) {
|
|
||||||
FieldInfo currentField = type.GetField(key);
|
|
||||||
if (currentField != null) {
|
|
||||||
object currentValue = currentField.GetValue(this);
|
|
||||||
LOG.Debug("Before: " + currentField.Name + "=" + currentValue);
|
|
||||||
if (currentField.FieldType == typeof(string)) {
|
|
||||||
currentField.SetValue(this, properties.GetProperty(key));
|
|
||||||
} else if (currentField.FieldType == typeof(bool) ||currentField.FieldType == typeof(bool?)) {
|
|
||||||
currentField.SetValue(this, properties.GetBoolProperty(key));
|
|
||||||
} else if (currentField.FieldType == typeof(int) || currentField.FieldType == typeof(int?)) {
|
|
||||||
currentField.SetValue(this, properties.GetIntProperty(key));
|
|
||||||
}
|
|
||||||
LOG.Debug("After: " + currentField.Name + "=" + currentField.GetValue(this));
|
|
||||||
} else {
|
|
||||||
LOG.Warn("Configuration for " + key + " not found! (Incorrect key?)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateLastUsedFieldValue(IField f) {
|
public void UpdateLastUsedFieldValue(IField f) {
|
||||||
if(f.Value != null) {
|
if(f.Value != null) {
|
||||||
string key = GetKeyForField(f);
|
string key = GetKeyForField(f);
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Greenshot.Core {
|
||||||
Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail
|
Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail
|
||||||
}
|
}
|
||||||
public enum OutputFormat {
|
public enum OutputFormat {
|
||||||
Bmp, Gif, Jepg, Png, Tiff
|
Bmp, Gif, Jpeg, Png, Tiff
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of CoreConfiguration.
|
/// Description of CoreConfiguration.
|
||||||
|
|
|
@ -36,13 +36,14 @@ namespace Greenshot.Configuration {
|
||||||
public class Language : LanguageContainer, ILanguage {
|
public class Language : LanguageContainer, ILanguage {
|
||||||
private static ILanguage uniqueInstance;
|
private static ILanguage uniqueInstance;
|
||||||
private const string LANGUAGE_FILENAME_PATTERN = @"language-*.xml";
|
private const string LANGUAGE_FILENAME_PATTERN = @"language-*.xml";
|
||||||
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
public static ILanguage GetInstance() {
|
public static ILanguage GetInstance() {
|
||||||
if(uniqueInstance == null) {
|
if(uniqueInstance == null) {
|
||||||
uniqueInstance = new LanguageContainer();
|
uniqueInstance = new LanguageContainer();
|
||||||
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
|
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
|
||||||
uniqueInstance.Load();
|
uniqueInstance.Load();
|
||||||
uniqueInstance.SetLanguage(AppConfig.GetInstance().Ui_Language);
|
uniqueInstance.SetLanguage(conf.Language);
|
||||||
Thread.CurrentThread.CurrentUICulture = new CultureInfo(uniqueInstance.CurrentLanguage);
|
Thread.CurrentThread.CurrentUICulture = new CultureInfo(uniqueInstance.CurrentLanguage);
|
||||||
}
|
}
|
||||||
return uniqueInstance;
|
return uniqueInstance;
|
||||||
|
|
|
@ -25,11 +25,14 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
public class FilenameHelper {
|
public class FilenameHelper {
|
||||||
private const int MAX_TITLE_LENGTH = 80;
|
private const int MAX_TITLE_LENGTH = 80;
|
||||||
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
private FilenameHelper() {
|
private FilenameHelper() {
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -82,22 +85,12 @@ namespace Greenshot.Helpers {
|
||||||
return FillPattern(pattern, captureDetails);
|
return FillPattern(pattern, captureDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFilenameFromPattern(string pattern, string imageFormat) {
|
public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat) {
|
||||||
return GetFilenameFromPattern(pattern, imageFormat, null);
|
return GetFilenameFromPattern(pattern, imageFormat, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFilenameFromPattern(string pattern, string imageFormat, ICaptureDetails captureDetails) {
|
public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails) {
|
||||||
string ext;
|
return FillPattern(pattern, captureDetails) + "." + imageFormat;
|
||||||
if (imageFormat.IndexOf('.') >= 0) {
|
|
||||||
ext = imageFormat.Substring(imageFormat.IndexOf('.')+1);
|
|
||||||
} else {
|
|
||||||
ext = imageFormat;
|
|
||||||
}
|
|
||||||
ext = ext.ToLower();
|
|
||||||
if(ext.Equals("jpeg")) {
|
|
||||||
ext = "jpg";
|
|
||||||
}
|
|
||||||
return FillPattern(pattern, captureDetails) + "." + ext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string FillPattern(string initialPattern, ICaptureDetails captureDetails) {
|
private static string FillPattern(string initialPattern, ICaptureDetails captureDetails) {
|
||||||
|
@ -127,9 +120,8 @@ namespace Greenshot.Helpers {
|
||||||
pattern = pattern.Replace("%user%", Environment.UserName);
|
pattern = pattern.Replace("%user%", Environment.UserName);
|
||||||
pattern = pattern.Replace("%hostname%", Environment.MachineName);
|
pattern = pattern.Replace("%hostname%", Environment.MachineName);
|
||||||
if(pattern.Contains("%NUM%")) {
|
if(pattern.Contains("%NUM%")) {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
uint num = conf.OutputFileIncrementingNumber++;
|
||||||
int num = conf.Output_File_IncrementingNumber++;
|
IniConfig.Save();
|
||||||
conf.Store();
|
|
||||||
pattern = pattern.Replace("%NUM%", zeroPad(num.ToString(), 6));
|
pattern = pattern.Replace("%NUM%", zeroPad(num.ToString(), 6));
|
||||||
}
|
}
|
||||||
// Use the last as it "might" have some nasty strings in it.
|
// Use the last as it "might" have some nasty strings in it.
|
||||||
|
|
|
@ -29,6 +29,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Forms;
|
using Greenshot.Forms;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ namespace Greenshot.Helpers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ImageOutput {
|
public class ImageOutput {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput));
|
||||||
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
private ImageOutput() {
|
private ImageOutput() {
|
||||||
}
|
}
|
||||||
|
@ -47,36 +49,29 @@ namespace Greenshot.Helpers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves image to stream with specified quality
|
/// Saves image to stream with specified quality
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SaveToStream(Image img, Stream stream, string extension, int quality) {
|
public static void SaveToStream(Image img, Stream stream, OutputFormat extension, int quality) {
|
||||||
ImageFormat imfo = null;
|
ImageFormat imfo = null;
|
||||||
|
|
||||||
// Make sure the extension is always without "." in front
|
switch (extension) {
|
||||||
if (extension.IndexOf('.') == 0) {
|
case OutputFormat.Bmp:
|
||||||
extension = extension.Substring(1);
|
imfo = ImageFormat.Bmp;
|
||||||
}
|
break;
|
||||||
|
case OutputFormat.Gif:
|
||||||
// Make sure the extension is always lowercase, before comparing with "jpg"
|
imfo = ImageFormat.Gif;
|
||||||
if (extension.ToLower().Equals("jpg")) {
|
break;
|
||||||
// we need jpeg string with e for reflection
|
case OutputFormat.Jpeg:
|
||||||
extension = "jpeg";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the extension and use it with the first character in uppercase
|
|
||||||
// for the GetProperty call
|
|
||||||
extension = extension.Substring(0, 1).ToUpper() + extension.Substring(1).ToLower();
|
|
||||||
try {
|
|
||||||
Type t = typeof(ImageFormat);
|
|
||||||
PropertyInfo pi = t.GetProperty(extension, typeof(ImageFormat));
|
|
||||||
imfo = (ImageFormat)pi.GetValue(null, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
MessageBox.Show(e.ToString());
|
|
||||||
MessageBox.Show("Could not use " + extension + " as image format. Using Jpeg.");
|
|
||||||
imfo = ImageFormat.Jpeg;
|
imfo = ImageFormat.Jpeg;
|
||||||
extension = imfo.ToString();
|
break;
|
||||||
|
case OutputFormat.Png:
|
||||||
|
imfo = ImageFormat.Png;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
imfo = ImageFormat.Png;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
PropertyItem pit = PropertyItemProvider.GetPropertyItem(0x0131, "Greenshot");
|
PropertyItem pit = PropertyItemProvider.GetPropertyItem(0x0131, "Greenshot");
|
||||||
img.SetPropertyItem(pit);
|
img.SetPropertyItem(pit);
|
||||||
if (extension.Equals("Jpeg")) {
|
if (imfo == ImageFormat.Jpeg) {
|
||||||
EncoderParameters parameters = new EncoderParameters(1);
|
EncoderParameters parameters = new EncoderParameters(1);
|
||||||
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
|
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
|
||||||
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
|
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
|
||||||
|
@ -98,16 +93,25 @@ namespace Greenshot.Helpers
|
||||||
if (!di.Exists) {
|
if (!di.Exists) {
|
||||||
Directory.CreateDirectory(di.FullName);
|
Directory.CreateDirectory(di.FullName);
|
||||||
}
|
}
|
||||||
|
string extension = Path.GetExtension(fullPath);
|
||||||
|
if (extension != null && extension.StartsWith(".")) {
|
||||||
|
extension = extension.Substring(1);
|
||||||
|
}
|
||||||
|
OutputFormat format = OutputFormat.Png;
|
||||||
|
try {
|
||||||
|
format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension);
|
||||||
|
} catch(ArgumentException ae) {
|
||||||
|
LOG.Warn("Couldn't parse extension: " + extension, ae);
|
||||||
|
}
|
||||||
// Create the stream and call SaveToStream
|
// Create the stream and call SaveToStream
|
||||||
using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
|
using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
|
||||||
SaveToStream(image, stream, Path.GetExtension(fullPath), quality);
|
SaveToStream(image, stream, format, quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform all registered code (e.g. Plugins) of file output
|
// Inform all registered code (e.g. Plugins) of file output
|
||||||
PluginHelper.instance.CreateImageOutputEvent(fullPath, image, captureDetails);
|
PluginHelper.instance.CreateImageOutputEvent(fullPath, image, captureDetails);
|
||||||
|
|
||||||
if ((bool)AppConfig.GetInstance().Output_File_CopyPathToClipboard) {
|
if (conf.OutputFileCopyPathToClipboard) {
|
||||||
ClipboardHelper.SetClipboardData(fullPath);
|
ClipboardHelper.SetClipboardData(fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +122,6 @@ namespace Greenshot.Helpers
|
||||||
/// <param name="img">the image to save</param>
|
/// <param name="img">the image to save</param>
|
||||||
/// <param name="fullPath">the absolute destination path including file name</param>
|
/// <param name="fullPath">the absolute destination path including file name</param>
|
||||||
public static void Save(Image img, string fullPath, ICaptureDetails captureDetails) {
|
public static void Save(Image img, string fullPath, ICaptureDetails captureDetails) {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
|
||||||
int q;
|
int q;
|
||||||
|
|
||||||
// Fix for bug 2912959
|
// Fix for bug 2912959
|
||||||
|
@ -128,12 +131,12 @@ namespace Greenshot.Helpers
|
||||||
isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
|
isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isJPG && (bool)conf.Output_File_PromptJpegQuality) {
|
if(isJPG && conf.OutputFilePromptJpegQuality) {
|
||||||
JpegQualityDialog jqd = new JpegQualityDialog();
|
JpegQualityDialog jqd = new JpegQualityDialog();
|
||||||
jqd.ShowDialog();
|
jqd.ShowDialog();
|
||||||
q = jqd.Quality;
|
q = jqd.Quality;
|
||||||
} else {
|
} else {
|
||||||
q = AppConfig.GetInstance().Output_File_JpegQuality;
|
q = conf.OutputFileJpegQuality;
|
||||||
}
|
}
|
||||||
Save(img, fullPath, q, captureDetails);
|
Save(img, fullPath, q, captureDetails);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +150,6 @@ namespace Greenshot.Helpers
|
||||||
|
|
||||||
public static string SaveWithDialog(Image image, ICaptureDetails captureDetails) {
|
public static string SaveWithDialog(Image image, ICaptureDetails captureDetails) {
|
||||||
string returnValue = null;
|
string returnValue = null;
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
|
||||||
SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails);
|
SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails);
|
||||||
DialogResult dialogResult = saveImageFileDialog.ShowDialog();
|
DialogResult dialogResult = saveImageFileDialog.ShowDialog();
|
||||||
if(dialogResult.Equals(DialogResult.OK)) {
|
if(dialogResult.Equals(DialogResult.OK)) {
|
||||||
|
@ -156,7 +158,7 @@ namespace Greenshot.Helpers
|
||||||
ImageOutput.Save(image, fileNameWithExtension, captureDetails);
|
ImageOutput.Save(image, fileNameWithExtension, captureDetails);
|
||||||
returnValue = fileNameWithExtension;
|
returnValue = fileNameWithExtension;
|
||||||
conf.Output_FileAs_Fullpath = fileNameWithExtension;
|
conf.Output_FileAs_Fullpath = fileNameWithExtension;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
} catch(System.Runtime.InteropServices.ExternalException) {
|
} catch(System.Runtime.InteropServices.ExternalException) {
|
||||||
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetInstance().GetString(LangKey.error));
|
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetInstance().GetString(LangKey.error));
|
||||||
//eagerlyCreatedDir = null;
|
//eagerlyCreatedDir = null;
|
||||||
|
|
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
@ -76,8 +77,8 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="image">The image to send</param>
|
/// <param name="image">The image to send</param>
|
||||||
/// <param name="captureDetails">ICaptureDetails</param>
|
/// <param name="captureDetails">ICaptureDetails</param>
|
||||||
public static void SendImage(Image image, ICaptureDetails captureDetails) {
|
public static void SendImage(Image image, ICaptureDetails captureDetails) {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
string filename = FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, conf.Output_File_Format, captureDetails);
|
string filename = FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, conf.OutputFileFormat, captureDetails);
|
||||||
string tmpFile = Path.Combine(Path.GetTempPath(),filename);
|
string tmpFile = Path.Combine(Path.GetTempPath(),filename);
|
||||||
LOG.Debug("Creating TMP File for Email: " + tmpFile);
|
LOG.Debug("Creating TMP File for Email: " + tmpFile);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Drawing;
|
using Greenshot.Drawing;
|
||||||
using Greenshot.Forms;
|
using Greenshot.Forms;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
|
@ -130,13 +131,13 @@ namespace Greenshot.Helpers {
|
||||||
public event OnImageOutputHandler OnImageOutput;
|
public event OnImageOutputHandler OnImageOutput;
|
||||||
private ContextMenuStrip mainMenu = null;
|
private ContextMenuStrip mainMenu = null;
|
||||||
|
|
||||||
public void SaveToStream(Image img, Stream stream, string extension, int quality) {
|
public void SaveToStream(Image img, Stream stream, OutputFormat extension, int quality) {
|
||||||
ImageOutput.SaveToStream(img, stream, extension, quality);
|
ImageOutput.SaveToStream(img, stream, extension, quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFilename(string format, ICaptureDetails captureDetails) {
|
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
return FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, format, captureDetails);
|
return FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, format, captureDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Greenshot.Helpers {
|
||||||
public PrintHelper(Image image, ICaptureDetails captureDetails) {
|
public PrintHelper(Image image, ICaptureDetails captureDetails) {
|
||||||
this.image = image;
|
this.image = image;
|
||||||
printDialog.UseEXDialog = true;
|
printDialog.UseEXDialog = true;
|
||||||
printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(AppConfig.GetInstance().Output_File_FilenamePattern, captureDetails);
|
printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
|
||||||
printDocument.PrintPage += DrawImageForPrint;
|
printDocument.PrintPage += DrawImageForPrint;
|
||||||
printDialog.Document = printDocument;
|
printDialog.Document = printDocument;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Drawing;
|
using Greenshot.Drawing;
|
||||||
|
|
||||||
namespace Greenshot.Forms {
|
namespace Greenshot.Forms {
|
||||||
|
@ -52,7 +53,7 @@ namespace Greenshot.Forms {
|
||||||
/// <param name="stream">The stream the image is stored on</param>
|
/// <param name="stream">The stream the image is stored on</param>
|
||||||
/// <param name="extension">The image type (extension), e.g. "png", "jpg", "bmp"</param>
|
/// <param name="extension">The image type (extension), e.g. "png", "jpg", "bmp"</param>
|
||||||
/// <param name="quality">Only needed for "jpg"</param>
|
/// <param name="quality">Only needed for "jpg"</param>
|
||||||
void SaveToStream(Stream stream, string extension, int quality);
|
void SaveToStream(Stream stream, OutputFormat extension, int quality);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
|
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
|
||||||
|
|
|
@ -25,6 +25,7 @@ using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Drawing;
|
using Greenshot.Drawing;
|
||||||
using Greenshot.Forms;
|
using Greenshot.Forms;
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ namespace Greenshot.Plugin {
|
||||||
/// <param name="stream">The Stream to save to</param>
|
/// <param name="stream">The Stream to save to</param>
|
||||||
/// <param name="format">The format to save with (png, jpg etc)</param>
|
/// <param name="format">The format to save with (png, jpg etc)</param>
|
||||||
/// <param name="quality">Jpeg quality</param>
|
/// <param name="quality">Jpeg quality</param>
|
||||||
void SaveToStream(Image image, Stream stream, string format, int quality);
|
void SaveToStream(Image image, Stream stream, OutputFormat format, int quality);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
||||||
|
@ -178,7 +179,7 @@ namespace Greenshot.Plugin {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="format">A string with the format</param>
|
/// <param name="format">A string with the format</param>
|
||||||
/// <returns>The filename which should be used to save the image</returns>
|
/// <returns>The filename which should be used to save the image</returns>
|
||||||
string GetFilename(string format, ICaptureDetails captureDetails);
|
string GetFilename(OutputFormat format, ICaptureDetails captureDetails);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a Thumbnail
|
/// Create a Thumbnail
|
||||||
|
|
|
@ -19,11 +19,14 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
|
using Greenshot.Editor;
|
||||||
|
|
||||||
namespace Greenshot.Controls {
|
namespace Greenshot.Controls {
|
||||||
public class ColorButton : ToolStripButton, INotifyPropertyChanged {
|
public class ColorButton : ToolStripButton, INotifyPropertyChanged {
|
||||||
|
@ -68,9 +71,9 @@ namespace Greenshot.Controls {
|
||||||
colorDialog.ShowDialog();
|
colorDialog.ShowDialog();
|
||||||
if (colorDialog.DialogResult != DialogResult.Cancel) {
|
if (colorDialog.DialogResult != DialogResult.Cancel) {
|
||||||
if(!colorDialog.Color.Equals(SelectedColor)) {
|
if(!colorDialog.Color.Equals(SelectedColor)) {
|
||||||
AppConfig conf = AppConfig.GetInstance();
|
EditorConfiguration conf = IniConfig.GetIniSection<EditorConfiguration>();
|
||||||
conf.Editor_RecentColors = colorDialog.RecentColors;
|
conf.Editor_RecentColors = colorDialog.RecentColors;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
SelectedColor = colorDialog.Color;
|
SelectedColor = colorDialog.Color;
|
||||||
if(PropertyChanged != null) {
|
if(PropertyChanged != null) {
|
||||||
PropertyChanged(this, new PropertyChangedEventArgs("SelectedColor"));
|
PropertyChanged(this, new PropertyChangedEventArgs("SelectedColor"));
|
||||||
|
|
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Capturing;
|
using Greenshot.Capturing;
|
||||||
using Greenshot.Configuration;
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Core;
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Drawing.Filters;
|
using Greenshot.Drawing.Filters;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
|
@ -50,7 +51,6 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
public FieldAggregator FieldAggregator = new FieldAggregator();
|
public FieldAggregator FieldAggregator = new FieldAggregator();
|
||||||
|
|
||||||
private AppConfig conf = AppConfig.GetInstance();
|
|
||||||
private ICaptureDetails captureDetails = null;
|
private ICaptureDetails captureDetails = null;
|
||||||
|
|
||||||
private int mX;
|
private int mX;
|
||||||
|
|
|
@ -291,7 +291,7 @@ namespace Greenshot.Forms {
|
||||||
get { return surface.CaptureDetails; }
|
get { return surface.CaptureDetails; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveToStream(Stream stream, string extension, int quality) {
|
public void SaveToStream(Stream stream, OutputFormat extension, int quality) {
|
||||||
using (Image image = surface.GetImageForExport()) {
|
using (Image image = surface.GetImageForExport()) {
|
||||||
ImageOutput.SaveToStream(image, stream, extension, quality);
|
ImageOutput.SaveToStream(image, stream, extension, quality);
|
||||||
}
|
}
|
||||||
|
|
34
GreenshotFlickrPlugin/FlickrConfiguration.cs
Normal file
34
GreenshotFlickrPlugin/FlickrConfiguration.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2010 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Greenshot.Core;
|
||||||
|
|
||||||
|
namespace GreenshotFlickrPlugin {
|
||||||
|
/// <summary>
|
||||||
|
/// Description of FlickrConfiguration.
|
||||||
|
/// </summary>
|
||||||
|
[IniSection("Flickr", Description="Greenshot Flickr Plugin configuration")]
|
||||||
|
public class FlickrConfiguration : IniSection {
|
||||||
|
[IniProperty("authentication.token", Description="Token for Flickr", DefaultValue="")]
|
||||||
|
public string Token;
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,17 +41,15 @@ namespace GreenshotFlickrPlugin {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FlickrPlugin : IGreenshotPlugin {
|
public class FlickrPlugin : IGreenshotPlugin {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FlickrPlugin));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FlickrPlugin));
|
||||||
private const string CONFIG_FILENAME = "flickr-config.properties";
|
|
||||||
private const string AUTHENTICATION_TOKEN_PROPERTY = "authentication.token";
|
|
||||||
private const string ApiKey = "f967e5148945cb3c4e149cc5be97796a";
|
private const string ApiKey = "f967e5148945cb3c4e149cc5be97796a";
|
||||||
private const string SharedSecret = "4180a21a1d2f8666";
|
private const string SharedSecret = "4180a21a1d2f8666";
|
||||||
private ILanguage lang = Language.GetInstance();
|
private ILanguage lang = Language.GetInstance();
|
||||||
private IGreenshotPluginHost host;
|
private IGreenshotPluginHost host;
|
||||||
private ICaptureHost captureHost = null;
|
private ICaptureHost captureHost = null;
|
||||||
private PluginAttribute myAttributes;
|
private PluginAttribute myAttributes;
|
||||||
private Properties config = null;
|
private FlickrConfiguration config;
|
||||||
|
|
||||||
public FlickrPlugin() { }
|
public FlickrPlugin() {}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of the IGreenshotPlugin.Initialize
|
/// Implementation of the IGreenshotPlugin.Initialize
|
||||||
|
@ -70,7 +68,7 @@ namespace GreenshotFlickrPlugin {
|
||||||
// Make sure the MODI-DLLs are found by adding a resolver
|
// Make sure the MODI-DLLs are found by adding a resolver
|
||||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyAssemblyResolver);
|
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyAssemblyResolver);
|
||||||
|
|
||||||
LoadConfig();
|
this.config = IniConfig.GetIniSection<FlickrConfiguration>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -100,12 +98,11 @@ namespace GreenshotFlickrPlugin {
|
||||||
public virtual void Configure() {
|
public virtual void Configure() {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.AppendLine("This plugin doesn't have a configuration screen.");
|
stringBuilder.AppendLine("This plugin doesn't have a configuration screen.");
|
||||||
stringBuilder.AppendLine("Configuration is stored at: " + Path.Combine(host.ConfigurationPath, CONFIG_FILENAME));
|
|
||||||
MessageBox.Show(stringBuilder.ToString());
|
MessageBox.Show(stringBuilder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method helps to resolve the MODI DLL files
|
/// This method helps to resolve the Flickr DLL file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender">object which is starting the resolve</param>
|
/// <param name="sender">object which is starting the resolve</param>
|
||||||
/// <param name="args">ResolveEventArgs describing the Assembly that needs to be found</param>
|
/// <param name="args">ResolveEventArgs describing the Assembly that needs to be found</param>
|
||||||
|
@ -120,24 +117,6 @@ namespace GreenshotFlickrPlugin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadConfig() {
|
|
||||||
string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME);
|
|
||||||
if (File.Exists(filename)) {
|
|
||||||
config = Properties.read(filename);
|
|
||||||
} else {
|
|
||||||
LOG.Debug("No flickr configuration found at: " + filename);
|
|
||||||
}
|
|
||||||
if (config == null) {
|
|
||||||
config = new Properties();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveConfig() {
|
|
||||||
string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME);
|
|
||||||
LOG.Debug("Saving configuration to: " + filename);
|
|
||||||
config.write(filename, "# The configuration file for the Greenshot Flickr Plugin");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will be called when the menu item in the Editor is clicked
|
/// This will be called when the menu item in the Editor is clicked
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -147,7 +126,7 @@ namespace GreenshotFlickrPlugin {
|
||||||
bool authentication = false;
|
bool authentication = false;
|
||||||
|
|
||||||
Flickr flickr = new Flickr(ApiKey, SharedSecret);
|
Flickr flickr = new Flickr(ApiKey, SharedSecret);
|
||||||
if(config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY) == null) {
|
if(config.Token == null) {
|
||||||
string frob = flickr.AuthGetFrob();
|
string frob = flickr.AuthGetFrob();
|
||||||
// Calculate the URL at Flickr to redirect the user to
|
// Calculate the URL at Flickr to redirect the user to
|
||||||
string flickrUrl = flickr.AuthCalcUrl(frob, AuthLevel.Write);
|
string flickrUrl = flickr.AuthCalcUrl(frob, AuthLevel.Write);
|
||||||
|
@ -164,8 +143,8 @@ namespace GreenshotFlickrPlugin {
|
||||||
LOG.Debug("User id is " + auth.User.UserId);
|
LOG.Debug("User id is " + auth.User.UserId);
|
||||||
LOG.Debug("User name is " + auth.User.UserName);
|
LOG.Debug("User name is " + auth.User.UserName);
|
||||||
LOG.Debug("User fullname is " + auth.User.FullName);
|
LOG.Debug("User fullname is " + auth.User.FullName);
|
||||||
config.AddProperty(AUTHENTICATION_TOKEN_PROPERTY, auth.Token);
|
config.Token = auth.Token;
|
||||||
SaveConfig();
|
IniConfig.Save();
|
||||||
authentication = true;
|
authentication = true;
|
||||||
} catch (FlickrException ex) {
|
} catch (FlickrException ex) {
|
||||||
// If user did not authenticat your application
|
// If user did not authenticat your application
|
||||||
|
@ -181,12 +160,12 @@ namespace GreenshotFlickrPlugin {
|
||||||
MessageBox.Show("No Authentication made!");
|
MessageBox.Show("No Authentication made!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
flickr.AuthToken = config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY);
|
flickr.AuthToken = config.Token;
|
||||||
FlickrUploadForm uploader = new FlickrUploadForm();
|
FlickrUploadForm uploader = new FlickrUploadForm();
|
||||||
DialogResult uploaderResult = uploader.ShowDialog();
|
DialogResult uploaderResult = uploader.ShowDialog();
|
||||||
if (uploaderResult == DialogResult.OK) {
|
if (uploaderResult == DialogResult.OK) {
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
try {
|
try {
|
||||||
string file = "test.png";
|
string file = "test.png";
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="FlickrConfiguration.cs" />
|
||||||
<Compile Include="FlickrPlugin.cs" />
|
<Compile Include="FlickrPlugin.cs" />
|
||||||
<Compile Include="Forms\FlickrAuthenticationForm.cs" />
|
<Compile Include="Forms\FlickrAuthenticationForm.cs" />
|
||||||
<Compile Include="Forms\FlickrAuthenticationForm.Designer.cs">
|
<Compile Include="Forms\FlickrAuthenticationForm.Designer.cs">
|
||||||
|
|
|
@ -84,9 +84,6 @@
|
||||||
<Generator>MSDiscoCodeGenerator</Generator>
|
<Generator>MSDiscoCodeGenerator</Generator>
|
||||||
<LastGenOutput>Reference.cs</LastGenOutput>
|
<LastGenOutput>Reference.cs</LastGenOutput>
|
||||||
</None>
|
</None>
|
||||||
<EmbeddedResource Include="Forms\LoginForm.resx">
|
|
||||||
<DependentUpon>LoginForm.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Forms" />
|
<Folder Include="Forms" />
|
||||||
|
|
|
@ -95,9 +95,6 @@ namespace Jira {
|
||||||
|
|
||||||
public class JiraConnector {
|
public class JiraConnector {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
||||||
private const string JIRA_URL_PROPERTY = "url";
|
|
||||||
private const string JIRA_USER_PROPERTY = "user";
|
|
||||||
private const string JIRA_PASSWORD_PROPERTY = "password";
|
|
||||||
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
|
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
|
||||||
private string credentials = null;
|
private string credentials = null;
|
||||||
private DateTime loggedInTime = DateTime.Now;
|
private DateTime loggedInTime = DateTime.Now;
|
||||||
|
|
|
@ -26,17 +26,17 @@ using Greenshot.Core;
|
||||||
|
|
||||||
namespace GreenshotJiraPlugin {
|
namespace GreenshotJiraPlugin {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of CoreConfiguration.
|
/// Description of JiraConfiguration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[IniSection("JIRA", Description="Greenshot JIRA Plugin configuration")]
|
[IniSection("Jira", Description="Greenshot Jira Plugin configuration")]
|
||||||
public class JiraConfiguration : IniSection {
|
public class JiraConfiguration : IniSection {
|
||||||
[IniProperty("Url", Description="Url to Jira system, including wsdl.", DefaultValue="http://jira/rpc/soap/jirasoapservice-v2?wsdl")]
|
[IniProperty("Url", Description="Url to Jira system, including wsdl.", DefaultValue="http://jira/rpc/soap/jirasoapservice-v2?wsdl")]
|
||||||
public string Url;
|
public string Url;
|
||||||
[IniProperty("Timeout", Description="Session timeout in minutes", DefaultValue="30")]
|
[IniProperty("Timeout", Description="Session timeout in minutes", DefaultValue="30")]
|
||||||
public int Timeout;
|
public int Timeout;
|
||||||
[IniProperty("User", Description="User for the JIRA System")]
|
[IniProperty("User", Description="User for the Jira System")]
|
||||||
public string User;
|
public string User;
|
||||||
[IniProperty("Password", Description="Password for the JIRA System, belonging to user.")]
|
[IniProperty("Password", Description="Password for the Jira System, belonging to user.")]
|
||||||
public string Password;
|
public string Password;
|
||||||
|
|
||||||
// This will not be stored
|
// This will not be stored
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace GreenshotJiraPlugin {
|
||||||
DialogResult result = jiraForm.ShowDialog();
|
DialogResult result = jiraForm.ShowDialog();
|
||||||
if (result == DialogResult.OK) {
|
if (result == DialogResult.OK) {
|
||||||
using (MemoryStream stream = new MemoryStream()) {
|
using (MemoryStream stream = new MemoryStream()) {
|
||||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||||
byte [] buffer = stream.GetBuffer();
|
byte [] buffer = stream.GetBuffer();
|
||||||
try {
|
try {
|
||||||
jiraForm.upload(buffer);
|
jiraForm.upload(buffer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue