diff --git a/Greenshot-OCR-Plugin/OCRPlugin.cs b/Greenshot-OCR-Plugin/OCRPlugin.cs index 604a13619..2c1c5a10b 100644 --- a/Greenshot-OCR-Plugin/OCRPlugin.cs +++ b/Greenshot-OCR-Plugin/OCRPlugin.cs @@ -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); } } diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 550a30a13..393f88f97 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -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(); 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; diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 52acddd89..cfbd67aa4 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -137,44 +137,35 @@ 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(); - helpOutput.AppendLine("\t/help"); - helpOutput.AppendLine("\t\tThis help."); - helpOutput.AppendLine(); - helpOutput.AppendLine(); - helpOutput.AppendLine("\t/help configure"); - helpOutput.AppendLine("\t\tA detailed listing of available settings for the configure command."); - helpOutput.AppendLine(); - helpOutput.AppendLine(); - helpOutput.AppendLine("\t/exit"); - helpOutput.AppendLine("\t\tTries to close all running instances."); - helpOutput.AppendLine(); - helpOutput.AppendLine(); - helpOutput.AppendLine("\t/configure [property=value] [property=value] ..."); - helpOutput.AppendLine("\t\tChange the configuration of Greenshot via the commandline."); - helpOutput.AppendLine("\t\tExample to change the language to English: greenshot.exe /configure Ui_Language=en-US"); - helpOutput.AppendLine("\t\tExample to change the destination: greenshot.exe /configure Output_File_Path=\"C:\\Documents and Settings\\\""); - helpOutput.AppendLine(); - helpOutput.AppendLine(); - helpOutput.AppendLine("\t/openfile [filename]"); - helpOutput.AppendLine("\t\tOpen the bitmap file in the running Greenshot instance or start a new instance"); - helpOutput.AppendLine(); - helpOutput.AppendLine(); - helpOutput.AppendLine("\t/norun"); - 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"); - } + helpOutput.AppendLine("Greenshot commandline options:"); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/help"); + helpOutput.AppendLine("\t\tThis help."); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/help configure"); + helpOutput.AppendLine("\t\tA detailed listing of available settings for the configure command."); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/exit"); + helpOutput.AppendLine("\t\tTries to close all running instances."); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/configure [property=value] [property=value] ..."); + helpOutput.AppendLine("\t\tChange the configuration of Greenshot via the commandline."); + helpOutput.AppendLine("\t\tExample to change the language to English: greenshot.exe /configure Ui_Language=en-US"); + helpOutput.AppendLine("\t\tExample to change the destination: greenshot.exe /configure Output_File_Path=\"C:\\Documents and Settings\\\""); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/openfile [filename]"); + helpOutput.AppendLine("\t\tOpen the bitmap file in the running Greenshot instance or start a new instance"); + helpOutput.AppendLine(); + helpOutput.AppendLine(); + helpOutput.AppendLine("\t/norun"); + 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; diff --git a/Greenshot/Test/SaveImageFileDialogTest.cs b/Greenshot/Test/SaveImageFileDialogTest.cs index 2682776ff..8384b0840 100644 --- a/Greenshot/Test/SaveImageFileDialogTest.cs +++ b/Greenshot/Test/SaveImageFileDialogTest.cs @@ -19,11 +19,11 @@ * along with this program. If not, see . */ 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(); //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"); diff --git a/GreenshotConfluencePlugin/Confluence.cs b/GreenshotConfluencePlugin/Confluence.cs index 498506fc6..41b3ba5dd 100644 --- a/GreenshotConfluencePlugin/Confluence.cs +++ b/GreenshotConfluencePlugin/Confluence.cs @@ -33,6 +33,7 @@ using Greenshot.Core; /// See: http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification /// 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 userMap = new Dictionary(); public ConfluenceConnector(string configurationPath) { - this.configurationPath = configurationPath; - this.config = LoadConfig(); + this.config = IniConfig.GetIniSection(); 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); - } - this.credentials = confluence.login(config.GetProperty(CONFLUENCE_USER_PROPERTY), tmpPassword); + 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); + } } 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(); } diff --git a/GreenshotConfluencePlugin/ConfluenceConfiguration.cs b/GreenshotConfluencePlugin/ConfluenceConfiguration.cs new file mode 100644 index 000000000..52dbabbb4 --- /dev/null +++ b/GreenshotConfluencePlugin/ConfluenceConfiguration.cs @@ -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 . + */ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +using Greenshot.Core; + +namespace GreenshotConfluencePlugin { + /// + /// Description of ConfluenceConfiguration. + /// + [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); + } + + /// + /// A form for username/password + /// + /// bool true if OK was pressed, false if cancel + 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; + } + } +} diff --git a/GreenshotConfluencePlugin/ConfluencePluginBase.cs b/GreenshotConfluencePlugin/ConfluencePluginBase.cs index caadabbfb..1dd64bf42 100644 --- a/GreenshotConfluencePlugin/ConfluencePluginBase.cs +++ b/GreenshotConfluencePlugin/ConfluencePluginBase.cs @@ -72,10 +72,7 @@ namespace GreenshotConfluencePlugin { /// Implementation of the IPlugin.Configure /// 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().ShowConfigDialog(); } /// @@ -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."); } } } diff --git a/GreenshotConfluencePlugin/Forms/LoginForm.Designer.cs b/GreenshotConfluencePlugin/Forms/LoginForm.Designer.cs index d55408e50..ff9c8f956 100644 --- a/GreenshotConfluencePlugin/Forms/LoginForm.Designer.cs +++ b/GreenshotConfluencePlugin/Forms/LoginForm.Designer.cs @@ -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; - } } diff --git a/GreenshotConfluencePlugin/Forms/LoginForm.cs b/GreenshotConfluencePlugin/Forms/LoginForm.cs index 9fb4dcce0..414ee8df9 100644 --- a/GreenshotConfluencePlugin/Forms/LoginForm.cs +++ b/GreenshotConfluencePlugin/Forms/LoginForm.cs @@ -26,7 +26,7 @@ using Greenshot.Core; namespace GreenshotConfluencePlugin { /// - /// Description of LoginForm. + /// Description of PasswordRequestForm. /// public partial class LoginForm : Form { private ILanguage lang = Language.GetInstance(); @@ -38,13 +38,14 @@ namespace GreenshotConfluencePlugin { InitializeComponent(); InitializeTexts(); } - + private void InitializeTexts() { this.label_url.Text = lang.GetString(LangKey.label_url); this.label_user.Text = lang.GetString(LangKey.label_user); 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); } @@ -62,7 +63,12 @@ namespace GreenshotConfluencePlugin { get {return textBoxPassword.Text;} 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; } @@ -77,4 +83,4 @@ namespace GreenshotConfluencePlugin { } } } -} \ No newline at end of file +} diff --git a/GreenshotConfluencePlugin/GreenshotConfluencePlugin.csproj b/GreenshotConfluencePlugin/GreenshotConfluencePlugin.csproj index 4f092f6db..708c0f4ce 100644 --- a/GreenshotConfluencePlugin/GreenshotConfluencePlugin.csproj +++ b/GreenshotConfluencePlugin/GreenshotConfluencePlugin.csproj @@ -50,6 +50,7 @@ + diff --git a/GreenshotConfluencePlugin/LanguageKeys.cs b/GreenshotConfluencePlugin/LanguageKeys.cs index e2f8c1be0..17ef23bd2 100644 --- a/GreenshotConfluencePlugin/LanguageKeys.cs +++ b/GreenshotConfluencePlugin/LanguageKeys.cs @@ -27,6 +27,7 @@ namespace GreenshotConfluencePlugin { label_url, label_user, label_password, + label_no_password_store, OK, CANCEL, upload_success, diff --git a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-de-DE.xml b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-de-DE.xml index 95211a9e7..4ac5238d1 100644 --- a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-de-DE.xml +++ b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-de-DE.xml @@ -16,6 +16,9 @@ Password + + Kennwort nicht speichern + OK diff --git a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-en-US.xml b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-en-US.xml index 2effd5cae..ca153e14a 100644 --- a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-en-US.xml +++ b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-en-US.xml @@ -13,6 +13,9 @@ Password + + Do not store the password + Please enter your Confluence login data diff --git a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-nl-NL.xml b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-nl-NL.xml index 1bb8528ab..39ec13751 100644 --- a/GreenshotConfluencePlugin/Languages/language_confluenceplugin-nl-NL.xml +++ b/GreenshotConfluencePlugin/Languages/language_confluenceplugin-nl-NL.xml @@ -13,6 +13,9 @@ Password + + Het wachtwoord niet opslaan + Geef uw Confluence login data diff --git a/GreenshotCore/Configuration/AppConfig.cs b/GreenshotCore/Configuration/AppConfig.cs index abd1d74ea..04e9f0752 100644 --- a/GreenshotCore/Configuration/AppConfig.cs +++ b/GreenshotCore/Configuration/AppConfig.cs @@ -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} - /// /// 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 LastUsedFieldValues = new Dictionary(); - // 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 - /// /// a private constructor because this is a singleton /// @@ -122,170 +62,11 @@ namespace Greenshot.Configuration { /// public static AppConfig GetInstance() { if (instance == null) { - instance = Load(); + instance = new AppConfig(); } return instance; } - public static void Reload() { - AppConfig newInstance = Load(); - instance.Copy(newInstance); - } - - /// - /// loads the configuration from the config file - /// - /// an instance of AppConfig with all values set from the config file - 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; - } - - /// - /// 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. - /// - 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(); - } - } - - /// - /// saves the configuration values to the supplied config file - /// - public void Store() { - Store(configfilepath); - } - - /// - /// saves the configuration values to the config path - /// - 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)); - } - } - - /// - /// 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. - /// - 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); diff --git a/GreenshotCore/Configuration/CoreConfiguration.cs b/GreenshotCore/Configuration/CoreConfiguration.cs index be4810551..3a4ee3a25 100644 --- a/GreenshotCore/Configuration/CoreConfiguration.cs +++ b/GreenshotCore/Configuration/CoreConfiguration.cs @@ -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 } /// /// Description of CoreConfiguration. diff --git a/GreenshotCore/Configuration/Language.cs b/GreenshotCore/Configuration/Language.cs index 9ce6cfbf7..ce66386a5 100644 --- a/GreenshotCore/Configuration/Language.cs +++ b/GreenshotCore/Configuration/Language.cs @@ -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(); 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; diff --git a/GreenshotCore/Helpers/FilenameHelper.cs b/GreenshotCore/Helpers/FilenameHelper.cs index 0fbcd9d4e..c5a4f4603 100644 --- a/GreenshotCore/Helpers/FilenameHelper.cs +++ b/GreenshotCore/Helpers/FilenameHelper.cs @@ -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(); + private FilenameHelper() { } /// @@ -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. diff --git a/GreenshotCore/Helpers/ImageOutput.cs b/GreenshotCore/Helpers/ImageOutput.cs index 1763c4f28..d9cee06d6 100644 --- a/GreenshotCore/Helpers/ImageOutput.cs +++ b/GreenshotCore/Helpers/ImageOutput.cs @@ -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 /// public class ImageOutput { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput)); + private static CoreConfiguration conf = IniConfig.GetIniSection(); private ImageOutput() { } @@ -47,36 +49,29 @@ namespace Greenshot.Helpers /// /// Saves image to stream with specified quality /// - 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."); - imfo = ImageFormat.Jpeg; - extension = imfo.ToString(); + switch (extension) { + case OutputFormat.Bmp: + imfo = ImageFormat.Bmp; + break; + case OutputFormat.Gif: + imfo = ImageFormat.Gif; + break; + case OutputFormat.Jpeg: + imfo = ImageFormat.Jpeg; + 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 /// the image to save /// the absolute destination path including file name 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; diff --git a/GreenshotCore/Helpers/MailHelper.cs b/GreenshotCore/Helpers/MailHelper.cs index c1986dca3..2dbfd6d66 100644 --- a/GreenshotCore/Helpers/MailHelper.cs +++ b/GreenshotCore/Helpers/MailHelper.cs @@ -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 { /// The image to send /// ICaptureDetails 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(); + string filename = FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, conf.OutputFileFormat, captureDetails); string tmpFile = Path.Combine(Path.GetTempPath(),filename); LOG.Debug("Creating TMP File for Email: " + tmpFile); diff --git a/GreenshotCore/Helpers/PluginHelper.cs b/GreenshotCore/Helpers/PluginHelper.cs index 2e8c57b7f..47a0fdd3d 100644 --- a/GreenshotCore/Helpers/PluginHelper.cs +++ b/GreenshotCore/Helpers/PluginHelper.cs @@ -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(); + return FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, format, captureDetails); } /// diff --git a/GreenshotCore/Helpers/PrintHelper.cs b/GreenshotCore/Helpers/PrintHelper.cs index 877968f1f..f72988fcc 100644 --- a/GreenshotCore/Helpers/PrintHelper.cs +++ b/GreenshotCore/Helpers/PrintHelper.cs @@ -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; } diff --git a/GreenshotCore/Interfaces/Forms/IImageEditor.cs b/GreenshotCore/Interfaces/Forms/IImageEditor.cs index c64e8c41d..b36fcd9e4 100644 --- a/GreenshotCore/Interfaces/Forms/IImageEditor.cs +++ b/GreenshotCore/Interfaces/Forms/IImageEditor.cs @@ -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 { /// The stream the image is stored on /// The image type (extension), e.g. "png", "jpg", "bmp" /// Only needed for "jpg" - void SaveToStream(Stream stream, string extension, int quality); + void SaveToStream(Stream stream, OutputFormat extension, int quality); /// /// Get the ToolStripMenuItem where plugins can place their Menu entrys diff --git a/GreenshotCore/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotCore/Interfaces/Plugin/PluginInterfaces.cs index f21cf870e..071a526d9 100644 --- a/GreenshotCore/Interfaces/Plugin/PluginInterfaces.cs +++ b/GreenshotCore/Interfaces/Plugin/PluginInterfaces.cs @@ -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 { /// The Stream to save to /// The format to save with (png, jpg etc) /// Jpeg quality - void SaveToStream(Image image, Stream stream, string format, int quality); + void SaveToStream(Image image, Stream stream, OutputFormat format, int quality); /// /// Return a filename for the current image format (png,jpg etc) with the default file pattern @@ -178,7 +179,7 @@ namespace Greenshot.Plugin { /// /// A string with the format /// The filename which should be used to save the image - string GetFilename(string format, ICaptureDetails captureDetails); + string GetFilename(OutputFormat format, ICaptureDetails captureDetails); /// /// Create a Thumbnail diff --git a/GreenshotEditor/Controls/ColorButton.cs b/GreenshotEditor/Controls/ColorButton.cs index 80a9ac8d8..a92b3c0c5 100644 --- a/GreenshotEditor/Controls/ColorButton.cs +++ b/GreenshotEditor/Controls/ColorButton.cs @@ -19,11 +19,14 @@ * along with this program. If not, see . */ 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(); conf.Editor_RecentColors = colorDialog.RecentColors; - conf.Store(); + IniConfig.Save(); SelectedColor = colorDialog.Color; if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("SelectedColor")); diff --git a/GreenshotEditor/Drawing/Surface.cs b/GreenshotEditor/Drawing/Surface.cs index 375dbea39..76976675a 100644 --- a/GreenshotEditor/Drawing/Surface.cs +++ b/GreenshotEditor/Drawing/Surface.cs @@ -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; diff --git a/GreenshotEditor/Forms/ImageEditorForm.cs b/GreenshotEditor/Forms/ImageEditorForm.cs index c43f98e45..3e0f0368c 100644 --- a/GreenshotEditor/Forms/ImageEditorForm.cs +++ b/GreenshotEditor/Forms/ImageEditorForm.cs @@ -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); } diff --git a/GreenshotFlickrPlugin/FlickrConfiguration.cs b/GreenshotFlickrPlugin/FlickrConfiguration.cs new file mode 100644 index 000000000..8a4982485 --- /dev/null +++ b/GreenshotFlickrPlugin/FlickrConfiguration.cs @@ -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 . + */ +using System; +using System.Collections.Generic; +using Greenshot.Core; + +namespace GreenshotFlickrPlugin { + /// + /// Description of FlickrConfiguration. + /// + [IniSection("Flickr", Description="Greenshot Flickr Plugin configuration")] + public class FlickrConfiguration : IniSection { + [IniProperty("authentication.token", Description="Token for Flickr", DefaultValue="")] + public string Token; + } +} diff --git a/GreenshotFlickrPlugin/FlickrPlugin.cs b/GreenshotFlickrPlugin/FlickrPlugin.cs index 5a3db76b5..a354db9c4 100644 --- a/GreenshotFlickrPlugin/FlickrPlugin.cs +++ b/GreenshotFlickrPlugin/FlickrPlugin.cs @@ -41,17 +41,15 @@ namespace GreenshotFlickrPlugin { /// 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() { } + public FlickrPlugin() {} /// /// Implementation of the IGreenshotPlugin.Initialize @@ -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(); } /// @@ -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()); } /// - /// This method helps to resolve the MODI DLL files + /// This method helps to resolve the Flickr DLL file /// /// object which is starting the resolve /// ResolveEventArgs describing the Assembly that needs to be found @@ -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"); - } - /// /// This will be called when the menu item in the Editor is clicked /// @@ -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"; diff --git a/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj b/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj index 0d12c0c81..b72ac1a19 100644 --- a/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj +++ b/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj @@ -51,6 +51,7 @@ + diff --git a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj index 3e72a8d0f..39a0ec5c5 100644 --- a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj +++ b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj @@ -84,9 +84,6 @@ MSDiscoCodeGenerator Reference.cs - - LoginForm.cs - diff --git a/GreenshotJiraPlugin/Jira.cs b/GreenshotJiraPlugin/Jira.cs index 8f8589392..dd1d7501f 100644 --- a/GreenshotJiraPlugin/Jira.cs +++ b/GreenshotJiraPlugin/Jira.cs @@ -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; diff --git a/GreenshotJiraPlugin/JiraConfiguration.cs b/GreenshotJiraPlugin/JiraConfiguration.cs index 3e1b71768..0cf8e6f97 100644 --- a/GreenshotJiraPlugin/JiraConfiguration.cs +++ b/GreenshotJiraPlugin/JiraConfiguration.cs @@ -26,17 +26,17 @@ using Greenshot.Core; namespace GreenshotJiraPlugin { /// - /// Description of CoreConfiguration. + /// Description of JiraConfiguration. /// - [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 diff --git a/GreenshotJiraPlugin/JiraPluginBase.cs b/GreenshotJiraPlugin/JiraPluginBase.cs index 75b55306f..4f9faa602 100644 --- a/GreenshotJiraPlugin/JiraPluginBase.cs +++ b/GreenshotJiraPlugin/JiraPluginBase.cs @@ -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);