From 3d77a9dd3ac7ee3b7dcbdee39ad53136cceaa029 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 2 May 2015 19:49:39 +0200 Subject: [PATCH] fixed progress dialog and added shouldstop event --- resources/lib/LibrarySync.py | 57 +++++++++++++++++++++++------------- resources/settings.xml | 5 +--- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index c53fdcc3..1adc1b64 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -34,18 +34,21 @@ class LibrarySync(): 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 addon = xbmcaddon.Addon(id='plugin.video.emby') - startupDone = WINDOW.getProperty("startup") == "done" syncInstallRunDone = addon.getSetting("SyncInstallRunDone") == "true" + dbSyncIndication = addon.getSetting("dbSyncIndication") == "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"): utils.logMsg("Sync Database", "Can not start SyncDatabaseShouldStop=True", 0) return True @@ -62,6 +65,10 @@ class LibrarySync(): # sync movies self.MoviesFullSync(connection,cursor,pDialog) + + if (self.ShouldStop()): + return False + #sync Tvshows and episodes self.TvShowsFullSync(connection,cursor,pDialog) @@ -72,8 +79,6 @@ class LibrarySync(): # Force refresh the library xbmc.executebuiltin("UpdateLibrary(video)") - xbmc.executebuiltin("Container.Refresh") - xbmc.executebuiltin("Container.Update") # set prop to show we have run for the first time WINDOW.setProperty("startup", "done") @@ -108,7 +113,10 @@ class LibrarySync(): #### PROCESS ADDS AND UPDATES ### for item in allEmbyMovies: - + + if (self.ShouldStop()): + return False + if not item.get('IsFolder'): allEmbyMovieIds.append(item["Id"]) @@ -157,7 +165,10 @@ class LibrarySync(): #### TVSHOW: PROCESS ADDS AND UPDATES ### for item in allEmbyTvShows: - + + if (self.ShouldStop()): + return False + if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: allEmbyTvShowIds.append(item["Id"]) @@ -210,7 +221,10 @@ class LibrarySync(): #### EPISODES: PROCESS ADDS AND UPDATES ### for item in allEmbyEpisodes: - + + if (self.ShouldStop()): + return False + allEmbyEpisodeIds.append(item["Id"]) #get the existing entry (if exists) in Kodi DB @@ -239,9 +253,15 @@ class LibrarySync(): def IncrementalSync(self, itemList): #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") - pDialog = xbmcgui.DialogProgressBG() - pDialog.create('Emby for Kodi', 'Performing incremental sync...') + #show the progress dialog + pDialog = None + if (dbSyncIndication): + pDialog = xbmcgui.DialogProgressBG() + pDialog.create('Emby for Kodi', 'Performing incremental sync...') connection = utils.KodiSQL() cursor = connection.cursor() @@ -283,20 +303,15 @@ class LibrarySync(): finally: cursor.close() xbmc.executebuiltin("UpdateLibrary(video)") - xbmc.executebuiltin("Container.Refresh") - xbmc.executebuiltin("Container.Update") + WINDOW.setProperty("SyncDatabaseRunning", "false") #close the progress dialog if(pDialog != None): pDialog.close() - def ShouldStop(self, prog): - - if(prog != None and type(prog) == xbmcgui.DialogProgress): - if(prog.iscanceled() == True): - return True - - if(xbmc.Player().isPlaying() or xbmc.abortRequested): + def ShouldStop(self): + + if(xbmc.abortRequested): return True if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): diff --git a/resources/settings.xml b/resources/settings.xml index ff9d43aa..58975d29 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -12,12 +12,9 @@ - - - - +