From cfbd7e0ec3624307cfb612fe4804d58c34b7eec9 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Fri, 27 Jul 2007 18:54:46 +0000 Subject: [PATCH 1/1] No new features here... (adding/testing of new files) --- src/common/CMakeLists.txt | 4 +- src/common/ircuser.cpp | 113 ++++++++++++++++++++++++++++++++++++++ src/common/ircuser.h | 93 +++++++++++++++++++++++++++++++ src/core/CMakeLists.txt | 4 +- src/core/server.cpp | 4 +- src/core/server.h | 4 ++ src/core/serverinfo.cpp | 112 +++++++++++++++++++++++++++++++++++++ src/core/serverinfo.h | 84 ++++++++++++++++++++++++++++ 8 files changed, 413 insertions(+), 5 deletions(-) create mode 100644 src/common/ircuser.cpp create mode 100644 src/common/ircuser.h create mode 100644 src/core/serverinfo.cpp create mode 100644 src/core/serverinfo.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index e4e49e6e..59582f86 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,5 +1,5 @@ -SET(common_SRCS global.cpp logger.cpp message.cpp settings.cpp util.cpp) -SET(common_HDRS message.h settings.h util.h) +SET(common_SRCS global.cpp logger.cpp message.cpp settings.cpp util.cpp ircuser.cpp) +SET(common_HDRS message.h settings.h util.h ircuser.h) SET(common_MOCS global.h logger.h quasselui.h) QT4_WRAP_CPP(_MOC ${common_MOCS}) diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp new file mode 100644 index 00000000..dd60aa90 --- /dev/null +++ b/src/common/ircuser.cpp @@ -0,0 +1,113 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "ircuser.h" +#include "util.h" + +IrcUser::IrcUser(QObject *parent) + : QObject(parent) { +} + +IrcUser::IrcUser(const QString &hostmask, QObject *parent) + : QObject(parent), + nick_(nickFromMask(hostmask)), + user_(userFromMask(hostmask)), + host_(hostFromMask(hostmask)) { +} + +IrcUser::~IrcUser() { +} + +void IrcUser::setUser(const QString &user) { + user_ = user; +} + +QString IrcUser::user() const { + return user_; +} + +void IrcUser::setHost(const QString &host) { + host_ = host; +} + +QString IrcUser::host() const { + return host_; +} + +void IrcUser::setNick(const QString &nick) { + nick_ = nick; +} + +QString IrcUser::nick() const { + return nick_; +} + +void IrcUser::setUsermodes(const QSet &usermodes) { + usermodes_ = usermodes; +} + +QSet IrcUser::usermodes() const { + return usermodes_; +} + +void IrcUser::setChannelmode(const QString &channel, const QSet &channelmode) { + if(channelmodes_.contains(channel)) + channelmodes_[channel] |= channelmode; + else + channelmodes_[channel] = channelmode; +} + +QSet IrcUser::channelmode(const QString &channel) const { + if(channelmodes_.contains(channel)) + throw NoSuchChannelException(); + else + return QSet(); +} + +void IrcUser::updateChannelmode(const QString &channel, const QString &channelmode, bool add) { + if(add) + addChannelmode(channel, channelmode); + else + removeChannelmode(channel, channelmode); +} + +void IrcUser::addChannelmode(const QString &channel, const QString &channelmode) { + if(!channelmodes_.contains(channel)) + channelmodes_[channel] = QSet(); + channelmodes_[channel] << channelmode; +} + +void IrcUser::removeChannelmode(const QString &channel, const QString &channelmode) { + if(channelmodes_.contains(channel)) + channelmodes_[channel].remove(channelmode); +} + +QStringList IrcUser::channels() const { + return channelmodes_.keys(); +} + +void IrcUser::joinChannel(const QString &channel) { + if(!channelmodes_.contains(channel)) + channelmodes_[channel] = QSet(); +} + +void IrcUser::partChannel(const QString &channel) { + channelmodes_.remove(channel); +} diff --git a/src/common/ircuser.h b/src/common/ircuser.h new file mode 100644 index 00000000..14151bec --- /dev/null +++ b/src/common/ircuser.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _IRCUSER_H_ +#define _IRCUSER_H_ + +#include +#include +#include +#include +#include +#include + +#include "global.h" + +class IrcUser : public QObject{ +// Q_OBJECT + +// Q_PROPERTY(QString user READ user WRITE setUser) +// Q_PROPERTY(QString host READ host WRITE setHost) +// Q_PROPERTY(QString nick READ nick WRITE setNick) +// Q_PROPERTY(QSet usermodes READ usermodes WRITE setUsermodes) +// Q_PROPERTY(QStringList channels READ channels) + +public: + IrcUser(QObject *parent = 0); + IrcUser(const QString &hostmask, QObject *parent = 0); + ~IrcUser(); + + void setUser(const QString &user); + QString user() const; + + void setHost(const QString &host); + QString host() const; + + void setNick(const QString &nick); + QString nick() const; + + void setUsermodes(const QSet &usermodes); + QSet usermodes() const; + + void setChannelmode(const QString &channel, const QSet &channelmode); + QSet channelmode(const QString &channel) const; + + void updateChannelmode(const QString &channel, const QString &channelmode, bool add=true); + void addChannelmode(const QString &channel, const QString &channelmode); + void removeChannelmode(const QString &channel, const QString &channelmode); + + QStringList channels() const; + + void joinChannel(const QString &channel); + void partChannel(const QString &channel); + +private: + inline bool operator==(const IrcUser &ircuser2) { + return (nick_.toLower() == ircuser2.nick().toLower()); + } + + inline bool operator==(const QString &nickname) { + return (nick_.toLower() == nickname.toLower()); + } + + QString nick_; + QString user_; + QString host_; + + QHash > channelmodes_; //keys: channelnames; values: Set of Channelmodes + QSet usermodes_; +}; + +struct IrcUserException : public Exception {}; +struct NoSuchChannelException : public IrcUserException {}; +struct NoSuchNickException : public IrcUserException {}; + + +#endif diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index db4cda71..1f0effef 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,6 +1,6 @@ -SET(core_SRCS core.cpp coreproxy.cpp coresession.cpp server.cpp sqlitestorage.cpp storage.cpp) +SET(core_SRCS core.cpp coreproxy.cpp coresession.cpp server.cpp serverinfo.cpp sqlitestorage.cpp storage.cpp) SET(core_HDRS ) -SET(core_MOCS core.h coreproxy.h coresession.h server.h sqlitestorage.h storage.h) +SET(core_MOCS core.h coreproxy.h coresession.h server.h serverinfo.h sqlitestorage.h storage.h) QT4_WRAP_CPP(_MOC ${core_MOCS}) ADD_LIBRARY(core ${core_SRCS} ${_MOC}) diff --git a/src/core/server.cpp b/src/core/server.cpp index 92fe8049..44d66ab5 100644 --- a/src/core/server.cpp +++ b/src/core/server.cpp @@ -36,10 +36,12 @@ Server::Server(UserId uid, QString net) : user(uid), network(net) { QString XQUOTE = QString('\134'); ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE; ctcpXDelimDequoteHash[XQUOTE + QString('a')] = XDELIM; + + serverinfo = new ServerInfo(); } Server::~Server() { - + delete serverinfo; } void Server::run() { diff --git a/src/core/server.h b/src/core/server.h index 0f9a1d74..bcc7ffdb 100644 --- a/src/core/server.h +++ b/src/core/server.h @@ -29,6 +29,7 @@ #include #include "message.h" +#include "serverinfo.h" #define DEFAULT_PORT 6667 @@ -185,6 +186,9 @@ class Server : public QThread { public: UnknownCmdError(QString cmd, QString prefix, QStringList params); }; + + // stuff needed for new separation of server information + ServerInfo *serverinfo; }; #endif diff --git a/src/core/serverinfo.cpp b/src/core/serverinfo.cpp new file mode 100644 index 00000000..bc9fe640 --- /dev/null +++ b/src/core/serverinfo.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "serverinfo.h" + +ServerInfo::ServerInfo(QObject *parent) + : QObject(parent) { +} + +ServerInfo::~ServerInfo() { +} + +void ServerInfo::setNetworkname(const QString &networkname) { + networkname_ = networkname; +} + +QString ServerInfo::networkname() const { + return networkname_; +} + +void ServerInfo::setCurrentServer(const QString ¤tServer) { + currentServer_ = currentServer; +} + +QString ServerInfo::currentServer() const { + return currentServer_; +} + +void ServerInfo::setOwnNick(const QString &ownnick) { + ownNick_ = ownnick; +} + +QString ServerInfo::ownNick() const { + return ownNick_; +} + +QList ServerInfo::ircUsers() const { + return ircUsers_.values(); +} + + +IrcUser *ServerInfo::newIrcUser(const QString &hostmask) { + IrcUser *ircuser = new IrcUser(hostmask); + return ircUsers_[ircuser->nick()] = ircuser; +} + +IrcUser *ServerInfo::ircUser(const QString &nickname) const { + if(ircUsers_.contains(nickname)) + return ircUsers_[nickname]; + else + throw NoSuchNickException(); +} + +void ServerInfo::setTopics(const QHash &topics) { + topics_ = topics; +} + +QHash ServerInfo::topics() const { + return topics_; +} + +void ServerInfo::updateTopic(const QString &channel, const QString &topic) { + topics_[channel] = topic; +} + +QString ServerInfo::topic(const QString &channel) const { + if(topics_.contains(channel)) + return topics_[channel]; + else + throw NoSuchChannelException(); +} + +void ServerInfo::setSupports(const QHash &supports) { + supports_ = supports; +} + +QHash ServerInfo::supports() const { + return supports_; +} + +QString ServerInfo::supports(const QString &feature) const { + if(supports_.contains(feature)) + return supports_[feature]; + else + throw UnsupportedFeatureException(); +} + +bool ServerInfo::isOwnNick(const QString &nick) const { + return (ownNick_.toLower() == nick.toLower()); +} + +bool ServerInfo::isOwnNick(const IrcUser &ircuser) const { + return (ircuser.nick().toLower() == ownNick_.toLower()); +} + + diff --git a/src/core/serverinfo.h b/src/core/serverinfo.h new file mode 100644 index 00000000..22421ec1 --- /dev/null +++ b/src/core/serverinfo.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _SERVERINFO_H_ +#define _SERVERINFO_H_ + +#include +#include +#include + +#include "global.h" +#include "ircuser.h" + +class ServerInfo : public QObject { + Q_OBJECT + + Q_PROPERTY(QString networkname READ networkname WRITE setNetworkname) + Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer) + Q_PROPERTY(QString ownNick READ ownNick WRITE setOwnNick) + Q_PROPERTY(QList ircUsers READ ircUsers) + +public: + ServerInfo(QObject *parent = 0); + ~ServerInfo(); + + void setNetworkname(const QString &networkname); + QString networkname() const; + + void setCurrentServer(const QString ¤tServer); + QString currentServer() const; + + void setOwnNick(const QString &ownnick); + QString ownNick() const; + + QList ircUsers() const; + IrcUser *newIrcUser(const QString &hostmask); + IrcUser *ircUser(const QString &nickname) const; + + void setTopics(const QHash &topics); + QHash topics() const; + + void updateTopic(const QString &channel, const QString &topic); + QString topic(const QString &channel) const; + + void setSupports(const QHash &supports); + QHash supports() const; + QString supports(const QString &feature) const; + + bool isOwnNick(const QString &nick) const; + bool isOwnNick(const IrcUser &ircuser) const; + +private: + QString networkname_; + QString currentServer_; + QString ownNick_; + + //VarMap networkSettings; + //VarMap identity; + + QHash ircUsers_; // stores all known nicks for the server + QHash topics_; // stores topics for each buffer + QHash supports_; // stores results from RPL_ISUPPORT +}; + +struct UnsupportedFeatureException : public Exception {}; + +#endif -- 2.20.1