kodi
VideoLibraryQueue.h
1 /*
2  * Copyright (C) 2014-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "threads/CriticalSection.h"
12 #include "utils/JobManager.h"
13 
14 #include <map>
15 #include <memory>
16 #include <set>
17 
18 class CFileItem;
20 class CVideoLibraryJob;
21 
28 class CVideoLibraryQueue : protected CJobQueue
29 {
30 public:
31  ~CVideoLibraryQueue() override;
32 
37 
45  void ScanLibrary(const std::string& directory, bool scanAll = false, bool showProgress = true);
46 
52  bool IsScanningLibrary() const;
53 
57  void StopLibraryScanning();
58 
67  bool CleanLibrary(const std::set<int>& paths = std::set<int>(),
68  bool asynchronous = true,
69  CGUIDialogProgressBarHandle* progressBar = NULL);
70 
77  bool CleanLibraryModal(const std::set<int>& paths = std::set<int>());
78 
88  void RefreshItem(std::shared_ptr<CFileItem> item,
89  bool ignoreNfo = false,
90  bool forceRefresh = true,
91  bool refreshAll = false,
92  const std::string& searchTitle = "");
93 
102  bool RefreshItemModal(std::shared_ptr<CFileItem> item,
103  bool forceRefresh = true,
104  bool refreshAll = false);
105 
112  void MarkAsWatched(const std::shared_ptr<CFileItem>& item, bool watched);
113 
119  void ResetResumePoint(const std::shared_ptr<CFileItem>& item);
120 
126  void AddJob(CVideoLibraryJob *job);
127 
133  void CancelJob(CVideoLibraryJob *job);
134 
138  void CancelAllJobs();
139 
143  bool IsRunning() const;
144 
145 protected:
146  // implementation of IJobCallback
147  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
148 
152  void Refresh();
153 
154 private:
156  CVideoLibraryQueue(const CVideoLibraryQueue&) = delete;
157  CVideoLibraryQueue const& operator=(CVideoLibraryQueue const&) = delete;
158 
159  typedef std::set<CVideoLibraryJob*> VideoLibraryJobs;
160  typedef std::map<std::string, VideoLibraryJobs> VideoLibraryJobMap;
161  VideoLibraryJobMap m_jobs;
162  CCriticalSection m_critical;
163 
164  bool m_modal = false;
165  bool m_cleaning = false;
166 };
void AddJob(CVideoLibraryJob *job)
Adds the given job to the queue.
Definition: VideoLibraryQueue.cpp:170
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
void StopLibraryScanning()
Stop and dequeue all scanning jobs.
Definition: VideoLibraryQueue.cpp:67
void OnJobComplete(unsigned int jobID, bool success, CJob *job) override
The callback used when a job completes.
Definition: VideoLibraryQueue.cpp:238
void ScanLibrary(const std::string &directory, bool scanAll=false, bool showProgress=true)
Enqueue a library scan job.
Definition: VideoLibraryQueue.cpp:43
Basic implementation/interface of a CJob which interacts with the video database. ...
Definition: VideoLibraryJob.h:19
void Refresh()
Notifies all to refresh the current listings.
Definition: VideoLibraryQueue.cpp:231
bool IsRunning() const
Whether any jobs are running or not.
Definition: VideoLibraryQueue.cpp:226
bool RefreshItemModal(std::shared_ptr< CFileItem > item, bool forceRefresh=true, bool refreshAll=false)
Refreshes the details of the given item with a modal dialog.
Definition: VideoLibraryQueue.cpp:137
void RefreshItem(std::shared_ptr< CFileItem > item, bool ignoreNfo=false, bool forceRefresh=true, bool refreshAll=false, const std::string &searchTitle="")
Enqueues a job to refresh the details of the given item.
Definition: VideoLibraryQueue.cpp:127
bool CleanLibraryModal(const std::set< int > &paths=std::set< int >())
Executes a library cleaning with a modal dialog.
Definition: VideoLibraryQueue.cpp:110
static CVideoLibraryQueue & GetInstance()
Gets the singleton instance of the video library queue.
Definition: VideoLibraryQueue.cpp:37
void MarkAsWatched(const std::shared_ptr< CFileItem > &item, bool watched)
Queue a watched status update job.
Definition: VideoLibraryQueue.cpp:154
bool IsScanningLibrary() const
Check if a library scan is in progress.
Definition: VideoLibraryQueue.cpp:48
void CancelAllJobs()
Cancels all running and queued jobs.
Definition: VideoLibraryQueue.cpp:217
void CancelJob(CVideoLibraryJob *job)
Cancels the given job and removes it from the queue.
Definition: VideoLibraryQueue.cpp:192
Definition: GUIDialogExtendedProgressBar.h:16
Queue for video library jobs.
Definition: VideoLibraryQueue.h:28
bool CleanLibrary(const std::set< int > &paths=std::set< int >(), bool asynchronous=true, CGUIDialogProgressBarHandle *progressBar=NULL)
Enqueue a library cleaning job.
Definition: VideoLibraryQueue.cpp:83
Represents a file on a share.
Definition: FileItem.h:102
void ResetResumePoint(const std::shared_ptr< CFileItem > &item)
Queue a reset resume point job.
Definition: VideoLibraryQueue.cpp:162
Job Queue class to handle a queue of unique jobs to be processed sequentially.
Definition: JobManager.h:63