~ubuntu-branches/ubuntu/trusty/konversation/trusty-security

« back to all changes in this revision

Viewing changes to src/irc/server.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-04-08 19:41:33 UTC
  • mfrom: (1.18.7)
  • Revision ID: package-import@ubuntu.com-20130408194133-lrytg1wgsemqj21f
Tags: 1.5~rc1+git20130408-0ubuntu1
* New git snapshot (LP: #1156019)
  + Contains new fixes and translation updates since last snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
#include <QTextCodec>
44
44
#include <QStringListModel>
 
45
#include <QStringBuilder>
45
46
 
46
47
#include <KInputDialog>
47
48
#include <KWindowSystem>
 
49
#include <KShell>
48
50
 
49
51
#include <solid/networking.h>
50
52
 
234
236
    m_unjoinedChannels.clear();
235
237
 
236
238
    m_queryNicks.clear();
 
239
    delete m_serverISON;
 
240
    m_serverISON = 0;
 
241
 
237
242
}
238
243
 
239
244
//... so called to match the ChatWindow derivatives.
253
258
 
254
259
void Server::doPreShellCommand()
255
260
{
256
 
    QString command = getIdentity()->getShellCommand();
257
 
    getStatusView()->appendServerMessage(i18n("Info"),"Running preconfigured command...");
258
 
 
259
 
    connect(&m_preShellCommand,SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(preShellCommandExited(int,QProcess::ExitStatus)));
260
 
    connect(&m_preShellCommand,SIGNAL(error(QProcess::ProcessError)), this, SLOT(preShellCommandError(QProcess::ProcessError)));
261
 
 
262
 
    const QStringList commandList = command.split(' ');
263
 
 
264
 
    for (QStringList::ConstIterator it = commandList.begin(); it != commandList.end(); ++it)
265
 
        m_preShellCommand << *it;
266
 
 
267
 
    m_preShellCommand.start();
268
 
    if (m_preShellCommand.state() == QProcess::NotRunning) preShellCommandExited(m_preShellCommand.exitCode(), m_preShellCommand.exitStatus());
 
261
    KShell::Errors e;
 
262
    QStringList command = KShell::splitArgs(getIdentity()->getShellCommand(), KShell::TildeExpand, &e);
 
263
    if (e != KShell::NoError)
 
264
    {
 
265
        //FIXME The flow needs to be refactored, add a finally-like method that does the ready-to-connect stuff
 
266
        // "The pre-connect shell command could not be understood!");
 
267
        preShellCommandExited(m_preShellCommand.exitCode(), m_preShellCommand.exitStatus());
 
268
    }
 
269
    else
 
270
    {
 
271
        // FIXME add i18n, and in preShellCommandExited and preShellCommandError
 
272
        getStatusView()->appendServerMessage(i18n("Info"), "Running pre-connect shell command...");
 
273
 
 
274
        connect(&m_preShellCommand, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(preShellCommandExited(int,QProcess::ExitStatus)));
 
275
        connect(&m_preShellCommand, SIGNAL(error(QProcess::ProcessError)), SLOT(preShellCommandError(QProcess::ProcessError)));
 
276
 
 
277
        m_preShellCommand.setProgram(command);
 
278
        m_preShellCommand.start();
 
279
        // NOTE: isConnecting is tested in connectToIRCServer so there's no guard here
 
280
        if (m_preShellCommand.state() == QProcess::NotRunning)
 
281
            preShellCommandExited(m_preShellCommand.exitCode(), m_preShellCommand.exitStatus());
 
282
    }
269
283
}
270
284
 
271
285
void Server::initTimers()
403
417
    if (exitStatus == QProcess::NormalExit)
404
418
        getStatusView()->appendServerMessage(i18n("Info"),"Process executed successfully!");
405
419
    else
406
 
        getStatusView()->appendServerMessage(i18n("Warning"),"There was a problem while executing the command!");
 
420
    {
 
421
        QString errorText = QLatin1String("There was a problem while executing the command: ") % m_preShellCommand.errorString();
 
422
        getStatusView()->appendServerMessage(i18n("Warning"), errorText);
 
423
    }
407
424
 
408
425
    connectToIRCServer();
409
426
    connectSignals();
413
430
{
414
431
    Q_UNUSED(error);
415
432
 
416
 
    getStatusView()->appendServerMessage(i18n("Warning"),"There was a problem while executing the command!");
 
433
    QString errorText = QLatin1String("There was a problem while executing the command: ") % m_preShellCommand.errorString();
 
434
    getStatusView()->appendServerMessage(i18n("Warning"), errorText);
417
435
 
418
436
    connectToIRCServer();
419
437
    connectSignals();
421
439
 
422
440
void Server::connectToIRCServer()
423
441
{
424
 
    if (!isConnected())
 
442
    if (!isConnected() && !isConnecting())
425
443
    {
426
444
        if (m_sslErrorLock)
427
445
        {
491
509
        m_inputFilter.reset();
492
510
    }
493
511
    else
494
 
        kDebug() << "connectToIRCServer() called while already connected: This should never happen.";
 
512
        kDebug() << "connectToIRCServer() called while already connected: This should never happen. (" << (isConnecting() << 1) + isConnected() << ')';
495
513
}
496
514
 
497
515
void Server::connectToIRCServerIn(uint delay)
902
920
 
903
921
    // Make a helper object to build ISON (notify) list and map offline nicks to addressbook.
904
922
    // TODO: Give the object a kick to get it started?
 
923
    Q_ASSERT(m_serverISON == 0);
905
924
    m_serverISON = new ServerISON(this);
906
925
    // get first notify very early
907
926
    startNotifyTimer(1000);
1755
1774
    ChannelNickPtr channelNick = getChannelNick(channelName, lcNickname);
1756
1775
    if (!channelNick)
1757
1776
    {
1758
 
        // Get watch list from preferences.
1759
 
        QString watchlist=getWatchListString();
1760
 
        // Create a lower case nick list from the watch list.
1761
 
        QStringList watchLowerList = watchlist.toLower().split(' ', QString::SkipEmptyParts);
1762
 
        // If on the watch list, add channel and nick to unjoinedChannels list.
1763
 
        if (watchLowerList.contains(lcNickname))
 
1777
        // If the nick is on the watch list, add channel and nick to unjoinedChannels list.
 
1778
        if (getWatchList().contains(lcNickname, Qt::CaseInsensitive))
1764
1779
        {
1765
1780
            channelNick = addNickToUnjoinedChannelsList(channelName, nickname);
1766
1781
            channelNick->setMode(mode);
3142
3157
        return QStringList();
3143
3158
}
3144
3159
 
3145
 
QString Server::getWatchListString() { return getWatchList().join(" "); }
3146
 
 
3147
3160
QStringList Server::getISONList()
3148
3161
{
3149
3162
    // no nickinfo ISON for the time being