Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
Ice.cpp
1
2
3#include "Ice.h"
4#include "ChannelIce.h"
5#ifdef HAVE_QXMPP
6#include "IceSignalQxmpp.h"
7#endif
8#include "FrmParameterICE.h"
9#include "RabbitCommonDir.h"
10
11#include <QCoreApplication>
12#include <QLocale>
13#include <QDebug>
14
15CICE::CICE(QObject *parent)
16 : QObject{parent},
17 m_Log("Channel.ICE")
18{
19 bool check = false;
20 QString szTranslatorFile = RabbitCommon::CDir::Instance()->GetDirTranslations()
21 + "/Channel_" + QLocale::system().name() + ".qm";
22 if(!m_Translator.load(szTranslatorFile))
23 qCritical(m_Log) << "Open translator file fail:" << szTranslatorFile;
24 qApp->installTranslator(&m_Translator);
25
26#ifdef HAVE_QXMPP
27 m_Signal = QSharedPointer<CIceSignal>(new CIceSignalQxmpp(this));
28 if(m_Signal)
29 {
30 check = connect(m_Signal.data(), SIGNAL(sigConnected()),
31 this, SLOT(slotConnected()));
32 Q_ASSERT(check);
33 check = connect(m_Signal.data(), SIGNAL(sigDisconnected()),
34 this, SLOT(slotDisconnected()));
35 Q_ASSERT(check);
36 check = connect(m_Signal.data(), SIGNAL(sigError(int, const QString&)),
37 this, SLOT(slotError(int, const QString&)));
38 Q_ASSERT(check);
39 }
40#endif
41
42#ifdef HAVE_ICE
43 check = connect(GetParameter(), SIGNAL(sigIceDebugChanged(bool)),
44 &g_LogCallback, SLOT(slotEnable(bool)));
45 Q_ASSERT(check);
46 g_LogCallback.slotEnable(GetParameter()->GetIceDebug());
47#endif
48}
49
50CICE::~CICE()
51{
52 qApp->removeTranslator(&m_Translator);
53}
54
56{
57 static CICE* p = nullptr;
58 if(!p) p = new CICE();
59 return p;
60}
61
62QSharedPointer<CIceSignal> CICE::GetSignal()
63{
64 return m_Signal;
65}
66
67CParameterICE* CICE::GetParameter()
68{
69 return &m_Parameter;
70}
71
72QWidget* CICE::GetParameterWidget(QWidget *parent)
73{
74 return new CFrmParameterICE(GetParameter(), parent);
75}
76
77void CICE::slotIceChanged()
78{
79 QSharedPointer<CIceSignal> signal = GetSignal();
80 if(!signal) return;
81 if(signal->IsConnected())
82 signal->Close();
83 CParameterICE* pPara = GetParameter();
84 if(pPara->getIce())
85 {
86 signal->Open(pPara->getSignalServer(), pPara->getSignalPort(),
87 pPara->getSignalUser(), pPara->getSignalPassword());
88 }
89}
90
91void CICE::slotStart()
92{
93 QSharedPointer<CIceSignal> signal = GetSignal();
94 if(!signal)
95 {
96 qCritical(m_Log) << "The signal is null";
97 return;
98 }
99 if(signal->IsConnected())
100 return;
101 CParameterICE* pPara = GetParameter();
102 if(pPara->getIce())
103 {
104 signal->Open(pPara->getSignalServer(), pPara->getSignalPort(),
105 pPara->getSignalUser(), pPara->getSignalPassword());
106 }
107}
108
109void CICE::slotStop()
110{
111 QSharedPointer<CIceSignal> signal = GetSignal();
112 if(!signal) return;
113 //if(signal->IsConnected())
114 signal->Close();
115}
116
117void CICE::slotConnected()
118{
119 CParameterICE* pPara = GetParameter();
120 qInfo(m_Log) << "User" << pPara->getSignalUser()
121 << "is connected to signal server:"
122 << pPara->getSignalServer() << ":" << pPara->getSignalPort();
123}
124
125void CICE::slotDisconnected()
126{
127 CParameterICE* pPara = GetParameter();
128 qInfo(m_Log) << "User" << pPara->getSignalUser()
129 << "is disconnected to signal server:"
130 << pPara->getSignalServer() << ":" << pPara->getSignalPort();
131}
132
133void CICE::slotError(int nError, const QString& szError)
134{
135 CParameterICE* pPara = GetParameter();
136 qInfo(m_Log) << "User" << pPara->getSignalUser()
137 << "signal server["
138 << pPara->getSignalServer() << ":" << pPara->getSignalPort()
139 << "] error:" << nError << szError;
140}
Set parameter dialog.
Provides a singleton object for management and access to ICE.
Definition Ice.h:26
static CICE * Instance()
Single instance.
Definition Ice.cpp:55
CICE(QObject *parent=nullptr)
Definition Ice.cpp:15
QXMPP implements ICE signaling class.
ICE parameter helper class.