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):
#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")
@ -109,6 +114,9 @@ class LibrarySync():
#### PROCESS ADDS AND UPDATES ###
for item in allEmbyMovies:
if (self.ShouldStop()):
return False
if not item.get('IsFolder'):
allEmbyMovieIds.append(item["Id"])
@ -158,6 +166,9 @@ 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"])
@ -211,6 +222,9 @@ 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):
def ShouldStop(self):
if(prog != None and type(prog) == xbmcgui.DialogProgress):
if(prog.iscanceled() == True):
return True
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
if(xbmc.abortRequested):
return True
if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"):

View file

@ -12,12 +12,9 @@
<setting id="deviceName" type="text" label="30016" default="Kodi" />
<setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" />
</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">
<!-- <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="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" />
<setting id="dbSyncIndication" type="bool" label="30241" default="false" visible="true" enable="true" />
</category>
<category label="Playback"> <!-- Extra Sync options -->
<setting id="smbusername" type="text" label="30007" default="" visible="true" enable="true" />