summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/ui/userinfodialog.cpp
blob: 130973ce8f51ed51ff66c08b6266c7729673b254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
    userinfodialog.h

    Copyright (c) 2003 by Zack Rusin <[email protected]>

    Kopete    (c) 2002-2003 by the Kopete developers <[email protected]>

    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#include "userinfodialog.h"
#include "kopeteuiglobal.h"

#include <tdehtml_part.h>
#include <ktextbrowser.h>
#include <kapplication.h>
#include <klineedit.h>
#include <klocale.h>
#include <kdebug.h>

#include <tqlabel.h>
#include <tqvbox.h>
#include <tqlayout.h>

namespace Kopete {

struct UserInfoDialog::UserInfoDialogPrivate {
	TQString name;
	TQString id;
	TQString awayMessage;
	TQString status;
	TQString warningLevel;
	TQString onlineSince;
	TQString info;
	TQString address;
	TQString phone;
	TQMap<TQString,TQString> customFields;
	TQVBoxLayout *topLayout;
	TQWidget     *page;
	DialogStyle style;
	TDEHTMLPart   *htmlPart;

	KLineEdit *nameEdit;
	KLineEdit *idEdit;
	KLineEdit *statusEdit;
	KLineEdit *warningEdit;
	KLineEdit *onlineEdit;
	KLineEdit *addressEdit;
	KLineEdit *phoneEdit;
	KTextBrowser *awayBrowser;
	KTextBrowser *infoBrowser;
};

UserInfoDialog::UserInfoDialog( const TQString& descr )
: KDialogBase( Kopete::UI::Global::mainWidget(), "userinfodialog", true, i18n( "User Info for %1" ).arg( descr ), KDialogBase::Ok )
{
	d = new UserInfoDialogPrivate;
	d->page = new TQWidget( this );
	setMainWidget( d->page );
	d->topLayout = new TQVBoxLayout( d->page, 0, spacingHint() );
	d->style = Widget;
}

UserInfoDialog::~UserInfoDialog()
{
	delete d; d=0;
}

void UserInfoDialog::setStyle( DialogStyle style )
{
	d->style = style;
}

void UserInfoDialog::setName( const TQString& name )
{
	d->name = name;
}

void UserInfoDialog::setId( const TQString& id )
{
	d->id = id;
}

void UserInfoDialog::setAwayMessage( const TQString& msg )
{
	d->awayMessage = msg;
}

void UserInfoDialog::setStatus( const TQString& status )
{
	d->status = status;
}

void UserInfoDialog::setWarningLevel(const TQString& level )
{
	d->warningLevel = level;
}

void UserInfoDialog::setOnlineSince( const TQString& since )
{
	d->onlineSince = since;
}

void UserInfoDialog::setInfo( const TQString& info )
{
	d->info = info;
}

void UserInfoDialog::setAddress( const TQString& addr )
{
	d->address = addr;
}

void UserInfoDialog::setPhone( const TQString& phone )
{
	d->phone = phone;
}

void UserInfoDialog::addCustomField( const TQString& /*name*/, const TQString& /*txt*/ )
{

}

void UserInfoDialog::addHTMLText( const TQString& /*str*/ )
{

}

TQHBox* UserInfoDialog::addLabelEdit( const TQString& label, const TQString& text, KLineEdit*& edit )
{
	TQHBox *box = new TQHBox( d->page );
	new TQLabel( label, box );
	edit = new KLineEdit( box );
  edit->setAlignment( TQt::AlignHCenter );
	edit->setText( text );
	edit->setReadOnly( true );
	return box;
}

void UserInfoDialog::fillHTML()
{
	d->htmlPart = new TDEHTMLPart( this );

	TQString text;
	/*
	if ( d->name.isEmpty() ) {
		text.append( TQString("<div id=\"name\"><b>") + i18n("Name : ") +
								 TQString("</b>") );
		text.append( d->name + TQString("</div><br>") );
	}

	if ( d->id.isEmpty() ) {
		text.append( "<div id=\"id\"><b>" + i18n("Id : ") + "</b>" );
		text.append( d->id + "</div><br>" );
	}

	if ( d->warningLevel.isEmpty() ) {
		text.append( "<div id=\"warningLevel\"><b>" + i18n("Warning Level : ") + "</b>" );
		text.append( d->warningLevel + "</div><br>" );
	}

	if ( d->onlineSince.isEmpty() ) {
		text.append( "<div id=\"onlineSince\"><b>" + i18n("Online Since : ") + "</b>" );
		text.append( d->onlineSince + "</div><br>" );
	}

	if ( d->address.isEmpty() ) {
		text.append( "<div id=\"address\"><b>" + i18n("Address : ") + "</b>" );
		text.append( d->address + "</div><br>" );
	}

	if ( d->phone.isEmpty() ) {
		text.append( "<div id=\"phone\"><b>" + i18n("Phone : ") + "</b>" );
		text.append( d->phone + "</div><br>" );
	}

	if ( d->status.isEmpty() ) {
		text.append( "<div id=\"status\"><b>" + i18n("Status : ") + "</b>" );
		text.append( d->status + "</div><br>" );
	}

	if ( d->awayMessage.isEmpty() ) {
		text.append( "<div id=\"awayMessage\"><b>" + i18n("Away Message : ") + "</b>" );
		text.append( d->awayMessage + "</div><br>" );
	}

	if ( d->info.isEmpty() ) {
		text.append( "<div id=\"info\"><b>" + i18n("Info : ") + "</b>" );
		text.append( d->info + "</div><br>" );
	}
*/
	d->htmlPart->setOnlyLocalReferences( true );
	d->htmlPart->begin();
	d->htmlPart->write( text );
	d->htmlPart->end();
}

void UserInfoDialog::fillWidgets()
{
	kdDebug(14010)<<"Creating widgets"<<endl;
	if ( !d->name.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Name:"), d->name, d->nameEdit ) );
	}

	if ( !d->id.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Contact ID:"), d->id, d->idEdit ) );
	}

	if ( !d->status.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Status:"), d->status, d->statusEdit ) );
	}

	if ( !d->warningLevel.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Warning level:"), d->warningLevel, d->warningEdit ) );
	}

	if ( !d->onlineSince.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Online since:"), d->onlineSince, d->onlineEdit ) );
	}

	if ( !d->address.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Address:"), d->address, d->addressEdit ) );
	}

	if ( !d->phone.isEmpty() ) {
		d->topLayout->addWidget( addLabelEdit( i18n("Phone:"), d->phone, d->phoneEdit ) );
	}

	if ( !d->awayMessage.isEmpty() ) {
		TQVBox *awayBox = new TQVBox( d->page );
		new TQLabel( i18n("Away message:"), awayBox );
		d->awayBrowser = new KTextBrowser( awayBox );
		d->awayBrowser->setText( d->awayMessage );
		d->topLayout->addWidget( awayBox );
	}

	if ( !d->info.isEmpty() ) {
		TQVBox *infoBox = new TQVBox( d->page );
		new TQLabel( i18n("User info:"), infoBox );
		d->infoBrowser = new KTextBrowser( infoBox );
		d->infoBrowser->setText( d->info );
		d->topLayout->addWidget( infoBox );
	}
}

void UserInfoDialog::setStyleSheet( const TQString& /*css*/ )
{
}

void UserInfoDialog::create()
{
	if ( d->style == HTML ) {
		fillHTML();
	} else {
		fillWidgets();
	}
}

void UserInfoDialog::show()
{
	create();
	KDialogBase::show();
}

}

#include "userinfodialog.moc"

// vim: set noet ts=4 sts=4 sw=4: