changed: update version strings for beta4
[xbmc.git] / xbmc / utils / SaveFileStateJob.h
blobd2bdf0928742fef5f4a6e2842f430fc9b89389aa
2 #ifndef SAVE_FILE_STATE_H__
3 #define SAVE_FILE_STATE_H__
5 #include "Job.h"
6 #include "FileItem.h"
8 class CSaveFileStateJob : public CJob
10 CFileItem m_item;
11 CBookmark m_bookmark;
12 bool m_updatePlayCount;
13 public:
14 CSaveFileStateJob(const CFileItem& item,
15 const CBookmark& bookmark,
16 bool updatePlayCount)
17 : m_item(item),
18 m_bookmark(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 != "")
30 if (m_item.IsVideo())
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);
49 updateListing = true;
51 else
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);
75 updateListing = true;
77 videodatabase.Close();
79 if (updateListing)
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);
91 if (m_item.IsAudio())
93 CLog::Log(LOGDEBUG, "%s - Saving file state for audio item %s", __FUNCTION__, progressTrackingFile.c_str());
95 if (m_updatePlayCount)
97 #if 0
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())
101 #endif
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();
116 return true;
119 #endif // SAVE_FILE_STATE_H__