1 /***************************************************************************
2 description
3 -------------------
4 begin :
5 copyright : (C) 2002 by nbetcher
6 email : nbetcher@usinternet.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "aimaddcontactpage.h"
19 #include "ui_aimaddcontactui.h"
20
21 #include "kopeteaccount.h"
22
23 #include <kmessagebox.h>
24
25 #include "oscarutils.h"
26
AIMAddContactPage(bool connected,QWidget * parent)27 AIMAddContactPage::AIMAddContactPage(bool connected, QWidget *parent)
28 : AddContactPage(parent)
29 {
30 m_gui = 0;
31 if(connected)
32 {
33 m_gui = new Ui::aimAddContactUI();
34 m_gui->setupUi(this);
35 connect(m_gui->icqRadioButton, &QRadioButton::toggled, m_gui->icqEdit, &QLineEdit::setEnabled);
36 connect(m_gui->aimRadioButton, &QRadioButton::toggled, m_gui->aimEdit, &QLineEdit::setEnabled);
37 m_gui->aimEdit->setFocus();
38 canadd = true;
39 }
40 else
41 {
42 QVBoxLayout *layout = new QVBoxLayout( this );
43 layout->setContentsMargins( 0, 0, 0, 0 );
44
45 layout->addWidget( new QLabel(i18n("You need to be connected to be able to add contacts.\nConnect to the AIM network and try again."), this) );
46 canadd = false;
47 }
48 }
49
~AIMAddContactPage()50 AIMAddContactPage::~AIMAddContactPage()
51 {
52 delete m_gui;
53 }
54
validateData()55 bool AIMAddContactPage::validateData()
56 {
57 if ( !canadd )
58 return false;
59
60 if ( !m_gui )
61 return false;
62
63 if ( m_gui->icqRadioButton->isChecked() )
64 {
65 ulong uin = m_gui->icqEdit->text().toULong();
66 if ( uin < 1000 )
67 {
68 KMessageBox::sorry( this, i18n("You must enter a valid ICQ number."), i18n("ICQ Plugin") );
69 return false;
70 }
71 return true;
72 }
73 else if ( m_gui->aimRadioButton->isChecked() )
74 {
75 QRegExp rx("^[0-9]*$");
76 if ( rx.exactMatch( m_gui->aimEdit->text() ) )
77 {
78 KMessageBox::sorry( this, i18n("You must enter a valid AOL screen name."), i18n("No Screen Name") );
79 return false;
80 }
81 return true;
82 }
83
84 return false;
85 }
86
apply(Kopete::Account * account,Kopete::MetaContact * metaContact)87 bool AIMAddContactPage::apply(Kopete::Account *account,
88 Kopete::MetaContact *metaContact)
89 {
90 if ( m_gui->icqRadioButton->isChecked() )
91 {
92 QString contactId = Oscar::normalize( m_gui->icqEdit->text() );
93 return account->addContact( contactId, metaContact, Kopete::Account::ChangeKABC );
94 }
95 else if ( m_gui->aimRadioButton->isChecked() )
96 {
97 QString contactId = Oscar::normalize( m_gui->aimEdit->text() );
98 return account->addContact( contactId, metaContact, Kopete::Account::ChangeKABC );
99 }
100 return false;
101 }
102
103