ShareX/ShareX/TaskSettings.cs

497 lines
21 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2015-08-13 13:07:38 +12:00
Copyright (c) 2007-2015 ShareX Team
2013-11-03 23:53:49 +13:00
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using Newtonsoft.Json;
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib;
using ShareX.ImageEffectsLib;
using ShareX.IndexerLib;
2015-08-25 04:38:35 +12:00
using ShareX.IRCLib;
using ShareX.MediaLib;
2014-12-11 09:25:20 +13:00
using ShareX.ScreenCaptureLib;
using ShareX.UploadersLib;
using System;
2013-11-03 23:53:49 +13:00
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
2014-04-01 01:20:12 +13:00
using System.Drawing.Design;
using System.Linq;
2013-11-03 23:53:49 +13:00
namespace ShareX
{
public class TaskSettings
{
2015-01-17 12:29:52 +13:00
public string Description = string.Empty;
2013-11-03 23:53:49 +13:00
public HotkeyType Job = HotkeyType.None;
public bool UseDefaultAfterCaptureJob = true;
public AfterCaptureTasks AfterCaptureJob = AfterCaptureTasks.CopyImageToClipboard | AfterCaptureTasks.SaveImageToFile | AfterCaptureTasks.UploadImageToHost;
public bool UseDefaultAfterUploadJob = true;
public AfterUploadTasks AfterUploadJob = AfterUploadTasks.CopyURLToClipboard;
public bool UseDefaultDestinations = true;
2014-12-28 23:07:34 +13:00
public ImageDestination ImageDestination = ImageDestination.Imgur;
public FileDestination ImageFileDestination = FileDestination.Dropbox;
2013-11-03 23:53:49 +13:00
public TextDestination TextDestination = TextDestination.Pastebin;
public FileDestination TextFileDestination = FileDestination.Dropbox;
2013-11-03 23:53:49 +13:00
public FileDestination FileDestination = FileDestination.Dropbox;
public UrlShortenerType URLShortenerDestination = UrlShortenerType.BITLY;
2014-07-14 08:59:17 +12:00
public URLSharingServices URLSharingServiceDestination = URLSharingServices.Twitter;
2014-05-31 13:27:47 +12:00
public bool OverrideFTP = false;
2013-11-09 05:12:56 +13:00
public int FTPIndex = 0;
2013-11-03 23:53:49 +13:00
public bool OverrideCustomUploader = false;
public int CustomUploaderIndex = 0;
2013-11-03 23:53:49 +13:00
public bool UseDefaultGeneralSettings = true;
public TaskSettingsGeneral GeneralSettings = new TaskSettingsGeneral();
public bool UseDefaultImageSettings = true;
public TaskSettingsImage ImageSettings = new TaskSettingsImage();
public bool UseDefaultCaptureSettings = true;
public TaskSettingsCapture CaptureSettings = new TaskSettingsCapture();
public bool UseDefaultUploadSettings = true;
public TaskSettingsUpload UploadSettings = new TaskSettingsUpload();
public bool UseDefaultActions = true;
public List<ExternalProgram> ExternalPrograms = new List<ExternalProgram>();
public bool UseDefaultToolsSettings = true;
public TaskSettingsTools ToolsSettings = new TaskSettingsTools();
2013-11-03 23:53:49 +13:00
public bool UseDefaultAdvancedSettings = true;
public TaskSettingsAdvanced AdvancedSettings = new TaskSettingsAdvanced();
public bool WatchFolderEnabled = false;
public List<WatchFolderSettings> WatchFolderList = new List<WatchFolderSettings>();
[JsonIgnore]
public TaskSettings TaskSettingsReference { get; private set; }
2014-07-10 11:16:27 +12:00
[JsonIgnore]
public TaskSettingsCapture TaskSettingsCaptureReference
{
get
{
if (UseDefaultCaptureSettings)
{
return Program.DefaultTaskSettings.CaptureSettings;
}
return TaskSettingsReference.CaptureSettings;
}
}
2013-11-03 23:53:49 +13:00
public override string ToString()
{
2015-01-17 12:29:52 +13:00
return !string.IsNullOrEmpty(Description) ? Description : Job.GetLocalizedDescription();
2013-11-03 23:53:49 +13:00
}
public bool IsUsingDefaultSettings
{
get
{
return UseDefaultAfterCaptureJob && UseDefaultAfterUploadJob && UseDefaultDestinations && !OverrideFTP && !OverrideCustomUploader && UseDefaultGeneralSettings &&
UseDefaultImageSettings && UseDefaultCaptureSettings && UseDefaultUploadSettings && UseDefaultActions && UseDefaultToolsSettings &&
2014-05-31 13:27:47 +12:00
UseDefaultAdvancedSettings && !WatchFolderEnabled;
2013-11-03 23:53:49 +13:00
}
}
public static TaskSettings GetDefaultTaskSettings()
{
TaskSettings taskSettings = new TaskSettings();
taskSettings.SetDefaultSettings();
taskSettings.TaskSettingsReference = Program.DefaultTaskSettings;
return taskSettings;
}
public static TaskSettings GetSafeTaskSettings(TaskSettings taskSettings)
{
TaskSettings safeTaskSettings;
if (taskSettings.IsUsingDefaultSettings && Program.DefaultTaskSettings != null)
{
safeTaskSettings = Program.DefaultTaskSettings.Copy();
safeTaskSettings.Description = taskSettings.Description;
safeTaskSettings.Job = taskSettings.Job;
}
else
{
safeTaskSettings = taskSettings.Copy();
safeTaskSettings.SetDefaultSettings();
}
safeTaskSettings.TaskSettingsReference = taskSettings;
return safeTaskSettings;
2013-11-03 23:53:49 +13:00
}
private void SetDefaultSettings()
{
if (Program.DefaultTaskSettings != null)
{
TaskSettings defaultTaskSettings = Program.DefaultTaskSettings.Copy();
if (UseDefaultAfterCaptureJob)
{
AfterCaptureJob = defaultTaskSettings.AfterCaptureJob;
}
if (UseDefaultAfterUploadJob)
{
AfterUploadJob = defaultTaskSettings.AfterUploadJob;
}
if (UseDefaultDestinations)
{
ImageDestination = defaultTaskSettings.ImageDestination;
ImageFileDestination = defaultTaskSettings.ImageFileDestination;
2013-11-03 23:53:49 +13:00
TextDestination = defaultTaskSettings.TextDestination;
TextFileDestination = defaultTaskSettings.TextFileDestination;
2013-11-03 23:53:49 +13:00
FileDestination = defaultTaskSettings.FileDestination;
URLShortenerDestination = defaultTaskSettings.URLShortenerDestination;
2014-07-14 08:59:17 +12:00
URLSharingServiceDestination = defaultTaskSettings.URLSharingServiceDestination;
2013-11-03 23:53:49 +13:00
}
if (UseDefaultGeneralSettings)
{
GeneralSettings = defaultTaskSettings.GeneralSettings;
}
if (UseDefaultImageSettings)
{
ImageSettings = defaultTaskSettings.ImageSettings;
}
if (UseDefaultCaptureSettings)
{
CaptureSettings = defaultTaskSettings.CaptureSettings;
}
2013-11-03 23:53:49 +13:00
if (UseDefaultUploadSettings)
{
UploadSettings = defaultTaskSettings.UploadSettings;
}
if (UseDefaultActions)
{
ExternalPrograms = defaultTaskSettings.ExternalPrograms;
}
if (UseDefaultToolsSettings)
2013-11-03 23:53:49 +13:00
{
ToolsSettings = defaultTaskSettings.ToolsSettings;
2013-11-03 23:53:49 +13:00
}
if (UseDefaultAdvancedSettings)
{
AdvancedSettings = defaultTaskSettings.AdvancedSettings;
}
}
}
2014-04-01 01:20:12 +13:00
public string CaptureFolder
{
get
{
if (!string.IsNullOrEmpty(AdvancedSettings.CapturePath))
2014-05-12 11:19:38 +12:00
{
2014-04-01 01:20:12 +13:00
return AdvancedSettings.CapturePath;
2014-05-12 11:19:38 +12:00
}
2014-04-01 01:20:12 +13:00
return Program.ScreenshotsFolder;
2014-04-01 01:20:12 +13:00
}
}
2013-11-03 23:53:49 +13:00
}
public class TaskSettingsGeneral
{
public bool PlaySoundAfterCapture = true;
public bool ShowAfterCaptureTasksForm = false;
public bool ShowBeforeUploadForm = false;
2013-11-03 23:53:49 +13:00
public bool PlaySoundAfterUpload = true;
public PopUpNotificationType PopUpNotification = PopUpNotificationType.ToastNotification;
2013-11-03 23:53:49 +13:00
public bool ShowAfterUploadForm = false;
public bool SaveHistory = true;
}
public class TaskSettingsImage
{
2014-03-13 22:13:02 +13:00
#region Image / General
2013-11-03 23:53:49 +13:00
public EImageFormat ImageFormat = EImageFormat.PNG;
public int ImageJPEGQuality = 90;
public GIFQuality ImageGIFQuality = GIFQuality.Default;
2013-11-03 23:53:49 +13:00
public int ImageSizeLimit = 1024;
public EImageFormat ImageFormat2 = EImageFormat.JPEG;
2014-03-13 22:13:02 +13:00
public FileExistAction FileExistAction = FileExistAction.Ask;
2013-11-03 23:53:49 +13:00
2014-03-13 22:13:02 +13:00
#endregion Image / General
2013-11-03 23:53:49 +13:00
#region Image / Effects
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
public List<ImageEffect> ImageEffects = ImageEffectManager.GetDefaultImageEffects();
2013-11-03 23:53:49 +13:00
public bool ShowImageEffectsWindowAfterCapture = false;
public bool ImageEffectOnlyRegionCapture = false;
2013-11-03 23:53:49 +13:00
#endregion Image / Effects
#region Image / Thumbnail
public int ThumbnailWidth = 200;
public int ThumbnailHeight = 0;
public string ThumbnailName = "-thumbnail";
public bool ThumbnailCheckSize = false;
#endregion Image / Thumbnail
2013-11-03 23:53:49 +13:00
}
public class TaskSettingsCapture
{
#region Capture / General
public bool ShowCursor = true;
2015-01-27 22:11:31 +13:00
public bool CaptureTransparent = false;
2013-11-03 23:53:49 +13:00
public bool CaptureShadow = true;
public int CaptureShadowOffset = 20;
public bool CaptureClientArea = false;
public bool IsDelayScreenshot = false;
public decimal DelayScreenshot = 2.0m;
public bool CaptureAutoHideTaskbar = false;
2015-04-27 07:52:01 +12:00
public Rectangle CaptureCustomRegion = new Rectangle(0, 0, 0, 0);
2013-11-03 23:53:49 +13:00
#endregion Capture / General
2014-07-10 11:16:27 +12:00
#region Capture / Region capture
2013-11-03 23:53:49 +13:00
public SurfaceOptions SurfaceOptions = new SurfaceOptions();
2014-07-10 11:16:27 +12:00
#endregion Capture / Region capture
2013-11-03 23:53:49 +13:00
#region Capture / Screen recorder
public FFmpegOptions FFmpegOptions = new FFmpegOptions();
2014-05-21 04:12:52 +12:00
public int ScreenRecordFPS = 20;
public int GIFFPS = 5;
public ScreenRecordGIFEncoding GIFEncoding = ScreenRecordGIFEncoding.FFmpeg;
2014-05-21 04:12:52 +12:00
public bool ScreenRecordFixedDuration = false;
public float ScreenRecordDuration = 3f;
public bool ScreenRecordAutoStart = true;
public float ScreenRecordStartDelay = 1f;
public bool ScreenRecordShowCursor = true;
public bool RunScreencastCLI = false;
public int VideoEncoderSelected = 0;
2014-05-21 04:12:52 +12:00
2013-11-03 23:53:49 +13:00
#endregion Capture / Screen recorder
#region Capture / Rectangle annotate
public RectangleAnnotateOptions RectangleAnnotateOptions = new RectangleAnnotateOptions();
#endregion Capture / Rectangle annotate
2013-11-03 23:53:49 +13:00
}
public class TaskSettingsUpload
{
#region Upload
2013-11-03 23:53:49 +13:00
public bool UseCustomTimeZone = false;
public TimeZoneInfo CustomTimeZone = TimeZoneInfo.Utc;
2013-11-03 23:53:49 +13:00
public string NameFormatPattern = "%y-%mo-%d_%h-%mi-%s"; // Test: %y %mo %mon %mon2 %d %h %mi %s %ms %w %w2 %pm %rn %ra %width %height %app %ver
public string NameFormatPatternActiveWindow = "%t_%y-%mo-%d_%h-%mi-%s";
public bool FileUploadUseNamePattern = false;
#endregion Upload
2013-11-03 23:53:49 +13:00
#region Upload / Clipboard upload
2014-05-08 04:26:14 +12:00
public bool ClipboardUploadURLContents = false;
public bool ClipboardUploadShortenURL = false;
public bool ClipboardUploadShareURL = false;
public bool ClipboardUploadAutoIndexFolder = false;
2013-11-03 23:53:49 +13:00
#endregion Upload / Clipboard upload
}
public class TaskSettingsTools
{
public IndexerSettings IndexerSettings = new IndexerSettings();
public VideoThumbnailOptions VideoThumbnailOptions = new VideoThumbnailOptions();
2015-08-25 04:38:35 +12:00
public IRCInfo IRCSettings = new IRCInfo();
}
2013-11-03 23:53:49 +13:00
public class TaskSettingsAdvanced
{
[Category("General"), DefaultValue(false), Description("Allow after capture tasks for image files by loading them as bitmap when files are handled during file upload, clipboard file upload, drag && drop file upload, watch folder and other image file tasks.")]
2013-11-03 23:53:49 +13:00
public bool ProcessImagesDuringFileUpload { get; set; }
[Category("General"), DefaultValue(false), Description("Use after capture tasks for clipboard image upload.")]
2013-11-03 23:53:49 +13:00
public bool ProcessImagesDuringClipboardUpload { get; set; }
[Category("General"), DefaultValue(true), Description("Allows file related after capture tasks (\"Perform actions\", \"Copy file to clipboard\" etc.) to be used when doing file upload.")]
public bool UseAfterCaptureTasksDuringFileUpload { get; set; }
2014-07-23 08:32:28 +12:00
[Category("General"), DefaultValue(true), Description("Save text as file for tasks such as clipboard text upload, drag and drop text upload, index folder etc.")]
public bool TextTaskSaveAsFile { get; set; }
[Category("General"), DefaultValue(false), Description("If task contains upload job then this setting will clear clipboard when task start.")]
public bool AutoClearClipboard { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom capture sound.")]
public bool UseCustomCaptureSound { get; set; }
[Category("Sound"), DefaultValue(""), Description("Capture sound file path."),
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
public string CustomCaptureSoundPath { get; set; }
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom task complete sound.")]
public bool UseCustomTaskCompletedSound { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Sound"), DefaultValue(""), Description("Task complete sound file path."),
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
public string CustomTaskCompletedSoundPath { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom error sound.")]
public bool UseCustomErrorSound { get; set; }
[Category("Sound"), DefaultValue(""), Description("Error sound file path."),
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
public string CustomErrorSoundPath { get; set; }
[Category("Image"), DefaultValue(256), Description("Preferred thumbnail width. 0 means aspect ratio will be used to adjust width according to height.")]
public int ThumbnailPreferredWidth { get; set; }
[Category("Image"), DefaultValue(0), Description("Preferred thumbnail height. 0 means aspect ratio will be used to adjust height according to width.")]
public int ThumbnailPreferredHeight { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Paths"), Description("Custom capture path takes precedence over path configured in Application configuration."),
Editor(typeof(DirectoryNameEditor), typeof(UITypeEditor))]
2014-04-01 01:20:12 +13:00
public string CapturePath { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Upload"), Description("Files with these file extensions will be uploaded using image uploader."),
Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public List<string> ImageExtensions { get; set; }
2015-08-16 20:34:46 +12:00
[Category("Upload"), Description("Files with these file extensions will be uploaded using text uploader."),
Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public List<string> TextExtensions { get; set; }
[Category("After upload"), DefaultValue(false), Description("If result URL starts with \"http://\" then replace it with \"https://\".")]
public bool ResultForceHTTPS { get; set; }
[Category("After upload"), DefaultValue("$result"),
2013-11-03 23:53:49 +13:00
Description("Clipboard content format after uploading. Supported variables: $result, $url, $shorturl, $thumbnailurl, $deletionurl, $filepath, $filename, $filenamenoext, $folderpath, $foldername, $uploadtime and other variables such as %y-%mo-%d etc.")]
public string ClipboardContentFormat { get; set; }
[Category("After upload"), DefaultValue("$result"), Description("Balloon tip content format after uploading. Supported variables: $result, $url, $shorturl, $thumbnailurl, $deletionurl, $filepath, $filename, $filenamenoext, $folderpath, $foldername, $uploadtime and other variables such as %y-%mo-%d etc.")]
2013-11-03 23:53:49 +13:00
public string BalloonTipContentFormat { get; set; }
[Category("After upload"), DefaultValue("$result"), Description("After upload task \"Open URL\" format. Supported variables: $result, $url, $shorturl, $thumbnailurl, $deletionurl, $filepath, $filename, $filenamenoext, $folderpath, $foldername, $uploadtime and other variables such as %y-%mo-%d etc.")]
public string OpenURLFormat { get; set; }
[Category("After upload"), DefaultValue(0), Description("Automatically shorten URL if the URL is longer than the specified number of characters. 0 means automatic URL shortening is not active.")]
public int AutoShortenURLLength { get; set; }
private float toastWindowDuration;
[Category("After upload / Notifications"), DefaultValue(3f), Description("Specify how long should toast notification window will stay on screen (in seconds).")]
public float ToastWindowDuration
{
get
{
return toastWindowDuration;
}
set
{
toastWindowDuration = Math.Max(value, 0f);
}
}
[Category("After upload / Notifications"), DefaultValue(ContentAlignment.BottomRight), Description("Specify where should toast notification window appear on the screen.")]
public ContentAlignment ToastWindowPlacement { get; set; }
2014-10-29 08:13:22 +13:00
[Category("After upload / Notifications"), DefaultValue(ToastClickAction.OpenUrl), Description("Specify action after toast notification window is left clicked."), TypeConverter(typeof(EnumDescriptionConverter))]
public ToastClickAction ToastWindowClickAction { get; set; }
private Size toastWindowSize;
[Category("After upload / Notifications"), DefaultValue(typeof(Size), "400, 300"), Description("Maximum toast notification window size.")]
public Size ToastWindowSize
{
get
{
return toastWindowSize;
}
set
{
toastWindowSize = new Size(Math.Max(value.Width, 100), Math.Max(value.Height, 100));
}
}
2013-11-03 23:53:49 +13:00
[Category("After upload"), DefaultValue(false), Description("After upload form will be automatically closed after 60 seconds.")]
public bool AutoCloseAfterUploadForm { get; set; }
[Category("Interaction"), DefaultValue(false), Description("Disable notifications")]
public bool DisableNotifications { get; set; }
[Category("Upload text"), DefaultValue("txt"), Description("File extension when saving text to the local hard disk.")]
public string TextFileExtension { get; set; }
[Category("Upload text"), DefaultValue("text"), Description("Text format e.g. csharp, cpp, etc.")]
public string TextFormat { get; set; }
[Category("Upload text"), DefaultValue(""), Description("Custom text input. Use %input for text input. Example you can create web page with your text in it."),
Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string TextCustom { get; set; }
2014-11-13 10:25:08 +13:00
[Category("Upload text"), DefaultValue(true), Description("HTML encode custom text input.")]
public bool TextCustomEncodeInput { get; set; }
[Category("Name pattern"), DefaultValue(100), Description("Maximum name pattern length for file name.")]
public int NamePatternMaxLength { get; set; }
[Category("Name pattern"), DefaultValue(50), Description("Maximum name pattern title (%t) length for file name.")]
public int NamePatternMaxTitleLength { get; set; }
[Category("History"), DefaultValue(false), Description("Only save to history if URL or shortened URL is not empty.")]
public bool HistorySaveOnlyURL { get; set; }
[Category("Tools"), DefaultValue("$r, $g, $b"), Description("Copy this color format to clipboard after using screen color picker. Formats: $r, $g, $b, $hex, $x, $y")]
2015-01-26 21:48:49 +13:00
public string ScreenColorPickerFormat { get; set; }
2013-11-03 23:53:49 +13:00
public TaskSettingsAdvanced()
{
this.ApplyDefaultPropertyValues();
ImageExtensions = Enum.GetNames(typeof(ImageFileExtensions)).ToList();
TextExtensions = Enum.GetNames(typeof(TextFileExtensions)).ToList();
2013-11-03 23:53:49 +13:00
}
}
}