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 ******************************************************************************/
35namespace librepcb {
36
37class Library;
38class SQLiteDatabase;
39class WorkspaceLibraryDbWriter;
40
41/*******************************************************************************
42 * Class WorkspaceLibraryScanner
43 ******************************************************************************/
44
52class WorkspaceLibraryScanner final : public QThread {
53 Q_OBJECT
54
55public:
56 // Constructors / Destructor
57 WorkspaceLibraryScanner(const FilePath& librariesPath,
58 const FilePath& dbFilePath) noexcept;
60 ~WorkspaceLibraryScanner() noexcept;
61
62 // Getters
63 int getProgressPercent() const noexcept { return mLastProgressPercent; }
64
65 // General Methods
66 void startScan() noexcept;
67
68 // Operator Overloadings
70 delete;
71
72signals:
74 void scanLibraryListUpdated(int libraryCount);
75 void scanProgressUpdate(int percent);
76 void scanSucceeded(int elementCount);
77 void scanFailed(QString errorMsg);
79
80private: // Methods
81 void run() noexcept override;
82 void scan() noexcept;
83 void getLibrariesOfDirectory(const QString& root,
84 QList<std::shared_ptr<Library>>& libs) noexcept;
85
86 QHash<FilePath, int> updateLibraries(
88 const QList<std::shared_ptr<Library>>& libs);
89 template <typename ElementType>
90 int addElementsToDb(WorkspaceLibraryDbWriter& writer, const FilePath& libPath,
91 const QStringList& dirs, int libId);
92 template <typename ElementType>
93 int addElementToDb(WorkspaceLibraryDbWriter& writer, int libId,
94 const ElementType& element);
95 template <typename ElementType>
96 void addTranslationsToDb(WorkspaceLibraryDbWriter& writer, int elementId,
97 const ElementType& element);
98 template <typename ElementType>
99 void addToCategories(WorkspaceLibraryDbWriter& writer, int elementId,
100 const ElementType& element);
101 template <typename ElementType>
102 std::unique_ptr<ElementType> openAndMigrate(const FilePath& fp);
103
104private: // Data
107 QSemaphore mSemaphore;
108 volatile bool mAbort;
110};
111
112/*******************************************************************************
113 * End of File
114 ******************************************************************************/
115
116} // namespace librepcb
117
118#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Library class represents a library directory.
Definition: library.h:46
The SQLiteDatabase class.
Definition: sqlitedatabase.h:43
Database write functions for librepcb::WorkspaceLibraryDb.
Definition: workspacelibrarydbwriter.h:57
The WorkspaceLibraryScanner class.
Definition: workspacelibraryscanner.h:52
void run() noexcept override
Definition: workspacelibraryscanner.cpp:89
~WorkspaceLibraryScanner() noexcept
Definition: workspacelibraryscanner.cpp:64
void scanProgressUpdate(int percent)
int addElementsToDb(WorkspaceLibraryDbWriter &writer, const FilePath &libPath, const QStringList &dirs, int libId)
Definition: workspacelibraryscanner.cpp:268
std::unique_ptr< ElementType > openAndMigrate(const FilePath &fp)
Definition: workspacelibraryscanner.cpp:375
void scanFailed(QString errorMsg)
volatile bool mAbort
Definition: workspacelibraryscanner.h:108
void scanSucceeded(int elementCount)
void scanLibraryListUpdated(int libraryCount)
QSemaphore mSemaphore
Definition: workspacelibraryscanner.h:107
void startScan() noexcept
Definition: workspacelibraryscanner.cpp:81
void getLibrariesOfDirectory(const QString &root, QList< std::shared_ptr< Library > > &libs) noexcept
Definition: workspacelibraryscanner.cpp:189
void scan() noexcept
Definition: workspacelibraryscanner.cpp:104
int addElementToDb(WorkspaceLibraryDbWriter &writer, int libId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:291
const FilePath mDbFilePath
Path to the SQLite database file.
Definition: workspacelibraryscanner.h:106
void addTranslationsToDb(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:354
void addToCategories(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition: workspacelibraryscanner.cpp:366
int getProgressPercent() const noexcept
Definition: workspacelibraryscanner.h:63
WorkspaceLibraryScanner(const WorkspaceLibraryScanner &other)=delete
QHash< FilePath, int > updateLibraries(SQLiteDatabase &db, WorkspaceLibraryDbWriter &writer, const QList< std::shared_ptr< Library > > &libs)
Definition: workspacelibraryscanner.cpp:210
int mLastProgressPercent
Definition: workspacelibraryscanner.h:109
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition: workspacelibraryscanner.h:105
WorkspaceLibraryScanner(const FilePath &librariesPath, const FilePath &dbFilePath) noexcept
Definition: workspacelibraryscanner.cpp:49
Definition: occmodel.cpp:77