LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 void addResourcesToDb(WorkspaceLibraryDbWriter& writer, int elementId,
103 const ElementType& element);
104 template <typename ElementType>
105 std::unique_ptr<ElementType> openAndMigrate(const FilePath& fp);
106
107private: // Data
110 QSemaphore mSemaphore;
111 volatile bool mAbort;
113};
114
115/*******************************************************************************
116 * End of File
117 ******************************************************************************/
118
119} // namespace librepcb
120
121#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
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:93
~WorkspaceLibraryScanner() noexcept
Definition workspacelibraryscanner.cpp:68
void scanProgressUpdate(int percent)
int addElementsToDb(WorkspaceLibraryDbWriter &writer, const FilePath &libPath, const QStringList &dirs, int libId)
Definition workspacelibraryscanner.cpp:272
std::unique_ptr< ElementType > openAndMigrate(const FilePath &fp)
Definition workspacelibraryscanner.cpp:401
void scanFailed(QString errorMsg)
volatile bool mAbort
Definition workspacelibraryscanner.h:111
void scanSucceeded(int elementCount)
void scanLibraryListUpdated(int libraryCount)
QSemaphore mSemaphore
Definition workspacelibraryscanner.h:110
void startScan() noexcept
Definition workspacelibraryscanner.cpp:85
void getLibrariesOfDirectory(const QString &root, QList< std::shared_ptr< Library > > &libs) noexcept
Definition workspacelibraryscanner.cpp:193
void scan() noexcept
Definition workspacelibraryscanner.cpp:108
int addElementToDb(WorkspaceLibraryDbWriter &writer, int libId, const ElementType &element)
Definition workspacelibraryscanner.cpp:295
const FilePath mDbFilePath
Path to the SQLite database file.
Definition workspacelibraryscanner.h:109
void addTranslationsToDb(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition workspacelibraryscanner.cpp:370
void addToCategories(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition workspacelibraryscanner.cpp:382
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:214
void addResourcesToDb(WorkspaceLibraryDbWriter &writer, int elementId, const ElementType &element)
Definition workspacelibraryscanner.cpp:391
int mLastProgressPercent
Definition workspacelibraryscanner.h:112
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition workspacelibraryscanner.h:108
Definition occmodel.cpp:76
Definition uuid.h:186