2
Copyright (c) 2007 Brad Hards <bradh@frogmouth.net>
4
Significant amounts of this code adapted from the openchange client utility,
5
which is Copyright (C) Julien Kerihuel 2007 <j.kerihuel@openchange.org>.
7
This program is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or (at your
10
option) any later version.
12
This program is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15
License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
#include "profileeditdialog.h"
29
#include <QVBoxLayout>
32
#include <libmapi/libmapi.h>
36
ProfileEditDialog::ProfileEditDialog( QWidget *parent,
37
const QString &profileName,
38
const QString &userName,
39
const QString &password,
40
const QString &serverAddress,
41
const QString &workstation,
42
const QString &domain )
45
setWindowTitle( i18n( "Add / Edit Profile" ) );
47
QVBoxLayout *mainLayout = new QVBoxLayout;
49
QLabel *nameLabel = new QLabel( i18n( "Profile name" ) );
50
mainLayout->addWidget( nameLabel );
51
m_profileNameEdit = new QLineEdit();
52
m_profileNameEdit->setText( profileName );
53
connect( m_profileNameEdit, SIGNAL( textEdited(QString) ),
54
this, SLOT( checkIfComplete() ) );
55
mainLayout->addWidget( m_profileNameEdit );
57
QLabel *usernameLabel = new QLabel( i18n( "Username" ) );
58
mainLayout->addWidget( usernameLabel );
59
m_usernameEdit = new QLineEdit();
60
m_usernameEdit->setText( userName );
61
connect( m_usernameEdit, SIGNAL( textEdited(QString) ),
62
this, SLOT( checkIfComplete() ) );
63
mainLayout->addWidget( m_usernameEdit );
65
QLabel *passwordLabel = new QLabel( i18n( "Password" ) );
66
mainLayout->addWidget( passwordLabel );
67
m_passwordEdit = new QLineEdit();
68
m_passwordEdit->setEchoMode( QLineEdit::Password );
69
m_passwordEdit->setText( password );
70
connect( m_passwordEdit, SIGNAL( textEdited(QString) ),
71
this, SLOT( checkIfComplete() ) );
72
mainLayout->addWidget( m_passwordEdit );
74
QLabel *addressLabel = new QLabel( i18n( "Server name or address" ) );
75
mainLayout->addWidget( addressLabel );
76
m_addressEdit = new QLineEdit();
77
m_addressEdit->setText( serverAddress );
78
connect( m_addressEdit, SIGNAL( textEdited(QString) ),
79
this, SLOT( checkIfComplete() ) );
80
mainLayout->addWidget( m_addressEdit );
82
QLabel *workstationLabel = new QLabel( i18n( "Local machine name or address" ) );
83
mainLayout->addWidget( workstationLabel );
84
m_workstationEdit = new QLineEdit();
85
if ( workstation.isEmpty() )
86
m_workstationEdit->setText( QHostInfo::localHostName() );
88
m_workstationEdit->setText( workstation );
89
connect( m_workstationEdit, SIGNAL( textEdited(QString) ),
90
this, SLOT( checkIfComplete() ) );
91
mainLayout->addWidget( m_workstationEdit );
93
QLabel *domainLabel = new QLabel( i18n( "Authentication domain" ) );
94
mainLayout->addWidget( domainLabel );
95
m_domainEdit = new QLineEdit();
96
m_domainEdit->setText( domain );
97
connect( m_domainEdit, SIGNAL( textEdited(QString) ),
98
this, SLOT( checkIfComplete() ) );
99
m_domainEdit->setToolTip( i18n( "The authentication domain (also known as realm) to use for this account. Ask your exchange server administrator if you are do not know about this." ) );
100
mainLayout->addWidget( m_domainEdit );
102
mainLayout->addStretch();
104
QHBoxLayout *buttonLayout = new QHBoxLayout;
106
m_okButton = new QPushButton( i18n( "OK" ) );
107
connect( m_okButton, SIGNAL( clicked() ),
108
this, SLOT( commitProfile() ) );
109
buttonLayout->addWidget( m_okButton );
111
QPushButton *cancelButton = new QPushButton( i18n( "Cancel" ) );
112
connect( cancelButton, SIGNAL( clicked() ),
113
this, SLOT( close() ) );
114
buttonLayout->addWidget( cancelButton );
116
mainLayout->addLayout( buttonLayout );
120
setLayout( mainLayout );
123
void ProfileEditDialog::checkIfComplete()
125
if ( m_profileNameEdit->text().isEmpty()
126
|| m_usernameEdit->text().isEmpty()
127
|| m_passwordEdit->text().isEmpty()
128
|| m_addressEdit->text().isEmpty()
129
|| m_workstationEdit->text().isEmpty()
130
|| m_domainEdit->text().isEmpty() )
131
m_okButton->setDisabled(true);
133
m_okButton->setEnabled(true);
136
uint32_t ProfileEditDialog::callback(struct SRowSet *rowset, void *private_var)
138
qDebug() << "ProfileEditDialog::callback() Found more than 1 match";
140
// TODO: Handle this. Need to find a way to produce this.
141
// Cancel user creation for now.
142
return rowset->cRows;
145
void ProfileEditDialog::commitProfile()
147
qDebug() << "committing profile: " << m_profileNameEdit->text();
149
enum MAPISTATUS retval;
150
struct mapi_profile testProfile;
152
// if the profile already exists, we overwrite it....
153
// maybe we should have a "do you really want to do this?", but that will be pretty annoying on edits.
154
retval = OpenProfile( &testProfile, m_profileNameEdit->text().toUtf8().constData(), 0 );
155
qDebug() << "openprofile result: " << retval;
156
if ( GetLastError() != MAPI_E_NOT_FOUND ) {
157
// then this one exists, and we should kill it
158
if ((retval = DeleteProfile(m_profileNameEdit->text().toUtf8().constData()) ) != MAPI_E_SUCCESS) {
159
mapi_errstr("DeleteProfile", GetLastError());
164
retval = CreateProfile(m_profileNameEdit->text().toUtf8().constData(),
165
m_usernameEdit->text().toUtf8().constData(),
166
m_passwordEdit->text().toUtf8().constData(), 0);
168
if (retval != MAPI_E_SUCCESS) {
169
mapi_errstr("CreateProfile", GetLastError());
173
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
175
m_addressEdit->text().toUtf8().constData() );
177
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
179
m_workstationEdit->text().toUtf8().constData() );
181
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
183
m_domainEdit->text().toUtf8().constData() );
185
/* This is only convenient here and should be replaced at some point */
186
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
187
"codepage", "0x4e4");
188
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
189
"language", "0x40c");
190
mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
194
// there needs to be some network magic in here.
195
struct mapi_session *session = NULL;
196
retval = MapiLogonProvider(&session, m_profileNameEdit->text().toUtf8().constData(),
197
m_passwordEdit->text().toUtf8().constData(), PROVIDER_ID_NSPI);
198
if (retval != MAPI_E_SUCCESS) {
199
mapi_errstr("MapiLogonProvider", GetLastError());
200
// TODO - we need to do something more creative here
204
retval = ProcessNetworkProfile(session, m_usernameEdit->text().toUtf8().constData(), (mapi_profile_callback_t) ProfileEditDialog::callback,
207
if (retval != MAPI_E_SUCCESS && retval != 0x1) {
208
mapi_errstr("ProcessNetworkProfile", GetLastError());
209
printf("Deleting profile\n");
210
if ((retval = DeleteProfile(m_profileNameEdit->text().toUtf8().constData())) != MAPI_E_SUCCESS) {
211
mapi_errstr("DeleteProfile", GetLastError());
217
// TODO: add in KWallet support
218
close(); // only if we added correctly.