Rabbit Remote Control 0.0.31
Loading...
Searching...
No Matches
PluginService.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "PluginService.h"
4
5#include "RabbitCommonDir.h"
6
7#include <QIcon>
8#include <QLocale>
9#include <QDebug>
10#include <QCoreApplication>
11#include <QLoggingCategory>
12
13Q_DECLARE_LOGGING_CATEGORY(Service)
14
15CPluginService::CPluginService(QObject *parent)
16 : QObject(parent)
17{}
18
19CPluginService::~CPluginService()
20{
21 qDebug(Service) << "CPluginService::~CPluginService";
22 qApp->removeTranslator(&m_Translator);
23}
24
25int CPluginService::InitTranslator()
26{
27 QString szTranslatorFile = RabbitCommon::CDir::Instance()->GetDirPluginsTranslation("plugins/Service")
28 + "/" + Name() + "_" + QLocale::system().name() + ".qm";
29 if(!m_Translator.load(szTranslatorFile))
30 {
31 qCritical(Service) << "Open translator file fail:" << szTranslatorFile;
32 return -1;
33 }
34 qApp->installTranslator(&m_Translator);
35 return 0;
36}
37
38const QString CPluginService::Id() const
39{
40 return Protocol() + "_" + Name();
41}
42
43const QIcon CPluginService::Icon() const
44{
45 return QIcon::fromTheme("network-wired");
46}
47
48const QString CPluginService::DisplayName() const
49{
50 return Name();
51}
52
54{
55 if(!m_Service)
56 m_Service = QSharedPointer<CService>(NewService());
57 if(m_Service)
58 m_Service->Init();
59}
60
61void CPluginService::Stop()
62{
63 if(m_Service)
64 m_Service->Clean();
65 m_Service.reset();
66}
virtual const QString DisplayName() const
The plugin display name.
virtual CService * NewService()=0
New service.
virtual void Start()
Start a Service.
virtual const QString Id() const
ID. Default: Protocol() + "_" + Name()
virtual const QString Name() const =0
This name must be the same as the project name (${PROJECT_NAME}).
virtual const QString Protocol() const =0
Plugin Protocol.