~ubuntu-branches/ubuntu/jaunty/quassel/jaunty

« back to all changes in this revision

Viewing changes to src/core/userinputhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-11-17 15:22:46 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20081117152246-3lwlpnr4r08910kv
Tags: 0.3.1-0ubuntu1
* New upstream release (LP: #271403)
* Drop all patches originated from upstream (quassel_*)
* Compile with non-builtin quassel icons
  + Introduce new quassel-data package
  + quassel and quassel-client depend on quassel-data
  + Don't manually enforce icon installation for desktop files in debian/rules
  + Add quassel_01_fix_iconloader.patch
* Drop perl build dependency, I have no clue why it was added in the first
  place. Neither changelog nor Bazaar knows, and since quassel compiles just
  fine without it, removing it should be save.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
      return;
39
39
    QString cmd;
40
40
    QString msg = msg_;
41
 
    // leading slashes indicate there's a command to call unless there is anothere one in the first section (like a path /proc/cpuinfo)
 
41
    // leading slashes indicate there's a command to call unless there is another one in the first section (like a path /proc/cpuinfo)
42
42
    int secondSlashPos = msg.indexOf('/', 1);
43
43
    int firstSpacePos = msg.indexOf(' ');
44
44
    if(!msg.startsWith('/') || (secondSlashPos != -1 && (secondSlashPos < firstSpacePos || firstSpacePos == -1))) {
72
72
  }
73
73
  if(me)
74
74
    me->setAwayMessage(awayMsg);
75
 
  
 
75
 
76
76
  putCmd("AWAY", serverEncode(awayMsg));
77
77
}
78
78
 
79
79
void UserInputHandler::handleBan(const BufferInfo &bufferInfo, const QString &msg) {
 
80
  banOrUnban(bufferInfo, msg, true);
 
81
}
 
82
 
 
83
void UserInputHandler::handleUnban(const BufferInfo &bufferInfo, const QString &msg) {
 
84
  banOrUnban(bufferInfo, msg, false);
 
85
}
 
86
 
 
87
void UserInputHandler::banOrUnban(const BufferInfo &bufferInfo, const QString &msg, bool ban) {
80
88
  QString banChannel;
81
89
  QString banUser;
82
90
 
104
112
      int secondLastPeriodPosition = generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1);
105
113
      generalizedHost.replace(0, secondLastPeriodPosition, "*");
106
114
    }
107
 
    banUser = QString("*!%1@%2").arg(ircuser->user()).arg(generalizedHost);
 
115
    banUser = QString("*!%1@%2").arg(ircuser->user(), generalizedHost);
108
116
  } else {
109
117
    banUser = params.join(" ");
110
118
  }
111
119
 
112
 
  QString banMsg = QString("MODE %1 +b %2").arg(banChannel).arg(banUser);
 
120
  QString banMode = ban ? "+b" : "-b";
 
121
  QString banMsg = QString("MODE %1 %2 %3").arg(banChannel, banMode, banUser);
113
122
  emit putRawLine(serverEncode(banMsg));
114
123
}
115
124
 
208
217
void UserInputHandler::handleMe(const BufferInfo &bufferInfo, const QString &msg) {
209
218
  if(bufferInfo.bufferName().isEmpty()) return; // server buffer
210
219
  networkConnection()->ctcpHandler()->query(bufferInfo.bufferName(), "ACTION", msg);
211
 
  emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick());
 
220
  emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
212
221
}
213
222
 
214
223
void UserInputHandler::handleMode(const BufferInfo &bufferInfo, const QString &msg) {
218
227
  // if the first argument is neither a channel nor us (user modes are only to oneself) the current buffer is assumed to be the target
219
228
  if(!params.isEmpty() && !network()->isChannelName(params[0]) && !network()->isMyNick(params[0]))
220
229
    params.prepend(bufferInfo.bufferName());
221
 
  
 
230
 
222
231
  // TODO handle correct encoding for buffer modes (channelEncode())
223
232
  emit putCmd("MODE", serverEncode(params));
224
233
}
242
251
  emit putCmd("NICK", serverEncode(nick));
243
252
}
244
253
 
 
254
void UserInputHandler::handleNotice(const BufferInfo &bufferInfo, const QString &msg) {
 
255
  QString bufferName = msg.section(' ', 0, 0);
 
256
  QString payload = msg.section(' ', 1);
 
257
  QList<QByteArray> params;
 
258
  params << serverEncode(bufferName) << channelEncode(bufferInfo.bufferName(), payload);
 
259
  emit putCmd("NOTICE", params);
 
260
  emit displayMsg(Message::Notice, bufferName, payload, network()->myNick(), Message::Self);
 
261
}
 
262
 
245
263
void UserInputHandler::handleOp(const BufferInfo &bufferInfo, const QString &msg) {
246
264
  QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
247
265
  QString m = "+"; for(int i = 0; i < nicks.count(); i++) m += 'o';
267
285
  } else {
268
286
    partReason = msg.mid(channelName.length() + 1);
269
287
  }
270
 
  
 
288
 
271
289
  if(partReason.isEmpty())
272
290
    partReason = networkConnection()->identity()->partReason();
273
291
 
299
317
 
300
318
void UserInputHandler::handleQuit(const BufferInfo &bufferInfo, const QString &msg) {
301
319
  Q_UNUSED(bufferInfo)
 
320
  networkConnection()->disconnectFromIrc(true, msg);
 
321
}
302
322
 
 
323
void UserInputHandler::issueQuit(const QString &reason) {
303
324
  QString quitReason;
304
 
  if(msg.isEmpty())
 
325
  if(reason.isEmpty())
305
326
    quitReason = networkConnection()->identity()->quitReason();
306
327
  else
307
 
    quitReason = msg;
308
 
 
 
328
    quitReason = reason;
309
329
  emit putCmd("QUIT", serverEncode(quitReason));
310
 
  networkConnection()->disconnectFromIrc();
311
330
}
312
331
 
313
332
void UserInputHandler::handleQuote(const BufferInfo &bufferInfo, const QString &msg) {
325
344
 
326
345
void UserInputHandler::handleTopic(const BufferInfo &bufferInfo, const QString &msg) {
327
346
  if(bufferInfo.bufferName().isEmpty()) return;
328
 
  if(!msg.isEmpty()) {
329
 
    QList<QByteArray> params;
330
 
    params << serverEncode(bufferInfo.bufferName()) << channelEncode(bufferInfo.bufferName(), msg);
331
 
    emit putCmd("TOPIC", params);
332
 
  } else {
333
 
    emit networkConnection()->putRawLine("TOPIC " + serverEncode(bufferInfo.bufferName()) + " :");
334
 
  }
 
347
  QList<QByteArray> params;
 
348
  params << serverEncode(bufferInfo.bufferName());
 
349
  if(!msg.isEmpty())
 
350
    params << channelEncode(bufferInfo.bufferName(), msg);
 
351
  emit putCmd("TOPIC", params);
335
352
}
336
353
 
337
354
void UserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString &msg) {
364
381
      return;
365
382
    }
366
383
  }
367
 
  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: %1 %2").arg(cmd).arg(msg));
 
384
  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: %1 %2").arg(cmd, msg));
368
385
}
369
386
 
370
387
void UserInputHandler::expand(const QString &alias, const BufferInfo &bufferInfo, const QString &msg) {
 
388
  QRegExp paramRangeR("\\$(\\d+)\\.\\.(\\d*)");
371
389
  QStringList commands = alias.split(QRegExp("; ?"));
372
390
  QStringList params = msg.split(' ');
373
391
  for(int i = 0; i < commands.count(); i++) {
374
392
    QString command = commands[i];
 
393
 
 
394
    // replace ranges like $1..3
 
395
    if(!params.isEmpty()) {
 
396
      int pos;
 
397
      while((pos = paramRangeR.indexIn(command)) != -1) {
 
398
        int start = paramRangeR.cap(1).toInt();
 
399
        bool ok;
 
400
        int end = paramRangeR.cap(2).toInt(&ok);
 
401
        if(!ok) {
 
402
          end = params.count();
 
403
        }
 
404
        if(end < start)
 
405
          command = command.replace(pos, paramRangeR.matchedLength(), QString());
 
406
        else {
 
407
          command = command.replace(pos, paramRangeR.matchedLength(), QStringList(params.mid(start - 1, end - start + 1)).join(" "));
 
408
        }
 
409
      }
 
410
    }
 
411
 
375
412
    for(int j = params.count(); j > 0; j--) {
376
413
      IrcUser *ircUser = network()->ircUser(params[j - 1]);
377
414
      command = command.replace(QString("$%1:hostname").arg(j), ircUser ? ircUser->host() : QString("*"));