[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [Aki] 827da95: Added BaseReply class. Takes care of what used to
From: Keith Rusler <xzekecomax () gmail ! com>
Date: 2010-11-20 2:50:33
Message-ID: 20101120025033.74798A60A6 () git ! kde ! org
[Download RAW message or body]
A libaki/irc/private/basereply_p.hpp [License: GPL(v2)]
A libaki/irc/private/basereply_p.cxx [License: GPL(v2)]
A libaki/irc/basereply.hpp [License: GPL(v2)]
A libaki/irc/basereply.cxx [License: GPL(v2)]
commit 827da9550f04dadd96c36402f81ba084eb93371a
Author: Keith Rusler <xzekecomax@gmail.com>
Date: Fri Nov 19 20:49:42 2010 -0600
Added BaseReply class. Takes care of what used to be the old Message class.
diff --git a/libaki/irc/CMakeLists.txt b/libaki/irc/CMakeLists.txt
index b1e40a5..18a286b 100644
--- a/libaki/irc/CMakeLists.txt
+++ b/libaki/irc/CMakeLists.txt
@@ -1,6 +1,7 @@
include(irc/private/CMakeLists.txt)
set(akicore_irc_SRCS
+ irc/basereply.cxx
irc/basesocket.cxx
irc/message.cxx
irc/nickinfo.cxx
diff --git a/libaki/irc/basereply.cxx b/libaki/irc/basereply.cxx
new file mode 100644
index 0000000..343dd4b
--- /dev/null
+++ b/libaki/irc/basereply.cxx
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2009-2010 Keith Rusler <xzekecomax@gmail.com>
+ *
+ * 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ */
+
+#include "basereply.hpp"
+#include "private/basereply_p.hpp"
+using namespace Aki;
+using namespace Irc;
+
+BaseReply::BaseReply()
+ : _d(new Aki::Irc::BaseReplyPrivate())
+{
+}
+
+BaseReply::BaseReply(const Aki::Irc::BaseReply& other)
+ : _d(other._d)
+{
+ Q_UNUSED(other)
+}
+
+BaseReply::~BaseReply()
+{
+}
+
+Aki::Irc::BaseReply&
+BaseReply::operator=(const Aki::Irc::BaseReply& other)
+{
+ if (_d != other._d) {
+ _d = other._d;
+ _d->command = other.command();
+ _d->isNumeric = other.isNumeric();
+ _d->message = other.message();
+ _d->params = other.params();
+ _d->replyCode = other.replyCode();
+ _d->sender = other.sender();
+ }
+ return *this;
+}
+
+bool
+BaseReply::operator==(const Aki::Irc::BaseReply& other) const
+{
+ Q_UNUSED(other)
+ return false;
+}
+
+QString
+BaseReply::command() const
+{
+ return _d->command;
+}
+
+bool
+BaseReply::isNumeric() const
+{
+ return _d->isNumeric;
+}
+
+QString
+BaseReply::message() const
+{
+ return _d->message;
+}
+
+QStringList
+BaseReply::params() const
+{
+ return _d->params;
+}
+
+Aki::Irc::BaseReply
+BaseReply::parse(const QString& line)
+{
+ if (line.isEmpty()) {
+ return Aki::Irc::BaseReply();
+ }
+
+ QString tmp = line;
+
+ Aki::Irc::BaseReply reply;
+ reply._d->message = line;
+
+ if (tmp.startsWith(':')) {
+ Aki::Irc::NickInfo sender;
+ sender.setHostmask(Aki::Irc::BaseReplyPrivate::removeStringToFirstWhitespace(&tmp, 1, 1));
+ reply._d->sender = sender;
+ }
+
+ reply._d->command = Aki::Irc::BaseReplyPrivate::removeStringToFirstWhitespace(&tmp);
+ reply._d->replyCode = static_cast<Aki::Irc::ReplyCodes>(reply.replyCode());
+
+ while (!line.isEmpty()) {
+ if (line.startsWith(':')) {
+ tmp.remove(0, 1);
+ reply._d->params << tmp;
+ tmp.clear();
+ } else {
+ reply._d->params << Aki::Irc::BaseReplyPrivate::removeStringToFirstWhitespace(&tmp);
+ }
+ }
+
+ if (reply.params().isEmpty()) {
+ return reply;
+ }
+
+ reply._d->params.removeAll("");
+ return reply;
+}
+
+Aki::Irc::ReplyCodes
+BaseReply::replyCode() const
+{
+ return _d->replyCode;
+}
+
+Aki::Irc::NickInfo
+BaseReply::sender() const
+{
+ return _d->sender;
+}
+
+QDebug
+operator<<(QDebug dbg, const Aki::Irc::BaseReply& reply)
+{
+ dbg << "\nSender: " << reply.sender().hostmask() << '\n'
+ << "---- Host: " << reply.sender().host() << '\n'
+ << "---- Nick: " << reply.sender().nick() << '\n'
+ << "---- User: " << reply.sender().user() << '\n'
+ << "Command: " << reply.command() << '\n'
+ << "IsNumeric: " << reply.isNumeric() << '\n'
+ << "Numeric: " << reply.isNumeric() << '\n'
+ << "Message: " << reply.message().remove("\r\n") << '\n'
+ << "Params: " << reply.params();
+ return dbg;
+}
diff --git a/libaki/irc/basereply.hpp b/libaki/irc/basereply.hpp
new file mode 100644
index 0000000..e880a6b
--- /dev/null
+++ b/libaki/irc/basereply.hpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2009-2010 Keith Rusler <xzekecomax@gmail.com>
+ *
+ * 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ */
+
+#ifndef AKI_IRC_BASEREPLY_HPP
+#define AKI_IRC_BASEREPLY_HPP
+
+#include "aki.hpp"
+#include "irc/nickinfo.hpp"
+#include "irc/replycodes.hpp"
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QStringList>
+
+namespace Aki
+{
+namespace Irc
+{
+class BaseReplyPrivate;
+class LIBAKI_EXPORT BaseReply
+{
+public:
+ BaseReply();
+ BaseReply (const Aki::Irc::BaseReply& other);
+ virtual ~BaseReply();
+ virtual Aki::Irc::BaseReply& operator=(const Aki::Irc::BaseReply& other);
+ virtual bool operator==(const Aki::Irc::BaseReply& other) const;
+ bool isNumeric() const;
+ QString command() const;
+ QString message() const;
+ QStringList params() const;
+ static Aki::Irc::BaseReply parse(const QString& line);
+ Aki::Irc::ReplyCodes replyCode() const;
+ Aki::Irc::NickInfo sender() const;
+private:
+ QSharedDataPointer<Aki::Irc::BaseReplyPrivate> _d;
+}; // End of class BaseReply.
+} // End of namespace Irc.
+} // End of namespace Aki.
+
+QDebug LIBAKI_EXPORT operator<<(QDebug dbg, const Aki::Irc::BaseReply& reply);
+
+#endif // AKI_IRC_BASEREPLY_HPP
diff --git a/libaki/irc/private/CMakeLists.txt b/libaki/irc/private/CMakeLists.txt
index 04b7ff1..6d263bd 100644
--- a/libaki/irc/private/CMakeLists.txt
+++ b/libaki/irc/private/CMakeLists.txt
@@ -1,4 +1,5 @@
set(akicore_ircprivate_SRCS
+ irc/private/basereply_p.cxx
irc/private/basesocket_p.cxx
irc/private/message_p.cxx
irc/private/nickinfo_p.cxx
diff --git a/libaki/irc/private/basereply_p.cxx b/libaki/irc/private/basereply_p.cxx
new file mode 100644
index 0000000..bbb72f2
--- /dev/null
+++ b/libaki/irc/private/basereply_p.cxx
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2009-2010 Keith Rusler <xzekecomax@gmail.com>
+ *
+ * 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ */
+
+#include "basereply_p.hpp"
+using namespace Aki;
+using namespace Irc;
+
+BaseReplyPrivate::BaseReplyPrivate()
+ : QSharedData(),
+ sender(Aki::Irc::NickInfo()),
+ command(QString()),
+ message(QString()),
+ replyCode(Aki::Irc::RPL_NULL),
+ isNumeric(false)
+{
+}
+
+BaseReplyPrivate::BaseReplyPrivate(const QSharedData& other)
+ : QSharedData(other),
+ sender(Aki::Irc::NickInfo()),
+ command(QString()),
+ message(QString()),
+ replyCode(Aki::Irc::RPL_NULL),
+ isNumeric(false)
+{
+}
+
+BaseReplyPrivate::~BaseReplyPrivate()
+{
+}
+
+QString
+BaseReplyPrivate::removeStringToFirstWhitespace(QString* line)
+{
+ QString tmp = line->left(line->indexOf(' '));
+ line->remove(0, tmp.length() + 1);
+ return tmp;
+}
+
+QString
+BaseReplyPrivate::removeStringToFirstWhitespace(QString* line, int start, int stop)
+{
+ QString tmp = line->mid(start, line->indexOf(' ') - stop);
+ line->remove(0, tmp.length() + 1 + stop);
+ return tmp;
+}
diff --git a/libaki/irc/private/basereply_p.hpp b/libaki/irc/private/basereply_p.hpp
new file mode 100644
index 0000000..ee1cadd
--- /dev/null
+++ b/libaki/irc/private/basereply_p.hpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2009-2010 Keith Rusler <xzekecomax@gmail.com>
+ *
+ * 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ */
+
+#ifndef AKI_IRC_BASEREPLY_P_HPP
+#define AKI_IRC_BASEREPLY_P_HPP
+
+#include "irc/nickinfo.hpp"
+#include "irc/replycodes.hpp"
+#include <QtCore/QSharedData>
+
+namespace Aki
+{
+namespace Irc
+{
+class BaseReplyPrivate : public QSharedData
+{
+public:
+ BaseReplyPrivate();
+ BaseReplyPrivate(const QSharedData& other);
+ ~BaseReplyPrivate();
+ static QString removeStringToFirstWhitespace(QString* line);
+ static QString removeStringToFirstWhitespace(QString* line, int start, int stop);
+public:
+ Aki::Irc::NickInfo sender;
+ QString command;
+ QString message;
+ QStringList params;
+ Aki::Irc::ReplyCodes replyCode;
+ bool isNumeric;
+}; // End of class BaseReplyPrivate.
+} // End of namespace Irc.
+} // End of namespace Aki.
+
+#endif // AKI_IRC_BASEREPLY_P_HPP
diff --git a/libaki/irc/private/message_p.cxx b/libaki/irc/private/message_p.cxx
index 40e368e..d5d3ae7 100644
--- a/libaki/irc/private/message_p.cxx
+++ b/libaki/irc/private/message_p.cxx
@@ -26,9 +26,12 @@ using namespace Irc;
MessagePrivate::MessagePrivate(Aki::Irc::Message* qq)
: sender(Aki::Irc::NickInfo()),
- message(QString()),
+ target(Aki::Irc::NickInfo()),
direction(Aki::Irc::Message::Outgoing),
+ state(Aki::Irc::Message::Unknown),
+ type(Aki::Irc::Message::Normal),
timeStamp(KDateTime()),
+ message(QString()),
_q(qq)
{
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic