~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to console/kabcclient/src/outputformatimpls.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
//  Copyright (C) 2005 - 2006 Kevin Krammer <kevin.krammer@gmx.at>
 
2
//  Copyright (C) 2005 - 2011 Kevin Krammer <kevin.krammer@gmx.at>
 
3
//  Copyright (C) 2011 Fernando Schapachnik <fernando@schapachnik.com.ar>
3
4
//
4
5
//  This program is free software; you can redistribute it and/or modify
5
6
//  it under the terms of the GNU General Public License as published by
390
391
///////////////////////////////////////////////////////////////////////////////
391
392
///////////////////////////////////////////////////////////////////////////////
392
393
 
393
 
MuttOutput::MuttOutput() : m_allEmails(false), m_queryFormat(false), m_altKeyFormat(false)
 
394
MuttOutput::MuttOutput()
 
395
    : m_allEmails(false), m_queryFormat(false), m_altKeyFormat(false),
 
396
      m_preferNickNameKey(false), m_alsoNickNameKey(false)
394
397
{
395
398
}
396
399
 
419
422
            m_queryFormat = false;
420
423
        else if ((*it) == "altkeys")
421
424
            m_altKeyFormat = true;
 
425
        else if ((*it) == "prefernick")
 
426
            m_preferNickNameKey = true;
 
427
        else if ((*it) == "alsonick")
 
428
            m_alsoNickNameKey = true;
422
429
        else
423
430
            return false;
424
431
    }
425
432
 
 
433
    if (m_alsoNickNameKey && m_preferNickNameKey)
 
434
    {
 
435
        kDebug() << "Both 'prefernick' and 'alsonick' specified, using only 'alsonick'";
 
436
        m_preferNickNameKey = false;
 
437
    }
 
438
 
426
439
    return true;
427
440
}
428
441
 
431
444
QString MuttOutput::optionUsage() const
432
445
{
433
446
    QString usage =
434
 
        i18n("Comma separated list of: allemails, query, alias, altkeys. Default is alias");
 
447
        i18n("Comma separated list of: allemails, query, alias, altkeys, prefernick, alsonick. "
 
448
             "Default is alias");
435
449
 
436
450
    usage += '\n';
437
451
 
458
472
    usage += i18n("Use alternative keys with alias format, e.g.\n\t\t"
459
473
                  "alias jdoe[tab]John Doe &lt;jdoe@foo.com&gt;");
460
474
 
 
475
    usage += '\n';
 
476
 
 
477
    usage += "prefernick\t";
 
478
    usage += i18n("If a nick name exists use it instead of the key, e.g.\n\t\t"
 
479
                  "alias johnny[tab]John Doe &lt;jdoe@foo.com&gt;");
 
480
 
 
481
    usage += '\n';
 
482
 
 
483
    usage += "alsonick\t";
 
484
    usage += i18n("Generate additional aliases with the nick name as the key, e.g.\n\t\t"
 
485
                  "alias johnny[tab]John Doe &lt;jdoe@foo.com&gt;\n\t\t"
 
486
                  "Deactivates 'prefernick' to avoid duplicates");
 
487
 
461
488
    return usage;
462
489
}
463
490
 
478
505
{
479
506
    if (stream.bad()) return false;
480
507
 
 
508
    const QString nickKeyString = nickNameKey(addressee);
 
509
 
 
510
    // if we have a key based on nick name and we prefer it over normal key use it
 
511
    // other wise use normal key
 
512
    const QString keyString =
 
513
        (m_preferNickNameKey && !nickKeyString.isEmpty()) ? nickKeyString : key(addressee);
 
514
    
481
515
    if (m_allEmails)
482
516
    {
483
517
        QStringList emails = addressee.emails();
487
521
 
488
522
        if (it != endIt)
489
523
        {
490
 
            const QString keyString = key(addressee);
491
 
 
492
524
            if (!(*it).isEmpty())
493
525
            {
494
526
                if (m_queryFormat)
503
535
                    stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
504
536
                           << fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
505
537
                           << fromUnicode(m_codec, *it).constData()                   << ">";
 
538
                           
 
539
                    if (m_alsoNickNameKey && !nickKeyString.isEmpty())
 
540
                    {
 
541
                        stream << std::endl;
 
542
                        stream << "alias "
 
543
                               << fromUnicode(m_codec, nickKeyString).constData()         << "\t";
 
544
                        stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
 
545
                               << fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
 
546
                               << fromUnicode(m_codec, *it).constData()                   << ">";
 
547
                    }
506
548
                }
507
549
 
508
550
                if (stream.bad()) return false;
533
575
                    stream << fromUnicode(m_codec, addressee.givenName()).constData()  << " "
534
576
                           << fromUnicode(m_codec, addressee.familyName()).constData() << " <"
535
577
                           << fromUnicode(m_codec, *it).constData()                    << ">";
 
578
                           
 
579
                    if (m_alsoNickNameKey && !nickKeyString.isEmpty())
 
580
                    {
 
581
                        stream << std::endl;
 
582
                        stream << "alias "
 
583
                               << fromUnicode(m_codec, nickKeyString).constData()         << "\t";
 
584
                        stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
 
585
                               << fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
 
586
                               << fromUnicode(m_codec, *it).constData()                   << ">";
 
587
                    }
536
588
                }
537
589
 
538
590
                if (stream.bad()) return false;
541
593
    }
542
594
    else
543
595
    {
544
 
        if (!addressee.preferredEmail().isEmpty())
 
596
        const QString preferredEmail = addressee.preferredEmail();
 
597
        if (!preferredEmail.isEmpty())
545
598
        {
546
599
            if (m_queryFormat)
547
600
            {
548
 
                stream << fromUnicode(m_codec, addressee.preferredEmail()).constData() << "\t"
549
 
                       << fromUnicode(m_codec, addressee.givenName()).constData()      << " "
 
601
                stream << fromUnicode(m_codec, preferredEmail).constData()        << "\t"
 
602
                       << fromUnicode(m_codec, addressee.givenName()).constData() << " "
550
603
                       << fromUnicode(m_codec, addressee.familyName()).constData();
551
604
            }
552
605
            else
553
606
            {
554
 
                stream << "alias " << fromUnicode(m_codec, key(addressee)).constData() << "\t";
555
 
                stream << fromUnicode(m_codec, addressee.givenName()).constData()      << " "
556
 
                       << fromUnicode(m_codec, addressee.familyName()).constData()     << " <"
557
 
                       << fromUnicode(m_codec, addressee.preferredEmail()).constData() << ">";
 
607
                stream << "alias " << fromUnicode(m_codec, keyString).constData()  << "\t";
 
608
                stream << fromUnicode(m_codec, addressee.givenName()).constData()  << " "
 
609
                       << fromUnicode(m_codec, addressee.familyName()).constData() << " <"
 
610
                       << fromUnicode(m_codec, preferredEmail).constData()         << ">";
 
611
 
 
612
                if (m_alsoNickNameKey && !nickKeyString.isEmpty())
 
613
                {
 
614
                    stream << std::endl;
 
615
                    stream << "alias "
 
616
                           << fromUnicode(m_codec, nickKeyString).constData()         << "\t";
 
617
                    stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
 
618
                           << fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
 
619
                           << fromUnicode(m_codec, preferredEmail).constData()        << ">";
 
620
                }
558
621
            }
559
622
        }
560
623
    }
602
665
        return addressee.givenName().left(3) + addressee.familyName().left(3);
603
666
}
604
667
 
 
668
QString MuttOutput::nickNameKey(const KABC::Addressee& addressee) const
 
669
{
 
670
    if (!addressee.nickName().isEmpty())
 
671
    {
 
672
        const QChar space = ' ';
 
673
        const QChar underscore = '_';
 
674
        return addressee.nickName().toLower().replace(space, underscore);
 
675
    }
 
676
    else
 
677
        return QString();
 
678
}
 
679
 
605
680
///////////////////////////////////////////////////////////////////////////////
606
681
///////////////////////////////////////////////////////////////////////////////
607
682