From 89fe64d019006e77ce21ff214d766e429e7ddaab Mon Sep 17 00:00:00 2001
From: angelblue05 <tamara.angel05@gmail.com>
Date: Sat, 17 Sep 2016 06:12:37 -0500
Subject: [PATCH] Update context menu

Also add the option to disable the context menu within the add-on
settings >  extras
---
 addon.xml                                     |  14 +--
 contextmenu.py                                |  11 +-
 resources/lib/dialogs/context.py              |  89 ++++++++++++++++
 resources/lib/kodimonitor.py                  |   5 +
 resources/settings.xml                        |   3 +-
 .../default/1080i/script-emby-context.xml     | 100 ++++++++++++++++++
 resources/skins/default/media/emby-icon.png   | Bin 0 -> 1850 bytes
 service.py                                    |   2 +
 8 files changed, 213 insertions(+), 11 deletions(-)
 create mode 100644 resources/lib/dialogs/context.py
 create mode 100644 resources/skins/default/1080i/script-emby-context.xml
 create mode 100644 resources/skins/default/media/emby-icon.png

diff --git a/addon.xml b/addon.xml
index 97ef4e0d..b37f1adc 100644
--- a/addon.xml
+++ b/addon.xml
@@ -17,19 +17,19 @@
   <extension point="xbmc.service" library="service.py" start="login">
   </extension>
   <extension point="kodi.context.item" library="contextmenu.py">
-		<item>
-			<label>30401</label>
+    <item>
+      <label>30401</label>
             <description>Settings for the Emby Server</description>
-            <visible>[!IsEmpty(ListItem.DBID) + !StringCompare(ListItem.DBID,-1)] | !IsEmpty(ListItem.Property(embyid))</visible>
-		</item>
-	</extension>
+            <visible>[!IsEmpty(ListItem.DBID) + !StringCompare(ListItem.DBID,-1) | !IsEmpty(ListItem.Property(embyid))] + !IsEmpty(Window(10000).Property(emby_context))</visible>
+    </item>
+  </extension>
   <extension point="xbmc.addon.metadata">
     <platform>all</platform>
     <language>en</language>
     <license>GNU GENERAL PUBLIC LICENSE. Version 2, June 1991</license>
-    <forum></forum>
+    <forum>http://emby.media/community/index.php?/forum/99-kodi/</forum>
     <website>http://emby.media/</website>
-    <source></source>
+    <source>https://github.com/MediaBrowser/plugin.video.emby</source>
     <summary lang="en"></summary>
     <description lang="en">Welcome to Emby for Kodi A whole new way to manage and view your media library. The Emby addon for Kodi combines the best of Kodi - ultra smooth navigation, beautiful UIs and playback of any file under the sun, and Emby - the most powerful fully open source multi-client media metadata indexer and server.&#10;&#10;Emby for Kodi is the absolute best way to enjoy the incredible Kodi playback engine combined with the power of Emby's centralized database. Features: Direct integration with the Kodi library for native Kodi speed Instant synchronization with the Emby server Full support for Movie, TV and Music collections Emby Server direct stream and transcoding support - use Kodi when you are away from home!</description>
   </extension>
diff --git a/contextmenu.py b/contextmenu.py
index 08efa137..5e90058d 100644
--- a/contextmenu.py
+++ b/contextmenu.py
@@ -24,6 +24,7 @@ import read_embyserver as embyserver
 import embydb_functions as embydb
 import musicutils as musicutils
 from utils import settings, dialog, language as lang, kodiSQL
+from dialogs import context
 
 #################################################################################################
 
@@ -130,9 +131,13 @@ class ContextMenu(object):
         # Addon settings
         options.append(OPTIONS['Addon'])
 
-        resp = dialog(type_="select", heading=lang(30401), list=options)
-        if resp > -1:
-            self._selected_option = options[resp]
+        addon = xbmcaddon.Addon('plugin.video.emby')
+        XML_PATH = (addon.getAddonInfo('path'), "default", "1080i")
+        dialog = context.ContextMenu("script-emby-context.xml", *XML_PATH)
+        dialog.set_options(options)
+        dialog.doModal()
+        if dialog.is_selected():
+            self._selected_option = dialog.get_selected()
 
         return self._selected_option
 
diff --git a/resources/lib/dialogs/context.py b/resources/lib/dialogs/context.py
new file mode 100644
index 00000000..670d6463
--- /dev/null
+++ b/resources/lib/dialogs/context.py
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+
+##################################################################################################
+
+import logging
+import os
+
+import xbmcgui
+import xbmcaddon
+
+from utils import language as lang
+
+##################################################################################################
+
+log = logging.getLogger("EMBY."+__name__)
+addon = xbmcaddon.Addon('plugin.video.emby')
+
+ACTION_PARENT_DIR = 9
+ACTION_PREVIOUS_MENU = 10
+ACTION_BACK = 92
+ACTION_SELECT_ITEM = 7
+ACTION_MOUSE_LEFT_CLICK = 100
+LIST = 155
+
+##################################################################################################
+
+
+class ContextMenu(xbmcgui.WindowXMLDialog):
+
+    _options = []
+    selected_option = None
+
+
+    def __init__(self, *args, **kwargs):
+
+        xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
+
+    def set_options(self, options=[]):
+        self._options = options
+
+    def is_selected(self):
+        return True if self.selected_option else False
+
+    def get_selected(self):
+        return self.selected_option
+
+    def onInit(self):
+
+        height = 479 + (len(self._options) * 55)
+        log.info("options: %s", self._options)
+        self.list_ = self.getControl(LIST)
+
+        for option in self._options:
+            self.list_.addItem(self._add_listitem(option))
+
+        self.background = self._add_editcontrol(730, height, 30, 450)
+        self.setFocus(self.list_)
+
+    def onAction(self, action):
+
+        if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
+            self.close()
+
+        if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK):
+
+            if self.getFocusId() == LIST:
+                option = self.list_.getSelectedItem()
+                self.selected_option = option.getLabel()
+                log.info('option selected: %s', self.selected_option)
+
+                self.close()
+
+    def _add_editcontrol(self, x, y, height, width, password=0):
+
+        media = os.path.join(addon.getAddonInfo('path'), 'resources', 'skins', 'default', 'media')
+        control = xbmcgui.ControlImage(0, 0, 0, 0,
+                                       filename=os.path.join(media, "white.png"),
+                                       aspectRatio=0,
+                                       colorDiffuse="ff111111")
+        control.setPosition(x, y)
+        control.setHeight(height)
+        control.setWidth(width)
+
+        self.addControl(control)
+        return control
+
+    @classmethod
+    def _add_listitem(cls, label):
+        return xbmcgui.ListItem(label)
diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py
index 35efa40f..da15013d 100644
--- a/resources/lib/kodimonitor.py
+++ b/resources/lib/kodimonitor.py
@@ -49,6 +49,11 @@ class KodiMonitor(xbmc.Monitor):
             log.info("New log level: %s", current_log_level)
             window('emby_logLevel', value=current_log_level)
 
+        current_context = "true" if settings('enableContext') == "true" else ""
+        if window('emby_context') != current_context:
+            log.info("New context setting: %s", current_context)
+            window('emby_context', value=current_context)
+
     def onNotification(self, sender, method, data):
 
         if method not in ('Playlist.OnAdd', 'Player.OnStop', 'Player.OnClear'):
diff --git a/resources/settings.xml b/resources/settings.xml
index f7787d3e..7eae30e8 100644
--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -63,7 +63,8 @@
 	<category label="30235"><!-- Extras -->
 	    <setting id="enableCoverArt" type="bool" label="30157" default="true" />
 	    <setting id="ignoreSpecialsNextEpisodes" type="bool" label="30527" default="false" />
-	    <setting id="skipContextMenu" type="bool" label="30520" default="false" />
+	    <setting id="enableContext" type="bool" label="Enable the Emby context menu" default="true" />
+	    <setting id="skipContextMenu" type="bool" label="30520" default="false" visible="eq(-1,true)" subsetting="true" />
 		<setting id="additionalUsers" type="text" label="30528" default="" />
 		<setting type="lsep" label="30534" />
 		<setting id="connectMsg" type="bool" label="30249" default="true" />
diff --git a/resources/skins/default/1080i/script-emby-context.xml b/resources/skins/default/1080i/script-emby-context.xml
new file mode 100644
index 00000000..276f4940
--- /dev/null
+++ b/resources/skins/default/1080i/script-emby-context.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<window>
+	<defaultcontrol always="true">155</defaultcontrol>
+	<zorder>0</zorder>
+	<include>dialogeffect</include>
+	<controls>
+		<control type="image">
+			<description>Background fade</description>
+			<width>100%</width>
+			<height>100%</height>
+			<texture>emby-bg-fade.png</texture>
+		</control>
+		
+		<control type="group">
+			<width>450</width>
+			<left>38%</left>
+			<top>36%</top>
+			<control type="image">
+				<description>Background box</description>
+				<texture colordiffuse="ff111111">white.png</texture>
+				<height>90</height>
+			</control>
+			
+			<control type="image">
+				<description>Emby logo</description>
+				<texture>emby-icon.png</texture>
+				<aspectratio>keep</aspectratio>
+				<height>40</height>
+				<top>15</top>
+				<left>370</left>
+			</control>
+
+			<control type="image">
+				<description>separator</description>
+				<width>100%</width>
+				<height>0.5</height>
+				<top>70</top>
+				<left>-5</left>
+				<texture colordiffuse="ff484848" border="90,3,90,3">emby-separator.png</texture>
+			</control>
+
+			<control type="group">
+				<width>450</width>
+				<top>90</top>
+				<control type="list" id="155">
+					<width>100%</width>
+					<height>100%</height>
+					<align>center</align>
+					<onup>155</onup>
+					<ondown>155</ondown>
+					<onleft>155</onleft>
+					<onright>155</onright>
+					<scrolltime>200</scrolltime>
+					<itemlayout height="55">
+						<control type="image">
+							<description>Background box</description>
+							<width>450</width>
+							<texture colordiffuse="ff111111">white.png</texture>
+						</control>
+						<control type="label">
+							<width>400</width>
+							<font>font11</font>
+							<textcolor>ff525252</textcolor>
+							<left>25</left>
+							<align>center</align>
+							<aligny>center</aligny>
+							<info>ListItem.Label</info>
+						</control>
+					</itemlayout>
+
+					<focusedlayout height="55">
+						<control type="image">
+							<description>Background box</description>
+							<width>450</width>
+							<texture colordiffuse="ff111111">white.png</texture>
+						</control>
+						<control type="image">
+							<width>400</width>
+							<left>25</left>
+							<align>center</align>
+							<texture border="5" colordiffuse="ff222222">white.png</texture>
+							<visible>Control.HasFocus(155)</visible>
+							<animation effect="fade" time="300">Visible</animation>
+							<animation effect="fade" time="300">Hidden</animation>
+						</control>
+						<control type="label">
+							<width>400</width>
+							<font>font11</font>
+							<textcolor>white</textcolor>
+							<left>25</left>
+							<align>center</align>
+							<aligny>center</aligny>
+							<info>ListItem.Label</info>
+						</control>
+					</focusedlayout>
+				</control>
+			</control>
+		</control>
+	</controls>
+</window>
\ No newline at end of file
diff --git a/resources/skins/default/media/emby-icon.png b/resources/skins/default/media/emby-icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..cb7c85caf3cba44da1dd5bb456035b7622204ff4
GIT binary patch
literal 1850
zcmb`Idr%Ws6vppvf(cQZh)ONcCPhWDBGeaJ#9fREj1Uk+5Y(Wwr4?IfD-scQv#12r
z*0fIXfkLRI6h)#U-~*CX6z~P26p%OgAPP2sAqfeabo-d;w9}c+bUJfpe&?Kf&-b0b
z?#&Dq`A+0GZ~y=k{ry&k007Y`1lSB3aYYg9Xp{#BtXoAhq;$>y9#*Thur)udOhj46
z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gmyZlm}_1t8H2ez1x|hy(O=4v7^|zb
zQcKV6MRApZ(2v^J@^WVev!Yer=~x;1rgUh|yQZb^RA7pW(TFR@$DSQJ4pKfE=@pnh
zh9`oZ%R5RI3z4<aOtfFTa5WMZ?L^ino3?3YjXwyCgHMY~9ZZj48Ox~aI6jd|A%yUl
zB;HMismLv0IaZb~#Q6k1uH~joeXl}&m3#)Ys;IVII8FpYSV~FtD+_>+nR{v~kTlW-
zTpit4nq!dhYKwe3TQ=hph<4qE@Kg=gSzZ`V=HWN$a?hvVX-pC{@K*~KAY+<C)8(1&
z$ajbweU@r$;QI^0a}rA(O+wrEo8qe!NEYfsWi2%Av3<Wzd+QW(9Q|P|pQ)2gu04ok
z@3BbWV}m`uI7%$LSu)S-M?`_<bZ=-r{%e2OH?e^)5_n=wVJ{E4$g`LCJL_XSx8I$g
zlNea$rVG08#p12vuC~TD2fbSs`NXTtdm#5H`FvIMqzI-x@jIYhgkzQXu$^Dkep_3o
z`|i^dqSYCwgJg|;e7S7VWZsf@i#i5uPE!kBZ&Bb)aFOK-dCTogybCq&TyMdvMB<T7
z*lozIYqojzkPD6NP|fowpx*|yi-(d1UP-o_HUTP;7#-2twmYR?A?KPm0r9O!;+X!b
z6rUMJJkoQkz8zN1@pz1h!%(F)2)b$MvRP<;ThXeXrD(IRK`*P>8HU%PA&ax1Q_Q?!
zJ|LCglXzNpxR+XmR{Y09<W63UGeD<F3GXaZQo!OF9w|;K?@7&G{}!?Kh9qF9_evP|
h$!9n#;kU3D-ILV;)mBPBpZ-aJ|0>bS;uX<pzW^P9ec}KB

literal 0
HcmV?d00001

diff --git a/service.py b/service.py
index 1e241927..944500d7 100644
--- a/service.py
+++ b/service.py
@@ -60,6 +60,8 @@ class Service(object):
 
         window('emby_logLevel', value=str(log_level))
         window('emby_kodiProfile', value=xbmc.translatePath('special://profile'))
+        context_menu = "true" if settings('enableContext') == "true" else ""
+        window('emby_context', value=context_menu)
 
         # Initial logging
         log.warn("======== START %s ========", self.addon_name)