2014-11-28 17:40:20 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Localization;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Server.Startup.Common.Browser;
|
|
|
|
|
using System;
|
|
|
|
|
using MonoMac.Foundation;
|
|
|
|
|
using MonoMac.AppKit;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Mac
|
|
|
|
|
{
|
|
|
|
|
public class MenuBarIcon
|
|
|
|
|
{
|
|
|
|
|
private NSMenuItem browseMenuItem;
|
|
|
|
|
private NSMenuItem configureMenuItem;
|
|
|
|
|
private NSMenuItem quitMenuItem;
|
|
|
|
|
private NSMenuItem communityMenuItem;
|
|
|
|
|
|
|
|
|
|
public static MenuBarIcon Instance;
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
public MenuBarIcon (ILogger logger)
|
2014-11-28 17:40:20 +00:00
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
2014-11-29 04:03:47 +00:00
|
|
|
|
Logger = logger;
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowIcon() {
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
NSApplication.SharedApplication.BeginInvokeOnMainThread (CreateMenus);
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
private void CreateMenus() {
|
|
|
|
|
|
|
|
|
|
CreateNsMenu ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Localize()
|
|
|
|
|
{
|
|
|
|
|
NSApplication.SharedApplication.BeginInvokeOnMainThread (() => {
|
|
|
|
|
|
|
|
|
|
var configManager = MainClass.AppHost.ServerConfigurationManager;
|
|
|
|
|
|
|
|
|
|
configManager.ConfigurationUpdated -= Instance_ConfigurationUpdated;
|
|
|
|
|
LocalizeText ();
|
|
|
|
|
configManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NSStatusItem statusItem;
|
|
|
|
|
private void CreateNsMenu() {
|
2014-11-28 17:40:20 +00:00
|
|
|
|
|
|
|
|
|
var menu = new NSMenu ();
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
|
2014-11-28 17:40:20 +00:00
|
|
|
|
statusItem.Menu = menu;
|
|
|
|
|
statusItem.Image = NSImage.ImageNamed("statusicon");
|
|
|
|
|
statusItem.HighlightMode = true;
|
|
|
|
|
|
|
|
|
|
menu.RemoveAllItems ();
|
|
|
|
|
|
|
|
|
|
browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate {
|
|
|
|
|
Browse (NSApplication.SharedApplication);
|
|
|
|
|
});
|
|
|
|
|
menu.AddItem (browseMenuItem);
|
|
|
|
|
|
|
|
|
|
configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate {
|
|
|
|
|
Configure (NSApplication.SharedApplication);
|
|
|
|
|
});
|
|
|
|
|
menu.AddItem (configureMenuItem);
|
|
|
|
|
|
|
|
|
|
communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate {
|
|
|
|
|
Community (NSApplication.SharedApplication);
|
|
|
|
|
});
|
|
|
|
|
menu.AddItem (communityMenuItem);
|
|
|
|
|
|
|
|
|
|
quitMenuItem = new NSMenuItem ("Quit", "q", delegate {
|
|
|
|
|
Quit (NSApplication.SharedApplication);
|
|
|
|
|
});
|
|
|
|
|
menu.AddItem (quitMenuItem);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
private ILogger Logger{ get; set;}
|
2014-11-28 17:40:20 +00:00
|
|
|
|
|
|
|
|
|
private void Quit(NSObject sender)
|
|
|
|
|
{
|
2014-11-29 04:03:47 +00:00
|
|
|
|
MainClass.AppHost.Shutdown();
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Community(NSObject sender)
|
|
|
|
|
{
|
|
|
|
|
BrowserLauncher.OpenCommunity(Logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Configure(NSObject sender)
|
|
|
|
|
{
|
2014-11-29 04:03:47 +00:00
|
|
|
|
BrowserLauncher.OpenDashboard(MainClass.AppHost, Logger);
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Browse(NSObject sender)
|
|
|
|
|
{
|
2014-11-29 04:03:47 +00:00
|
|
|
|
BrowserLauncher.OpenWebClient(MainClass.AppHost, Logger);
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Terminate()
|
|
|
|
|
{
|
|
|
|
|
NSApplication.SharedApplication.InvokeOnMainThread (() => NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _uiCulture;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the ConfigurationUpdated event of the Instance control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The source of the event.</param>
|
|
|
|
|
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
|
|
|
|
void Instance_ConfigurationUpdated(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-11-29 04:03:47 +00:00
|
|
|
|
var configManager = MainClass.AppHost.ServerConfigurationManager;
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(configManager.Configuration.UICulture, _uiCulture,
|
2014-11-28 17:40:20 +00:00
|
|
|
|
StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
LocalizeText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LocalizeText()
|
|
|
|
|
{
|
2014-11-29 04:03:47 +00:00
|
|
|
|
var configManager = MainClass.AppHost.ServerConfigurationManager;
|
|
|
|
|
|
|
|
|
|
_uiCulture = configManager.Configuration.UICulture;
|
2014-11-28 17:40:20 +00:00
|
|
|
|
|
|
|
|
|
NSApplication.SharedApplication.BeginInvokeOnMainThread (LocalizeInternal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LocalizeInternal() {
|
|
|
|
|
|
2014-11-29 04:03:47 +00:00
|
|
|
|
var localization = MainClass.AppHost.LocalizationManager;
|
|
|
|
|
|
|
|
|
|
quitMenuItem.Title = localization.GetLocalizedString("LabelExit");
|
|
|
|
|
communityMenuItem.Title = localization.GetLocalizedString("LabelVisitCommunity");
|
|
|
|
|
browseMenuItem.Title = localization.GetLocalizedString("LabelBrowseLibrary");
|
|
|
|
|
configureMenuItem.Title = localization.GetLocalizedString("LabelConfigureMediaBrowser");
|
2014-11-28 17:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|