1 /*
2     icqreadaway.cpp  -  ICQ Protocol Plugin
3 
4     Copyright (c) 2003 by Stefan Gehn <metz@gehn.net>
5 
6     Kopete    (c) 2003 by the Kopete developers  <kopete-devel@kde.org>
7 
8     *************************************************************************
9     *                                                                       *
10     * This program is free software; you can redistribute it and/or modify  *
11     * it under the terms of the GNU General Public License as published by  *
12     * the Free Software Foundation; either version 2 of the License, or     *
13     * (at your option) any later version.                                   *
14     *                                                                       *
15     *************************************************************************
16 */
17 
18 #include "icqreadaway.h"
19 
20 #include "icqprotocol.h"
21 #include "icqaccount.h"
22 #include "icqcontact.h"
23 
24 #include <ktextbrowser.h>
25 #include <klocale.h>
26 #include <krun.h>
27 
28 #include <assert.h>
29 
ICQReadAway(ICQContact * c,QWidget * parent,const char * name)30 ICQReadAway::ICQReadAway(ICQContact *c, QWidget *parent, const char* name)
31 	: KDialog(parent, QString(), KDialog::Close | KDialog::User1, 0, KGuiItem(i18n("&Fetch Again")))
32 {
33 	assert(c);
34 
35 	mAccount = static_cast<ICQAccount*>(c->account());
36 	mContact = c;
37 	setCaption(i18n("'%2' Message for %1", c->displayName(), c->onlineStatus().description()));
38 
39 	QWidget *mMainWidget = makeVBoxMainWidget();
40 
41 	awayMessageBrowser = new KTextBrowser(mMainWidget);
42 	awayMessageBrowser->setObjectName("userInfoView");
43 	awayMessageBrowser->setTextFormat(Qt::AutoText);
44 	awayMessageBrowser->setNotifyClick(true);
45 	awayMessageBrowser->setText(mContact->awayMessage());
46 
47 	QObject::connect(awayMessageBrowser, &KTextBrowser::urlClick, this, &ICQReadAway::slotUrlClicked);
48 	QObject::connect(awayMessageBrowser, &KTextBrowser::mailClick, this, &ICQReadAway::slotMailClicked);
49 
50 	connect(this, &ICQReadAway::user1Clicked, this, &ICQReadAway::slotFetchAwayMessage);
51 	connect(this, &ICQReadAway::closeClicked, this, &ICQReadAway::slotCloseClicked);
52 
53 	connect(c, SIGNAL(awayMessageChanged()),
54 		this, SLOT(slotAwayMessageChanged()));
55 
56 	slotFetchAwayMessage();
57 }
58 
slotFetchAwayMessage()59 void ICQReadAway::slotFetchAwayMessage()
60 {
61 	if(!mAccount->isConnected())
62 		return;
63 
64 	awayMessageBrowser->setDisabled(true);
65 	enableButton(User1,false);
66 
67 	mAccount->engine()->requestAwayMessage(mContact);
68 
69 	setCaption(i18n("Fetching '%2' Message for %1...", mContact->displayName(), mContact->onlineStatus().description()));
70 } // END slotFetchAwayMessage()
71 
slotAwayMessageChanged()72 void ICQReadAway::slotAwayMessageChanged()
73 {
74 	setCaption(i18n("'%2' Message for %1", mContact->displayName(), mContact->onlineStatus().description()));
75 	awayMessageBrowser->setText(mContact->awayMessage());
76 
77 	awayMessageBrowser->setDisabled(false);
78 	enableButton(User1,true);
79 
80 } // END slotAwayMessageChanged()
81 
slotCloseClicked()82 void ICQReadAway::slotCloseClicked()
83 {
84 	emit closing();
85 }
86 
slotUrlClicked(const QString & url)87 void ICQReadAway::slotUrlClicked(const QString &url)
88 {
89 	new KRun(KUrl(url));
90 }
91 
slotMailClicked(const QString &,const QString & address)92 void ICQReadAway::slotMailClicked(const QString&, const QString &address)
93 {
94 	new KRun(KUrl(address));
95 }
96 
97