Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / kopeteaddedinfoevent.cpp
blob973d7050e5eaa33fc13ba0285fa05f9e4a143341
1 /*
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 *************************************************************************
8 * *
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. *
13 * *
14 *************************************************************************
16 #include "kopeteaddedinfoevent.h"
18 #include <klocale.h>
19 #include <kdebug.h>
21 #include "kopeteaccount.h"
22 #include "kopeteprotocol.h"
23 #include "ui/contactaddednotifydialog.h"
25 namespace Kopete {
27 class AddedInfoEvent::Private
29 public:
30 QString contactId;
31 Kopete::Account *account;
32 ShowActionOptions actions;
34 QString contactNickname;
36 bool suppressClose;
37 UI::ContactAddedNotifyDialog* addDialog;
40 AddedInfoEvent::AddedInfoEvent( const QString& contactId, Kopete::Account *account )
41 : InfoEvent(account), d( new Private() )
43 d->suppressClose = false;
44 d->addDialog = 0;
45 d->contactId = contactId;
46 d->account = account;
47 d->actions = AllActions;
50 AddedInfoEvent::~AddedInfoEvent()
52 if( d->addDialog )
53 d->addDialog->deleteLater();
55 delete d;
58 QString AddedInfoEvent::contactId() const
60 return d->contactId;
63 Kopete::Account* AddedInfoEvent::account() const
65 return d->account;
68 void AddedInfoEvent::showActions( ShowActionOptions actions )
70 d->actions = actions;
73 void AddedInfoEvent::setContactNickname( const QString& nickname )
75 d->contactNickname = nickname;
78 void AddedInfoEvent::activate( uint actionId )
80 if ( actionId == AddAction )
82 if ( d->addDialog )
84 d->addDialog->raise();
86 else
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()) );
99 d->addDialog->show();
102 else
104 InfoEvent::activate( actionId );
106 if ( !d->suppressClose && actionId != InfoAction && d->account->isConnected() )
107 close();
111 MetaContact* AddedInfoEvent::addContact() const
113 if( !d->addDialog )
114 return 0L;
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()
140 if( !d->addDialog )
141 return;
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() )
152 close();
155 void AddedInfoEvent::addDialogInfo()
157 activate( InfoAction );
160 void AddedInfoEvent::addDialogFinished()
162 if( d->addDialog )
164 d->addDialog->deleteLater();
165 d->addDialog = 0;
171 #include "kopeteaddedinfoevent.moc"