LibrePCB Developers Documentation
workspacelibraryscanner.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_CORE_WORKSPACELIBRARYSCANNER_H
21 #define LIBREPCB_CORE_WORKSPACELIBRARYSCANNER_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/filepath.h"
27 
28 #include <QtCore>
29 
30 #include <memory>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class Library;
38 class SQLiteDatabase;
39 class TransactionalFileSystem;
40 class WorkspaceLibraryDbWriter;
41 
42 /*******************************************************************************
43  * Class WorkspaceLibraryScanner
44  ******************************************************************************/
45 
53 class WorkspaceLibraryScanner final : public QThread {
54  Q_OBJECT
55 
56 public:
57  // Constructors / Destructor
58  WorkspaceLibraryScanner(const FilePath& librariesPath,
59  const FilePath& dbFilePath) noexcept;
60  WorkspaceLibraryScanner(const WorkspaceLibraryScanner& other) = delete;
61  ~WorkspaceLibraryScanner() noexcept;
62 
63  // Getters
64  int getProgressPercent() const noexcept { return mLastProgressPercent; }
65 
66  // General Methods
67  void startScan() noexcept;
68 
69  // Operator Overloadings
71  delete;
72 
73 signals:
74  void scanStarted();
75  void scanLibraryListUpdated(int libraryCount);
76  void scanProgressUpdate(int percent);
77  void scanSucceeded(int elementCount);
78  void scanFailed(QString errorMsg);
79  void scanFinished();
80 
81 private: // Methods
82  void run() noexcept override;
83  void scan() noexcept;
84  void getLibrariesOfDirectory(std::shared_ptr<TransactionalFileSystem> fs,
85  const QString& root,
86  QList<std::shared_ptr<Library>>& libs) noexcept;
87  QHash<FilePath, int> updateLibraries(
89  const QList<std::shared_ptr<Library>>& libs);
90  template <typename ElementType>
92  std::shared_ptr<TransactionalFileSystem> fs,
93  const FilePath& libPath, const QStringList& dirs,
94  int libId);
95  template <typename ElementType>
96  int addElementToDb(WorkspaceLibraryDbWriter& writer, int libId,
97  const ElementType& element);
98  template <typename ElementType>
99  void addTranslationsToDb(WorkspaceLibraryDbWriter& writer, int elementId,
100  const ElementType& element);
101  template <typename ElementType>
102  void addToCategories(WorkspaceLibraryDbWriter& writer, int elementId,
103  const ElementType& element);
104 
105 private: // Data
108  QSemaphore mSemaphore;
109  volatile bool mAbort;
111 };
112 
113 /*******************************************************************************
114  * End of File
115  ******************************************************************************/
116 
117 } // namespace librepcb
118 
119 #endif
int getProgressPercent() const noexcept
Definition: workspacelibraryscanner.h:64
~WorkspaceLibraryScanner() noexcept
Definition: workspacelibraryscanner.cpp:62
WorkspaceLibraryScanner & operator=(const WorkspaceLibraryScanner &rhs)=delete
QHash< FilePath, int > updateLibraries(SQLiteDatabase &db, WorkspaceLibraryDbWriter &writer, const QList< std::shared_ptr< Library >> &libs)
Definition: workspacelibraryscanner.cpp:212
void addTranslationsToDb(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:334
int mLastProgressPercent
Definition: workspacelibraryscanner.h:110
int addElementsToDb(WorkspaceLibraryDbWriter &writer, std::shared_ptr< TransactionalFileSystem > fs, const FilePath &libPath, const QStringList &dirs, int libId)
Definition: workspacelibraryscanner.cpp:268
WorkspaceLibraryScanner(const FilePath &librariesPath, const FilePath &dbFilePath) noexcept
Definition: workspacelibraryscanner.cpp:48
Definition: airwiresbuilder.cpp:34
QSemaphore mSemaphore
Definition: workspacelibraryscanner.h:108
void startScan() noexcept
Definition: workspacelibraryscanner.cpp:79
Database write functions for librepcb::WorkspaceLibraryDb.
Definition: workspacelibrarydbwriter.h:55
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition: workspacelibraryscanner.h:106
The WorkspaceLibraryScanner class.
Definition: workspacelibraryscanner.h:53
void scanProgressUpdate(int percent)
void scan() noexcept
Definition: workspacelibraryscanner.cpp:102
void run() noexcept override
Definition: workspacelibraryscanner.cpp:87
int addElementToDb(WorkspaceLibraryDbWriter &writer, int libId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:294
void scanFailed(QString errorMsg)
void getLibrariesOfDirectory(std::shared_ptr< TransactionalFileSystem > fs, const QString &root, QList< std::shared_ptr< Library >> &libs) noexcept
Definition: workspacelibraryscanner.cpp:189
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
The SQLiteDatabase class.
Definition: sqlitedatabase.h:43
volatile bool mAbort
Definition: workspacelibraryscanner.h:109
const FilePath mDbFilePath
Path to the SQLite database file.
Definition: workspacelibraryscanner.h:107
void addToCategories(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:346
void scanLibraryListUpdated(int libraryCount)
void scanSucceeded(int elementCount)