You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.0 KiB
C++

3 years ago
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "plugin.hh"
#include "strophe.hh"
3 years ago
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
#define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0"
namespace c {
extern "C" {
3 years ago
#include "plugin.h"
3 years ago
#include "config.h"
#include "account.h"
#include "connection.h"
#include "command.h"
#include "input.h"
#include "buffer.h"
#include "completion.h"
3 years ago
struct t_weechat_plugin *weechat_xmpp_plugin() {
3 years ago
return (struct t_weechat_plugin*)&*weechat::globals::plugin;
3 years ago
};
const char *weechat_xmpp_plugin_name() {
return WEECHAT_XMPP_PLUGIN_NAME;
3 years ago
};
const char *weechat_xmpp_plugin_version() {
return WEECHAT_XMPP_PLUGIN_VERSION;
3 years ago
};
3 years ago
}
}
3 years ago
namespace weechat {
plugin::plugin()
3 years ago
// try not to think about it too hard
: plugin(nullptr) {
}
plugin::plugin(struct t_weechat_plugin* plugin)
: std::reference_wrapper<struct t_weechat_plugin>(*plugin) {
}
3 years ago
bool plugin::init(std::vector<std::string>) {
if (!c::config__init())
{
weechat::printf(nullptr, "%s: Error during config init",
3 years ago
this->name());
3 years ago
return false;
}
3 years ago
c::config__read();
3 years ago
c::connection__init();
3 years ago
c::command__init();
3 years ago
c::completion__init();
3 years ago
3 years ago
this->m_process_timer =
weechat::hook_timer(plugin::timer_interval_sec * 1000, 0, 0,
3 years ago
&c::account__timer_cb);
3 years ago
if (!weechat::bar_search("typing"))
3 years ago
{
weechat::bar_new("typing", "off", "400", "window", "${typing}",
"bottom", "horizontal", "vertical",
"1", "1", "default", "default", "default", "default",
"off", "xmpp_typing");
3 years ago
}
3 years ago
this->m_typing_bar_item =
weechat::bar_item_new("xmpp_typing",
(char* (*)(const void*, void*,
t_gui_bar_item*, t_gui_window*,
3 years ago
t_gui_buffer*, t_hashtable*))(
&c::buffer__typing_bar_cb));
3 years ago
3 years ago
weechat::hook_signal("input_text_changed", &c::input__text_changed_cb);
3 years ago
return true;
}
bool plugin::end() {
3 years ago
this->m_typing_bar_item.reset();
3 years ago
3 years ago
this->m_process_timer.reset();
3 years ago
c::config__write();
3 years ago
c::account__disconnect_all();
3 years ago
c::account__free_all();
3 years ago
xmpp::shutdown();
3 years ago
return true;
3 years ago
}
std::string_view plugin::name() const {
return plugin_get_name(*this);
3 years ago
}
3 years ago
weechat::plugin globals::plugin;
hook::hook(struct t_hook* hook)
: std::reference_wrapper<struct t_hook>(*hook) {
}
hook::~hook() {
weechat::unhook(*this);
}
3 years ago
3 years ago
gui_bar_item::gui_bar_item(struct t_gui_bar_item* item)
: std::reference_wrapper<struct t_gui_bar_item>(*item) {
}
3 years ago
3 years ago
gui_bar_item::~gui_bar_item() {
weechat::bar_item_remove(*this);
}
3 years ago
}
extern "C" {
WEECHAT_PLUGIN_NAME(WEECHAT_XMPP_PLUGIN_NAME);
WEECHAT_PLUGIN_DESCRIPTION(N_("XMPP client protocol"));
WEECHAT_PLUGIN_AUTHOR("bqv <weechat@fron.io>");
WEECHAT_PLUGIN_VERSION(WEECHAT_XMPP_PLUGIN_VERSION);
WEECHAT_PLUGIN_LICENSE("MPL2");
WEECHAT_PLUGIN_PRIORITY(5500);
weechat::rc weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
3 years ago
{
3 years ago
weechat::globals::plugin = (struct weechat::t_weechat_plugin*)plugin;
3 years ago
std::vector<std::string> args(argv, argv+argc);
3 years ago
return weechat::globals::plugin.init(args)
? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
3 years ago
}
weechat::rc weechat_plugin_end(struct t_weechat_plugin *)
3 years ago
{
3 years ago
return weechat::globals::plugin.end()
? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
3 years ago
}
}