2 kopeteaddedinfoevent.cpp - Kopete Added Info Event
4 Copyright (c) 2008 by Roman Jarosz <kedgedev@centrum.cz>
5 Kopete (c) 2008 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2 of the License, or (at your option) any later version. *
14 *************************************************************************
16 #include "kopeteaddedinfoevent.h"
21 #include "kopeteaccount.h"
22 #include "kopeteprotocol.h"
23 #include "ui/contactaddednotifydialog.h"
27 class AddedInfoEvent::Private
31 Kopete::Account
*account
;
32 ShowActionOptions actions
;
34 QString contactNickname
;
37 UI::ContactAddedNotifyDialog
* addDialog
;
40 AddedInfoEvent::AddedInfoEvent( const QString
& contactId
, Kopete::Account
*account
)
41 : InfoEvent(account
), d( new Private() )
43 d
->suppressClose
= false;
45 d
->contactId
= contactId
;
47 d
->actions
= AllActions
;
50 AddedInfoEvent::~AddedInfoEvent()
53 d
->addDialog
->deleteLater();
58 QString
AddedInfoEvent::contactId() const
63 Kopete::Account
* AddedInfoEvent::account() const
68 void AddedInfoEvent::showActions( ShowActionOptions actions
)
73 void AddedInfoEvent::setContactNickname( const QString
& nickname
)
75 d
->contactNickname
= nickname
;
78 void AddedInfoEvent::activate( uint actionId
)
80 if ( actionId
== AddAction
)
84 d
->addDialog
->raise();
88 UI::ContactAddedNotifyDialog::HideWidgetOptions hideFlags
= UI::ContactAddedNotifyDialog::DefaultHide
;
89 if ( !(d
->actions
& AuthorizeAction
) )
90 hideFlags
|= UI::ContactAddedNotifyDialog::AuthorizeCheckBox
;
91 if ( !(d
->actions
& InfoAction
) )
92 hideFlags
|= UI::ContactAddedNotifyDialog::InfoButton
;
94 d
->addDialog
= new UI::ContactAddedNotifyDialog( d
->contactId
, d
->contactNickname
, d
->account
, hideFlags
);
95 d
->addDialog
->setAttribute( Qt::WA_DeleteOnClose
, false );
97 connect( d
->addDialog
, SIGNAL(finished()), this, SLOT(addDialogFinished()) );
98 connect( d
->addDialog
, SIGNAL(applyClicked(const QString
&)), this, SLOT(addDialogOk()) );
104 InfoEvent::activate( actionId
);
106 if ( !d
->suppressClose
&& actionId
!= InfoAction
&& d
->account
->isConnected() )
111 MetaContact
* AddedInfoEvent::addContact() const
116 return d
->addDialog
->addContact();
119 void AddedInfoEvent::sendEvent()
121 setTitle( i18n( "You have been added" ) );
123 if ( d
->actions
& AddAction
)
124 addAction( AddAction
, i18n("Add...") );
125 if ( d
->actions
& AuthorizeAction
)
126 addAction( AuthorizeAction
, i18n("Authorize") );
127 if ( d
->actions
& BlockAction
)
128 addAction( BlockAction
, i18n("Block") );
129 if ( d
->actions
& InfoAction
)
130 addAction( InfoAction
, i18n("Info...") );
132 setText( i18n( "The contact <b>%1</b> has added you to his/her contact list.",
133 ( d
->contactNickname
.isEmpty() ) ? d
->contactId
: d
->contactNickname
) );
135 InfoEvent::sendEvent();
138 void AddedInfoEvent::addDialogOk()
143 d
->suppressClose
= true;
144 if ( d
->addDialog
->authorized() )
145 activate( AuthorizeAction
);
148 if ( d
->addDialog
->added() )
149 activate( AddContactAction
);
151 if ( d
->account
->isConnected() )
155 void AddedInfoEvent::addDialogInfo()
157 activate( InfoAction
);
160 void AddedInfoEvent::addDialogFinished()
164 d
->addDialog
->deleteLater();
171 #include "kopeteaddedinfoevent.moc"