2 #ifndef SAVE_FILE_STATE_H__
3 #define SAVE_FILE_STATE_H__
8 class CSaveFileStateJob
: public CJob
12 bool m_updatePlayCount
;
14 CSaveFileStateJob(const CFileItem
& item
,
15 const CBookmark
& bookmark
,
19 m_updatePlayCount(updatePlayCount
) {}
20 virtual ~CSaveFileStateJob() {}
21 virtual bool DoWork();
24 bool CSaveFileStateJob::DoWork()
26 CStdString progressTrackingFile
= m_item
.m_strPath
;
28 if (progressTrackingFile
!= "")
32 CLog::Log(LOGDEBUG
, "%s - Saving file state for video item %s", __FUNCTION__
, progressTrackingFile
.c_str());
34 CVideoDatabase videodatabase
;
35 if (videodatabase
.Open())
37 bool updateListing
= false;
38 // No resume & watched status for livetv
39 if (!m_item
.IsLiveTV())
41 if (m_updatePlayCount
)
43 CLog::Log(LOGDEBUG
, "%s - Marking video item %s as watched", __FUNCTION__
, progressTrackingFile
.c_str());
45 // consider this item as played
46 videodatabase
.IncrementPlayCount(m_item
);
47 m_item
.GetVideoInfoTag()->m_playCount
++;
48 m_item
.SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED
, true);
52 videodatabase
.UpdateLastPlayed(m_item
);
54 if (m_bookmark
.timeInSeconds
< 0.0f
)
56 videodatabase
.ClearBookMarksOfFile(progressTrackingFile
, CBookmark::RESUME
);
58 else if (m_bookmark
.timeInSeconds
> 0.0f
)
60 videodatabase
.AddBookMarkToFile(progressTrackingFile
, m_bookmark
, CBookmark::RESUME
);
64 if (g_settings
.m_currentVideoSettings
!= g_settings
.m_defaultVideoSettings
)
66 videodatabase
.SetVideoSettings(progressTrackingFile
, g_settings
.m_currentVideoSettings
);
69 if ((m_item
.IsDVDImage() ||
70 m_item
.IsDVDFile() ) &&
71 m_item
.HasVideoInfoTag() &&
72 m_item
.GetVideoInfoTag()->HasStreamDetails())
74 videodatabase
.SetStreamDetailsForFile(m_item
.GetVideoInfoTag()->m_streamDetails
,progressTrackingFile
);
77 videodatabase
.Close();
81 CUtil::DeleteVideoDatabaseDirectoryCache();
82 CFileItemPtr
msgItem(new CFileItem(m_item
));
83 if (m_item
.HasProperty("original_listitem_url"))
84 msgItem
->m_strPath
= m_item
.GetProperty("original_listitem_url");
85 CGUIMessage
message(GUI_MSG_NOTIFY_ALL
, g_windowManager
.GetActiveWindow(), 0, GUI_MSG_UPDATE_ITEM
, 1, msgItem
); // 1 to update the listing as well
86 g_windowManager
.SendThreadMessage(message
);
93 CLog::Log(LOGDEBUG
, "%s - Saving file state for audio item %s", __FUNCTION__
, progressTrackingFile
.c_str());
95 if (m_updatePlayCount
)
98 // Can't write to the musicdatabase while scanning for music info
99 CGUIDialogMusicScan
*dialog
= (CGUIDialogMusicScan
*)g_windowManager
.GetWindow(WINDOW_DIALOG_MUSIC_SCAN
);
100 if (dialog
&& !dialog
->IsDialogRunning())
103 // consider this item as played
104 CLog::Log(LOGDEBUG
, "%s - Marking audio item %s as listened", __FUNCTION__
, progressTrackingFile
.c_str());
106 CMusicDatabase musicdatabase
;
107 if (musicdatabase
.Open())
109 musicdatabase
.IncrTop100CounterByFileName(progressTrackingFile
);
110 musicdatabase
.Close();
119 #endif // SAVE_FILE_STATE_H__