fixed progress dialog and added shouldstop event

This commit is contained in:
Marcel van der Veldt 2015-05-02 19:49:39 +02:00
parent 367b658a29
commit 3d77a9dd3a
2 changed files with 37 additions and 25 deletions

View file

@ -34,18 +34,21 @@ class LibrarySync():
def FullLibrarySync(self): def FullLibrarySync(self):
#show the progress dialog
pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Performing full sync')
#set some variable to check if this is the first run #set some variable to check if this is the first run
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon(id='plugin.video.emby')
startupDone = WINDOW.getProperty("startup") == "done" startupDone = WINDOW.getProperty("startup") == "done"
syncInstallRunDone = addon.getSetting("SyncInstallRunDone") == "true" syncInstallRunDone = addon.getSetting("SyncInstallRunDone") == "true"
dbSyncIndication = addon.getSetting("dbSyncIndication") == "true"
WINDOW.setProperty("SyncDatabaseRunning", "true") WINDOW.setProperty("SyncDatabaseRunning", "true")
#show the progress dialog
pDialog = None
if (syncInstallRunDone == False or dbSyncIndication):
pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Performing full sync')
if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"):
utils.logMsg("Sync Database", "Can not start SyncDatabaseShouldStop=True", 0) utils.logMsg("Sync Database", "Can not start SyncDatabaseShouldStop=True", 0)
return True return True
@ -62,6 +65,10 @@ class LibrarySync():
# sync movies # sync movies
self.MoviesFullSync(connection,cursor,pDialog) self.MoviesFullSync(connection,cursor,pDialog)
if (self.ShouldStop()):
return False
#sync Tvshows and episodes #sync Tvshows and episodes
self.TvShowsFullSync(connection,cursor,pDialog) self.TvShowsFullSync(connection,cursor,pDialog)
@ -72,8 +79,6 @@ class LibrarySync():
# Force refresh the library # Force refresh the library
xbmc.executebuiltin("UpdateLibrary(video)") xbmc.executebuiltin("UpdateLibrary(video)")
xbmc.executebuiltin("Container.Refresh")
xbmc.executebuiltin("Container.Update")
# set prop to show we have run for the first time # set prop to show we have run for the first time
WINDOW.setProperty("startup", "done") WINDOW.setProperty("startup", "done")
@ -109,6 +114,9 @@ class LibrarySync():
#### PROCESS ADDS AND UPDATES ### #### PROCESS ADDS AND UPDATES ###
for item in allEmbyMovies: for item in allEmbyMovies:
if (self.ShouldStop()):
return False
if not item.get('IsFolder'): if not item.get('IsFolder'):
allEmbyMovieIds.append(item["Id"]) allEmbyMovieIds.append(item["Id"])
@ -158,6 +166,9 @@ class LibrarySync():
#### TVSHOW: PROCESS ADDS AND UPDATES ### #### TVSHOW: PROCESS ADDS AND UPDATES ###
for item in allEmbyTvShows: for item in allEmbyTvShows:
if (self.ShouldStop()):
return False
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
allEmbyTvShowIds.append(item["Id"]) allEmbyTvShowIds.append(item["Id"])
@ -211,6 +222,9 @@ class LibrarySync():
#### EPISODES: PROCESS ADDS AND UPDATES ### #### EPISODES: PROCESS ADDS AND UPDATES ###
for item in allEmbyEpisodes: for item in allEmbyEpisodes:
if (self.ShouldStop()):
return False
allEmbyEpisodeIds.append(item["Id"]) allEmbyEpisodeIds.append(item["Id"])
#get the existing entry (if exists) in Kodi DB #get the existing entry (if exists) in Kodi DB
@ -239,7 +253,13 @@ class LibrarySync():
def IncrementalSync(self, itemList): def IncrementalSync(self, itemList):
#this will only perform sync for items received by the websocket #this will only perform sync for items received by the websocket
addon = xbmcaddon.Addon(id='plugin.video.emby')
dbSyncIndication = addon.getSetting("dbSyncIndication") == "true"
WINDOW.setProperty("SyncDatabaseRunning", "true")
#show the progress dialog
pDialog = None
if (dbSyncIndication):
pDialog = xbmcgui.DialogProgressBG() pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Performing incremental sync...') pDialog.create('Emby for Kodi', 'Performing incremental sync...')
@ -283,20 +303,15 @@ class LibrarySync():
finally: finally:
cursor.close() cursor.close()
xbmc.executebuiltin("UpdateLibrary(video)") xbmc.executebuiltin("UpdateLibrary(video)")
xbmc.executebuiltin("Container.Refresh") WINDOW.setProperty("SyncDatabaseRunning", "false")
xbmc.executebuiltin("Container.Update")
#close the progress dialog #close the progress dialog
if(pDialog != None): if(pDialog != None):
pDialog.close() pDialog.close()
def ShouldStop(self, prog): def ShouldStop(self):
if(prog != None and type(prog) == xbmcgui.DialogProgress): if(xbmc.abortRequested):
if(prog.iscanceled() == True):
return True
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
return True return True
if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"):

View file

@ -12,12 +12,9 @@
<setting id="deviceName" type="text" label="30016" default="Kodi" /> <setting id="deviceName" type="text" label="30016" default="Kodi" />
<setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" /> <setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" />
</category> </category>
<!-- <category label="Manual sync"> <setting label="Run manual full sync now" type="action" action="RunScript(plugin.video.mbsync, fullsync)" /> <setting label="Run manual incremental sync now" type="action" action="RunScript(plugin.video.mbsync, incrementalsync)" /> <setting label="Reset entire local library" type="action" action="RunScript(plugin.video.mbsync, reset)" /> </category> -->
<category label="Sync Options"> <category label="Sync Options">
<!-- <setting id="syncMovieBoxSets" type="bool" label="30238" default="true" visible="true" enable="true" /> --> <!-- <setting id="syncMovieBoxSets" type="bool" label="30238" default="true" visible="true" enable="true" /> -->
<setting id="enablePlayCountSync" type="bool" label="30240" default="true" visible="true" enable="true" /> <setting id="dbSyncIndication" type="bool" label="30241" default="false" visible="true" enable="true" />
<setting id="dbSyncIndication" type="labelenum" label="30241" values="None|Notify OnChange|Notify OnFinish|BG Progress|Dialog Progress" default="None" />
<setting id="playCountSyncIndication" type="labelenum" label="30242" values="None|Notify OnChange|Notify OnFinish|BG Progress|Dialog Progress" default="None" />
</category> </category>
<category label="Playback"> <!-- Extra Sync options --> <category label="Playback"> <!-- Extra Sync options -->
<setting id="smbusername" type="text" label="30007" default="" visible="true" enable="true" /> <setting id="smbusername" type="text" label="30007" default="" visible="true" enable="true" />