Project

General

Profile

0001-Don-t-send-exec-output-by-default.patch

Add -o option - Sputnick, 09/28/2009 06:32 PM

View differences:

src/client/clientuserinputhandler.cpp
60 60
  for(int i = 0; i < clist.count(); i++) {
61 61
    QString cmd = clist.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper();
62 62
    if(cmd == "EXEC")
63
      handleExec(clist.at(i).first, clist.at(i).second.section(' ', 1));
63
      handleExec(clist.at(i).first, clist.at(i).second.section(' ', 1).trimmed());
64 64
    else
65 65
      emit sendInput(clist.at(i).first, clist.at(i).second);
66 66
  }
67 67
}
68 68

  
69
void ClientUserInputHandler::handleExec(const BufferInfo &bufferInfo, const QString &execString) {
69
void ClientUserInputHandler::handleExec(const BufferInfo &bufferInfo, const QString &execString_) {
70
  QString execString = execString_;
71
  bool sendOutput = false;
72
  if(execString.startsWith("-o ")) {
73
    execString.remove(0, 3);
74
    sendOutput = true;
75
  }
70 76
  ExecWrapper *exec = new ExecWrapper(this); // gets suicidal when it's done
71
  exec->start(bufferInfo, execString);
77
  exec->start(bufferInfo, execString, sendOutput);
72 78
}
src/client/execwrapper.cpp
26 26
#include "messagemodel.h"
27 27
#include "quassel.h"
28 28

  
29
ExecWrapper::ExecWrapper(QObject* parent) : QObject(parent) {
29
ExecWrapper::ExecWrapper(QObject* parent)
30
: QObject(parent),
31
  _sendOutput(true)
32
{
30 33
  connect(&_process, SIGNAL(readyReadStandardOutput()), SLOT(processReadStdout()));
31 34
  connect(&_process, SIGNAL(readyReadStandardError()), SLOT(processReadStderr()));
32 35
  connect(&_process, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(processFinished(int, QProcess::ExitStatus)));
......
36 39
  connect(this, SIGNAL(error(QString)), SLOT(postStderr(QString)));
37 40
}
38 41

  
39
void ExecWrapper::start(const BufferInfo &info, const QString &command) {
42
void ExecWrapper::start(const BufferInfo &info, const QString &command, bool sendOutput) {
40 43
  _bufferInfo = info;
44
  _sendOutput = sendOutput;
41 45
  QString params;
42 46

  
43 47
  QRegExp rx("^\\s*(\\S+)(\\s+(.*))?$");
......
68 72
}
69 73

  
70 74
void ExecWrapper::postStdout(const QString &msg) {
71
  if(_bufferInfo.isValid())
72
    Client::userInput(_bufferInfo, msg);
75
  if(_bufferInfo.isValid()) {
76
    if(_sendOutput)
77
      Client::userInput(_bufferInfo, msg);
78
    else
79
      Client::messageModel()->insertMessage(_bufferInfo, Message::Info, msg);
80
  }
73 81
}
74 82

  
75 83
void ExecWrapper::postStderr(const QString &msg) {
76 84
  if(_bufferInfo.isValid())
77
    Client::messageModel()->insertErrorMessage(_bufferInfo, msg);
85
    Client::messageModel()->insertMessage(_bufferInfo, Message::Error, msg);
78 86
}
79 87

  
80 88
void ExecWrapper::processFinished(int exitCode, QProcess::ExitStatus status) {
src/client/execwrapper.h
32 32
  ExecWrapper(QObject *parent = 0);
33 33

  
34 34
public slots:
35
  void start(const BufferInfo &info, const QString &command);
35
  void start(const BufferInfo &info, const QString &command, bool sendOutput = true);
36 36

  
37 37
signals:
38 38
  void error(const QString &errorMsg);
......
53 53
  QString _scriptName;
54 54
  QString _stdoutBuffer;
55 55
  QString _stderrBuffer;
56
  bool _sendOutput;
56 57
};
57 58

  
58 59
#endif
src/client/messagemodel.cpp
70 70
  return false;
71 71
}
72 72

  
73
void MessageModel::insertMessage(BufferInfo bufferInfo, Message::Type type, const QString &string) {
74
  Message msg(bufferInfo, type, string);
75
  if(!messagesIsEmpty())
76
    msg.setMsgId(lastMessageItem()->msgId());
77
  else
78
    msg.setMsgId(0);
79

  
80
  int idx = messageCount();
81
  beginInsertRows(QModelIndex(), idx, idx);
82
  insertMessage__(idx, msg);
83
  endInsertRows();
84
}
85

  
73 86
bool MessageModel::insertMessage(const Message &msg, bool fakeMsg) {
74 87
  MsgId id = msg.msgId();
75 88
  int idx = indexForId(id);
......
348 361
  _nextDayChange = _nextDayChange.addSecs(86400);
349 362
}
350 363

  
351
void MessageModel::insertErrorMessage(BufferInfo bufferInfo, const QString &errorString) {
352
  int idx = messageCount();
353
  beginInsertRows(QModelIndex(), idx, idx);
354
  Message msg(bufferInfo, Message::Error, errorString);
355
  if(!messagesIsEmpty())
356
    msg.setMsgId(messageItemAt(idx-1)->msgId());
357
  else
358
    msg.setMsgId(0);
359
  insertMessage__(idx, msg);
360
  endInsertRows();
361
}
362

  
363 364
void MessageModel::requestBacklog(BufferId bufferId) {
364 365
  if(_messagesWaiting.contains(bufferId))
365 366
    return;
src/client/messagemodel.h
75 75
  void requestBacklog(BufferId bufferId);
76 76
  void messagesReceived(BufferId bufferId, int count);
77 77
  void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
78
  void insertErrorMessage(BufferInfo bufferInfo, const QString &errorString);
78
  void insertMessage(BufferInfo bufferInfo, Message::Type type, const QString &string);
79 79

  
80 80
protected:
81 81
//   virtual MessageModelItem *createMessageModelItem(const Message &) = 0;
src/common/aliasmanager.cpp
97 97

  
98 98
#ifdef Q_OS_LINUX
99 99
  // let's add aliases for scripts that only run on linux
100
  aliases << Alias("inxi", "/exec inxi $0")
101
          << Alias("sysinfo", "/exec inxi -d");
100
  aliases << Alias("inxi", "/exec -o inxi $0")
101
          << Alias("sysinfo", "/exec -o inxi -d");
102 102
#endif
103 103

  
104 104
  return aliases;
105
-