~ubuntu-branches/ubuntu/lucid/konversation/lucid-updates

« back to all changes in this revision

Viewing changes to src/application.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2009-05-15 11:24:24 UTC
  • mfrom: (1.15.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20090515112424-b74i26lciabf4qnk
Tags: 1.1.75+svn968012-1
* New upstream development snapshot:
  - Last Changed Author: hein
  - Last Changed Rev: 968012
  - Last Changed Date: 2009-05-14 21:03:55 +0300
* Update README.source.
* Use dh --quilt instead of custom patch handling, build depend on
  quilt 0.46-7~.
* Update patches to upstream changes.
* Update konversation.install: remove docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
188
188
                this,SLOT (dbusInfo(const QString&)) );
189
189
            connect(dbusObject,SIGNAL (dbusInsertMarkerLine()),
190
190
                mainWindow,SIGNAL(insertMarkerLine()));
191
 
            connect(dbusObject, SIGNAL(connectTo(Konversation::ConnectionFlag, const QString&, uint, const QString&, const QString&, const QString&, bool)),
192
 
                m_connectionManager, SLOT(connectTo(Konversation::ConnectionFlag, const QString&, uint, const QString&, const QString&, const QString&, bool)));
 
191
            connect(dbusObject, SIGNAL(connectTo(Konversation::ConnectionFlag, const QString&, const QString&, const QString&, const QString&, const QString&, bool)),
 
192
                m_connectionManager, SLOT(connectTo(Konversation::ConnectionFlag, const QString&, const QString&, const QString&, const QString&, const QString&, bool)));
193
193
        }
194
194
 
195
195
        m_notificationHandler = new Konversation::NotificationHandler(this);
201
201
    {
202
202
        getConnectionManager()->connectTo(Konversation::SilentlyReuseConnection,
203
203
                                          args->getOption("server"),
204
 
                                          args->getOption("port").toUInt(),
 
204
                                          args->getOption("port"),
205
205
                                          args->getOption("password"),
206
206
                                          args->getOption("nick"),
207
207
                                          args->getOption("channel"),
463
463
 
464
464
    KConfigGroup cgAutoreplace(KGlobal::config()->group("Autoreplace List"));
465
465
    // Read all default entries
466
 
    QStringList autoreplaceList(Preferences::autoreplaceList());
 
466
    QList<QStringList> autoreplaceList(Preferences::autoreplaceList());
467
467
    // Read all entries
468
468
    index=0;
469
 
    while (cgAutoreplace.hasKey(QString("Autoreplace%1").arg(index)))
 
469
    // legacy code for old autoreplace format 4/6/09
 
470
    QString autoReplaceString("Autoreplace");
 
471
    while (cgAutoreplace.hasKey(autoReplaceString + QString::number(index)))
470
472
    {
471
473
  // read entry and get length of the string
472
 
        QString entry=cgAutoreplace.readEntry(QString("Autoreplace%1").arg(index++));
473
 
        unsigned int length=entry.length()-1;
 
474
        QString entry=cgAutoreplace.readEntry(autoReplaceString + QString::number(index++));
 
475
        int length=entry.length()-1;
474
476
        // if there's a "#" in the end, strip it (used to preserve blanks at the end of the replacement text)
475
477
        // there should always be one, but older versions did not do it, so we check first
476
478
        if (entry.at(length)=='#')
477
479
            entry=entry.left(length);
 
480
        QString regex = entry.section(',',0,0);
 
481
        QString direction = entry.section(',',1,1);
 
482
        QString pattern = entry.section(',',2,2);
 
483
        QString replace = entry.section(',',3);
478
484
        // add entry to internal list
479
 
        autoreplaceList.append(entry);
 
485
        autoreplaceList.append(QStringList() << regex << direction << pattern << replace);
480
486
    } // while
 
487
    //end legacy code for old autoreplace format
 
488
    index=0; //new code for autoreplace config
 
489
    QString indexString(QString::number(index));
 
490
    QString regexString("Regex");
 
491
    QString directString("Direction");
 
492
    QString patternString("Pattern");
 
493
    QString replaceString("Replace");
 
494
    while (cgAutoreplace.hasKey(patternString + indexString))
 
495
    {
 
496
        QString pattern = cgAutoreplace.readEntry(patternString + indexString);
 
497
        QString regex = cgAutoreplace.readEntry(regexString + indexString, QString("0"));
 
498
        QString direction = cgAutoreplace.readEntry(directString + indexString, QString("o"));
 
499
        QString replace = cgAutoreplace.readEntry(replaceString + indexString, QString());
 
500
        if (replace.length()>0)
 
501
        {
 
502
            int repLen=replace.length()-1;
 
503
            if (replace.at(repLen)=='#')
 
504
                replace=replace.left(repLen);
 
505
        }
 
506
        if (pattern.length()>0)
 
507
        {
 
508
            int patLen=pattern.length()-1;
 
509
            if (pattern.at(patLen)=='#')
 
510
                pattern=pattern.left(patLen);
 
511
        }
 
512
        index++;
 
513
        indexString = QString::number(index);
 
514
        autoreplaceList.append(QStringList() << regex << direction << pattern << replace);
 
515
    }
481
516
    // Put back the changed autoreplace list
482
517
    Preferences::setAutoreplaceList(autoreplaceList);
483
518
 
782
817
void KonversationApplication::openQuickConnectDialog()
783
818
{
784
819
    quickConnectDialog = new QuickConnectDialog(mainWindow);
785
 
    connect(quickConnectDialog, SIGNAL(connectClicked(Konversation::ConnectionFlag, const QString&, uint,
786
 
        const QString&, const QString&, const QString&, bool)),
787
 
        m_connectionManager, SLOT(connectTo(Konversation::ConnectionFlag, const QString&, uint,
 
820
    connect(quickConnectDialog, SIGNAL(connectClicked(Konversation::ConnectionFlag, const QString&,
 
821
        const QString&, const QString&, const QString&, const QString&, bool)),
 
822
        m_connectionManager, SLOT(connectTo(Konversation::ConnectionFlag, const QString&, const QString&,
788
823
        const QString&, const QString&, const QString&, bool)));
789
824
    quickConnectDialog->show();
790
825
}
802
837
    //kaddresbook uses the utf separator 0xE120, so treat that as a separator as well
803
838
    QString nickServer = nick_server;
804
839
    nickServer.replace(QChar(0xE120), "@");
805
 
    ircnick = nickServer.section("@",0,0);
806
 
    serverOrGroup = nickServer.section("@",1);
 
840
    ircnick = nickServer.section('@',0,0);
 
841
    serverOrGroup = nickServer.section('@',1);
807
842
}
808
843
 
809
844
NickInfoPtr KonversationApplication::getNickInfo(const QString &ircnick, const QString &serverOrGroup)
829
864
QString KonversationApplication::doAutoreplace(const QString& text,bool output)
830
865
{
831
866
    // get autoreplace list
832
 
    QStringList autoreplaceList=Preferences::autoreplaceList();
 
867
    QList<QStringList> autoreplaceList=Preferences::autoreplaceList();
833
868
    // working copy
834
869
    QString line=text;
835
870
 
837
872
    for (int index=0;index<autoreplaceList.count();index++)
838
873
    {
839
874
        // get autoreplace definition
840
 
        QString definition=autoreplaceList[index];
 
875
        QStringList definition=autoreplaceList[index];
841
876
        // split definition in parts
842
 
        QString regex=definition.section(',',0,0);
843
 
        QString direction=definition.section(',',1,1);
844
 
        QString pattern=definition.section(',',2,2);
845
 
        QString replacement=definition.section(',',3);
 
877
        QString regex=definition.at(0);
 
878
        QString direction=definition.at(1);
 
879
        QString pattern=definition.at(2);
 
880
        QString replacement=definition.at(3);
846
881
 
847
882
        QString isDirection=output ? "o" : "i";
848
883
 
859
894
                int index = 0;
860
895
 
861
896
                do {
862
 
                    replacement = definition.section(',',3);
863
897
                    // find matches
864
898
                    index = line.indexOf(needleReg, index);
865
899
 
873
907
                        {
874
908
                            replacement.replace(QString("%%1").arg(capture),captures[capture]);
875
909
                        }
876
 
                        replacement.replace(QRegExp("%[0-9]"),QString());
 
910
                        replacement.remove(QRegExp("%[0-9]"));
877
911
                        // replace input with replacement
878
912
                        line.replace(index, captures[0].length(), replacement);
879
913
                        index += replacement.length();
882
916
            }
883
917
            else
884
918
            {
885
 
                QRegExp needleReg("\\b" + QRegExp::escape(pattern) + "\\b");
886
 
                needleReg.setCaseSensitivity(Qt::CaseInsensitive);
887
 
                line.replace(needleReg,replacement);
 
919
                QRegExp needleReg(pattern);
 
920
                needleReg.setPatternSyntax(QRegExp::FixedString);
 
921
                int index=line.indexOf(needleReg);
 
922
                while (index>=0)
 
923
                {   
 
924
                    int length,nextLength,patLen,repLen;
 
925
                    patLen=pattern.length();
 
926
                    repLen=replacement.length();
 
927
                    length=index;
 
928
                    length+=patLen;
 
929
                    nextLength=length;
 
930
                    //nextlength is used to account for the replacement taking up less space
 
931
                    QChar before,after;
 
932
                    if (index!=0) before = line.at(index-1);
 
933
                    if (line.length() > length) after = line.at(length);
 
934
 
 
935
                    if (index==0 || before.isSpace() || before.isPunct())
 
936
                    {
 
937
                        if (line.length() == length || after.isSpace() || after.isPunct())
 
938
                        {
 
939
                            line.replace(index,patLen,replacement);
 
940
                            nextLength = index+repLen;
 
941
                        }
 
942
                    }
 
943
                    index=line.indexOf(needleReg,nextLength);
 
944
                }
888
945
            }
889
946
        }
890
947
    }