1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef LANGUAGESERVICE_H |
6 | #define LANGUAGESERVICE_H |
7 | |
8 | #include "languagegenerator.h" |
9 | #include <framework/framework.h> |
10 | |
11 | namespace dpfservice { |
12 | |
13 | class LanguageService final : public dpf::PluginService, |
14 | dpf::AutoServiceRegister<LanguageService>, |
15 | dpf::QtClassFactory<LanguageGenerator>, |
16 | dpf::QtClassManager<LanguageGenerator> |
17 | { |
18 | Q_OBJECT |
19 | Q_DISABLE_COPY(LanguageService) |
20 | public: |
21 | explicit LanguageService(QObject *parent = nullptr) |
22 | : dpf::PluginService (parent) |
23 | { |
24 | |
25 | } |
26 | |
27 | static QString name() |
28 | { |
29 | return "org.deepin.service.LanguageService"; |
30 | } |
31 | |
32 | template<class T> |
33 | bool regClass(const QString &name, QString *error= nullptr) { |
34 | return dpf::QtClassFactory<LanguageGenerator>::regClass<T>(name, error); |
35 | } |
36 | |
37 | template<class T> |
38 | T* create(const QString &name, QString *error = nullptr) { |
39 | auto value = dpf::QtClassManager<LanguageGenerator>::value(name); |
40 | if (!value) { |
41 | value = dpf::QtClassFactory<LanguageGenerator>::create(name); |
42 | dpf::QtClassManager<LanguageGenerator>::append(name, value, error); |
43 | } |
44 | return dynamic_cast<T*>(value); |
45 | } |
46 | }; |
47 | |
48 | } // namespace dpfservice |
49 | #endif // LANGUAGESERVICE_H |
50 |