diff options
Diffstat (limited to 'xbmc/music/jobs')
-rw-r--r-- | xbmc/music/jobs/CMakeLists.txt | 15 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryCleaningJob.cpp | 40 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryCleaningJob.h | 38 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryExportJob.cpp | 43 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryExportJob.h | 42 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryImportJob.cpp | 42 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryImportJob.h | 42 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryJob.cpp | 24 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryJob.h | 50 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryProgressJob.cpp | 24 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryProgressJob.h | 29 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryScanningJob.cpp | 58 | ||||
-rw-r--r-- | xbmc/music/jobs/MusicLibraryScanningJob.h | 50 |
13 files changed, 497 insertions, 0 deletions
diff --git a/xbmc/music/jobs/CMakeLists.txt b/xbmc/music/jobs/CMakeLists.txt new file mode 100644 index 0000000..8ee0f5d --- /dev/null +++ b/xbmc/music/jobs/CMakeLists.txt @@ -0,0 +1,15 @@ +set(SOURCES MusicLibraryJob.cpp + MusicLibraryProgressJob.cpp + MusicLibraryCleaningJob.cpp + MusicLibraryExportJob.cpp + MusicLibraryImportJob.cpp + MusicLibraryScanningJob.cpp) + +set(HEADERS MusicLibraryJob.h + MusicLibraryProgressJob.h + MusicLibraryCleaningJob.h + MusicLibraryExportJob.h + MusicLibraryImportJob.h + MusicLibraryScanningJob.h) + +core_add_library(music_jobs) diff --git a/xbmc/music/jobs/MusicLibraryCleaningJob.cpp b/xbmc/music/jobs/MusicLibraryCleaningJob.cpp new file mode 100644 index 0000000..4361566 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryCleaningJob.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "MusicLibraryCleaningJob.h" + +#include "dialogs/GUIDialogProgress.h" +#include "music/MusicDatabase.h" + +CMusicLibraryCleaningJob::CMusicLibraryCleaningJob(CGUIDialogProgress* progressDialog) + : CMusicLibraryProgressJob(nullptr) +{ + if (progressDialog) + SetProgressIndicators(nullptr, progressDialog); + SetAutoClose(true); +} + +CMusicLibraryCleaningJob::~CMusicLibraryCleaningJob() = default; + +bool CMusicLibraryCleaningJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(), GetType()) != 0) + return false; + + const CMusicLibraryCleaningJob* cleaningJob = dynamic_cast<const CMusicLibraryCleaningJob*>(job); + if (cleaningJob == nullptr) + return false; + + return true; +} + +bool CMusicLibraryCleaningJob::Work(CMusicDatabase &db) +{ + db.Cleanup(GetProgressDialog()); + return true; +} diff --git a/xbmc/music/jobs/MusicLibraryCleaningJob.h b/xbmc/music/jobs/MusicLibraryCleaningJob.h new file mode 100644 index 0000000..6e893c6 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryCleaningJob.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "music/jobs/MusicLibraryProgressJob.h" + +#include <set> + +/*! + \brief Music library job implementation for cleaning the video library. +*/ +class CMusicLibraryCleaningJob : public CMusicLibraryProgressJob +{ +public: + /*! + \brief Creates a new music library cleaning job. + \param[in] progressDialog Progress dialog to be used to display the cleaning progress + */ + CMusicLibraryCleaningJob(CGUIDialogProgress* progressDialog); + ~CMusicLibraryCleaningJob() override; + + // specialization of CJob + const char *GetType() const override { return "MusicLibraryCleaningJob"; } + bool operator==(const CJob* job) const override; + +protected: + // implementation of CMusicLibraryJob + bool Work(CMusicDatabase &db) override; + +private: + +}; diff --git a/xbmc/music/jobs/MusicLibraryExportJob.cpp b/xbmc/music/jobs/MusicLibraryExportJob.cpp new file mode 100644 index 0000000..ca63d13 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryExportJob.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "MusicLibraryExportJob.h" + +#include "dialogs/GUIDialogProgress.h" +#include "music/MusicDatabase.h" +#include "settings/LibExportSettings.h" + +CMusicLibraryExportJob::CMusicLibraryExportJob(const CLibExportSettings& settings, CGUIDialogProgress* progressDialog) + : CMusicLibraryProgressJob(NULL), + m_settings(settings) +{ + if (progressDialog) + SetProgressIndicators(NULL, progressDialog); + SetAutoClose(true); +} + +CMusicLibraryExportJob::~CMusicLibraryExportJob() = default; + +bool CMusicLibraryExportJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(), GetType()) != 0) + return false; + + const CMusicLibraryExportJob* exportJob = dynamic_cast<const CMusicLibraryExportJob*>(job); + if (exportJob == NULL) + return false; + + return !(m_settings != exportJob->m_settings); +} + +bool CMusicLibraryExportJob::Work(CMusicDatabase &db) +{ + db.ExportToXML(m_settings, GetProgressDialog()); + + return true; +} diff --git a/xbmc/music/jobs/MusicLibraryExportJob.h b/xbmc/music/jobs/MusicLibraryExportJob.h new file mode 100644 index 0000000..4dc759e --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryExportJob.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "MusicLibraryProgressJob.h" +#include "settings/LibExportSettings.h" + +class CGUIDialogProgress; + +/*! + \brief Music library job implementation for exporting the music library. +*/ +class CMusicLibraryExportJob : public CMusicLibraryProgressJob +{ +public: + /*! + \brief Creates a new music library export job for the given paths. + + \param[in] settings Library export settings + \param[in] progressDialog Progress dialog to be used to display the export progress + */ + CMusicLibraryExportJob(const CLibExportSettings& settings, CGUIDialogProgress* progressDialog); + + ~CMusicLibraryExportJob() override; + + // specialization of CJob + const char *GetType() const override { return "MusicLibraryExportJob"; } + bool operator==(const CJob* job) const override; + +protected: + // implementation of CMusicLibraryJob + bool Work(CMusicDatabase &db) override; + +private: + CLibExportSettings m_settings; +}; diff --git a/xbmc/music/jobs/MusicLibraryImportJob.cpp b/xbmc/music/jobs/MusicLibraryImportJob.cpp new file mode 100644 index 0000000..6fcae05 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryImportJob.cpp @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2017-2018 Team Kodi +* This file is part of Kodi - https://kodi.tv +* +* SPDX-License-Identifier: GPL-2.0-or-later +* See LICENSES/README.md for more information. +*/ + +#include "MusicLibraryImportJob.h" + +#include "dialogs/GUIDialogProgress.h" +#include "music/MusicDatabase.h" + +CMusicLibraryImportJob::CMusicLibraryImportJob(const std::string& xmlFile, CGUIDialogProgress* progressDialog) + : CMusicLibraryProgressJob(nullptr) + , m_xmlFile(xmlFile) +{ + if (progressDialog) + SetProgressIndicators(nullptr, progressDialog); + SetAutoClose(true); +} + +CMusicLibraryImportJob::~CMusicLibraryImportJob() = default; + +bool CMusicLibraryImportJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(), GetType()) != 0) + return false; + + const CMusicLibraryImportJob* importJob = dynamic_cast<const CMusicLibraryImportJob*>(job); + if (importJob == nullptr) + return false; + + return !(m_xmlFile != importJob->m_xmlFile); +} + +bool CMusicLibraryImportJob::Work(CMusicDatabase &db) +{ + db.ImportFromXML(m_xmlFile, GetProgressDialog()); + + return true; +} diff --git a/xbmc/music/jobs/MusicLibraryImportJob.h b/xbmc/music/jobs/MusicLibraryImportJob.h new file mode 100644 index 0000000..bcca44f --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryImportJob.h @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2017-2018 Team Kodi +* This file is part of Kodi - https://kodi.tv +* +* SPDX-License-Identifier: GPL-2.0-or-later +* See LICENSES/README.md for more information. +*/ + +#pragma once + +#include "MusicLibraryProgressJob.h" + +class CGUIDialogProgress; + +/*! +\brief Music library job implementation for importing data to the music library. +*/ +class CMusicLibraryImportJob : public CMusicLibraryProgressJob +{ +public: + /*! + \brief Creates a new music library import job for the given xml file. + + \param[in] xmlFile xml file to import + \param[in] progressDialog Progress dialog to be used to display the import progress + */ + CMusicLibraryImportJob(const std::string &xmlFile, CGUIDialogProgress* progressDialog); + + ~CMusicLibraryImportJob() override; + + // specialization of CJob + const char *GetType() const override { return "MusicLibraryImportJob"; } + bool operator==(const CJob* job) const override; + +protected: + // implementation of CMusicLibraryJob + bool Work(CMusicDatabase &db) override; + +private: + std::string m_xmlFile; +}; + diff --git a/xbmc/music/jobs/MusicLibraryJob.cpp b/xbmc/music/jobs/MusicLibraryJob.cpp new file mode 100644 index 0000000..281d7f9 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryJob.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "MusicLibraryJob.h" + +#include "music/MusicDatabase.h" + +CMusicLibraryJob::CMusicLibraryJob() = default; + +CMusicLibraryJob::~CMusicLibraryJob() = default; + +bool CMusicLibraryJob::DoWork() +{ + CMusicDatabase db; + if (!db.Open()) + return false; + + return Work(db); +} diff --git a/xbmc/music/jobs/MusicLibraryJob.h b/xbmc/music/jobs/MusicLibraryJob.h new file mode 100644 index 0000000..81f68b7 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryJob.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "utils/Job.h" + +class CMusicDatabase; + +/*! + \brief Basic implementation/interface of a CJob which interacts with the + music database. + */ +class CMusicLibraryJob : public CJob +{ +public: + ~CMusicLibraryJob() override; + + /*! + \brief Whether the job can be cancelled or not. + */ + virtual bool CanBeCancelled() const { return false; } + + /*! + \brief Tries to cancel the running job. + \return True if the job was cancelled, false otherwise + */ + virtual bool Cancel() { return false; } + + // implementation of CJob + bool DoWork() override; + const char *GetType() const override { return "MusicLibraryJob"; } + bool operator==(const CJob* job) const override { return false; } + +protected: + CMusicLibraryJob(); + + /*! + \brief Worker method to be implemented by an actual implementation. + + \param[in] db Already open music database to be used for interaction + \return True if the process succeeded, false otherwise + */ + virtual bool Work(CMusicDatabase &db) = 0; +}; diff --git a/xbmc/music/jobs/MusicLibraryProgressJob.cpp b/xbmc/music/jobs/MusicLibraryProgressJob.cpp new file mode 100644 index 0000000..d07e85b --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryProgressJob.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "MusicLibraryProgressJob.h" + +CMusicLibraryProgressJob::CMusicLibraryProgressJob(CGUIDialogProgressBarHandle* progressBar) + : CProgressJob(progressBar) +{ } + +CMusicLibraryProgressJob::~CMusicLibraryProgressJob() = default; + +bool CMusicLibraryProgressJob::DoWork() +{ + bool result = CMusicLibraryJob::DoWork(); + + MarkFinished(); + + return result; +} diff --git a/xbmc/music/jobs/MusicLibraryProgressJob.h b/xbmc/music/jobs/MusicLibraryProgressJob.h new file mode 100644 index 0000000..ae843da --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryProgressJob.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "music/jobs/MusicLibraryJob.h" +#include "utils/ProgressJob.h" + +/*! + \brief Combined base implementation of a music library job with a progress bar. + */ +class CMusicLibraryProgressJob : public CProgressJob, public CMusicLibraryJob +{ +public: + ~CMusicLibraryProgressJob() override; + + // implementation of CJob + bool DoWork() override; + const char *GetType() const override { return "CMusicLibraryProgressJob"; } + bool operator==(const CJob* job) const override { return false; } + +protected: + explicit CMusicLibraryProgressJob(CGUIDialogProgressBarHandle* progressBar); +}; diff --git a/xbmc/music/jobs/MusicLibraryScanningJob.cpp b/xbmc/music/jobs/MusicLibraryScanningJob.cpp new file mode 100644 index 0000000..d2626a1 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryScanningJob.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "MusicLibraryScanningJob.h" + +#include "music/MusicDatabase.h" + +CMusicLibraryScanningJob::CMusicLibraryScanningJob(const std::string& directory, int flags, bool showProgress /* = true */) + : m_scanner(), + m_directory(directory), + m_showProgress(showProgress), + m_flags(flags) +{ } + +CMusicLibraryScanningJob::~CMusicLibraryScanningJob() = default; + +bool CMusicLibraryScanningJob::Cancel() +{ + if (!m_scanner.IsScanning()) + return true; + + m_scanner.Stop(); + return true; +} + +bool CMusicLibraryScanningJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(), GetType()) != 0) + return false; + + const CMusicLibraryScanningJob* scanningJob = dynamic_cast<const CMusicLibraryScanningJob*>(job); + if (scanningJob == nullptr) + return false; + + return m_directory == scanningJob->m_directory && + m_flags == scanningJob->m_flags; +} + +bool CMusicLibraryScanningJob::Work(CMusicDatabase &db) +{ + m_scanner.ShowDialog(m_showProgress); + if (m_flags & MUSIC_INFO::CMusicInfoScanner::SCAN_ALBUMS) + // Scrape additional album information + m_scanner.FetchAlbumInfo(m_directory, m_flags & MUSIC_INFO::CMusicInfoScanner::SCAN_RESCAN); + else if (m_flags & MUSIC_INFO::CMusicInfoScanner::SCAN_ARTISTS) + // Scrape additional artist information + m_scanner.FetchArtistInfo(m_directory, m_flags & MUSIC_INFO::CMusicInfoScanner::SCAN_RESCAN); + else + // Scan tags from music files, and optionally scrape artist and album info + m_scanner.Start(m_directory, m_flags); + + return true; +} diff --git a/xbmc/music/jobs/MusicLibraryScanningJob.h b/xbmc/music/jobs/MusicLibraryScanningJob.h new file mode 100644 index 0000000..6c5ea13 --- /dev/null +++ b/xbmc/music/jobs/MusicLibraryScanningJob.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "music/infoscanner/MusicInfoScanner.h" +#include "music/jobs/MusicLibraryJob.h" + +#include <string> + +/*! + \brief Music library job implementation for scanning items. + Uses CMusicInfoScanner for scanning and can be run with or + without a visible progress bar. + */ +class CMusicLibraryScanningJob : public CMusicLibraryJob +{ +public: + /*! + \brief Creates a new music library tag scanning and data scraping job. + \param[in] directory Directory to be scanned for new items + \param[in] flags What kind of scan to do + \param[in] showProgress Whether to show a progress bar or not + */ + CMusicLibraryScanningJob(const std::string& directory, int flags, bool showProgress = true); + ~CMusicLibraryScanningJob() override; + + // specialization of CMusicLibraryJob + bool CanBeCancelled() const override { return true; } + bool Cancel() override; + + // specialization of CJob + const char *GetType() const override { return "MusicLibraryScanningJob"; } + bool operator==(const CJob* job) const override; + +protected: + // implementation of CMusicLibraryJob + bool Work(CMusicDatabase &db) override; + +private: + MUSIC_INFO::CMusicInfoScanner m_scanner; + std::string m_directory; + bool m_showProgress; + int m_flags; +}; |