mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
Added a PleaseWait form which allows the user to cancel the operation. This already is implemented for the Imgur plug-in but should be used for all the others with long operations. Also fixed a bug in the Imgur plug-in: while retrieving the history a "no longer available" answer was not processed.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1984 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
b589d756d6
commit
a8025ac8cf
6 changed files with 256 additions and 15 deletions
|
@ -129,19 +129,32 @@ namespace GreenshotImgurPlugin {
|
|||
Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload the capture to imgur
|
||||
/// </summary>
|
||||
/// <param name="captureDetails"></param>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="uploadURL">out string for the url</param>
|
||||
/// <returns>true if the upload succeeded</returns>
|
||||
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
|
||||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
||||
|
||||
host.SaveToStream(image, stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
|
||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
|
||||
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
|
||||
CheckHistory();
|
||||
ImgurInfo imgurInfo = null;
|
||||
|
||||
// Run upload in the background
|
||||
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait), Language.GetString("CANCEL"),
|
||||
delegate() {
|
||||
imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
|
||||
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
|
||||
CheckHistory();
|
||||
}
|
||||
);
|
||||
|
||||
imgurInfo.Image = ImageHelper.CreateThumbnail(image, 90, 90);
|
||||
IniConfig.Save();
|
||||
uploadURL = imgurInfo.Page;
|
||||
|
@ -156,9 +169,8 @@ namespace GreenshotImgurPlugin {
|
|||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.Error(e);
|
||||
MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
|
||||
} finally {
|
||||
backgroundForm.CloseDialog();
|
||||
}
|
||||
}
|
||||
uploadURL = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue