No new features here... (adding/testing of new files)
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 27 Jul 2007 18:54:46 +0000 (18:54 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 27 Jul 2007 18:54:46 +0000 (18:54 +0000)
src/common/CMakeLists.txt
src/common/ircuser.cpp [new file with mode: 0644]
src/common/ircuser.h [new file with mode: 0644]
src/core/CMakeLists.txt
src/core/server.cpp
src/core/server.h
src/core/serverinfo.cpp [new file with mode: 0644]
src/core/serverinfo.h [new file with mode: 0644]

index e4e49e6..59582f8 100644 (file)
@@ -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})
 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 (file)
index 0000000..dd60aa9
--- /dev/null
@@ -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<QString> &usermodes) {
+  usermodes_ = usermodes;
+}
+
+QSet<QString> IrcUser::usermodes() const {
+  return usermodes_;
+}
+
+void IrcUser::setChannelmode(const QString &channel, const QSet<QString> &channelmode) {
+  if(channelmodes_.contains(channel))
+    channelmodes_[channel] |= channelmode;
+  else
+    channelmodes_[channel] = channelmode;
+}
+
+QSet<QString> IrcUser::channelmode(const QString &channel) const {
+  if(channelmodes_.contains(channel))
+    throw NoSuchChannelException();
+  else
+    return QSet<QString>();
+}
+
+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<QString>();
+  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<QString>();
+}
+
+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 (file)
index 0000000..14151be
--- /dev/null
@@ -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 <QtCore>
+#include <QObject>
+#include <QHash>
+#include <QSet>
+#include <QString>
+#include <QStringList>
+
+#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<QString> 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<QString> &usermodes);
+  QSet<QString> usermodes() const;
+  
+  void setChannelmode(const QString &channel, const QSet<QString> &channelmode);
+  QSet<QString> 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<QString, QSet<QString> > channelmodes_; //keys: channelnames; values: Set of Channelmodes
+  QSet<QString> usermodes_;
+};
+
+struct IrcUserException : public Exception {};
+struct NoSuchChannelException : public IrcUserException {};
+struct NoSuchNickException : public IrcUserException {};
+
+
+#endif
index db4cda7..1f0effe 100644 (file)
@@ -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_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})
 
 QT4_WRAP_CPP(_MOC ${core_MOCS})
 ADD_LIBRARY(core ${core_SRCS} ${_MOC})
index 92fe804..44d66ab 100644 (file)
@@ -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;
   QString XQUOTE = QString('\134');
   ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE;
   ctcpXDelimDequoteHash[XQUOTE + QString('a')] = XDELIM;
+  
+  serverinfo = new ServerInfo();
 }
 
 Server::~Server() {
 }
 
 Server::~Server() {
-
+  delete serverinfo;
 }
 
 void Server::run() {
 }
 
 void Server::run() {
index 0f9a1d7..bcc7ffd 100644 (file)
@@ -29,6 +29,7 @@
 #include <QTimer>
 
 #include "message.h"
 #include <QTimer>
 
 #include "message.h"
+#include "serverinfo.h"
 
 #define DEFAULT_PORT 6667
 
 
 #define DEFAULT_PORT 6667
 
@@ -185,6 +186,9 @@ class Server : public QThread {
       public:
         UnknownCmdError(QString cmd, QString prefix, QStringList params);
     };
       public:
         UnknownCmdError(QString cmd, QString prefix, QStringList params);
     };
+    
+    // stuff needed for new separation of server information
+    ServerInfo *serverinfo;
 };
 
 #endif
 };
 
 #endif
diff --git a/src/core/serverinfo.cpp b/src/core/serverinfo.cpp
new file mode 100644 (file)
index 0000000..bc9fe64
--- /dev/null
@@ -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 &currentServer) {
+  currentServer_ = currentServer;
+}
+
+QString ServerInfo::currentServer() const {
+  return currentServer_;
+}
+
+void ServerInfo::setOwnNick(const QString &ownnick) {
+  ownNick_ = ownnick;
+}
+
+QString ServerInfo::ownNick() const {
+  return ownNick_;
+}
+
+QList<IrcUser *> 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<QString, QString> &topics) {
+  topics_ = topics;
+}
+
+QHash<QString, QString> 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<QString, QString> &supports) {
+  supports_ = supports;
+}
+
+QHash<QString, QString> 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 (file)
index 0000000..22421ec
--- /dev/null
@@ -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 <QString>
+#include <QList>
+#include <QHash>
+
+#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<IrcUser *> ircUsers READ ircUsers)
+  
+public:
+  ServerInfo(QObject *parent = 0);
+  ~ServerInfo();
+
+  void setNetworkname(const QString &networkname);
+  QString networkname() const;
+  
+  void setCurrentServer(const QString &currentServer);
+  QString currentServer() const;
+  
+  void setOwnNick(const QString &ownnick);
+  QString ownNick() const;
+  
+  QList<IrcUser *> ircUsers() const;
+  IrcUser *newIrcUser(const QString &hostmask);
+  IrcUser *ircUser(const QString &nickname) const;
+  
+  void setTopics(const QHash<QString, QString> &topics);
+  QHash<QString, QString> topics() const;
+  
+  void updateTopic(const QString &channel, const QString &topic);
+  QString topic(const QString &channel) const;
+  
+  void setSupports(const QHash<QString, QString> &supports);
+  QHash<QString, QString> 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<QString, IrcUser *> ircUsers_;  // stores all known nicks for the server
+  QHash<QString, QString> topics_; // stores topics for each buffer
+  QHash<QString, QString> supports_;  // stores results from RPL_ISUPPORT
+};
+
+struct UnsupportedFeatureException : public Exception {};
+
+#endif