diff --git a/ShareX.UploadersLib/Properties/Resources.Designer.cs b/ShareX.UploadersLib/Properties/Resources.Designer.cs index 73bdd673f..9535f5e79 100644 --- a/ShareX.UploadersLib/Properties/Resources.Designer.cs +++ b/ShareX.UploadersLib/Properties/Resources.Designer.cs @@ -936,6 +936,15 @@ internal static System.Drawing.Bitmap Sul { } } + /// + /// Looks up a localized string similar to Unable to find a valid Twitter account.. + /// + internal static string TaskHelpers_TweetMessage_Unable_to_find_valid_Twitter_account_ { + get { + return ResourceManager.GetString("TaskHelpers_TweetMessage_Unable_to_find_valid_Twitter_account_", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// diff --git a/ShareX.UploadersLib/Properties/Resources.de.resx b/ShareX.UploadersLib/Properties/Resources.de.resx index bc5d09016..fadeeeefa 100644 --- a/ShareX.UploadersLib/Properties/Resources.de.resx +++ b/ShareX.UploadersLib/Properties/Resources.de.resx @@ -259,4 +259,7 @@ Hergestellte Ordner: Bitte wähle einen der Pomf Hochlader vom Pomf Tab im Zieleinstellungs-Fenster aus. + + Kann kein gültiges Twitter Konto finden. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.fr.resx b/ShareX.UploadersLib/Properties/Resources.fr.resx index d791aeb2b..af91fd3af 100644 --- a/ShareX.UploadersLib/Properties/Resources.fr.resx +++ b/ShareX.UploadersLib/Properties/Resources.fr.resx @@ -259,4 +259,7 @@ Dossiers créés: Merci de sélectionner un des services de mise en ligne Pomf dans la fenêtre "Paramètres de destinations -> Pomf". + + Impossible de trouver un compte Twitter valide. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.nl-NL.resx b/ShareX.UploadersLib/Properties/Resources.nl-NL.resx index 38926fbaa..4969b217d 100644 --- a/ShareX.UploadersLib/Properties/Resources.nl-NL.resx +++ b/ShareX.UploadersLib/Properties/Resources.nl-NL.resx @@ -259,4 +259,7 @@ Aangemaakte mappen: Selecteer een van de Pomf uploaders van het venster "Instellingen voor bestemmingen" -> Pomf tabblad. + + Kan geen geldig Twitter account vinden. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.pt-BR.resx b/ShareX.UploadersLib/Properties/Resources.pt-BR.resx index 5826f23d7..7c5c16f35 100644 --- a/ShareX.UploadersLib/Properties/Resources.pt-BR.resx +++ b/ShareX.UploadersLib/Properties/Resources.pt-BR.resx @@ -259,4 +259,7 @@ Pastas criadas: Por favor selecione um dos uploaders Pomf em "Configurações de destino -> Pomf". + + Não foi possível encontrar uma conta válida do Twitter. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.resx b/ShareX.UploadersLib/Properties/Resources.resx index 04a54618d..9af13a177 100644 --- a/ShareX.UploadersLib/Properties/Resources.resx +++ b/ShareX.UploadersLib/Properties/Resources.resx @@ -497,4 +497,7 @@ Created folders: ..\favicons\openload.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Unable to find a valid Twitter account. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.ru.resx b/ShareX.UploadersLib/Properties/Resources.ru.resx index 0c6d0af5b..339278a01 100644 --- a/ShareX.UploadersLib/Properties/Resources.ru.resx +++ b/ShareX.UploadersLib/Properties/Resources.ru.resx @@ -259,4 +259,7 @@ Пожалуйста, выберите один из сервисов Pomf в окне «Настройки сервисов», вкладка «Pomf». + + Не удалось найти рабочий аккаунт Twitter. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.tr.resx b/ShareX.UploadersLib/Properties/Resources.tr.resx index 70d5e1d85..1085401fb 100644 --- a/ShareX.UploadersLib/Properties/Resources.tr.resx +++ b/ShareX.UploadersLib/Properties/Resources.tr.resx @@ -259,4 +259,7 @@ Oluşturulmuş dizinler: Lütfen geçerli bir Pomf yükleyici seçiniz "Hedef ayarları penceresi -> Pomf sekmesi". + + Geçerli Twitter hesabı bulunamadı. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.vi-VN.resx b/ShareX.UploadersLib/Properties/Resources.vi-VN.resx index 42b32a6b5..3b5c5647f 100644 --- a/ShareX.UploadersLib/Properties/Resources.vi-VN.resx +++ b/ShareX.UploadersLib/Properties/Resources.vi-VN.resx @@ -259,4 +259,7 @@ Các thư mục đã tạo: Làm mới danh sách thư mục thất bại + + Không thể tìm thấy tài khoàn Twitter hợp lệ. + \ No newline at end of file diff --git a/ShareX.UploadersLib/Properties/Resources.zh-CN.resx b/ShareX.UploadersLib/Properties/Resources.zh-CN.resx index 3572cac03..d857db966 100644 --- a/ShareX.UploadersLib/Properties/Resources.zh-CN.resx +++ b/ShareX.UploadersLib/Properties/Resources.zh-CN.resx @@ -259,4 +259,7 @@ 请从“目的地设置窗口 -> Pomf上传程序”中选择其中的一个Pomf上传程序。 + + 无法找到可用的Twitter账号。 + \ No newline at end of file diff --git a/ShareX.UploadersLib/ShareX.UploadersLib.csproj b/ShareX.UploadersLib/ShareX.UploadersLib.csproj index 975ddecf0..97642f67c 100644 --- a/ShareX.UploadersLib/ShareX.UploadersLib.csproj +++ b/ShareX.UploadersLib/ShareX.UploadersLib.csproj @@ -208,6 +208,20 @@ + + + + + + + + + + + + + + @@ -269,6 +283,7 @@ + @@ -902,6 +917,7 @@ + diff --git a/ShareX.UploadersLib/SharingService.cs b/ShareX.UploadersLib/SharingService.cs new file mode 100644 index 000000000..346330e38 --- /dev/null +++ b/ShareX.UploadersLib/SharingService.cs @@ -0,0 +1,15 @@ +namespace ShareX.UploadersLib +{ + /// + /// Defines a service capable of sharing a URL to (eg. Facebook, Twitter) + /// + public abstract class SharingService : UploaderService + { + /// + /// Shares the URL with the service + /// + /// the unencoded URL to share + /// the uploaders configuration for the task + public abstract void ShareURL(string url, UploadersConfig uploadersConfig); + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/DeliciousSharingService.cs b/ShareX.UploadersLib/SharingServices/DeliciousSharingService.cs new file mode 100644 index 000000000..d10639d23 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/DeliciousSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class DeliciousSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Delicious; + protected override string UrlFormatString { get; } = "https://delicious.com/save?v=5&url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/EmailSharingService.cs b/ShareX.UploadersLib/SharingServices/EmailSharingService.cs new file mode 100644 index 000000000..6c53c58f6 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/EmailSharingService.cs @@ -0,0 +1,49 @@ +using System.Windows.Forms; +using ShareX.HelpersLib; +using ShareX.UploadersLib.FileUploaders; + +namespace ShareX.UploadersLib.SharingServices +{ + public class EmailSharingService : SharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Email; + public override bool CheckConfig(UploadersConfig config) + { + return !string.IsNullOrEmpty(config.EmailSmtpServer) + && config.EmailSmtpPort > 0 + && !string.IsNullOrEmpty(config.EmailFrom) + && !string.IsNullOrEmpty(config.EmailPassword); + } + + public override void ShareURL(string url, UploadersConfig uploadersConfig) + { + if (!CheckConfig(uploadersConfig)) + { + URLHelpers.OpenURL("mailto:?body=" + URLHelpers.URLEncode(url)); + return; + } + + using (EmailForm emailForm = new EmailForm(uploadersConfig.EmailRememberLastTo ? uploadersConfig.EmailLastTo : string.Empty, + uploadersConfig.EmailDefaultSubject, url)) + { + if (emailForm.ShowDialog() == DialogResult.OK) + { + if (uploadersConfig.EmailRememberLastTo) + { + uploadersConfig.EmailLastTo = emailForm.ToEmail; + } + + Email email = new Email + { + SmtpServer = uploadersConfig.EmailSmtpServer, + SmtpPort = uploadersConfig.EmailSmtpPort, + FromEmail = uploadersConfig.EmailFrom, + Password = uploadersConfig.EmailPassword + }; + + email.Send(emailForm.ToEmail, emailForm.Subject, emailForm.Body); + } + } + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/FacebookSharingService.cs b/ShareX.UploadersLib/SharingServices/FacebookSharingService.cs new file mode 100644 index 000000000..7a1b01bc2 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/FacebookSharingService.cs @@ -0,0 +1,9 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class FacebookSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Facebook; + + protected override string UrlFormatString { get; } = "https://www.facebook.com/sharer/sharer.php?u={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/GooglePlusSharingService.cs b/ShareX.UploadersLib/SharingServices/GooglePlusSharingService.cs new file mode 100644 index 000000000..74af89049 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/GooglePlusSharingService.cs @@ -0,0 +1,9 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class GooglePlusSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.GooglePlus; + + protected override string UrlFormatString { get; } = "https://plus.google.com/share?url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/LinkedInSharingService.cs b/ShareX.UploadersLib/SharingServices/LinkedInSharingService.cs new file mode 100644 index 000000000..64b5f39ec --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/LinkedInSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class LinkedInSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.LinkedIn; + protected override string UrlFormatString { get; } = "https://www.linkedin.com/shareArticle?url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/PinterestSharingService.cs b/ShareX.UploadersLib/SharingServices/PinterestSharingService.cs new file mode 100644 index 000000000..bf5875152 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/PinterestSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class PinterestSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Pinterest; + protected override string UrlFormatString { get; } = "http://pinterest.com/pin/create/button/?url={0}&media={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/PushbulletSharingService.cs b/ShareX.UploadersLib/SharingServices/PushbulletSharingService.cs new file mode 100644 index 000000000..029718a08 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/PushbulletSharingService.cs @@ -0,0 +1,25 @@ +using ShareX.HelpersLib; +using ShareX.UploadersLib.FileUploaders; + +namespace ShareX.UploadersLib.SharingServices +{ + public class PushbulletSharingService : SharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Pushbullet; + + public override bool CheckConfig(UploadersConfig uploadersConfig) + { + var pushbulletSettings = uploadersConfig.PushbulletSettings; + + return pushbulletSettings != null + && !string.IsNullOrEmpty(pushbulletSettings.UserAPIKey) + && pushbulletSettings.DeviceList != null + && pushbulletSettings.DeviceList.IsValidIndex(pushbulletSettings.SelectedDevice); + } + + public override void ShareURL(string url, UploadersConfig uploadersConfig) + { + new Pushbullet(uploadersConfig.PushbulletSettings).PushLink(url, "ShareX: URL Share"); + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/RedditSharingService.cs b/ShareX.UploadersLib/SharingServices/RedditSharingService.cs new file mode 100644 index 000000000..c3a4f06bf --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/RedditSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class RedditSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Reddit; + protected override string UrlFormatString { get; } = "http://www.reddit.com/submit?url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/SimpleSharingService.cs b/ShareX.UploadersLib/SharingServices/SimpleSharingService.cs new file mode 100644 index 000000000..28c7c31ec --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/SimpleSharingService.cs @@ -0,0 +1,26 @@ +using System.ComponentModel; +using ShareX.HelpersLib; + +namespace ShareX.UploadersLib.SharingServices +{ + /// + /// Base class for services that just open a share dialog in a browser + /// + public abstract class SimpleSharingService : SharingService + { + /// + /// A string formatted URL that opens a share dialog + /// + /// a string with a one placeholder for the URL to share + [Localizable(false)] + protected abstract string UrlFormatString { get; } + + public override void ShareURL(string url, UploadersConfig uploadersConfig) + { + string encodedUrl = URLHelpers.URLEncode(url); + URLHelpers.OpenURL(string.Format(UrlFormatString, encodedUrl)); + } + + public override bool CheckConfig(UploadersConfig uploadersConfig) => true; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/StumbleUponSharingService.cs b/ShareX.UploadersLib/SharingServices/StumbleUponSharingService.cs new file mode 100644 index 000000000..612e5b531 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/StumbleUponSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class StumbleUponSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.StumbleUpon; + protected override string UrlFormatString { get; } = "https://delicious.com/save?v=5&url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/TumblrSharingService.cs b/ShareX.UploadersLib/SharingServices/TumblrSharingService.cs new file mode 100644 index 000000000..d7021a583 --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/TumblrSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class TumblrSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Tumblr; + protected override string UrlFormatString { get; } = "https://www.tumblr.com/share?v=3&u={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/TwitterSharingService.cs b/ShareX.UploadersLib/SharingServices/TwitterSharingService.cs new file mode 100644 index 000000000..70ce2122c --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/TwitterSharingService.cs @@ -0,0 +1,50 @@ +using System; +using System.Windows.Forms; +using ShareX.HelpersLib; +using ShareX.UploadersLib.HelperClasses; +using ShareX.UploadersLib.ImageUploaders; +using ShareX.UploadersLib.Properties; + +namespace ShareX.UploadersLib.SharingServices +{ + public class TwitterSharingService : SharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.Twitter; + public override bool CheckConfig(UploadersConfig config) + { + return config.TwitterOAuthInfoList != null + && config.TwitterOAuthInfoList.IsValidIndex(config.TwitterSelectedAccount) + && OAuthInfo.CheckOAuth(config.TwitterOAuthInfoList[config.TwitterSelectedAccount]); + } + + public override void ShareURL(string url, UploadersConfig uploadersConfig) + { + if (!CheckConfig(uploadersConfig)) + { + //URLHelpers.OpenURL("https://twitter.com/intent/tweet?text=" + encodedUrl); + MessageBox.Show(Resources.TaskHelpers_TweetMessage_Unable_to_find_valid_Twitter_account_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + OAuthInfo twitterOAuth = uploadersConfig.TwitterOAuthInfoList[uploadersConfig.TwitterSelectedAccount]; + + if (uploadersConfig.TwitterSkipMessageBox) + { + try + { + new Twitter(twitterOAuth).TweetMessage(url); + } + catch (Exception ex) + { + DebugHelper.WriteException(ex); + } + } + else + { + using (TwitterTweetForm twitter = new TwitterTweetForm(twitterOAuth, url)) + { + twitter.ShowDialog(); + } + } + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/SharingServices/VkSharingService.cs b/ShareX.UploadersLib/SharingServices/VkSharingService.cs new file mode 100644 index 000000000..ad646538c --- /dev/null +++ b/ShareX.UploadersLib/SharingServices/VkSharingService.cs @@ -0,0 +1,8 @@ +namespace ShareX.UploadersLib.SharingServices +{ + public class VkSharingService : SimpleSharingService + { + public override URLSharingServices EnumValue { get; } = URLSharingServices.VK; + protected override string UrlFormatString { get; } = "http://vk.com/share.php?url={0}"; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/UploaderFactory.cs b/ShareX.UploadersLib/UploaderFactory.cs index 91dc619df..a3ac43587 100644 --- a/ShareX.UploadersLib/UploaderFactory.cs +++ b/ShareX.UploadersLib/UploaderFactory.cs @@ -34,6 +34,7 @@ public static class UploaderFactory private static readonly TextUploaderService[] textUploaderServices = Helpers.GetInstances(); private static readonly FileUploaderService[] fileUploaderServices = Helpers.GetInstances(); private static readonly URLShortenerService[] urlShortenerServices = Helpers.GetInstances(); + private static readonly SharingService[] sharingServices = Helpers.GetInstances(); public static ImageUploaderService GetImageUploaderServiceByEnum(ImageDestination enumValue) { @@ -54,5 +55,10 @@ public static URLShortenerService GetURLShortenerServiceByEnum(UrlShortenerType { return urlShortenerServices.First(x => x.EnumValue == enumValue); } + + public static SharingService GetSharingServiceByEnum(URLSharingServices enumValue) + { + return sharingServices.First(x => x.EnumValue == enumValue); + } } } \ No newline at end of file diff --git a/ShareX.UploadersLib/UploadersConfig.cs b/ShareX.UploadersLib/UploadersConfig.cs index 8aca93c8e..975a67ea1 100644 --- a/ShareX.UploadersLib/UploadersConfig.cs +++ b/ShareX.UploadersLib/UploadersConfig.cs @@ -350,79 +350,5 @@ public class UploadersConfig : SettingsBase public int CustomURLShortenerSelected = 0; #endregion Custom Uploaders - - #region Helper Methods - - public bool IsValid(int index) - { - Enum destination = (Enum)Enum.ToObject(typeof(T), index); - - if (destination is ImageDestination) - { - return IsValid((ImageDestination)destination); - } - - if (destination is TextDestination) - { - return IsValid((TextDestination)destination); - } - - if (destination is FileDestination) - { - return IsValid((FileDestination)destination); - } - - if (destination is UrlShortenerType) - { - return IsValid((UrlShortenerType)destination); - } - - if (destination is URLSharingServices) - { - return IsValid((URLSharingServices)destination); - } - - return true; - } - - public bool IsValid(ImageDestination destination) - { - if (destination == ImageDestination.FileUploader) return true; - return UploaderFactory.GetImageUploaderServiceByEnum(destination).CheckConfig(this); - } - - public bool IsValid(TextDestination destination) - { - if (destination == TextDestination.FileUploader) return true; - return UploaderFactory.GetTextUploaderServiceByEnum(destination).CheckConfig(this); - } - - public bool IsValid(FileDestination destination) - { - return UploaderFactory.GetFileUploaderServiceByEnum(destination).CheckConfig(this); - } - - public bool IsValid(UrlShortenerType destination) - { - return UploaderFactory.GetURLShortenerServiceByEnum(destination).CheckConfig(this); - } - - public bool IsValid(URLSharingServices destination) - { - switch (destination) - { - case URLSharingServices.Email: - return !string.IsNullOrEmpty(EmailSmtpServer) && EmailSmtpPort > 0 && !string.IsNullOrEmpty(EmailFrom) && !string.IsNullOrEmpty(EmailPassword); - case URLSharingServices.Twitter: - return TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount) && OAuthInfo.CheckOAuth(TwitterOAuthInfoList[TwitterSelectedAccount]); - case URLSharingServices.Pushbullet: - return PushbulletSettings != null && !string.IsNullOrEmpty(PushbulletSettings.UserAPIKey) && PushbulletSettings.DeviceList != null && - PushbulletSettings.DeviceList.IsValidIndex(PushbulletSettings.SelectedDevice); - } - - return true; - } - - #endregion Helper Methods } } \ No newline at end of file diff --git a/ShareX.UploadersLib/UploadersConfigValidator.cs b/ShareX.UploadersLib/UploadersConfigValidator.cs new file mode 100644 index 000000000..d61c2a329 --- /dev/null +++ b/ShareX.UploadersLib/UploadersConfigValidator.cs @@ -0,0 +1,66 @@ +using System; + +namespace ShareX.UploadersLib +{ + public static class UploadersConfigValidator + { + public static bool Validate(int index, UploadersConfig config) + { + Enum destination = (Enum)Enum.ToObject(typeof(T), index); + + if (destination is ImageDestination) + { + return Validate((ImageDestination)destination, config); + } + + if (destination is TextDestination) + { + return Validate((TextDestination)destination, config); + } + + if (destination is FileDestination) + { + return Validate((FileDestination)destination, config); + } + + if (destination is UrlShortenerType) + { + return Validate((UrlShortenerType)destination, config); + } + + if (destination is URLSharingServices) + { + return Validate((URLSharingServices)destination, config); + } + + return true; + } + + public static bool Validate(ImageDestination destination, UploadersConfig config) + { + if (destination == ImageDestination.FileUploader) return true; + return UploaderFactory.GetImageUploaderServiceByEnum(destination).CheckConfig(config); + } + + public static bool Validate(TextDestination destination, UploadersConfig config) + { + if (destination == TextDestination.FileUploader) return true; + return UploaderFactory.GetTextUploaderServiceByEnum(destination).CheckConfig(config); + } + + public static bool Validate(FileDestination destination, UploadersConfig config) + { + return UploaderFactory.GetFileUploaderServiceByEnum(destination).CheckConfig(config); + } + + public static bool Validate(UrlShortenerType destination, UploadersConfig config) + { + return UploaderFactory.GetURLShortenerServiceByEnum(destination).CheckConfig(config); + } + + public static bool Validate(URLSharingServices destination, UploadersConfig config) + { + return UploaderFactory.GetSharingServiceByEnum(destination).CheckConfig(config); + } + } +} \ No newline at end of file diff --git a/ShareX/Controls/BeforeUploadControl.cs b/ShareX/Controls/BeforeUploadControl.cs index 3242bf1d6..4d083f1bd 100644 --- a/ShareX/Controls/BeforeUploadControl.cs +++ b/ShareX/Controls/BeforeUploadControl.cs @@ -191,7 +191,7 @@ private void AddDestination(int index, EDataType dataType, TaskSettings taskS { Enum destination = (Enum)Enum.ToObject(typeof(T), index); - if (Program.UploadersConfig.IsValid(index)) + if (UploadersConfigValidator.Validate(index, Program.UploadersConfig)) { RadioButton rb = new RadioButton() { AutoSize = true }; diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 2c92bc945..3119c515d 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -456,7 +456,7 @@ private void EnableDisableToolStripMenuItems(params ToolStripDropDownItem[] p { for (int i = 0; i < parent.DropDownItems.Count; i++) { - parent.DropDownItems[i].Enabled = Program.UploadersConfig.IsValid(i); + parent.DropDownItems[i].Enabled = UploadersConfigValidator.Validate(i, Program.UploadersConfig); } } } diff --git a/ShareX/Forms/TaskSettingsForm.cs b/ShareX/Forms/TaskSettingsForm.cs index 623c94c39..998503514 100644 --- a/ShareX/Forms/TaskSettingsForm.cs +++ b/ShareX/Forms/TaskSettingsForm.cs @@ -550,7 +550,7 @@ private void EnableDisableToolStripMenuItems(params ToolStripDropDownItem[] p { for (int i = 0; i < parent.DropDownItems.Count; i++) { - parent.DropDownItems[i].Enabled = Program.UploadersConfig.IsValid(i); + parent.DropDownItems[i].Enabled = UploadersConfigValidator.Validate(i, Program.UploadersConfig); } } } diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index 91e04b660..bc5476212 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -894,104 +894,10 @@ public UploadResult ShortenURL(string url) public void ShareURL(string url) { - if (!string.IsNullOrEmpty(url)) - { - string encodedUrl = URLHelpers.URLEncode(url); + if (string.IsNullOrEmpty(url)) return; - switch (Info.TaskSettings.URLSharingServiceDestination) - { - case URLSharingServices.Email: - if (Program.UploadersConfig.IsValid(URLSharingServices.Email)) - { - using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty, - Program.UploadersConfig.EmailDefaultSubject, url)) - { - if (emailForm.ShowDialog() == DialogResult.OK) - { - if (Program.UploadersConfig.EmailRememberLastTo) - { - Program.UploadersConfig.EmailLastTo = emailForm.ToEmail; - } - - Email email = new Email - { - SmtpServer = Program.UploadersConfig.EmailSmtpServer, - SmtpPort = Program.UploadersConfig.EmailSmtpPort, - FromEmail = Program.UploadersConfig.EmailFrom, - Password = Program.UploadersConfig.EmailPassword - }; - - email.Send(emailForm.ToEmail, emailForm.Subject, emailForm.Body); - } - } - } - else - { - URLHelpers.OpenURL("mailto:?body=" + encodedUrl); - } - break; - case URLSharingServices.Twitter: - if (Program.UploadersConfig.IsValid(URLSharingServices.Twitter)) - { - OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList[Program.UploadersConfig.TwitterSelectedAccount]; - - if (Program.UploadersConfig.TwitterSkipMessageBox) - { - try - { - new Twitter(twitterOAuth).TweetMessage(url); - } - catch (Exception ex) - { - DebugHelper.WriteException(ex); - } - } - else - { - using (TwitterTweetForm twitter = new TwitterTweetForm(twitterOAuth, url)) - { - twitter.ShowDialog(); - } - } - } - else - { - //URLHelpers.OpenURL("https://twitter.com/intent/tweet?text=" + encodedUrl); - MessageBox.Show(Resources.TaskHelpers_TweetMessage_Unable_to_find_valid_Twitter_account_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - break; - case URLSharingServices.Facebook: - URLHelpers.OpenURL("https://www.facebook.com/sharer/sharer.php?u=" + encodedUrl); - break; - case URLSharingServices.GooglePlus: - URLHelpers.OpenURL("https://plus.google.com/share?url=" + encodedUrl); - break; - case URLSharingServices.Reddit: - URLHelpers.OpenURL("http://www.reddit.com/submit?url=" + encodedUrl); - break; - case URLSharingServices.Pinterest: - URLHelpers.OpenURL(string.Format("http://pinterest.com/pin/create/button/?url={0}&media={0}", encodedUrl)); - break; - case URLSharingServices.Tumblr: - URLHelpers.OpenURL("https://www.tumblr.com/share?v=3&u=" + encodedUrl); - break; - case URLSharingServices.LinkedIn: - URLHelpers.OpenURL("https://www.linkedin.com/shareArticle?url=" + encodedUrl); - break; - case URLSharingServices.StumbleUpon: - URLHelpers.OpenURL("http://www.stumbleupon.com/submit?url=" + encodedUrl); - break; - case URLSharingServices.Delicious: - URLHelpers.OpenURL("https://delicious.com/save?v=5&url=" + encodedUrl); - break; - case URLSharingServices.VK: - URLHelpers.OpenURL("http://vk.com/share.php?url=" + encodedUrl); - break; - case URLSharingServices.Pushbullet: - new Pushbullet(Program.UploadersConfig.PushbulletSettings).PushLink(url, "ShareX: URL Share"); - break; - } - } + UploaderFactory.GetSharingServiceByEnum(Info.TaskSettings.URLSharingServiceDestination) + .ShareURL(url, Program.UploadersConfig); } private void PrepareUploader(Uploader currentUploader)