~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to libkopete/ui/contactaddednotifydialog.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2005      Olivier Goffart           <ogoffart@kde.org>
 
3
 
 
4
    Kopete    (c) 2005-2007 by the Kopete developers  <kopete-devel@kde.org>
 
5
 
 
6
    *************************************************************************
 
7
    *                                                                       *
 
8
    * This library is free software; you can redistribute it and/or         *
 
9
    * modify it under the terms of the GNU Lesser General Public            *
 
10
    * License as published by the Free Software Foundation; either          *
 
11
    * version 2 of the License, or (at your option) any later version.      *
 
12
    *                                                                       *
 
13
    *************************************************************************
 
14
*/
 
15
 
 
16
#include "contactaddednotifydialog.h"
 
17
 
 
18
 
 
19
#include <qlabel.h>
 
20
#include <qcheckbox.h>
 
21
#include <qapplication.h>
 
22
 
 
23
#include <klocale.h>
 
24
#include <kcombobox.h>
 
25
#include <klineedit.h>
 
26
#include <kpushbutton.h>
 
27
#include <kiconloader.h>
 
28
 
 
29
#include <kabc/addressee.h>
 
30
 
 
31
#include "kopetegroup.h"
 
32
#include "kopeteaccount.h"
 
33
#include "kopeteuiglobal.h"
 
34
#include "kopeteprotocol.h"
 
35
#include "kopetecontactlist.h"
 
36
#include "kopetemetacontact.h"
 
37
#include "addressbooklinkwidget.h"
 
38
#include "addressbookselectordialog.h"
 
39
#include "ui_contactaddednotifywidget.h"
 
40
 
 
41
namespace Kopete {
 
42
 
 
43
namespace UI {
 
44
 
 
45
struct ContactAddedNotifyDialog::Private
 
46
{
 
47
        Ui::ContactAddedNotifyWidget *widget;
 
48
        Account *account;
 
49
        QString contactId;
 
50
        QString addressbookId;
 
51
};
 
52
 
 
53
 
 
54
ContactAddedNotifyDialog::ContactAddedNotifyDialog(const QString& contactId,
 
55
                const QString& contactNick, Kopete::Account *account, const HideWidgetOptions &hide)
 
56
        : KDialog( Global::mainWidget() ), d(new Private())
 
57
{
 
58
        setCaption( i18n("Someone Has Added You") );
 
59
        setButtons( KDialog::Ok | KDialog::Cancel );
 
60
    setAttribute( Qt::WA_DeleteOnClose );
 
61
 
 
62
        d->widget=new Ui::ContactAddedNotifyWidget;
 
63
        QWidget* w = new QWidget(this);
 
64
        d->widget->setupUi(w);
 
65
        setMainWidget(w);
 
66
 
 
67
        d->account=account;
 
68
        d->contactId=contactId;
 
69
        d->widget->m_label->setText(i18n("<qt><img src=\"kopete-account-icon:%1\" /> The contact <b>%2</b> has added you to his/her contact list. (Account %3)</qt>",
 
70
                        QString(QUrl::toPercentEncoding( account->protocol()->pluginId() )) + QString::fromLatin1(":")
 
71
                                         +  QString(QUrl::toPercentEncoding( account->accountId() )) ,
 
72
                                  contactNick.isEmpty() ? contactId : contactNick + QString::fromLatin1(" < ") + contactId + QString::fromLatin1(" >")  ,
 
73
                                  account->accountLabel()       )   );
 
74
        if( hide & InfoButton)
 
75
                d->widget->m_infoButton->hide() ;
 
76
        if( hide & AuthorizeCheckBox )
 
77
        {
 
78
                d->widget->m_authorizeCb->hide();
 
79
                d->widget->m_authorizeCb->setChecked(false);
 
80
        }
 
81
        if( hide & AddCheckBox )
 
82
        {
 
83
                d->widget->m_addCb->hide();
 
84
                d->widget->m_addCb->setChecked(false);
 
85
        }
 
86
        if( hide & AddGroupBox )
 
87
                d->widget->m_contactInfoBox->hide();
 
88
 
 
89
        // Populate the groups list
 
90
        QListIterator<Group *> it(Kopete::ContactList::self()->groups());
 
91
        while ( it.hasNext() )
 
92
        {
 
93
                Group *g = it.next();
 
94
                QString groupname = g->displayName();
 
95
                if ( g->type() == Group::Normal && !groupname.isEmpty() )
 
96
                {
 
97
                        d->widget->m_groupList->addItem(groupname);
 
98
                }
 
99
        }
 
100
        d->widget->m_groupList->setEditText(QString()); //default to top-level
 
101
 
 
102
        connect( d->widget->widAddresseeLink, SIGNAL(addresseeChanged(KABC::Addressee)), this, SLOT(slotAddresseeSelected(KABC::Addressee)) );
 
103
        connect( d->widget->m_infoButton, SIGNAL(clicked()), this, SLOT(slotInfoClicked()) );
 
104
 
 
105
        connect( this, SIGNAL(okClicked()) , this , SLOT(slotFinished()));
 
106
 
 
107
}
 
108
 
 
109
 
 
110
ContactAddedNotifyDialog::~ContactAddedNotifyDialog()
 
111
{
 
112
        delete d->widget;
 
113
        delete d;
 
114
}
 
115
 
 
116
bool ContactAddedNotifyDialog::added() const
 
117
{
 
118
        return d->widget->m_addCb->isChecked();
 
119
}
 
120
 
 
121
bool ContactAddedNotifyDialog::authorized() const
 
122
{
 
123
        return d->widget->m_authorizeCb->isChecked();
 
124
}
 
125
 
 
126
QString ContactAddedNotifyDialog::displayName() const
 
127
{
 
128
        return d->widget->m_displayNameEdit->text();
 
129
}
 
130
 
 
131
Group *ContactAddedNotifyDialog::group() const
 
132
{
 
133
        QString grpName=d->widget->m_groupList->currentText();
 
134
        if(grpName.isEmpty())
 
135
                return Group::topLevel();
 
136
 
 
137
        return ContactList::self()->findGroup( grpName  );
 
138
}
 
139
 
 
140
MetaContact *ContactAddedNotifyDialog::addContact() const
 
141
{
 
142
        if(!added() || !d->account)
 
143
                return 0L;
 
144
 
 
145
        MetaContact *metacontact=d->account->addContact(d->contactId, displayName(), group());
 
146
        if(!metacontact)
 
147
                return 0L;
 
148
 
 
149
        metacontact->setKabcId(d->addressbookId);
 
150
 
 
151
        return metacontact;
 
152
}
 
153
 
 
154
void ContactAddedNotifyDialog::slotAddresseeSelected( const KABC::Addressee & addr )
 
155
{
 
156
        if ( !addr.isEmpty() )
 
157
        {
 
158
                d->addressbookId = addr.uid();
 
159
        }
 
160
}
 
161
 
 
162
void ContactAddedNotifyDialog::slotInfoClicked()
 
163
{
 
164
        emit infoClicked(d->contactId);
 
165
}
 
166
 
 
167
void ContactAddedNotifyDialog::slotFinished()
 
168
{
 
169
        emit applyClicked(d->contactId);
 
170
}
 
171
 
 
172
 
 
173
 
 
174
} // namespace UI
 
175
} // namespace Kopete
 
176
#include "contactaddednotifydialog.moc"