~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to libkopete/kopetecontact.cpp

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
 
83
83
        Kopete::StatusMessage statusMessage;
84
84
        KToggleAction* toggleAlwaysVisibleAction;
 
85
 
 
86
        Kopete::Contact::NameType preferredNameType;
 
87
        QString oldName;
85
88
};
86
89
 
 
90
/* static */
 
91
Kopete::Contact::NameType Kopete::Contact::nameTypeFromString(const QString &nameType)
 
92
{
 
93
        if (nameType == "nickName")
 
94
                return Kopete::Contact::NickName;
 
95
        else if (nameType == "customName")
 
96
                return Kopete::Contact::CustomName;
 
97
        else if (nameType == "formattedName")
 
98
                return Kopete::Contact::FormattedName;
 
99
        else if (nameType == "contactId")
 
100
                return Kopete::Contact::ContactId;
 
101
        else // fallback to custom name
 
102
                return Kopete::Contact::CustomName;
 
103
}
 
104
 
 
105
/* static */
 
106
const QString Kopete::Contact::nameTypeToString(Kopete::Contact::NameType nameType)
 
107
{
 
108
        switch (nameType)
 
109
        {
 
110
                case Kopete::Contact::NickName:
 
111
                        return QString("nickName");
 
112
                case Kopete::Contact::FormattedName:
 
113
                        return QString("formattedName");
 
114
                case Kopete::Contact::ContactId:
 
115
                        return QString("contactId");
 
116
                case Kopete::Contact::CustomName:
 
117
                default: // fallback to custom name
 
118
                        return QString("customName");
 
119
        }
 
120
}
 
121
 
87
122
Contact::Contact( Account *account, const QString &contactId,
88
123
        MetaContact *parent, const QString &icon )
89
124
        : ContactListElement( parent ), d(new Private())
98
133
        d->account = account;
99
134
        d->idleTime = 0;
100
135
        d->icon = icon;
 
136
        d->preferredNameType = Kopete::Contact::CustomName;
 
137
        d->oldName = displayName();
 
138
 
 
139
        connect( this, SIGNAL(propertyChanged(Kopete::PropertyContainer*,QString,QVariant,QVariant)),
 
140
                this, SLOT(slotPropertyChanged(Kopete::PropertyContainer*,QString,QVariant,QVariant)) );
101
141
 
102
142
        bool duplicate = false;
103
143
        // If can happend that a MetaContact may be used without a account
243
283
        KMenu *menu = new KMenu();
244
284
 
245
285
        QString titleText;
246
 
        const QString nick = nickName();
 
286
        const QString nick = displayName();
247
287
        if( nick == contactId() )
248
288
                titleText = QString::fromLatin1( "%1 (%2)" ).arg( contactId(), onlineStatus().description() );
249
289
        else
600
640
                              QString(QUrl::toPercentEncoding( contactId() )) );
601
641
        }
602
642
 
603
 
        // TODO:  the nickname should be a configurable properties, like others. -Olivier
604
 
        QString nick = nickName();
 
643
        QString nick = displayName();
605
644
        if ( nick == contactId() )
606
645
        {
607
646
                tip = i18nc( "@label:textbox %3 is contact-display-name, %1 is its status",
816
855
        return contactId();
817
856
}
818
857
 
 
858
void Kopete::Contact::setCustomName( const QString &name )
 
859
{
 
860
        setProperty( Kopete::Global::Properties::self()->customName(), name );
 
861
}
 
862
 
 
863
QString Kopete::Contact::customName() const
 
864
{
 
865
        const QString name = property( Kopete::Global::Properties::self()->customName() ).value().toString();
 
866
        if (!name.isEmpty())
 
867
                return name;
 
868
        return nickName();
 
869
}
 
870
 
819
871
void Kopete::Contact::setPhoto(const QString &photoPath)
820
872
{
821
873
        setProperty( Kopete::Global::Properties::self()->photo(), photoPath );
822
874
}
823
875
 
 
876
void Kopete::Contact::slotPropertyChanged(Kopete::PropertyContainer *, const QString &key,
 
877
        const QVariant &, const QVariant &)
 
878
{
 
879
        if (key != Kopete::Global::Properties::self()->customName().key()
 
880
                && key != Kopete::Global::Properties::self()->fullName().key()
 
881
                && key != Kopete::Global::Properties::self()->firstName().key()
 
882
                && key != Kopete::Global::Properties::self()->lastName().key()
 
883
                && key != Kopete::Global::Properties::self()->nickName().key())
 
884
                return;
 
885
 
 
886
        const QString oldName = d->oldName;
 
887
        const QString newName = displayName();
 
888
        if (oldName != newName) {
 
889
                d->oldName = newName;
 
890
                emit displayNameChanged(oldName, newName);
 
891
        }
 
892
}
 
893
 
 
894
void Kopete::Contact::setPreferredNameType(Kopete::Contact::NameType preferredNameType)
 
895
{
 
896
        if (d->preferredNameType != preferredNameType)
 
897
        {
 
898
                const QString oldName = displayName();
 
899
                d->preferredNameType = preferredNameType;
 
900
                const QString newName = displayName();
 
901
                if (oldName != newName) {
 
902
                        d->oldName = newName;
 
903
                        emit displayNameChanged(oldName, newName);
 
904
                }
 
905
        }
 
906
}
 
907
 
 
908
Kopete::Contact::NameType Kopete::Contact::preferredNameType() const
 
909
{
 
910
        return d->preferredNameType;
 
911
}
 
912
 
 
913
QString Kopete::Contact::displayName() const
 
914
{
 
915
        QString name;
 
916
        switch (d->preferredNameType)
 
917
        {
 
918
                case NickName:
 
919
                        name = nickName();
 
920
                        break;
 
921
                case FormattedName:
 
922
                        name = formattedName();
 
923
                        break;
 
924
                case ContactId:
 
925
                        name = contactId();
 
926
                        break;
 
927
                case CustomName:
 
928
                default: // fallback to custom name
 
929
                        name = customName();
 
930
                        break;
 
931
        }
 
932
        if (name.isEmpty())
 
933
                return contactId();
 
934
        else
 
935
                return name;
 
936
}
 
937
 
824
938
 
825
939
} //END namespace Kopete
826
940