From kde-commits Thu Jul 01 13:27:47 2010 From: Peter Simonsson Date: Thu, 01 Jul 2010 13:27:47 +0000 To: kde-commits Subject: [Konversation] 33ad527: Clean up outputfilter a bit and fix the Message-Id: <20100701132747.39F14BB56C5 () projects ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=127800793203097 commit 33ad52765845a6b480e8adb36d72d17c00a9729a Author: Peter Simonsson Date: Fri Aug 6 00:59:39 2004 +0000 Clean up outputfilter a bit and fix the double dcc requests bug svn path=/trunk/kdeextragear-2/konversation/; revision=336475 diff --git a/konversation/channel.cpp b/konversation/channel.cpp index 842bb1c..f846960 100644 --- a/konversation/channel.cpp +++ b/konversation/channel.cpp @@ -736,19 +736,23 @@ void Channel::sendChannelText(const QString& sendLine) } // encoding stuff is done in Server() - output = server->getOutputFilter()->parse(server->getNickname(),output,getName()); + Konversation::OutputFilterResult result = server->getOutputFilter()->parse(server->getNickname(),output,getName()); // Is there something we need to display for ourselves? - if(!output.isEmpty()) + if(!result.output.isEmpty()) { - if(server->getOutputFilter()->isAction()) appendAction(server->getNickname(),output); - else if(server->getOutputFilter()->isCommand()) appendCommandMessage(server->getOutputFilter()->getType(),output); - else if(server->getOutputFilter()->isProgram()) appendServerMessage(server->getOutputFilter()->getType(),output); - else if(server->getOutputFilter()->isQuery()) appendQuery(server->getOutputFilter()->getType(),output); - else append(server->getNickname(),output); + if(result.type == Konversation::Action) appendAction(server->getNickname(), result.output); + else if(result.type == Konversation::Command) appendCommandMessage(result.typeString, result.output); + else if(result.type == Konversation::Program) appendServerMessage(result.typeString, result.output); + else if(result.type == Konversation::Query) appendQuery(result.typeString, result.output); + else append(server->getNickname(), result.output); } // Send anything else to the server - server->queueList(server->getOutputFilter()->getServerOutputList()); + if(!result.toServer.isEmpty()) { + server->queue(result.toServer); + } else { + server->queueList(result.toServerList); + } } void Channel::newTextInView(const QString& highlightColor,bool important) diff --git a/konversation/editserverdialog.h b/konversation/editserverdialog.h index f7e7dc3..c44a314 100644 --- a/konversation/editserverdialog.h +++ b/konversation/editserverdialog.h @@ -17,6 +17,8 @@ #include +#include + /* @author Dario Abatianni */ @@ -61,5 +63,52 @@ class EditServerDialog : public KDialogBase KLineEdit* channelKeyInput; KComboBox* identityCombo; }; - +/* +namespace Konversation +{ + typedef struct ChannelSettings + { + QString channel; + QString password; + }; + + typedef QValueList ChannelList; + + class EditServerDialog : public KDialogBase + { + Q_OBJECT + public: + EditServerDialog(QWidget* parent, const QString& group, + const QString& name, + unsigned int port, + const QString& password, + const QString& identity, + const QString& connectCommands, + bool autoConnect, + ChannelList channels); + ~EditServerDialog(); + + QString group(); + QString server(); + unsigned int port(); + QString password(); + QString identity(); + QString connectCommands(); + bool autoConnect(); + ChannelList channels(); + + protected slots: + void slotOk(); + + private: + KLineEdit* m_groupInput; + KLineEdit* m_serverInput; + KLineEdit* m_portInput; + KLineEdit* m_passwordInput; + KLineEdit* m_connectCommandsInput; + KComboBox* m_identityCombo; + QCheckBox* m_autoConnectCheck; + }; +}; +*/ #endif diff --git a/konversation/outputfilter.cpp b/konversation/outputfilter.cpp index d63c857..07d4fa1 100644 --- a/konversation/outputfilter.cpp +++ b/konversation/outputfilter.cpp @@ -87,21 +87,13 @@ namespace Konversation { return false; } - QString& OutputFilter::parse(const QString& myNick,const QString& originalLine,const QString& name) + OutputFilterResult OutputFilter::parse(const QString& myNick,const QString& originalLine,const QString& name) { setCommandChar(); - toServer=QString::null; - toServerList=QStringList::QStringList(); - output=QString::null; - type=QString::null; + OutputFilterResult result; destination=name; - action=false; - program=false; - command=false; - query=false; - QString inputLine(originalLine); if(!KonversationApplication::preferences.getDisableExpansion()) @@ -126,15 +118,16 @@ namespace Konversation { // Action? if(line.startsWith(commandChar+"me ") && !destination.isEmpty()) { - toServer="PRIVMSG "+name+" :"+'\x01'+"ACTION "+inputLine.mid(4)+'\x01'; - output=inputLine.mid(4); - action=true; + result.toServer = "PRIVMSG " + name + " :" + '\x01' + "ACTION " + inputLine.mid(4) + '\x01'; + result.output = inputLine.mid(4); + result.type = Action; } // Convert double command chars at the beginning to single ones else if(line.startsWith(commandChar+commandChar) && !destination.isEmpty()) { - toServer="PRIVMSG "+name+" :"+inputLine.mid(1); - output=inputLine.mid(1); + result.toServer = "PRIVMSG " + name + " :" + inputLine.mid(1); + result.output = inputLine.mid(1); + result.type = Message; } // Server command? else if(line.startsWith(commandChar)) @@ -143,183 +136,194 @@ namespace Konversation { QString parameter = inputLine.section(' ', 1); parameter = parameter.stripWhiteSpace(); - if (command == "join") parseJoin(parameter); - else if(command == "part") parsePart(parameter); - else if(command == "leave") parsePart(parameter); - else if(command == "quit") parseQuit(parameter); - else if(command == "notice") parseNotice(parameter); - else if(command == "j") parseJoin(parameter); - else if(command == "msg") parseMsg(myNick,parameter); - else if(command == "smsg") parseSMsg(parameter); + if (command == "join") result = parseJoin(parameter); + else if(command == "part") result = parsePart(parameter); + else if(command == "leave") result = parsePart(parameter); + else if(command == "quit") result = parseQuit(parameter); + else if(command == "notice") result = parseNotice(parameter); + else if(command == "j") result = parseJoin(parameter); + else if(command == "msg") result = parseMsg(myNick,parameter); + else if(command == "smsg") result = parseSMsg(parameter); else if(command == "query") parseQuery(parameter); - else if(command == "op") parseOp(parameter); - else if(command == "deop") parseDeop(parameter); - else if(command == "voice") parseVoice(parameter); - else if(command == "unvoice") parseUnvoice(parameter); - else if(command == "ctcp") parseCtcp(parameter); - else if(command == "kick") parseKick(parameter); - else if(command == "topic") parseTopic(parameter); - else if(command == "away") parseAway(parameter); - else if(command == "invite") parseInvite(parameter); - else if(command == "exec") parseExec(parameter); - else if(command == "notify") parseNotify(parameter); - else if(command == "oper") parseOper(myNick,parameter); - else if(command == "ban") parseBan(parameter); - else if(command == "unban") parseUnban(parameter); - else if(command == "ignore") parseIgnore(parameter); - else if(command == "quote") parseQuote(parameter); - else if(command == "say") parseSay(parameter); - - else if(command == "raw") parseRaw(parameter); - else if(command == "dcc") parseDcc(parameter); + else if(command == "op") result = parseOp(parameter); + else if(command == "deop") result = parseDeop(parameter); + else if(command == "voice") result = parseVoice(parameter); + else if(command == "unvoice") result = parseUnvoice(parameter); + else if(command == "ctcp") result = parseCtcp(parameter); + else if(command == "kick") result = parseKick(parameter); + else if(command == "topic") result = parseTopic(parameter); + else if(command == "away") result = parseAway(parameter); + else if(command == "invite") result = parseInvite(parameter); + else if(command == "exec") result = parseExec(parameter); + else if(command == "notify") result = parseNotify(parameter); + else if(command == "oper") result = parseOper(myNick,parameter); + else if(command == "ban") result = parseBan(parameter); + else if(command == "unban") result = parseUnban(parameter); + else if(command == "ignore") result = parseIgnore(parameter); + else if(command == "quote") result = parseQuote(parameter); + else if(command == "say") result = parseSay(parameter); + + else if(command == "raw") result = parseRaw(parameter); + else if(command == "dcc") result = parseDcc(parameter); else if(command == "konsole") parseKonsole(); else if(command == "aaway") parseAaway(parameter); - else if(command == "ame") parseAme(parameter); - else if(command == "amsg") parseAmsg(parameter); + else if(command == "ame") result = parseAme(parameter); + else if(command == "amsg") result = parseAmsg(parameter); else if(command == "server") parseServer(parameter); - else if(command == "prefs") parsePrefs(parameter); + else if(command == "prefs") result = parsePrefs(parameter); // Forward unknown commands to server else { - toServer = inputLine.mid(1); - m_server->setLastUnknownCommand(destination, toServer); + result.toServer = inputLine.mid(1); + result.type = Message; + m_server->setLastUnknownCommand(destination, result.toServer); } } // Ordinary message to channel/query? else if(!destination.isEmpty()) { - toServer="PRIVMSG "+destination+" :"+inputLine; - output=inputLine; + result.toServer = "PRIVMSG " + destination + " :" + inputLine; + result.output = inputLine; + result.type = Message; } // Eveything else goes to the server unchanged else { - toServer=inputLine; - output=inputLine; - type=i18n("Raw"); - program=true; + result.toServer = inputLine; + result.output = inputLine; + result.typeString = i18n("Raw"); + result.type = Program; } - return output; + return result; } - void OutputFilter::parseOp(const QString ¶meter) + OutputFilterResult OutputFilter::parseOp(const QString ¶meter) { - changeMode(parameter,'o','+'); + return changeMode(parameter,'o','+'); } - void OutputFilter::parseDeop(const QString ¶meter) + OutputFilterResult OutputFilter::parseDeop(const QString ¶meter) { - changeMode(parameter,'o','-'); + return changeMode(parameter,'o','-'); } - void OutputFilter::parseVoice(const QString ¶meter) + OutputFilterResult OutputFilter::parseVoice(const QString ¶meter) { - changeMode(parameter,'v','+'); + return changeMode(parameter,'v','+'); } - void OutputFilter::parseUnvoice(const QString ¶meter) + OutputFilterResult OutputFilter::parseUnvoice(const QString ¶meter) { - changeMode(parameter,'v','-'); + return changeMode(parameter,'v','-'); } - void OutputFilter::parseJoin(const QString &channelName) + OutputFilterResult OutputFilter::parseJoin(const QString &channelName) { + OutputFilterResult result; + if(channelName.isEmpty()) { - type=i18n("Usage"); - output=i18n("Usage: %1JOIN [password]").arg(commandChar); - program=true; + result = usage(i18n("Usage: %1JOIN [password]").arg(commandChar)); + } else { + result.toServer = "JOIN " + channelName; } - else - toServer="JOIN " + channelName; + + return result; } - void OutputFilter::parseKick(const QString ¶meter) + OutputFilterResult OutputFilter::parseKick(const QString ¶meter) { + OutputFilterResult result; + if(isAChannel(destination)) { // get nick to kick - QString victim=parameter.left(parameter.find(" ")); + QString victim = parameter.left(parameter.find(" ")); + if(victim.isEmpty()) { - type=i18n("Usage"); - output=i18n("Usage: %1KICK [reason]").arg(commandChar); - program=true; + result = usage(i18n("Usage: %1KICK [reason]").arg(commandChar)); } else { // get kick reason (if any) - QString reason=parameter.mid(victim.length()+1); + QString reason = parameter.mid(victim.length() + 1); + // if no reason given, take default reason - if(reason.isEmpty()) reason = m_server->getIdentity()->getKickReason(); - toServer="KICK "+destination+" "+victim+" :"+reason; + if(reason.isEmpty()) { + reason = m_server->getIdentity()->getKickReason(); + } + + result.toServer = "KICK " + destination + " " + victim + " :" + reason; } } else { - type=i18n("Error"); - output=i18n("%1KICK only works from within channels.").arg(commandChar); - program=true; + result = error(i18n("%1KICK only works from within channels.").arg(commandChar)); } + + return result; } - void OutputFilter::parsePart(const QString ¶meter) + OutputFilterResult OutputFilter::parsePart(const QString ¶meter) { + OutputFilterResult result; + // No parameter, try default part message if(parameter.isEmpty()) { // But only if we actually are in a channel - if(isAChannel(destination)) toServer = "PART " + destination + " :" + m_server->getIdentity()->getPartReason(); - else - { - type=i18n("Error"); - output=i18n("%1PART without parameters only works from within a channel or a query.").arg(commandChar); - program=true; + if(isAChannel(destination)) { + result.toServer = "PART " + destination + " :" + m_server->getIdentity()->getPartReason(); + } else { + result = error(i18n("%1PART without parameters only works from within a channel or a query.").arg(commandChar)); } - } - else - { + } else { // part a given channel if(isAChannel(parameter)) { // get channel name - QString channel=parameter.left(parameter.find(" ")); + QString channel = parameter.left(parameter.find(" ")); // get part reason (if any) - QString reason=parameter.mid(channel.length()+1); + QString reason = parameter.mid(channel.length() + 1); + // if no reason given, take default reason - if(reason.isEmpty()) reason = m_server->getIdentity()->getPartReason(); - toServer="PART "+channel+" :"+reason; + if(reason.isEmpty()) { + reason = m_server->getIdentity()->getPartReason(); + } + + result.toServer = "PART " + channel + " :" + reason; } // part this channel with a given reason else { - if(isAChannel(destination)) toServer="PART "+destination+" :"+parameter; - else - { - type=i18n("Error"); - output=i18n("%1PART without channel name only works from within a channel.").arg(commandChar); - program=true; + if(isAChannel(destination)) { + result.toServer = "PART " + destination + " :" + parameter; + } else { + result = error(i18n("%1PART without channel name only works from within a channel.").arg(commandChar)); } } } + + return result; } - void OutputFilter::parseTopic(const QString ¶meter) + OutputFilterResult OutputFilter::parseTopic(const QString ¶meter) { + OutputFilterResult result; + // No parameter, try to get current topic if(parameter.isEmpty()) { // But only if we actually are in a channel - if(isAChannel(destination)) toServer="TOPIC "+destination; - else - { - type=i18n("Error"); - output=i18n("%1TOPIC without parameters only works from within a channel.").arg(commandChar); - program=true; + if(isAChannel(destination)) { + result.toServer = "TOPIC " + destination; + } else { + result = error(i18n("%1TOPIC without parameters only works from within a channel.").arg(commandChar)); } } else @@ -332,29 +336,36 @@ namespace Konversation { // get topic (if any) QString topic=parameter.mid(channel.length()+1); // if no topic given, retrieve topic - if(topic.isEmpty()) toServer="TOPIC "+channel; + if(topic.isEmpty()) { + result.toServer = "TOPIC " + channel; + } // otherwise set topic there - else toServer="TOPIC "+channel+" :"+topic; + else + { + result.toServer = "TOPIC " + channel + " :" + topic; + } } // set this channel's topic else { - if(isAChannel(destination)) toServer="TOPIC "+destination+" :"+parameter; - else - { - type=i18n("Error"); - output=i18n("%1TOPIC without channel name only works from within a channel.").arg(commandChar); - program=true; + if(isAChannel(destination)) { + result.toServer = "TOPIC " + destination + " :" + parameter; + } else { + result = error(i18n("%1TOPIC without channel name only works from within a channel.").arg(commandChar)); } } } + + return result; } - void OutputFilter::parseAway(const QString &reason) + OutputFilterResult OutputFilter::parseAway(const QString &reason) { + OutputFilterResult result; + if(reason.isEmpty()) { - toServer="AWAY"; + result.toServer = "AWAY"; } else { @@ -364,363 +375,390 @@ namespace Konversation { emit sendToAllChannels(message.replace(QRegExp("%s",false),reason)); } - toServer="AWAY :"+reason; + result.toServer = "AWAY :" + reason; } - // remove lines in output to prevent them sent twice in sending channel - output=QString::null; - toServerList.clear(); + + return result; } - void OutputFilter::parseQuit(const QString &reason) + OutputFilterResult OutputFilter::parseQuit(const QString &reason) { - toServer = "QUIT :"; + OutputFilterResult result; + + result.toServer = "QUIT :"; // if no reason given, take default reason if(reason.isEmpty()) - toServer += m_server->getIdentity()->getPartReason(); + result.toServer += m_server->getIdentity()->getPartReason(); else - toServer += reason; + result.toServer += reason; + + return result; } - void OutputFilter::parseNotice(const QString ¶meter) + OutputFilterResult OutputFilter::parseNotice(const QString ¶meter) { - QString recipient=parameter.left(parameter.find(" ")); - QString message=parameter.mid(recipient.length()+1); + OutputFilterResult result; + QString recipient = parameter.left(parameter.find(" ")); + QString message = parameter.mid(recipient.length()+1); if(parameter.isEmpty() || message.isEmpty()) { - type=i18n("Usage"); - output=i18n("Usage: %1NOTICE ").arg(commandChar); - program=true; + result = usage(i18n("Usage: %1NOTICE ").arg(commandChar)); } else { - type=i18n("Notice"); - toServer="NOTICE "+recipient+" :"+message; - output=i18n("Sending notice \"%1\" to %2.").arg(message).arg(recipient); - program=true; + result.typeString = i18n("Notice"); + result.toServer = "NOTICE " + recipient + " :" + message; + result.output=i18n("Sending notice \"%1\" to %2.").arg(message).arg(recipient); + result.type = Program; } + + return result; } - void OutputFilter::parseMsg(const QString &myNick, const QString ¶meter) + OutputFilterResult OutputFilter::parseMsg(const QString &myNick, const QString ¶meter) { - QString recipient=parameter.left(parameter.find(" ")); - QString message=parameter.mid(recipient.length()+1); + OutputFilterResult result; + QString recipient = parameter.left(parameter.find(" ")); + QString message = parameter.mid(recipient.length() + 1); if(message.startsWith(commandChar+"me")) { - toServer="PRIVMSG "+recipient+" :"+'\x01'+"ACTION "+message.mid(4)+'\x01'; - output=QString("* %1 %2").arg(myNick).arg(message.mid(4)); + result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "ACTION " + message.mid(4) + '\x01'; + result.output = QString("* %1 %2").arg(myNick).arg(message.mid(4)); } else { - toServer="PRIVMSG "+recipient+" :"+message; - output=message; + result.toServer = "PRIVMSG " + recipient + " :" + message; + result.output = message; } - type="-> "+recipient; - query=true; + + result.typeString= "-> " + recipient; + result.type = Query; + return result; } - void OutputFilter::parseSMsg(const QString ¶meter) + OutputFilterResult OutputFilter::parseSMsg(const QString ¶meter) { - QString recipient=parameter.left(parameter.find(" ")); - QString message=parameter.mid(recipient.length()+1); + OutputFilterResult result; + QString recipient = parameter.left(parameter.find(" ")); + QString message = parameter.mid(recipient.length() + 1); - if(message.startsWith(commandChar+"me")) + if(message.startsWith(commandChar + "me")) { - toServer="PRIVMSG "+recipient+" :"+'\x01'+"ACTION "+message.mid(4)+'\x01'; + result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "ACTION " + message.mid(4) + '\x01'; } else { - toServer="PRIVMSG "+recipient+" :"+message; + result.toServer = "PRIVMSG " + recipient + " :" + message; } + + return result; } - void OutputFilter::parseCtcp(const QString ¶meter) + OutputFilterResult OutputFilter::parseCtcp(const QString ¶meter) { - QString recipient=parameter.section(' ',0,0); // who is the recipient? - QString request=parameter.section(' ',1,1); // what is the first word of the ctcp? - QString message=parameter.section(' ',1); // what is the complete ctcp command? + OutputFilterResult result; + QString recipient = parameter.section(' ', 0, 0); // who is the recipient? + QString request = parameter.section(' ', 1, 1); // what is the first word of the ctcp? + QString message = parameter.section(' ', 1); // what is the complete ctcp command? - if(request.lower()=="ping") + if(request.lower() == "ping") { #if QT_VERSION < 0x030100 - unsigned int time_t=toTime_t(QDateTime::currentDateTime()); + unsigned int time_t = toTime_t(QDateTime::currentDateTime()); #else - unsigned int time_t=QDateTime::currentDateTime().toTime_t(); + unsigned int time_t = QDateTime::currentDateTime().toTime_t(); #endif - toServer=QString("PRIVMSG %1 :\x01PING %2\x01").arg(recipient).arg(time_t); - output=i18n("Sending CTCP-%1 request to %2").arg("PING").arg(recipient); + result.toServer = QString("PRIVMSG %1 :\x01PING %2\x01").arg(recipient).arg(time_t); + result.output = i18n("Sending CTCP-%1 request to %2").arg("PING").arg(recipient); } else { - toServer=QString("PRIVMSG "+recipient+" :"+'\x01'+message+'\x01'); - output=i18n("Sending CTCP-%1 request to %2").arg(message).arg(recipient); + result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + message + '\x01'; + result.output = i18n("Sending CTCP-%1 request to %2").arg(message).arg(recipient); } - type=i18n("CTCP"); - program=true; + + result.typeString = i18n("CTCP"); + result.type = Program; + return result; } void OutputFilter::parseQuery(const QString ¶meter) { - QStringList queryList=QStringList::split(' ',parameter); - for(unsigned int index=0;index and +k also! - QString token=QString::QString(); - QString tmpToken=QString::null; - QStringList nickList=QStringList::split(' ',parameter); + QString token; + QString tmpToken; + QStringList nickList = QStringList::split(' ', parameter); + if(nickList.count()) { // Check if the user specified a channel if(isAChannel(nickList[0])) { - token="MODE "+nickList[0]; + token = "MODE " + nickList[0]; // remove the first element nickList.remove(nickList.begin()); } // Add default destination if it is a channel - else if(isAChannel(destination)) token="MODE "+destination; + else if(isAChannel(destination)) { + token = "MODE " + destination; + } + // Only continue if there was no error if(token.length()) { - unsigned int modeCount=nickList.count(); - /* if(modeCount>3) - { - modeCount=3; - output=i18n("Modes can only take a certain number of nick names at the same time." - "The server may truncate your mode list."); - type=i18n("Warning"); - program=true; - } */ - + unsigned int modeCount = nickList.count(); QString modes; - modes.fill(mode,modeCount); + modes.fill(mode, modeCount); - token+=QString(" ")+giveTake+modes; - tmpToken=token; + token += " " + giveTake + modes; + tmpToken = token; - for(unsigned int index=0;index + } else if(parameterList.count()==2) { // DCC SEND emit requestDccSend(parameterList[1]); - else if(parameterList.count()>2) // DCC SEND [file] ... - { - // TODO: make sure this will work: - // output=i18n("Usage: %1DCC SEND nickname [fi6lename] [filename] ...").arg(commandChar); + } else if(parameterList.count()>2) { // DCC SEND [file] ... + // TODO: make sure this will work: + //output=i18n("Usage: %1DCC SEND nickname [fi6lename] [filename] ...").arg(commandChar); QFile file(parameterList[2]); - if(file.exists()) + + if(file.exists()) { emit openDccSend(parameterList[1],parameterList[2]); - else - { - type=i18n("Error"); - output=i18n("Error: File \"%1\" does not exist.").arg(parameterList[2]); - program=true; + } else { + result = error(i18n("Error: File \"%1\" does not exist.").arg(parameterList[2])); } } else // Don't know how this should happen, but ... { - type=i18n("Usage"); - output=i18n("Usage: %1DCC [SEND nickname filename]").arg(commandChar); - program=true; + result = usage(i18n("Usage: %1DCC [SEND nickname filename]").arg(commandChar)); } } // TODO: DCC Chat etc. comes here else if(dccType=="chat") { - if(parameterList.count()==2) + if(parameterList.count()==2) { emit requestDccChat(parameterList[1]); - else - { - type=i18n("Usage"); - output=i18n("Usage: %1DCC [CHAT nickname]").arg(commandChar); - program=true; + } else { + result = usage(i18n("Usage: %1DCC [CHAT nickname]").arg(commandChar)); } } else { - type=i18n("Error"); - output=i18n("Error: Unrecognized command DCC %1. Possible commands are SEND, CHAT, CLOSE.").arg(parameterList[0]); - program=true; + result = error(i18n("Error: Unrecognized command DCC %1. Possible commands are SEND, CHAT, CLOSE.").arg(parameterList[0])); } } + + return result; } - void OutputFilter::sendRequest(const QString &recipient,const QString &fileName,const QString &address,const QString &port,unsigned long size) + OutputFilterResult OutputFilter::sendRequest(const QString &recipient,const QString &fileName,const QString &address,const QString &port,unsigned long size) { + OutputFilterResult result; QFile file(fileName); QFileInfo info(file); - toServer="PRIVMSG "+recipient+" :"+'\x01'+"DCC SEND "+info.fileName().replace(QRegExp(" "),"_")+" "+address+" "+port+" "+QString::number(size)+'\x01'; - output=i18n("Offering \"%1\" to %2 for upload.").arg(fileName).arg(recipient); - type=i18n("DCC"); - program=true; + result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC SEND " + info.fileName().replace(QRegExp(" "),"_") + + " " + address + " " + port + " " + QString::number(size) + '\x01'; + result.output = i18n("Offering \"%1\" to %2 for upload.").arg(fileName).arg(recipient); + result.typeString = i18n("DCC"); + result.type = Program; + + return result; } // Accepting Resume Request - void OutputFilter::acceptRequest(const QString &recipient,const QString &fileName,const QString &port,int startAt) + OutputFilterResult OutputFilter::acceptRequest(const QString &recipient,const QString &fileName,const QString &port,int startAt) { - toServer="PRIVMSG "+recipient+" :"+'\x01'+"DCC ACCEPT "+fileName+" "+port+" "+QString::number(startAt)+'\x01'; - output=i18n("Accepting DCC Resume request from \"%1\" for file \"%2\".").arg(recipient).arg(fileName); - type=i18n("DCC"); - program=true; + OutputFilterResult result; + result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC ACCEPT " + fileName + " " + port + + " " + QString::number(startAt) + '\x01'; + result.output = i18n("Accepting DCC Resume request from \"%1\" for file \"%2\".").arg(recipient).arg(fileName); + result.typeString = i18n("DCC"); + result.type = Program; + + return result; } - void OutputFilter::resumeRequest(const QString &sender,const QString &fileName,const QString &port,int startAt) + OutputFilterResult OutputFilter::resumeRequest(const QString &sender,const QString &fileName,const QString &port,int startAt) { + OutputFilterResult result; QString newFileName(fileName); - newFileName.replace(QRegExp(" "),"_"); - toServer="PRIVMSG "+sender+" :"+'\x01'+"DCC RESUME "+newFileName+" "+port+" "+QString::number(startAt)+'\x01'; - output=i18n("Sending DCC Resume request to \"%1\" for file \"%2\".").arg(sender).arg(fileName); - type=i18n("DCC"); - program=true; + newFileName.replace(QRegExp(" "), "_"); + result.toServer = "PRIVMSG " + sender + " :" + '\x01' + "DCC RESUME " + newFileName + " " + port + " " + + QString::number(startAt) + '\x01'; + result.output = i18n("Sending DCC Resume request to \"%1\" for file \"%2\".").arg(sender).arg(fileName); + result.typeString = i18n("DCC"); + result.type = Program; + return result; } - void OutputFilter::parseInvite(const QString ¶meter) + OutputFilterResult OutputFilter::parseInvite(const QString ¶meter) { + OutputFilterResult result; + if(parameter.isEmpty()) { - type=i18n("Usage"); - output=i18n("Usage: INVITE [channel]"); - program=true; + result = usage(i18n("Usage: INVITE [channel]")); } else { - QString nick=parameter.section(' ',0,0); - QString channel=parameter.section(' ',1,1); + QString nick = parameter.section(' ', 0, 0); + QString channel = parameter.section(' ', 1, 1); if(channel.isEmpty()) { - if(isAChannel(destination)) channel=destination; - else - { - type=i18n("Error"); - output=i18n("Error: INVITE without channel name works only from within channels."); - program=true; + if(isAChannel(destination)) { + channel = destination; + } else { + result = error(i18n("Error: INVITE without channel name works only from within channels.")); } } if(!channel.isEmpty()) { - if(isAChannel(channel)) toServer="INVITE "+nick+" "+channel; - else - { - type=i18n("Error"); - output=i18n("Error: %1 is not a channel.").arg(channel); - program=true; + if(isAChannel(channel)) { + result.toServer = "INVITE " + nick + " " + channel; + } else { + result = error(i18n("Error: %1 is not a channel.").arg(channel)); } } } + + return result; } - void OutputFilter::parseExec(const QString& parameter) + OutputFilterResult OutputFilter::parseExec(const QString& parameter) { + OutputFilterResult result; + if(parameter.isEmpty()) { - type=i18n("Usage"); - output=i18n("Usage: EXEC