diff --git a/NzbDrone.Core/Providers/XbmcProvider.cs b/NzbDrone.Core/Providers/XbmcProvider.cs index 7a4a090e5..6e7f6e867 100644 --- a/NzbDrone.Core/Providers/XbmcProvider.cs +++ b/NzbDrone.Core/Providers/XbmcProvider.cs @@ -31,6 +31,11 @@ namespace NzbDrone.Core.Providers _eventClientProvider = eventClientProvider; } + public XbmcProvider() + { + + } + public virtual void Notify(string header, string message) { //Always use EventServer, until Json has real support for it @@ -41,11 +46,6 @@ namespace NzbDrone.Core.Providers } } - public XbmcProvider() - { - - } - public virtual void Update(Series series) { //Use Json for Eden/Nightly or depricated HTTP for 10.x (Dharma) to get the proper path @@ -376,6 +376,26 @@ namespace NzbDrone.Core.Providers return false; } + public virtual void TestNotification(string hosts) + { + foreach (var host in hosts.Split(',')) + { + Logger.Trace("Sending Test Notifcation to XBMC Host: {0}", host); + _eventClientProvider.SendNotification("Test Notification", "Success! Notifications are setup correctly", IconType.Jpeg, "NzbDrone.jpg", GetHostWithoutPort(host)); + } + } + + public virtual void TestJsonApi(string hosts, string username, string password) + { + foreach (var host in hosts.Split(',')) + { + Logger.Trace("Sending Test Notifcation to XBMC Host: {0}", host); + var version = GetJsonVersion(host, username, password); + if (version == 0) + throw new Exception("Failed to get JSON version in test"); + } + } + private string GetHostWithoutPort(string address) { return address.Split(':')[0]; diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 9aebcc3c6..bf9a7ac18 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -18,11 +18,13 @@ namespace NzbDrone.Web.Controllers private readonly GrowlProvider _growlProvider; private readonly SeasonProvider _seasonProvider; private readonly ProwlProvider _prowlProvider; + private readonly XbmcProvider _xbmcProvider; public CommandController(JobProvider jobProvider, SabProvider sabProvider, SmtpProvider smtpProvider, TwitterProvider twitterProvider, EpisodeProvider episodeProvider, GrowlProvider growlProvider, - SeasonProvider seasonProvider, ProwlProvider prowlProvider) + SeasonProvider seasonProvider, ProwlProvider prowlProvider, + XbmcProvider xbmcProvider) { _jobProvider = jobProvider; _sabProvider = sabProvider; @@ -32,6 +34,7 @@ namespace NzbDrone.Web.Controllers _growlProvider = growlProvider; _seasonProvider = seasonProvider; _prowlProvider = prowlProvider; + _xbmcProvider = xbmcProvider; } public JsonResult RssSync() @@ -164,5 +167,33 @@ namespace NzbDrone.Web.Controllers return JsonNotificationResult.Info("Success!", "SABnzbd settings have been verified successfully! Version: " + version); } + + public JsonResult TestXbmcNotification(string hosts) + { + try + { + _xbmcProvider.TestNotification(hosts); + return JsonNotificationResult.Info("Success!", "Test Notification Sent Successfully"); + } + catch(Exception) + { + } + + return JsonNotificationResult.Oops("Failed to send test notification, please review your settings."); + } + + public JsonResult TestXbmcJsonApi(string hosts, string username, string password) + { + try + { + _xbmcProvider.TestJsonApi(hosts, username, password); + return JsonNotificationResult.Info("Success!", "Successfully tested JSON API"); + } + catch (Exception) + { + } + + return JsonNotificationResult.Oops("Failed to test JSON API, please review your settings."); + } } } diff --git a/NzbDrone.Web/Scripts/NzbDrone/settings.js b/NzbDrone.Web/Scripts/NzbDrone/settings.js index f0417b9cd..e5dca31c8 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/settings.js +++ b/NzbDrone.Web/Scripts/NzbDrone/settings.js @@ -9,7 +9,8 @@ $('#MultiEpisodeStyle').live('change', function () { createExamples(); }); var testProwlUrl = '../Command/TestProwl'; var testSabUrl = '../Command/TestSabnzbd'; var testEmailUrl = '../Command/TestEmail'; - +var testXbmcNotificationUrl = '../Command/TestXbmcNotification'; +var testXbmcJsonApiUrl = '../Command/TestXbmcJsonApi'; function createExamples() { createSingleEpisodeExample(); @@ -200,10 +201,7 @@ function testSmtpSettings() { password: password, fromAddress: fromAddress, toAddresses: toAddresses - }), - error: function (req, status, error) { - alert("Sorry! We could send a test email at this time. " + error); - } + }) }); return false; @@ -222,11 +220,34 @@ function registerGrowl() { data: jQuery.param({ host: host, password: password - }), - error: function (req, status, error) { - alert("Sorry! We could send a test email at this time. " + error); - } + }) }); return false; -} \ No newline at end of file +} + +//XBMC +$(document).on('click', '#xbmc-test-notification', function() { + var hosts = $('#XbmcHosts').val(); + + $.ajax({ + url: testXbmcNotificationUrl, + data: jQuery.param({ hosts: hosts }) + }); +}); + +$(document).on('click', '#xbmc-test-jsonapi', function () { + var hosts = $('#XbmcHosts').val(); + var username = $('#XbmcUsername').val(); + var password = $('#XbmcPassword').val(); + + + $.ajax({ + url: testXbmcJsonApiUrl, + data: jQuery.param({ + hosts: hosts, + username: username, + password: password + }) + }); +}); \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Xbmc.cshtml b/NzbDrone.Web/Views/Settings/Xbmc.cshtml index 2cebdb847..46a6456da 100644 --- a/NzbDrone.Web/Views/Settings/Xbmc.cshtml +++ b/NzbDrone.Web/Views/Settings/Xbmc.cshtml @@ -51,4 +51,14 @@ @Html.DescriptionFor(m => m.XbmcPassword) @Html.TextBoxFor(m => m.XbmcPassword, new { @class = "inputClass", type = "password" }) + + + + + + \ No newline at end of file