summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/icq/ui/icqaddcontactpage.cpp
blob: 719b0bd7010518fb78acb6b75208352ff796766a (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
 /*
    icqaddcontactpage.cpp  -  ICQ Protocol Plugin

    Copyright (c) 2002 by Stefan Gehn <metz AT gehn.net>
    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>

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

#include "icqaddcontactpage.h"

#include <ctype.h>

#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqcombobox.h>
#include <tqcheckbox.h>
#include <tqlineedit.h>
#include <tqtabwidget.h>
#include <tqlabel.h>

#include <kdebug.h>
#include <kiconloader.h>
#include <tdelistview.h>
#include <tdelocale.h>
#include <kpushbutton.h>
#include <tdemessagebox.h>

#include "icqadd.h"
#include "icqaccount.h"
#include "icqprotocol.h"
#include "icqsearchdialog.h"


ICQAddContactPage::ICQAddContactPage(ICQAccount *owner, TQWidget *parent, const char *name)
	: AddContactPage(parent,name)
{
	kdDebug(14153) << k_funcinfo << "called" << endl;
	mAccount = owner;
	m_searchDialog = 0L;

	(new TQVBoxLayout(this))->setAutoAdd(true);
	addUI = new icqAddUI(this);
	connect( addUI->searchButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( showSearchDialog() ) );
}

ICQAddContactPage::~ICQAddContactPage()
{
}

void ICQAddContactPage::setUINFromSearch( const TQString& uin )
{
	addUI->uinEdit->setText( uin );
}

void ICQAddContactPage::showEvent(TQShowEvent *e)
{
//	slotSelectionChanged();
	AddContactPage::showEvent(e);
}

bool ICQAddContactPage::apply(Kopete::Account* , Kopete::MetaContact *parentContact  )
{
	kdDebug(14153) << k_funcinfo << "called; adding contact..." << endl;

	TQString contactId = addUI->uinEdit->text();
	kdDebug(14153) << k_funcinfo << "uin=" << contactId << endl;
	return mAccount->addContact(contactId, parentContact, Kopete::Account::ChangeKABC );

}

bool ICQAddContactPage::validateData()
{
	if(!mAccount->isConnected())
	{
		// Account currently offline
		addUI->searchButton->setEnabled( false );
		addUI->uinEdit->setEnabled( false );
		KMessageBox::sorry( this, i18n("You must be online to add a contact."), i18n("ICQ Plugin") );
		return false;
	}
	
	TQ_ULONG uin = addUI->uinEdit->text().toULong();
	if ( uin < 1000 )
	{
		// Invalid (or missing) UIN
		KMessageBox::sorry( this, i18n("You must enter a valid UIN."), i18n("ICQ Plugin") );
		return false;
	}
	else
	{
		// UIN is valid
		return true;
	}
}

void ICQAddContactPage::showSearchDialog()
{
	if ( m_searchDialog )
		m_searchDialog->raise();
	else
	{
		m_searchDialog = new ICQSearchDialog( mAccount, this, "icqSearchDialog" );
		m_searchDialog->show();
		connect( m_searchDialog, TQT_SIGNAL( finished() ), this, TQT_SLOT( searchDialogDestroyed() ) );
	}
}

void ICQAddContactPage::searchDialogDestroyed()
{
	TQObject::disconnect( this, 0, m_searchDialog, 0 );
	m_searchDialog->delayedDestruct();
	m_searchDialog = NULL;
}


#include "icqaddcontactpage.moc"
// vim: set noet ts=4 sts=4 sw=4:
// kate: indent-mode csands; space-indent off; replace-tabs off;