-
Notifications
You must be signed in to change notification settings - Fork 3
/
RetroChessPlugin.cpp
199 lines (165 loc) · 6.13 KB
/
RetroChessPlugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*******************************************************************************
* RetroChessPlugin.cpp *
* *
* Copyright (C) 2020 RetroShare Team <[email protected]> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <QTranslator>
#include <QApplication>
#include <QString>
#include <QIcon>
#include <QMessageBox>
#include "gui/chat/ChatWidget.h"
#include "RetroChessPlugin.h"
#include "interface/rsRetroChess.h"
#include "gui/NEMainpage.h"
#include "gui/RetroChessNotify.h"
#include "gui/RetroChessChatWidgetHolder.h"
#include <retroshare-gui/RsAutoUpdatePage.h>
#include <retroshare/rsplugin.h>
#include <retroshare/rsversion.h>
#define IMAGE_RetroChess ":/images/chess.png"
static void *inited = new RetroChessPlugin() ;
extern "C" {
// This is *the* functions required by RS plugin system to give RS access to the plugin.
// Be careful to:
// - always respect the C linkage convention
// - always return an object of type RsPlugin*
//
void *RETROSHARE_PLUGIN_provide()
{
static RetroChessPlugin *p = new RetroChessPlugin() ;
return (void*)p ;
}
// This symbol contains the svn revision number grabbed from the executable.
// It will be tested by RS to load the plugin automatically, since it is safe to load plugins
// with same revision numbers, assuming that the revision numbers are up-to-date.
//
uint32_t RETROSHARE_PLUGIN_revision = abs(atoi(RS_EXTRA_VERSION)) ;
// This symbol contains the svn revision number grabbed from the executable.
// It will be tested by RS to load the plugin automatically, since it is safe to load plugins
// with same revision numbers, assuming that the revision numbers are up-to-date.
//
uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ;
}
void RetroChessPlugin::getPluginVersion(int& major, int& minor, int& build, int& svn_rev) const
{
major = RS_MAJOR_VERSION ;
minor = RS_MINOR_VERSION ;
build = RS_MINI_VERSION ;
svn_rev = abs(atoi(RS_EXTRA_VERSION)) ;
}
RetroChessPlugin::RetroChessPlugin()
{
qRegisterMetaType<RsPeerId>("RsPeerId");
mainpage = NULL ;
mRetroChess = NULL ;
mPlugInHandler = NULL;
mPeers = NULL;
config_page = NULL ;
mIcon = NULL ;
mRetroChessNotify = new RetroChessNotify;
}
void RetroChessPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{
mPeers = interfaces.mPeers;
}
/*ConfigPage *RetroChessPlugin::qt_config_page() const
{
// The config pages are deleted when config is closed, so it's important not to static the
// created object.
//
return new AudioInputConfig() ;
}*/
QDialog *RetroChessPlugin::qt_about_page() const
{
static QMessageBox *about_dialog = NULL ;
if(about_dialog == NULL)
{
about_dialog = new QMessageBox() ;
QString text ;
text += QObject::tr("<h3>RetroShare RetroChess plugin</h3><br/> *Contributors: Chozabu,Texas-C<br/>") ;
text += QObject::tr("<br/>The RetroChess plugin adds RetroChess to the private chat window of RetroShare.<UL>") ;
about_dialog->setText(text) ;
about_dialog->setStandardButtons(QMessageBox::Ok) ;
}
return about_dialog ;
}
ChatWidgetHolder *RetroChessPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget) const
{
switch (chatWidget->chatType())
{
case ChatWidget::CHATTYPE_PRIVATE:
return new RetroChessChatWidgetHolder(chatWidget, mRetroChessNotify);
case ChatWidget::CHATTYPE_UNKNOWN:
case ChatWidget::CHATTYPE_LOBBY:
case ChatWidget::CHATTYPE_DISTANT:
break;
}
return NULL;
}
p3Service *RetroChessPlugin::p3_service() const
{
if(mRetroChess == NULL)
rsRetroChess = mRetroChess = new p3RetroChess(mPlugInHandler,mRetroChessNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months
return mRetroChess ;
}
void RetroChessPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
{
mPlugInHandler = pgHandler;
}
QIcon *RetroChessPlugin::qt_icon() const
{
if (mIcon == NULL)
{
Q_INIT_RESOURCE(RetroChess_images);
mIcon = new QIcon(IMAGE_RetroChess);
}
return mIcon;
}
MainPage *RetroChessPlugin::qt_page() const
{
// return chess game's main page here(which used for display)
if(mainpage == NULL)
{
mainpage = new NEMainpage(0, mRetroChessNotify);//mPeers, mFiles) ;
//tpage = new NEMainpage( );
//mainpage = tpage;
}
return mainpage ;
}
std::string RetroChessPlugin::getShortPluginDescription() const
{
return "RetroChess";
}
std::string RetroChessPlugin::getPluginName() const
{
return "RetroChess";
}
QTranslator* RetroChessPlugin::qt_translator(QApplication */*app*/, const QString& languageCode, const QString& externalDir) const
{
return NULL;
}
void RetroChessPlugin::qt_sound_events(SoundEvents &/*events*/) const
{
// events.addEvent(QApplication::translate("RetroChess", "RetroChess"), QApplication::translate("RetroChess", "Incoming call"), RetroChess_SOUND_INCOMING_CALL);
}
/*ToasterNotify *RetroChessPlugin::qt_toasterNotify(){
if (!mRetroChessToasterNotify) {
mRetroChessToasterNotify = new RetroChessToasterNotify(mRetroChess, mRetroChessNotify);
}
return mRetroChessToasterNotify;
}*/