This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Lua4RSPlugin.cpp
185 lines (153 loc) · 4.93 KB
/
Lua4RSPlugin.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
#include <QIcon>
#include <QTranslator>
#include <QApplication>
#include <QString>
#include <QMessageBox>
#include <QIcon>
#include <retroshare/rsversion.h>
#include "gui/Lua4RSConfig.h"
#include "Lua4RSNotify.h"
#include "Lua4RSPlugin.h"
#include "gui/Lua4RSWidget.h"
#include "interface/L4RInterface.h"
#include "Lua/LuaCore.h"
#include "service/p3Lua4RS.h"
#define LUA_ICON_LINK ":/images/lua_logo.png"
#if LUA_VERSION_NUM < 502
#error "###############################################"
#error "# You need at least Lua 5.2 for this plugin #"
#error "# See contrib/get_lua5.2.3.sh #"
#error "###############################################"
#endif
extern "C" {
#ifdef WIN32
__declspec(dllexport)
#endif
RsPlugin *RETROSHARE_PLUGIN_provide()
{
return new Lua4RSPlugin();
}
// 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.
//
#ifdef WIN32
__declspec(dllexport)
#endif
uint32_t RETROSHARE_PLUGIN_revision = 1;
// 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.
//
#ifdef WIN32
__declspec(dllexport)
#endif
uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ;
}
Lua4RSPlugin::Lua4RSPlugin()
{
_icon = NULL;
_mainpage = NULL;
_notify = NULL;
_peers = NULL;
_pluginHandler = NULL;
_service = NULL;
}
void Lua4RSPlugin::stop()
{
L4R::L4RConfig->getCore()->shutDown();
_service->fullstop();
}
p3Config *Lua4RSPlugin::p3_config() const
{
return (p3Config *)_service;
}
void Lua4RSPlugin::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 = 0;
}
void Lua4RSPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{
// get stuff
_peers = interfaces.mPeers;
_notify = interfaces.mNotify;
if(_service == NULL)
{
_service = new p3Lua4RS();
L4R::L4RConfig = _service;
}
// setup other stuff
_notify->registerNotifyClient(L4R::L4RConfig->getCore()->notify());
}
void Lua4RSPlugin::getLibraries(std::list<RsLibraryInfo> &libraries)
{
libraries.push_back(RsLibraryInfo("Lua", LUA_RELEASE));
}
MainPage* Lua4RSPlugin::qt_page() const
{
if(_mainpage == NULL) {
_mainpage = new Lua4RSWidget();
L4R::L4RConfig->getCore()->setUi(dynamic_cast<Lua4RSWidget*>(_mainpage));
}
return _mainpage ;
}
QIcon* Lua4RSPlugin::qt_icon() const
{
if(_icon == NULL)
{
Q_INIT_RESOURCE(Lua4RS_images);
_icon = new QIcon(LUA_ICON_LINK);
}
return _icon ;
}
QTranslator* Lua4RSPlugin::qt_translator(QApplication* /*app*/, const QString& languageCode, const QString& externalDir) const
{
if (languageCode == "en") {
return NULL;
}
QTranslator* translator = new QTranslator();
if (translator->load(externalDir + "/Lua4RS_" + languageCode + ".qm")) {
return translator;
} else if (translator->load(":/lang/Lua4RS_" + languageCode + ".qm")) {
return translator;
}
delete(translator);
return NULL;
}
ConfigPage *Lua4RSPlugin::qt_config_page() const
{
return new Lua4RSConfig();
}
QDialog *Lua4RSPlugin::qt_about_page() const
{
static QMessageBox *about_dialog = NULL;
if(about_dialog == NULL)
{
about_dialog = new QMessageBox();
QString text;
text += QObject::tr("<h3>RetroShare Lua4RS plugin</h3><br/> * Contributors: sehraf, far*call<br/>");
text += QObject::tr("<br/>The Lua4Rs plugin lets you interact with RetroShare.<br/>");
text += QObject::tr("<br/>It exposes most RetroShare functions to Lua and provides a trigger system.<br/>");
text += QObject::tr("<br/>You can write scripts that react to events (from RetroShare) <br/>");
text += QObject::tr("<br/>like a friend comes online or you received a new message plus lots more.<br/>");
text += QObject::tr("<br/>With access to most RetroShare functions, you can do the same in the Lua language as you can do in C++.<br/>");
about_dialog->setText(text);
about_dialog->setStandardButtons(QMessageBox::Ok);
}
return about_dialog;
}
std::string Lua4RSPlugin::getShortPluginDescription() const
{
return QApplication::translate("Lua4RS", "This plugin provides Lua scripting capabilities to RetroShare.").toUtf8().constData();
}
void Lua4RSPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
{
_pluginHandler = pgHandler;
}
std::string Lua4RSPlugin::getPluginName() const
{
return QApplication::translate("Lua4RS", "Lua4RS").toUtf8().constData();
}