def advanced_menu():
    """ Second Level Menu which provides advanced options """

    for camera_number in "123456":

        if settings.enabled_camera(camera_number):

            list_label = settings.getCameraName(camera_number)

            # List submenus for each enabled camera
            addDirectoryItem(name=list_label + ' ' + utils.translation(32029),
                             isFolder=True,
                             icon=utils.get_icon(camera_number),
                             fanart=utils.get_fanart(camera_number),
                             parameters={
                                 'action': 'advanced_camera',
                                 'camera_number': camera_number
                             })

    # Toggle Preview Ability to be activated by alarms
    addDirectoryItem(name=utils.translation(32217),
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'toggle_preview'})

    # Add-on Settings
    addDirectoryItem(name=utils.translation(32028),
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'settings'})

    # Restart the preview service
    addDirectoryItem(name='Restart Preview Service',
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'restart_service'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def advanced_menu():                                                
    """ Second Level Menu which provides advanced options """
    
    for camera_number in "123456":
        
        if settings.enabled_camera(camera_number):
            
            list_label = settings.getCameraName(camera_number)
            
            # List submenus for each enabled camera
            addDirectoryItem(name =  list_label + ' ' + utils.translation(32029),
                             isFolder = True,
                             icon = utils.get_icon(camera_number),
                             fanart = utils.get_fanart(camera_number),
                             parameters = {'action': 'advanced_camera',
                                           'camera_number': camera_number})
    

    # Toggle Preview Ability to be activated by alarms
    addDirectoryItem(name = utils.translation(32217),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'toggle_preview'})

    # Add-on Settings  
    addDirectoryItem(name = utils.translation(32028),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'settings'})

    # Restart the preview service
    addDirectoryItem(name = 'Restart Preview Service',
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'restart_service'})
        
    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def main_menu():                                                
    """ First Level Menu to access main functions """

    if settings.atLeastOneCamera():

        # All Camera Player
        addDirectoryItem(name = utils.translation(32027),
                         icon = utils.get_icon('default'),
                         fanart = utils.get_fanart('default'),
                         parameters = {'action': 'all_cameras'})

        for camera_number in "123456":
            
            if settings.enabled_camera(camera_number):
                
                camera = Camera(camera_number)
                list_label = settings.getCameraName(camera_number)

                # Build Context Menu
                li = li = xbmcgui.ListItem(list_label)
                context_items = []

                if settings.getSetting('enabled_preview', camera_number) == 'true':
                    #Show Preview
                    context_items.append((utils.translation(32210), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=show_preview&camera_number=%s)' %camera_number))

                    #Disable Preview
                    context_items.append((utils.translation(32212), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=disable_preview&camera_number=%s)' %camera_number))
                else:
                    #Enable Preview
                    context_items.append((utils.translation(32211), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=enable_preview&camera_number=%s)' %camera_number))
                
                camera_type = settings.getCameraType(camera_number)
                if camera_type < 3:
                    #Play Stream no Controls
                    context_items.append((utils.translation(32214), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=single_camera_no_controls&camera_number=%s)' %camera_number))

                    #Camera Settings
                    context_items.append((utils.translation(32215), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=camera_settings&camera_number=%s)' %camera_number))

                # Update Fanart
                if settings.getSetting_int('fanart') == 1:
                    context_items.append((utils.translation(32213), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=update_fanart&camera_number=%s)' %camera_number))
                    
                li.addContextMenuItems(context_items, replaceItems=True)

                # Fanart URL
                new_art_url = None
                if camera.Connected(monitor):
                    new_art_url = camera.getSnapShotUrl()
                else:
                    if camera.Connected(monitor, False):
                        new_art_url = camera.getSnapShotUrl()
                
                # Single Camera Player for enabled cameras
                addDirectoryItem(name = list_label, 
                                 icon = utils.get_icon(camera_number),
                                 fanart = utils.get_fanart(camera_number, new_art_url),
                                 li = li, 
                                 parameters = {'action': 'single_camera',
                                               'camera_number': camera_number})

        # Link to Second Level Advanced Menu
        addDirectoryItem(name = utils.translation(32029),
                         isFolder = True,
                         icon = utils.get_icon('advanced'), 
                         fanart = utils.get_fanart('default'),
                         parameters={'action': 'advanced'})

    else:

        # Add-on Settings if no cameras are configured
        addDirectoryItem(name = utils.translation(32028),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'settings'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
    utils.cleanup_images()     
def main_menu():
    """ First Level Menu to access main functions """

    if settings.atLeastOneCamera():

        # All Camera Player
        addDirectoryItem(name=utils.translation(32027),
                         icon=utils.get_icon('default'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'all_cameras'})

        for camera_number in "123456":

            if settings.enabled_camera(camera_number):

                camera = Camera(camera_number)
                list_label = settings.getCameraName(camera_number)

                # Build Context Menu
                li = li = xbmcgui.ListItem(list_label)
                context_items = []

                if settings.getSetting('enabled_preview',
                                       camera_number) == 'true':
                    #Show Preview
                    context_items.append((utils.translation(
                        32210
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=show_preview&camera_number=%s)'
                                          % camera_number))

                    #Disable Preview
                    context_items.append((utils.translation(
                        32212
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=disable_preview&camera_number=%s)'
                                          % camera_number))
                else:
                    #Enable Preview
                    context_items.append((utils.translation(
                        32211
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=enable_preview&camera_number=%s)'
                                          % camera_number))

                camera_type = settings.getCameraType(camera_number)
                if camera_type < 3:
                    #Play Stream no Controls
                    context_items.append((utils.translation(
                        32214
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=single_camera_no_controls&camera_number=%s)'
                                          % camera_number))

                    #Camera Settings
                    context_items.append((utils.translation(
                        32215
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=camera_settings&camera_number=%s)'
                                          % camera_number))

                # Update Fanart
                if settings.getSetting_int('fanart') == 1:
                    context_items.append((utils.translation(
                        32213
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=update_fanart&camera_number=%s)'
                                          % camera_number))

                li.addContextMenuItems(context_items, replaceItems=True)

                # Fanart URL
                new_art_url = None
                if camera.Connected(monitor):
                    new_art_url = camera.getSnapShotUrl()
                else:
                    if camera.Connected(monitor, False):
                        new_art_url = camera.getSnapShotUrl()

                # Single Camera Player for enabled cameras
                addDirectoryItem(name=list_label,
                                 icon=utils.get_icon(camera_number),
                                 fanart=utils.get_fanart(
                                     camera_number, new_art_url),
                                 li=li,
                                 parameters={
                                     'action': 'single_camera',
                                     'camera_number': camera_number
                                 })

        # Link to Second Level Advanced Menu
        addDirectoryItem(name=utils.translation(32029),
                         isFolder=True,
                         icon=utils.get_icon('advanced'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'advanced'})

    else:

        # Add-on Settings if no cameras are configured
        addDirectoryItem(name=utils.translation(32028),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'settings'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
    utils.cleanup_images()