/*! Creates a new message from \a data and \a parent. */ IrcMessage* IrcMessage::fromData(const QByteArray& data, QObject* parent) { IrcMessage* message = 0; IrcParser parser; if (parser.parse(data)) { const QMetaObject* metaObject = irc_command_meta_object(parser.command()); Q_ASSERT(metaObject); message = qobject_cast<IrcMessage*>(metaObject->newInstance(Q_ARG(QObject*, parent))); Q_ASSERT(message); message->d_ptr->parser = parser; IrcSession* session = qobject_cast<IrcSession*>(parent); if (session) { IrcSender sender = message->sender(); if (sender.isValid() && sender.name() == session->nickName()) message->d_ptr->flags |= Own; if (session->d_ptr->capabilities.contains("identify-msg") && (message->d_ptr->type == Private || message->d_ptr->type == Notice)) { QString msg = message->property("message").toString(); if (msg.startsWith("+")) message->d_ptr->flags |= Identified; else if (msg.startsWith("-")) message->d_ptr->flags |= Unidentified; } } } return message; }
/*! Creates a new message from \a data and \a connection. */ IrcMessage* IrcMessage::fromData(const QByteArray& data, IrcConnection* connection) { IrcMessage* message = 0; IrcMessageData md = IrcMessageData::fromData(data); const QMetaObject* metaObject = irc_command_meta_object(md.command); if (metaObject) { message = qobject_cast<IrcMessage*>(metaObject->newInstance(Q_ARG(IrcConnection*, connection))); Q_ASSERT(message); message->d_ptr->data = md; } return message; }
/*! Creates a new message from \a prefix, \a command and \a parameters with \a connection. */ IrcMessage* IrcMessage::fromParameters(const QString& prefix, const QString& command, const QStringList& parameters, IrcConnection* connection) { IrcMessage* message = 0; const QMetaObject* metaObject = irc_command_meta_object(command); if (metaObject) { message = qobject_cast<IrcMessage*>(metaObject->newInstance(Q_ARG(IrcConnection*, connection))); Q_ASSERT(message); message->setPrefix(prefix); message->setCommand(command); message->setParameters(parameters); } return message; }