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) {
|
||||
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);
|
||||
|
||||
using (FileStream stream = File.Create(filePath)) {
|
||||
|
@ -177,10 +177,10 @@ namespace GreenshotOCR {
|
|||
graphics.Clear(Color.White);
|
||||
graphics.DrawImage(capturedImage, Point.Empty);
|
||||
}
|
||||
host.SaveToStream(tmpImage, stream, "bmp", 100);
|
||||
host.SaveToStream(tmpImage, stream, OutputFormat.Bmp, 100);
|
||||
}
|
||||
} 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 Rectangle captureRect = Rectangle.Empty;
|
||||
private ICapture capture = null;
|
||||
private AppConfig conf = AppConfig.GetInstance();
|
||||
private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private ILanguage lang = Language.GetInstance();
|
||||
|
||||
public CaptureForm() {
|
||||
|
@ -70,10 +70,10 @@ namespace Greenshot.Forms {
|
|||
}
|
||||
|
||||
void DoCaptureFeedback() {
|
||||
if((bool)conf.Ui_Effects_CameraSound) {
|
||||
if(conf.PlayCameraSound) {
|
||||
SoundHelper.Play();
|
||||
}
|
||||
if((bool)conf.Ui_Effects_Flashlight) {
|
||||
if(conf.ShowFlash) {
|
||||
FlashlightForm flashlightForm = new FlashlightForm();
|
||||
flashlightForm.Bounds = capture.ScreenBounds;
|
||||
flashlightForm.FadeIn();
|
||||
|
@ -153,14 +153,14 @@ namespace Greenshot.Forms {
|
|||
capture.CaptureDetails.CaptureMode = mode;
|
||||
|
||||
// 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
|
||||
capture = WindowCapture.CaptureCursor(capture);
|
||||
capture.CursorVisible = false;
|
||||
// Check if needed
|
||||
if (captureMouseCursor && mode != CaptureMode.Clipboard && mode != CaptureMode.File) {
|
||||
capture.CursorVisible = (conf.Capture_Mousepointer.HasValue && conf.Capture_Mousepointer.Value);
|
||||
capture.CursorVisible = conf.CaptureMousepointer;
|
||||
}
|
||||
|
||||
switch(mode) {
|
||||
|
@ -240,27 +240,27 @@ namespace Greenshot.Forms {
|
|||
}
|
||||
|
||||
private ICapture AddConfiguredDestination(ICapture capture) {
|
||||
if ((conf.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault) {
|
||||
if (conf.OutputDestinations.Contains(Destination.FileDefault)) {
|
||||
capture.CaptureDetails.AddDestination(CaptureDestination.File);
|
||||
}
|
||||
|
||||
if ((conf.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog) {
|
||||
if (conf.OutputDestinations.Contains(Destination.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);
|
||||
}
|
||||
|
||||
if ((conf.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer) {
|
||||
if (conf.OutputDestinations.Contains(Destination.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);
|
||||
}
|
||||
|
||||
if ((conf.Output_Destinations & ScreenshotDestinations.EMail) == ScreenshotDestinations.EMail) {
|
||||
if (conf.OutputDestinations.Contains(Destination.EMail)) {
|
||||
capture.CaptureDetails.AddDestination(CaptureDestination.EMail);
|
||||
}
|
||||
return capture;
|
||||
|
@ -334,7 +334,7 @@ namespace Greenshot.Forms {
|
|||
// or use the file that was written
|
||||
bool fileWritten = false;
|
||||
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);
|
||||
|
||||
// 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
|
||||
*/
|
||||
private void finishCapture() {
|
||||
bool fromWindow = (conf.Capture_Complete_Window.HasValue && conf.Capture_Complete_Window.Value);
|
||||
|
||||
// Get title
|
||||
if (selectedCaptureWindow != null) {
|
||||
if (capture == null) {
|
||||
|
@ -418,7 +416,7 @@ namespace Greenshot.Forms {
|
|||
if ( (captureMode == CaptureMode.Window || captureMode == CaptureMode.ActiveWindow) && selectedCaptureWindow != null) {
|
||||
Image capturedWindowImage = null;
|
||||
// What type of capturing? (From Screen or from window)
|
||||
if (fromWindow) {
|
||||
if (conf.CaptureCompleteWindow) {
|
||||
// "Capture" the windows content
|
||||
capturedWindowImage = selectedCaptureWindow.Image;
|
||||
if (capturedWindowImage != null) {
|
||||
|
@ -510,7 +508,7 @@ namespace Greenshot.Forms {
|
|||
capture = WindowCapture.CaptureScreen(capture);
|
||||
selectedCaptureWindow = new WindowDetails(hWnd);
|
||||
// Content only
|
||||
if ((conf.Capture_Window_Content.HasValue && conf.Capture_Window_Content.Value)) {
|
||||
if (conf.CaptureWindowContent) {
|
||||
// Print Tree for debugging
|
||||
selectedCaptureWindow.PrintTree("");
|
||||
WindowDetails contentWindow = selectedCaptureWindow.GetContent();
|
||||
|
@ -553,7 +551,7 @@ namespace Greenshot.Forms {
|
|||
if (windowRectangle.Contains(Cursor.Position)) {
|
||||
WindowDetails selectedChild = null;
|
||||
// Content only
|
||||
if ((conf.Capture_Window_Content.HasValue && conf.Capture_Window_Content.Value)) {
|
||||
if (conf.CaptureWindowContent) {
|
||||
WindowDetails childWindow = window.GetContent();
|
||||
if (childWindow != null && childWindow.Rectangle.Contains(Cursor.Position)) {
|
||||
return childWindow;
|
||||
|
|
|
@ -137,14 +137,6 @@ namespace Greenshot {
|
|||
}
|
||||
StringBuilder helpOutput = new StringBuilder();
|
||||
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();
|
||||
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\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");
|
||||
}
|
||||
Console.WriteLine(helpOutput.ToString());
|
||||
|
||||
// If attach didn't work, wait for key otherwise the console will close to quickly
|
||||
|
@ -371,7 +362,7 @@ namespace Greenshot {
|
|||
exit();
|
||||
break;
|
||||
case CommandEnum.ReloadConfig:
|
||||
AppConfig.Reload();
|
||||
// TODO: Reload the configuration
|
||||
// Even update language when needed
|
||||
UpdateUI();
|
||||
break;
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Configuration;
|
||||
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Forms;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Greenshot.Test
|
||||
{
|
||||
|
@ -62,12 +62,12 @@ namespace Greenshot.Test
|
|||
|
||||
[Test]
|
||||
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_File_Path = @"c:\path\to\greenshot_testdir\";
|
||||
conf.Output_File_FilenamePattern = "gstest_%NUM%";
|
||||
conf.Output_File_Format = "Jpeg";
|
||||
conf.Output_File_IncrementingNumber = 28;
|
||||
conf.OutputFileFilenamePattern = "gstest_%NUM%";
|
||||
conf.OutputFileFormat = OutputFormat.Jpeg;
|
||||
conf.OutputFileIncrementingNumber = 28;
|
||||
SaveImageFileDialog sifd = new SaveImageFileDialog();
|
||||
|
||||
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
|
||||
/// </summary>
|
||||
namespace Confluence {
|
||||
#region transport classes
|
||||
public class Page {
|
||||
public Page(RemotePage page) {
|
||||
id = page.id;
|
||||
|
@ -42,101 +43,43 @@ namespace Confluence {
|
|||
set;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class ConfluenceConnector {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
||||
private const string CONFLUENCE_URL_PROPERTY = "url";
|
||||
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 const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
|
||||
|
||||
private string credentials = null;
|
||||
private DateTime loggedInTime = DateTime.Now;
|
||||
private bool loggedIn = false;
|
||||
private string tmpPassword = null;
|
||||
private Properties config;
|
||||
private ConfluenceConfiguration config;
|
||||
private ConfluenceSoapServiceService confluence;
|
||||
private Dictionary<string, string> userMap = new Dictionary<string, string>();
|
||||
|
||||
public ConfluenceConnector(string configurationPath) {
|
||||
this.configurationPath = configurationPath;
|
||||
this.config = LoadConfig();
|
||||
this.config = IniConfig.GetIniSection<ConfluenceConfiguration>();
|
||||
confluence = new ConfluenceSoapServiceService();
|
||||
confluence.Url = config.GetProperty(CONFLUENCE_URL_PROPERTY);
|
||||
confluence.Url = config.Url;
|
||||
}
|
||||
|
||||
~ConfluenceConnector() {
|
||||
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() {
|
||||
logout();
|
||||
try {
|
||||
if (HasPassword()) {
|
||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), config.GetProperty(CONFLUENCE_PASSWORD_PROPERTY));
|
||||
} else if (tmpPassword != null) {
|
||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), tmpPassword);
|
||||
if (config.HasPassword()) {
|
||||
this.credentials = confluence.login(config.User, config.Password);
|
||||
} else if (config.HasTmpPassword()) {
|
||||
this.credentials = confluence.login(config.User, config.TmpPassword);
|
||||
} else {
|
||||
LoginForm pwForm = new LoginForm();
|
||||
pwForm.User = config.GetProperty(CONFLUENCE_USER_PROPERTY);
|
||||
pwForm.Url = config.GetProperty(CONFLUENCE_URL_PROPERTY);
|
||||
DialogResult result = pwForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
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);
|
||||
if (config.ShowConfigDialog()) {
|
||||
if (config.HasPassword()) {
|
||||
this.credentials = confluence.login(config.User, config.Password);
|
||||
} else if (config.HasTmpPassword()) {
|
||||
this.credentials = confluence.login(config.User, config.TmpPassword);
|
||||
}
|
||||
this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), tmpPassword);
|
||||
} else {
|
||||
throw new Exception("User pressed cancel!");
|
||||
}
|
||||
|
@ -146,12 +89,13 @@ namespace Confluence {
|
|||
} catch (Exception e) {
|
||||
this.loggedIn = false;
|
||||
this.credentials = null;
|
||||
e.Data.Add("user",config.GetProperty(CONFLUENCE_USER_PROPERTY));
|
||||
e.Data.Add("url",config.GetProperty(CONFLUENCE_URL_PROPERTY));
|
||||
if (e.Message.Contains("com.atlassian.confluence.rpc.AuthenticationFailedException")) {
|
||||
e.Data.Add("user",config.User);
|
||||
e.Data.Add("url",config.Url);
|
||||
if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
|
||||
// Login failed due to wrong user or password, password should be removed!
|
||||
this.tmpPassword = null;
|
||||
throw new Exception(e.Message.Replace("com.atlassian.confluence.rpc.AuthenticationFailedException: ",""));
|
||||
config.Password = null;
|
||||
config.TmpPassword = null;
|
||||
throw new Exception(e.Message.Replace(AUTH_FAILED_EXCEPTION_NAME+ ": ",""));
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -167,7 +111,7 @@ namespace Confluence {
|
|||
|
||||
private void checkCredentials() {
|
||||
if (loggedIn) {
|
||||
if (loggedInTime.AddMinutes(DEFAULT_TIMEOUT).CompareTo(DateTime.Now) < 0) {
|
||||
if (loggedInTime.AddMinutes(config.Timeout-1).CompareTo(DateTime.Now) < 0) {
|
||||
logout();
|
||||
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
|
||||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
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());
|
||||
IniConfig.GetIniSection<ConfluenceConfiguration>().ShowConfigDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -110,21 +107,21 @@ namespace GreenshotConfluencePlugin {
|
|||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
|
||||
ConfluenceForm confluenceForm = new ConfluenceForm(confluenceConnector);
|
||||
confluenceForm.setFilename(host.GetFilename("png", imageEditor.CaptureDetails));
|
||||
confluenceForm.setFilename(host.GetFilename(OutputFormat.Png, imageEditor.CaptureDetails));
|
||||
DialogResult result = confluenceForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
||||
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||
byte [] buffer = stream.GetBuffer();
|
||||
try {
|
||||
confluenceForm.upload(buffer);
|
||||
LOG.Debug("Uploaded to Confluence.");
|
||||
MessageBox.Show(lang.GetString(LangKey.upload_success));
|
||||
} catch(Exception e) {
|
||||
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.label_url = new System.Windows.Forms.Label();
|
||||
this.textBoxUrl = new System.Windows.Forms.TextBox();
|
||||
this.checkBoxDoNotStorePassword = new System.Windows.Forms.CheckBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// 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.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.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.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.Text = "Password";
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonOK.TabIndex = 2;
|
||||
|
@ -85,7 +88,8 @@ namespace GreenshotConfluencePlugin {
|
|||
//
|
||||
// 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.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCancel.TabIndex = 3;
|
||||
|
@ -97,37 +101,50 @@ namespace GreenshotConfluencePlugin {
|
|||
//
|
||||
this.label_user.Location = new System.Drawing.Point(12, 47);
|
||||
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.Text = "User";
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(190, 20);
|
||||
this.textBoxUser.Size = new System.Drawing.Size(276, 20);
|
||||
this.textBoxUser.TabIndex = 4;
|
||||
//
|
||||
// label_url
|
||||
//
|
||||
this.label_url.Location = new System.Drawing.Point(12, 21);
|
||||
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.Text = "Url";
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(190, 20);
|
||||
this.textBoxUrl.Size = new System.Drawing.Size(276, 20);
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
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.textBoxUrl);
|
||||
this.Controls.Add(this.label_user);
|
||||
|
@ -137,10 +154,11 @@ namespace GreenshotConfluencePlugin {
|
|||
this.Controls.Add(this.label_password);
|
||||
this.Controls.Add(this.textBoxPassword);
|
||||
this.Name = "LoginForm";
|
||||
this.Text = "Please enter your Confluence password";
|
||||
this.Text = "Please enter your Confluence data";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
private System.Windows.Forms.CheckBox checkBoxDoNotStorePassword;
|
||||
private System.Windows.Forms.TextBox textBoxUrl;
|
||||
private System.Windows.Forms.Label label_url;
|
||||
private System.Windows.Forms.TextBox textBoxUser;
|
||||
|
@ -149,6 +167,5 @@ namespace GreenshotConfluencePlugin {
|
|||
private System.Windows.Forms.TextBox textBoxPassword;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Button buttonOK;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ using Greenshot.Core;
|
|||
|
||||
namespace GreenshotConfluencePlugin {
|
||||
/// <summary>
|
||||
/// Description of LoginForm.
|
||||
/// Description of PasswordRequestForm.
|
||||
/// </summary>
|
||||
public partial class LoginForm : Form {
|
||||
private ILanguage lang = Language.GetInstance();
|
||||
|
@ -45,6 +45,7 @@ namespace GreenshotConfluencePlugin {
|
|||
this.label_password.Text = lang.GetString(LangKey.label_password);
|
||||
this.buttonOK.Text = lang.GetString(LangKey.OK);
|
||||
this.buttonCancel.Text = lang.GetString(LangKey.CANCEL);
|
||||
this.checkBoxDoNotStorePassword.Text = lang.GetString(LangKey.label_no_password_store);
|
||||
this.Text = lang.GetString(LangKey.login_title);
|
||||
}
|
||||
|
||||
|
@ -63,6 +64,11 @@ namespace GreenshotConfluencePlugin {
|
|||
set {textBoxPassword.Text = value;}
|
||||
}
|
||||
|
||||
public bool DoNotStorePassword {
|
||||
get {return checkBoxDoNotStorePassword.Checked;}
|
||||
set {checkBoxDoNotStorePassword.Checked = value;}
|
||||
}
|
||||
|
||||
void ButtonOKClick(object sender, EventArgs e) {
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConfluenceConfiguration.cs" />
|
||||
<Compile Include="ConfluencePluginBase.cs" />
|
||||
<Compile Include="Forms\ConfluenceForm.cs" />
|
||||
<Compile Include="Forms\ConfluenceForm.Designer.cs">
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace GreenshotConfluencePlugin {
|
|||
label_url,
|
||||
label_user,
|
||||
label_password,
|
||||
label_no_password_store,
|
||||
OK,
|
||||
CANCEL,
|
||||
upload_success,
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
<resource name="label_password">
|
||||
Password
|
||||
</resource>
|
||||
<resource name="label_no_password_store">
|
||||
Kennwort nicht speichern
|
||||
</resource>
|
||||
<resource name="OK">
|
||||
OK
|
||||
</resource>
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<resource name="label_password">
|
||||
Password
|
||||
</resource>
|
||||
<resource name="label_no_password_store">
|
||||
Do not store the password
|
||||
</resource>
|
||||
<resource name="login_title">
|
||||
Please enter your Confluence login data
|
||||
</resource>
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<resource name="label_password">
|
||||
Password
|
||||
</resource>
|
||||
<resource name="label_no_password_store">
|
||||
Het wachtwoord niet opslaan
|
||||
</resource>
|
||||
<resource name="login_title">
|
||||
Geef uw Confluence login data
|
||||
</resource>
|
||||
|
|
|
@ -36,8 +36,6 @@ using Greenshot.Drawing;
|
|||
using Greenshot.Drawing.Fields;
|
||||
|
||||
namespace Greenshot.Configuration {
|
||||
public enum ScreenshotDestinations {Editor=1, FileDefault=2, FileWithDialog=4, Clipboard=8, Printer=16, EMail=32}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
@ -48,68 +46,10 @@ namespace Greenshot.Configuration {
|
|||
public class 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;
|
||||
|
||||
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>
|
||||
/// a private constructor because this is a singleton
|
||||
/// </summary>
|
||||
|
@ -122,170 +62,11 @@ namespace Greenshot.Configuration {
|
|||
/// <returns></returns>
|
||||
public static AppConfig GetInstance() {
|
||||
if (instance == null) {
|
||||
instance = Load();
|
||||
instance = new AppConfig();
|
||||
}
|
||||
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) {
|
||||
if(f.Value != null) {
|
||||
string key = GetKeyForField(f);
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Greenshot.Core {
|
|||
Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail
|
||||
}
|
||||
public enum OutputFormat {
|
||||
Bmp, Gif, Jepg, Png, Tiff
|
||||
Bmp, Gif, Jpeg, Png, Tiff
|
||||
}
|
||||
/// <summary>
|
||||
/// Description of CoreConfiguration.
|
||||
|
|
|
@ -36,13 +36,14 @@ namespace Greenshot.Configuration {
|
|||
public class Language : LanguageContainer, ILanguage {
|
||||
private static ILanguage uniqueInstance;
|
||||
private const string LANGUAGE_FILENAME_PATTERN = @"language-*.xml";
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
public static ILanguage GetInstance() {
|
||||
if(uniqueInstance == null) {
|
||||
uniqueInstance = new LanguageContainer();
|
||||
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
|
||||
uniqueInstance.Load();
|
||||
uniqueInstance.SetLanguage(AppConfig.GetInstance().Ui_Language);
|
||||
uniqueInstance.SetLanguage(conf.Language);
|
||||
Thread.CurrentThread.CurrentUICulture = new CultureInfo(uniqueInstance.CurrentLanguage);
|
||||
}
|
||||
return uniqueInstance;
|
||||
|
|
|
@ -25,11 +25,14 @@ using System.Windows.Forms;
|
|||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
public class FilenameHelper {
|
||||
private const int MAX_TITLE_LENGTH = 80;
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private FilenameHelper() {
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -82,22 +85,12 @@ namespace Greenshot.Helpers {
|
|||
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);
|
||||
}
|
||||
|
||||
public static string GetFilenameFromPattern(string pattern, string imageFormat, ICaptureDetails captureDetails) {
|
||||
string ext;
|
||||
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;
|
||||
public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails) {
|
||||
return FillPattern(pattern, captureDetails) + "." + imageFormat;
|
||||
}
|
||||
|
||||
private static string FillPattern(string initialPattern, ICaptureDetails captureDetails) {
|
||||
|
@ -127,9 +120,8 @@ namespace Greenshot.Helpers {
|
|||
pattern = pattern.Replace("%user%", Environment.UserName);
|
||||
pattern = pattern.Replace("%hostname%", Environment.MachineName);
|
||||
if(pattern.Contains("%NUM%")) {
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
int num = conf.Output_File_IncrementingNumber++;
|
||||
conf.Store();
|
||||
uint num = conf.OutputFileIncrementingNumber++;
|
||||
IniConfig.Save();
|
||||
pattern = pattern.Replace("%NUM%", zeroPad(num.ToString(), 6));
|
||||
}
|
||||
// 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.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
|
@ -39,6 +40,7 @@ namespace Greenshot.Helpers
|
|||
/// </summary>
|
||||
public class ImageOutput {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private ImageOutput() {
|
||||
}
|
||||
|
@ -47,36 +49,29 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Saves image to stream with specified quality
|
||||
/// </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;
|
||||
|
||||
// Make sure the extension is always without "." in front
|
||||
if (extension.IndexOf('.') == 0) {
|
||||
extension = extension.Substring(1);
|
||||
}
|
||||
|
||||
// Make sure the extension is always lowercase, before comparing with "jpg"
|
||||
if (extension.ToLower().Equals("jpg")) {
|
||||
// we need jpeg string with e for reflection
|
||||
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.");
|
||||
switch (extension) {
|
||||
case OutputFormat.Bmp:
|
||||
imfo = ImageFormat.Bmp;
|
||||
break;
|
||||
case OutputFormat.Gif:
|
||||
imfo = ImageFormat.Gif;
|
||||
break;
|
||||
case OutputFormat.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");
|
||||
img.SetPropertyItem(pit);
|
||||
if (extension.Equals("Jpeg")) {
|
||||
if (imfo == ImageFormat.Jpeg) {
|
||||
EncoderParameters parameters = new EncoderParameters(1);
|
||||
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
|
||||
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
|
||||
|
@ -98,16 +93,25 @@ namespace Greenshot.Helpers
|
|||
if (!di.Exists) {
|
||||
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
|
||||
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
|
||||
PluginHelper.instance.CreateImageOutputEvent(fullPath, image, captureDetails);
|
||||
|
||||
if ((bool)AppConfig.GetInstance().Output_File_CopyPathToClipboard) {
|
||||
if (conf.OutputFileCopyPathToClipboard) {
|
||||
ClipboardHelper.SetClipboardData(fullPath);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +122,6 @@ namespace Greenshot.Helpers
|
|||
/// <param name="img">the image to save</param>
|
||||
/// <param name="fullPath">the absolute destination path including file name</param>
|
||||
public static void Save(Image img, string fullPath, ICaptureDetails captureDetails) {
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
int q;
|
||||
|
||||
// Fix for bug 2912959
|
||||
|
@ -128,12 +131,12 @@ namespace Greenshot.Helpers
|
|||
isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
|
||||
}
|
||||
|
||||
if(isJPG && (bool)conf.Output_File_PromptJpegQuality) {
|
||||
if(isJPG && conf.OutputFilePromptJpegQuality) {
|
||||
JpegQualityDialog jqd = new JpegQualityDialog();
|
||||
jqd.ShowDialog();
|
||||
q = jqd.Quality;
|
||||
} else {
|
||||
q = AppConfig.GetInstance().Output_File_JpegQuality;
|
||||
q = conf.OutputFileJpegQuality;
|
||||
}
|
||||
Save(img, fullPath, q, captureDetails);
|
||||
}
|
||||
|
@ -147,7 +150,6 @@ namespace Greenshot.Helpers
|
|||
|
||||
public static string SaveWithDialog(Image image, ICaptureDetails captureDetails) {
|
||||
string returnValue = null;
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails);
|
||||
DialogResult dialogResult = saveImageFileDialog.ShowDialog();
|
||||
if(dialogResult.Equals(DialogResult.OK)) {
|
||||
|
@ -156,7 +158,7 @@ namespace Greenshot.Helpers
|
|||
ImageOutput.Save(image, fileNameWithExtension, captureDetails);
|
||||
returnValue = fileNameWithExtension;
|
||||
conf.Output_FileAs_Fullpath = fileNameWithExtension;
|
||||
conf.Store();
|
||||
IniConfig.Save();
|
||||
} catch(System.Runtime.InteropServices.ExternalException) {
|
||||
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetInstance().GetString(LangKey.error));
|
||||
//eagerlyCreatedDir = null;
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
|||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Plugin;
|
||||
using Microsoft.Win32;
|
||||
|
||||
|
@ -76,8 +77,8 @@ namespace Greenshot.Helpers {
|
|||
/// <param name="image">The image to send</param>
|
||||
/// <param name="captureDetails">ICaptureDetails</param>
|
||||
public static void SendImage(Image image, ICaptureDetails captureDetails) {
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
string filename = FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, conf.Output_File_Format, captureDetails);
|
||||
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
string filename = FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, conf.OutputFileFormat, captureDetails);
|
||||
string tmpFile = Path.Combine(Path.GetTempPath(),filename);
|
||||
LOG.Debug("Creating TMP File for Email: " + tmpFile);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ using System.Windows.Forms;
|
|||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
|
@ -130,13 +131,13 @@ namespace Greenshot.Helpers {
|
|||
public event OnImageOutputHandler OnImageOutput;
|
||||
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);
|
||||
}
|
||||
|
||||
public string GetFilename(string format, ICaptureDetails captureDetails) {
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
return FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, format, captureDetails);
|
||||
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
||||
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
return FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, format, captureDetails);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Greenshot.Helpers {
|
|||
public PrintHelper(Image image, ICaptureDetails captureDetails) {
|
||||
this.image = image;
|
||||
printDialog.UseEXDialog = true;
|
||||
printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(AppConfig.GetInstance().Output_File_FilenamePattern, captureDetails);
|
||||
printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
|
||||
printDocument.PrintPage += DrawImageForPrint;
|
||||
printDialog.Document = printDocument;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.IO;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing;
|
||||
|
||||
namespace Greenshot.Forms {
|
||||
|
@ -52,7 +53,7 @@ namespace Greenshot.Forms {
|
|||
/// <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="quality">Only needed for "jpg"</param>
|
||||
void SaveToStream(Stream stream, string extension, int quality);
|
||||
void SaveToStream(Stream stream, OutputFormat extension, int quality);
|
||||
|
||||
/// <summary>
|
||||
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
|
||||
|
|
|
@ -25,6 +25,7 @@ using System.IO;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Forms;
|
||||
|
||||
|
@ -170,7 +171,7 @@ namespace Greenshot.Plugin {
|
|||
/// <param name="stream">The Stream to save to</param>
|
||||
/// <param name="format">The format to save with (png, jpg etc)</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>
|
||||
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
||||
|
@ -178,7 +179,7 @@ namespace Greenshot.Plugin {
|
|||
/// </summary>
|
||||
/// <param name="format">A string with the format</param>
|
||||
/// <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>
|
||||
/// Create a Thumbnail
|
||||
|
|
|
@ -19,11 +19,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Editor;
|
||||
|
||||
namespace Greenshot.Controls {
|
||||
public class ColorButton : ToolStripButton, INotifyPropertyChanged {
|
||||
|
@ -68,9 +71,9 @@ namespace Greenshot.Controls {
|
|||
colorDialog.ShowDialog();
|
||||
if (colorDialog.DialogResult != DialogResult.Cancel) {
|
||||
if(!colorDialog.Color.Equals(SelectedColor)) {
|
||||
AppConfig conf = AppConfig.GetInstance();
|
||||
EditorConfiguration conf = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
conf.Editor_RecentColors = colorDialog.RecentColors;
|
||||
conf.Store();
|
||||
IniConfig.Save();
|
||||
SelectedColor = colorDialog.Color;
|
||||
if(PropertyChanged != null) {
|
||||
PropertyChanged(this, new PropertyChangedEventArgs("SelectedColor"));
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
|||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Drawing.Filters;
|
||||
using Greenshot.Helpers;
|
||||
|
@ -50,7 +51,6 @@ namespace Greenshot.Drawing {
|
|||
|
||||
public FieldAggregator FieldAggregator = new FieldAggregator();
|
||||
|
||||
private AppConfig conf = AppConfig.GetInstance();
|
||||
private ICaptureDetails captureDetails = null;
|
||||
|
||||
private int mX;
|
||||
|
|
|
@ -291,7 +291,7 @@ namespace Greenshot.Forms {
|
|||
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()) {
|
||||
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,15 +41,13 @@ namespace GreenshotFlickrPlugin {
|
|||
/// </summary>
|
||||
public class FlickrPlugin : IGreenshotPlugin {
|
||||
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 SharedSecret = "4180a21a1d2f8666";
|
||||
private ILanguage lang = Language.GetInstance();
|
||||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private Properties config = null;
|
||||
private FlickrConfiguration config;
|
||||
|
||||
public FlickrPlugin() {}
|
||||
|
||||
|
@ -70,7 +68,7 @@ namespace GreenshotFlickrPlugin {
|
|||
// Make sure the MODI-DLLs are found by adding a resolver
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyAssemblyResolver);
|
||||
|
||||
LoadConfig();
|
||||
this.config = IniConfig.GetIniSection<FlickrConfiguration>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -100,12 +98,11 @@ namespace GreenshotFlickrPlugin {
|
|||
public virtual void Configure() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method helps to resolve the MODI DLL files
|
||||
/// This method helps to resolve the Flickr DLL file
|
||||
/// </summary>
|
||||
/// <param name="sender">object which is starting the resolve</param>
|
||||
/// <param name="args">ResolveEventArgs describing the Assembly that needs to be found</param>
|
||||
|
@ -120,24 +117,6 @@ namespace GreenshotFlickrPlugin {
|
|||
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>
|
||||
/// This will be called when the menu item in the Editor is clicked
|
||||
/// </summary>
|
||||
|
@ -147,7 +126,7 @@ namespace GreenshotFlickrPlugin {
|
|||
bool authentication = false;
|
||||
|
||||
Flickr flickr = new Flickr(ApiKey, SharedSecret);
|
||||
if(config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY) == null) {
|
||||
if(config.Token == null) {
|
||||
string frob = flickr.AuthGetFrob();
|
||||
// Calculate the URL at Flickr to redirect the user to
|
||||
string flickrUrl = flickr.AuthCalcUrl(frob, AuthLevel.Write);
|
||||
|
@ -164,8 +143,8 @@ namespace GreenshotFlickrPlugin {
|
|||
LOG.Debug("User id is " + auth.User.UserId);
|
||||
LOG.Debug("User name is " + auth.User.UserName);
|
||||
LOG.Debug("User fullname is " + auth.User.FullName);
|
||||
config.AddProperty(AUTHENTICATION_TOKEN_PROPERTY, auth.Token);
|
||||
SaveConfig();
|
||||
config.Token = auth.Token;
|
||||
IniConfig.Save();
|
||||
authentication = true;
|
||||
} catch (FlickrException ex) {
|
||||
// If user did not authenticat your application
|
||||
|
@ -181,12 +160,12 @@ namespace GreenshotFlickrPlugin {
|
|||
MessageBox.Show("No Authentication made!");
|
||||
return;
|
||||
}
|
||||
flickr.AuthToken = config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY);
|
||||
flickr.AuthToken = config.Token;
|
||||
FlickrUploadForm uploader = new FlickrUploadForm();
|
||||
DialogResult uploaderResult = uploader.ShowDialog();
|
||||
if (uploaderResult == DialogResult.OK) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
||||
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
try {
|
||||
string file = "test.png";
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FlickrConfiguration.cs" />
|
||||
<Compile Include="FlickrPlugin.cs" />
|
||||
<Compile Include="Forms\FlickrAuthenticationForm.cs" />
|
||||
<Compile Include="Forms\FlickrAuthenticationForm.Designer.cs">
|
||||
|
|
|
@ -84,9 +84,6 @@
|
|||
<Generator>MSDiscoCodeGenerator</Generator>
|
||||
<LastGenOutput>Reference.cs</LastGenOutput>
|
||||
</None>
|
||||
<EmbeddedResource Include="Forms\LoginForm.resx">
|
||||
<DependentUpon>LoginForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Forms" />
|
||||
|
|
|
@ -95,9 +95,6 @@ namespace Jira {
|
|||
|
||||
public class 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 string credentials = null;
|
||||
private DateTime loggedInTime = DateTime.Now;
|
||||
|
|
|
@ -26,17 +26,17 @@ using Greenshot.Core;
|
|||
|
||||
namespace GreenshotJiraPlugin {
|
||||
/// <summary>
|
||||
/// Description of CoreConfiguration.
|
||||
/// Description of JiraConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("JIRA", Description="Greenshot JIRA Plugin configuration")]
|
||||
[IniSection("Jira", Description="Greenshot Jira Plugin configuration")]
|
||||
public class JiraConfiguration : IniSection {
|
||||
[IniProperty("Url", Description="Url to Jira system, including wsdl.", DefaultValue="http://jira/rpc/soap/jirasoapservice-v2?wsdl")]
|
||||
public string Url;
|
||||
[IniProperty("Timeout", Description="Session timeout in minutes", DefaultValue="30")]
|
||||
public int Timeout;
|
||||
[IniProperty("User", Description="User for the JIRA System")]
|
||||
[IniProperty("User", Description="User for the Jira System")]
|
||||
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;
|
||||
|
||||
// This will not be stored
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace GreenshotJiraPlugin {
|
|||
DialogResult result = jiraForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
||||
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||
byte [] buffer = stream.GetBuffer();
|
||||
try {
|
||||
jiraForm.upload(buffer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue