From d2502858d6c01bd62735440df3e9df3a317dc9a4 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Sat, 14 May 2011 22:52:58 +0200 Subject: [PATCH] Added basic IRC backend support --- CMakeLists.txt | 35 +++++++-- backends/CMakeLists.txt | 5 ++ backends/libircclient-qt/CMakeLists.txt | 7 ++ backends/libircclient-qt/main.cpp | 97 +++++++++++++++++++++++++ spectrum/src/CMakeLists.txt | 1 + spectrum/src/sample.cfg | 3 +- 6 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 backends/libircclient-qt/CMakeLists.txt create mode 100644 backends/libircclient-qt/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bc0e72d..87645e11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,15 @@ find_package(Boost COMPONENTS date_time system filesystem program_options regex set(Protobuf_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") find_package(Protobuf REQUIRED) +set(IRCClientQt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules") +find_package(IRCClientQt) + find_package(Doxygen) +INCLUDE(FindQt4) +FIND_PACKAGE(Qt4 COMPONENTS QtCore) + + message(" Supported features") message("-----------------------") if (SQLITE3_FOUND) @@ -44,14 +51,24 @@ if (PROTOBUF_FOUND) ADD_DEFINITIONS(-DWITH_PROTOBUF) include_directories(${PROTOBUF_INCLUDE_DIRS}) message("Network plugins : yes") + + if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR) + message("Libpurple plugin : yes") + else() + message("Libpurple plugin : no (install libpurple)") + endif() + + if(IRC_FOUND) + ADD_DEFINITIONS(-DIRC_SHARED) + message("IRC plugin : yes") + else() + message("IRC plugin : no (install libircclient-qt and Google Protocol Buffers)") + endif() + else() message("Network plugins : no (install Google Protocol Buffers)") -endif() - -if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR AND PROTOBUF_FOUND) - message("Libpurple backend : yes") -else() - message("Libpurple backend : no (install libpurple and Google Protocol Buffers)") + message("Libpurple plugin : no (install libpurple and Google Protocol Buffers)") + message("IRC plugin : no (install libircclient-qt and Google Protocol Buffers)") endif() if(CMAKE_BUILD_TYPE MATCHES Debug) @@ -70,7 +87,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) ADD_DEFINITIONS(-Wundef -Wunused) message("Debug : yes") else(CMAKE_BUILD_TYPE MATCHES Debug) - message("Debug : no") + message("Debug : no (run \"cmake . -DCMAKE_BUILD_TYPE=Debug\")") endif(CMAKE_BUILD_TYPE MATCHES Debug) @@ -83,6 +100,8 @@ include_directories(${EVENT_INCLUDE_DIRS}) include_directories(${GLIB2_INCLUDE_DIR}) include_directories(${SWIFTEN_INCLUDE_DIR}) include_directories(${Boost_INCLUDE_DIRS}) +include_directories(${IRC_INCLUDE_DIR}) +include(${QT_USE_FILE}) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(include) @@ -94,7 +113,7 @@ if(DOXYGEN_FOUND) message("Docs : yes") ADD_SUBDIRECTORY(docs) else(DOXYGEN_FOUND) - message("Docs : no") + message("Docs : no (install doxygen)") endif(DOXYGEN_FOUND) message("----------------------") diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt index 44b743ed..d005be0b 100644 --- a/backends/CMakeLists.txt +++ b/backends/CMakeLists.txt @@ -1,3 +1,8 @@ if (PROTOBUF_FOUND) ADD_SUBDIRECTORY(libpurple) + + if (IRC_FOUND) + ADD_SUBDIRECTORY(libircclient-qt) + endif() + endif() diff --git a/backends/libircclient-qt/CMakeLists.txt b/backends/libircclient-qt/CMakeLists.txt new file mode 100644 index 00000000..1c2f06b5 --- /dev/null +++ b/backends/libircclient-qt/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.6) +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(libircclient-qt_backend ${SRC}) + +target_link_libraries(libircclient-qt_backend ${IRC_LIBRARIES} ${QT_LIBRARIES} transport) + diff --git a/backends/libircclient-qt/main.cpp b/backends/libircclient-qt/main.cpp new file mode 100644 index 00000000..2bf7a927 --- /dev/null +++ b/backends/libircclient-qt/main.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com + * + * This example is free, and not covered by LGPL license. There is no + * restriction applied to their modification, redistribution, using and so on. + * You can study them, modify them, use them in your own program - either + * completely or partially. By using it you may give me some credits in your + * program, but you don't have to. + */ + +#include "transport/config.h" +#include "transport/networkplugin.h" +#include "ircsession.h" +#include +#include "Swiften/EventLoop/Qt/QtEventLoop.h" + +using namespace boost::program_options; +using namespace Transport; + +class IRCNetworkPlugin; +IRCNetworkPlugin * np = NULL; + +class IRCNetworkPlugin : public NetworkPlugin { + public: + IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) { + this->config = config; + } + + void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { + } + + void handleLogoutRequest(const std::string &user, const std::string &legacyName) { + } + + void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) { + } + + private: + Config *config; +}; + +int main (int argc, char* argv[]) { + std::string host; + int port; + + + boost::program_options::options_description desc("Usage: spectrum [OPTIONS] \nAllowed options"); + desc.add_options() + ("host,h", value(&host), "host") + ("port,p", value(&port), "port") + ; + try + { + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + boost::program_options::notify(vm); + } + catch (std::runtime_error& e) + { + std::cout << desc << "\n"; + exit(1); + } + catch (...) + { + std::cout << desc << "\n"; + exit(1); + } + + + if (argc < 5) { + qDebug("Usage: %s ", argv[0]); + return 1; + } + +// QStringList channels; +// for (int i = 3; i < argc; ++i) +// { +// channels.append(argv[i]); +// } +// +// MyIrcSession session; +// session.setNick(argv[2]); +// session.setAutoJoinChannels(channels); +// session.connectToServer(argv[1], 6667); + + Config config; + if (!config.load(argv[5])) { + std::cerr << "Can't open " << argv[1] << " configuration file.\n"; + return 1; + } + QCoreApplication app(argc, argv); + + Swift::QtEventLoop eventLoop; + np = new IRCNetworkPlugin(&config, &eventLoop, host, port); + + return app.exec(); +} diff --git a/spectrum/src/CMakeLists.txt b/spectrum/src/CMakeLists.txt index 7fcaac91..dcef1bef 100644 --- a/spectrum/src/CMakeLists.txt +++ b/spectrum/src/CMakeLists.txt @@ -4,6 +4,7 @@ FILE(GLOB SRC *.cpp) ADD_EXECUTABLE(spectrum ${SRC}) ADD_DEPENDENCIES(spectrum libpurple_backend) +ADD_DEPENDENCIES(spectrum libircclient-qt_backend) target_link_libraries(spectrum ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport) diff --git a/spectrum/src/sample.cfg b/spectrum/src/sample.cfg index 1c2a05a9..9494e4f0 100644 --- a/spectrum/src/sample.cfg +++ b/spectrum/src/sample.cfg @@ -4,7 +4,8 @@ password = secret server = 127.0.0.1 port = 5222 server_mode = 1 -backend=../../backends/libpurple/libpurple_backend +#backend=../../backends/libpurple/libpurple_backend +backend=../../backends/libircclient-qt/libircclient-qt_backend protocol=prpl-jabber [database]