If you copy a URL of an image, you can now upload this image using
Clipboard Upload.
TODO: This could extend to files too.
This commit is contained in:
mcored 2014-05-07 20:33:36 +08:00
parent 97b38ae48f
commit 8ddae5f03d
6 changed files with 156 additions and 104 deletions

View file

@ -60,9 +60,11 @@ You should have received a copy of the GNU General Public License
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HelpersLib
@ -1122,5 +1124,27 @@ public static Image LoadImage(string filePath)
return null;
}
public static Image LoadRemoteImage(string url)
{
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream stream = httpWebReponse.GetResponseStream())
{
return Image.FromStream(stream);
}
}
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
return null;
}
}
}

View file

@ -41,12 +41,16 @@ private void InitializeComponent()
this.tpTask = new System.Windows.Forms.TabPage();
this.chkOverrideFTP = new System.Windows.Forms.CheckBox();
this.cboFTPaccounts = new System.Windows.Forms.ComboBox();
this.btnAfterCapture = new HelpersLib.MenuButton();
this.btnAfterUpload = new HelpersLib.MenuButton();
this.btnDestinations = new HelpersLib.MenuButton();
this.cmsDestinations = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmiImageUploaders = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiTextUploaders = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiFileUploaders = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiURLShorteners = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiSocialServices = new System.Windows.Forms.ToolStripMenuItem();
this.btnTask = new HelpersLib.MenuButton();
this.tpGeneral = new System.Windows.Forms.TabPage();
this.panelGeneral = new System.Windows.Forms.Panel();
this.lblAfterTaskNotification = new System.Windows.Forms.Label();
@ -122,6 +126,10 @@ private void InitializeComponent()
this.tpActions = new System.Windows.Forms.TabPage();
this.pActions = new System.Windows.Forms.Panel();
this.btnActionsAdd = new System.Windows.Forms.Button();
this.lvActions = new HelpersLib.MyListView();
this.chActionsName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chActionsPath = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chActionsArgs = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.btnActionsEdit = new System.Windows.Forms.Button();
this.btnActionsRemove = new System.Windows.Forms.Button();
this.chkUseDefaultActions = new System.Windows.Forms.CheckBox();
@ -154,14 +162,7 @@ private void InitializeComponent()
this.tpAdvanced = new System.Windows.Forms.TabPage();
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
this.btnAfterCapture = new HelpersLib.MenuButton();
this.btnAfterUpload = new HelpersLib.MenuButton();
this.btnDestinations = new HelpersLib.MenuButton();
this.btnTask = new HelpersLib.MenuButton();
this.lvActions = new HelpersLib.MyListView();
this.chActionsName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chActionsPath = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chActionsArgs = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chkClipboardUploadContents = new System.Windows.Forms.CheckBox();
this.tcHotkeySettings.SuspendLayout();
this.tpTask.SuspendLayout();
this.cmsDestinations.SuspendLayout();
@ -324,6 +325,42 @@ private void InitializeComponent()
this.cboFTPaccounts.TabIndex = 13;
this.cboFTPaccounts.SelectedIndexChanged += new System.EventHandler(this.cboFTPaccounts_SelectedIndexChanged);
//
// btnAfterCapture
//
this.btnAfterCapture.Location = new System.Drawing.Point(6, 93);
this.btnAfterCapture.Menu = this.cmsAfterCapture;
this.btnAfterCapture.Name = "btnAfterCapture";
this.btnAfterCapture.Size = new System.Drawing.Size(506, 23);
this.btnAfterCapture.TabIndex = 4;
this.btnAfterCapture.Text = "After capture...";
this.btnAfterCapture.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnAfterCapture.UseMnemonic = false;
this.btnAfterCapture.UseVisualStyleBackColor = true;
//
// btnAfterUpload
//
this.btnAfterUpload.Location = new System.Drawing.Point(6, 149);
this.btnAfterUpload.Menu = this.cmsAfterUpload;
this.btnAfterUpload.Name = "btnAfterUpload";
this.btnAfterUpload.Size = new System.Drawing.Size(506, 23);
this.btnAfterUpload.TabIndex = 6;
this.btnAfterUpload.Text = "After upload...";
this.btnAfterUpload.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnAfterUpload.UseMnemonic = false;
this.btnAfterUpload.UseVisualStyleBackColor = true;
//
// btnDestinations
//
this.btnDestinations.Location = new System.Drawing.Point(6, 205);
this.btnDestinations.Menu = this.cmsDestinations;
this.btnDestinations.Name = "btnDestinations";
this.btnDestinations.Size = new System.Drawing.Size(506, 23);
this.btnDestinations.TabIndex = 8;
this.btnDestinations.Text = "Destinations...";
this.btnDestinations.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnDestinations.UseMnemonic = false;
this.btnDestinations.UseVisualStyleBackColor = true;
//
// cmsDestinations
//
this.cmsDestinations.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -370,6 +407,18 @@ private void InitializeComponent()
this.tsmiSocialServices.Size = new System.Drawing.Size(212, 22);
this.tsmiSocialServices.Text = "Social networking services";
//
// btnTask
//
this.btnTask.Location = new System.Drawing.Point(6, 37);
this.btnTask.Menu = this.cmsTask;
this.btnTask.Name = "btnTask";
this.btnTask.Size = new System.Drawing.Size(506, 23);
this.btnTask.TabIndex = 2;
this.btnTask.Text = "Task...";
this.btnTask.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnTask.UseMnemonic = false;
this.btnTask.UseVisualStyleBackColor = true;
//
// tpGeneral
//
this.tpGeneral.Controls.Add(this.panelGeneral);
@ -1307,6 +1356,38 @@ private void InitializeComponent()
this.btnActionsAdd.UseVisualStyleBackColor = true;
this.btnActionsAdd.Click += new System.EventHandler(this.btnActionsAdd_Click);
//
// lvActions
//
this.lvActions.CheckBoxes = true;
this.lvActions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chActionsName,
this.chActionsPath,
this.chActionsArgs});
this.lvActions.FullRowSelect = true;
this.lvActions.Location = new System.Drawing.Point(8, 40);
this.lvActions.MultiSelect = false;
this.lvActions.Name = "lvActions";
this.lvActions.Size = new System.Drawing.Size(496, 280);
this.lvActions.TabIndex = 3;
this.lvActions.UseCompatibleStateImageBehavior = false;
this.lvActions.View = System.Windows.Forms.View.Details;
this.lvActions.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvActions_ItemChecked);
//
// chActionsName
//
this.chActionsName.Text = "Name";
this.chActionsName.Width = 100;
//
// chActionsPath
//
this.chActionsPath.Text = "Path";
this.chActionsPath.Width = 250;
//
// chActionsArgs
//
this.chActionsArgs.Text = "Args";
this.chActionsArgs.Width = 134;
//
// btnActionsEdit
//
this.btnActionsEdit.Location = new System.Drawing.Point(88, 8);
@ -1533,6 +1614,7 @@ private void InitializeComponent()
//
// tpUploadClipboard
//
this.tpUploadClipboard.Controls.Add(this.chkClipboardUploadContents);
this.tpUploadClipboard.Controls.Add(this.cbClipboardUploadAutoIndexFolder);
this.tpUploadClipboard.Controls.Add(this.cbClipboardUploadAutoDetectURL);
this.tpUploadClipboard.Location = new System.Drawing.Point(4, 22);
@ -1546,23 +1628,22 @@ private void InitializeComponent()
// cbClipboardUploadAutoIndexFolder
//
this.cbClipboardUploadAutoIndexFolder.AutoSize = true;
this.cbClipboardUploadAutoIndexFolder.Location = new System.Drawing.Point(16, 40);
this.cbClipboardUploadAutoIndexFolder.Location = new System.Drawing.Point(16, 64);
this.cbClipboardUploadAutoIndexFolder.Name = "cbClipboardUploadAutoIndexFolder";
this.cbClipboardUploadAutoIndexFolder.Size = new System.Drawing.Size(407, 17);
this.cbClipboardUploadAutoIndexFolder.Size = new System.Drawing.Size(387, 17);
this.cbClipboardUploadAutoIndexFolder.TabIndex = 2;
this.cbClipboardUploadAutoIndexFolder.Text = "If clipboard text contains a folder path then index that folder and upload the in" +
"dex";
this.cbClipboardUploadAutoIndexFolder.Text = "If clipboard contains a folder path then index that folder and upload the index";
this.cbClipboardUploadAutoIndexFolder.UseVisualStyleBackColor = true;
this.cbClipboardUploadAutoIndexFolder.CheckedChanged += new System.EventHandler(this.cbClipboardUploadAutoIndexFolder_CheckedChanged);
//
// cbClipboardUploadAutoDetectURL
//
this.cbClipboardUploadAutoDetectURL.AutoSize = true;
this.cbClipboardUploadAutoDetectURL.Location = new System.Drawing.Point(16, 16);
this.cbClipboardUploadAutoDetectURL.Location = new System.Drawing.Point(16, 40);
this.cbClipboardUploadAutoDetectURL.Name = "cbClipboardUploadAutoDetectURL";
this.cbClipboardUploadAutoDetectURL.Size = new System.Drawing.Size(418, 17);
this.cbClipboardUploadAutoDetectURL.Size = new System.Drawing.Size(271, 17);
this.cbClipboardUploadAutoDetectURL.TabIndex = 1;
this.cbClipboardUploadAutoDetectURL.Text = "Automatically detect URL when doing clipboard text upload and use URL shortener";
this.cbClipboardUploadAutoDetectURL.Text = "If clipboard contains a URL then use URL shortener";
this.cbClipboardUploadAutoDetectURL.UseVisualStyleBackColor = true;
this.cbClipboardUploadAutoDetectURL.CheckedChanged += new System.EventHandler(this.cbClipboardUploadAutoDetectURL_CheckedChanged);
//
@ -1655,85 +1736,16 @@ private void InitializeComponent()
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged);
//
// btnAfterCapture
// chkClipboardUploadContents
//
this.btnAfterCapture.Location = new System.Drawing.Point(6, 93);
this.btnAfterCapture.Menu = this.cmsAfterCapture;
this.btnAfterCapture.Name = "btnAfterCapture";
this.btnAfterCapture.Size = new System.Drawing.Size(506, 23);
this.btnAfterCapture.TabIndex = 4;
this.btnAfterCapture.Text = "After capture...";
this.btnAfterCapture.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnAfterCapture.UseMnemonic = false;
this.btnAfterCapture.UseVisualStyleBackColor = true;
//
// btnAfterUpload
//
this.btnAfterUpload.Location = new System.Drawing.Point(6, 149);
this.btnAfterUpload.Menu = this.cmsAfterUpload;
this.btnAfterUpload.Name = "btnAfterUpload";
this.btnAfterUpload.Size = new System.Drawing.Size(506, 23);
this.btnAfterUpload.TabIndex = 6;
this.btnAfterUpload.Text = "After upload...";
this.btnAfterUpload.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnAfterUpload.UseMnemonic = false;
this.btnAfterUpload.UseVisualStyleBackColor = true;
//
// btnDestinations
//
this.btnDestinations.Location = new System.Drawing.Point(6, 205);
this.btnDestinations.Menu = this.cmsDestinations;
this.btnDestinations.Name = "btnDestinations";
this.btnDestinations.Size = new System.Drawing.Size(506, 23);
this.btnDestinations.TabIndex = 8;
this.btnDestinations.Text = "Destinations...";
this.btnDestinations.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnDestinations.UseMnemonic = false;
this.btnDestinations.UseVisualStyleBackColor = true;
//
// btnTask
//
this.btnTask.Location = new System.Drawing.Point(6, 37);
this.btnTask.Menu = this.cmsTask;
this.btnTask.Name = "btnTask";
this.btnTask.Size = new System.Drawing.Size(506, 23);
this.btnTask.TabIndex = 2;
this.btnTask.Text = "Task...";
this.btnTask.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnTask.UseMnemonic = false;
this.btnTask.UseVisualStyleBackColor = true;
//
// lvActions
//
this.lvActions.CheckBoxes = true;
this.lvActions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chActionsName,
this.chActionsPath,
this.chActionsArgs});
this.lvActions.FullRowSelect = true;
this.lvActions.Location = new System.Drawing.Point(8, 40);
this.lvActions.MultiSelect = false;
this.lvActions.Name = "lvActions";
this.lvActions.Size = new System.Drawing.Size(496, 280);
this.lvActions.TabIndex = 3;
this.lvActions.UseCompatibleStateImageBehavior = false;
this.lvActions.View = System.Windows.Forms.View.Details;
this.lvActions.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvActions_ItemChecked);
//
// chActionsName
//
this.chActionsName.Text = "Name";
this.chActionsName.Width = 100;
//
// chActionsPath
//
this.chActionsPath.Text = "Path";
this.chActionsPath.Width = 250;
//
// chActionsArgs
//
this.chActionsArgs.Text = "Args";
this.chActionsArgs.Width = 134;
this.chkClipboardUploadContents.AutoSize = true;
this.chkClipboardUploadContents.Location = new System.Drawing.Point(16, 16);
this.chkClipboardUploadContents.Name = "chkClipboardUploadContents";
this.chkClipboardUploadContents.Size = new System.Drawing.Size(323, 17);
this.chkClipboardUploadContents.TabIndex = 3;
this.chkClipboardUploadContents.Text = "If clipboard contains a file path or URL then upload its contents";
this.chkClipboardUploadContents.UseVisualStyleBackColor = true;
this.chkClipboardUploadContents.CheckedChanged += new System.EventHandler(this.chkClipboardUploadContents_CheckedChanged);
//
// TaskSettingsForm
//
@ -1940,6 +1952,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button btnScreenRecorderAVIOptions;
private System.Windows.Forms.Label lblScreenRecorderCLI;
private System.Windows.Forms.CheckBox chkRunScreencastCLI;
private System.Windows.Forms.CheckBox chkClipboardUploadContents;

View file

@ -196,8 +196,9 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false)
cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern;
// Upload / Clipboard upload
cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoDetectURL;
cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShortenURL;
cbClipboardUploadAutoIndexFolder.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder;
chkClipboardUploadContents.Checked = TaskSettings.UploadSettings.ClipboardUploadFileContents;
// Indexer
pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings;
@ -908,7 +909,7 @@ private void txtNameFormatPattern_TextChanged(object sender, EventArgs e)
private void cbClipboardUploadAutoDetectURL_CheckedChanged(object sender, EventArgs e)
{
TaskSettings.UploadSettings.ClipboardUploadAutoDetectURL = cbClipboardUploadAutoDetectURL.Checked;
TaskSettings.UploadSettings.ClipboardUploadShortenURL = cbClipboardUploadAutoDetectURL.Checked;
}
private void cbClipboardUploadAutoIndexFolder_CheckedChanged(object sender, EventArgs e)
@ -916,6 +917,11 @@ private void cbClipboardUploadAutoIndexFolder_CheckedChanged(object sender, Even
TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder = cbClipboardUploadAutoIndexFolder.Checked;
}
private void chkClipboardUploadContents_CheckedChanged(object sender, EventArgs e)
{
TaskSettings.UploadSettings.ClipboardUploadFileContents = chkClipboardUploadContents.Checked;
}
#endregion Upload
#region Indexer

View file

@ -302,8 +302,9 @@ public class TaskSettingsUpload
#region Upload / Clipboard upload
public bool ClipboardUploadAutoDetectURL = false;
public bool ClipboardUploadShortenURL = false;
public bool ClipboardUploadAutoIndexFolder = false;
public bool ClipboardUploadFileContents = false;
#endregion Upload / Clipboard upload
}

View file

@ -36,15 +36,15 @@ namespace ShareX
{
public static class UploadManager
{
public static void UploadFile(string filePath, TaskSettings taskSettings = null)
public async static void UploadFile(string filePath, TaskSettings taskSettings = null)
{
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
if (!string.IsNullOrEmpty(filePath))
{
if (File.Exists(filePath))
if (File.Exists(filePath) || Helpers.IsValidURLRegex(filePath))
{
UploadTask task = UploadTask.CreateFileUploaderTask(filePath, taskSettings);
UploadTask task = await UploadTask.CreateFileUploaderTaskAsync(filePath, taskSettings);
TaskManager.Start(task);
}
else if (Directory.Exists(filePath))
@ -171,7 +171,11 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
if (!string.IsNullOrEmpty(text))
{
if (taskSettings.UploadSettings.ClipboardUploadAutoDetectURL && Helpers.IsValidURLRegex(text))
if (taskSettings.UploadSettings.ClipboardUploadFileContents && Helpers.IsValidURLRegex(text))
{
UploadFile(text, taskSettings);
}
else if (taskSettings.UploadSettings.ClipboardUploadShortenURL && Helpers.IsValidURLRegex(text))
{
ShortenURL(text.Trim(), taskSettings);
}

View file

@ -93,7 +93,7 @@ public static UploadTask CreateDataUploaderTask(EDataType dataType, Stream strea
return task;
}
public static UploadTask CreateFileUploaderTask(string filePath, TaskSettings taskSettings)
public async static System.Threading.Tasks.Task<UploadTask> CreateFileUploaderTaskAsync(string filePath, TaskSettings taskSettings)
{
EDataType dataType = Helpers.FindDataType(filePath);
UploadTask task = new UploadTask(taskSettings);
@ -107,15 +107,19 @@ public static UploadTask CreateFileUploaderTask(string filePath, TaskSettings ta
task.Info.FileName = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
}
if (task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload && dataType == EDataType.Image)
if ((task.Info.TaskSettings.UploadSettings.ClipboardUploadFileContents || task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload) && dataType == EDataType.Image)
{
task.Info.Job = TaskJob.ImageJob;
task.tempImage = ImageHelpers.LoadImage(filePath);
if (File.Exists(filePath))
task.tempImage = ImageHelpers.LoadImage(filePath);
else if (Helpers.IsValidURLRegex(filePath))
task.tempImage = await System.Threading.Tasks.TaskEx.Run<Image>(() => ImageHelpers.LoadRemoteImage(filePath));
}
else
{
task.Info.Job = TaskJob.FileUpload;
task.Data = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
if (File.Exists(filePath))
task.Data = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
return task;