~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/resources/openchange/profileeditdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2007 Brad Hards <bradh@frogmouth.net>
 
3
 
 
4
    Significant amounts of this code adapted from the openchange client utility,
 
5
    which is Copyright (C) Julien Kerihuel 2007 <j.kerihuel@openchange.org>.
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
 
20
    02110-1301, USA.
 
21
*/
 
22
 
 
23
#include "profileeditdialog.h"
 
24
 
 
25
#include <klocale.h>
 
26
 
 
27
#include <QHostInfo>
 
28
#include <QLabel>
 
29
#include <QVBoxLayout>
 
30
 
 
31
extern "C" {
 
32
#include <libmapi/libmapi.h>
 
33
#include <talloc.h>
 
34
}
 
35
 
 
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 )
 
43
  : QDialog( parent )
 
44
{
 
45
  setWindowTitle( i18n( "Add / Edit Profile" ) );
 
46
 
 
47
  QVBoxLayout *mainLayout = new QVBoxLayout;
 
48
 
 
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 );
 
56
 
 
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 );
 
64
 
 
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 );
 
73
 
 
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 );
 
81
 
 
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() );
 
87
  else
 
88
    m_workstationEdit->setText( workstation );
 
89
  connect( m_workstationEdit, SIGNAL( textEdited(QString) ),
 
90
           this, SLOT( checkIfComplete() ) );
 
91
  mainLayout->addWidget( m_workstationEdit );
 
92
 
 
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 );
 
101
 
 
102
  mainLayout->addStretch();
 
103
 
 
104
  QHBoxLayout *buttonLayout = new QHBoxLayout;
 
105
 
 
106
  m_okButton = new QPushButton( i18n( "OK" ) );
 
107
  connect( m_okButton, SIGNAL( clicked() ),
 
108
           this, SLOT( commitProfile() ) );
 
109
  buttonLayout->addWidget( m_okButton );
 
110
 
 
111
  QPushButton *cancelButton = new QPushButton( i18n( "Cancel" ) );
 
112
  connect( cancelButton, SIGNAL( clicked() ),
 
113
           this, SLOT( close() ) );
 
114
  buttonLayout->addWidget( cancelButton );
 
115
 
 
116
  mainLayout->addLayout( buttonLayout );
 
117
 
 
118
  checkIfComplete();
 
119
 
 
120
  setLayout( mainLayout );
 
121
}
 
122
 
 
123
void ProfileEditDialog::checkIfComplete()
 
124
{
 
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);
 
132
  else
 
133
    m_okButton->setEnabled(true);
 
134
}
 
135
 
 
136
uint32_t ProfileEditDialog::callback(struct SRowSet *rowset, void *private_var)
 
137
{
 
138
  qDebug() << "ProfileEditDialog::callback() Found more than 1 match";
 
139
 
 
140
  // TODO: Handle this. Need to find a way to produce this.
 
141
  // Cancel user creation for now.
 
142
  return rowset->cRows;
 
143
}
 
144
 
 
145
void ProfileEditDialog::commitProfile()
 
146
{
 
147
  qDebug() << "committing profile: " << m_profileNameEdit->text();
 
148
 
 
149
  enum MAPISTATUS         retval;
 
150
  struct mapi_profile     testProfile;
 
151
 
 
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());
 
160
      return;
 
161
    }
 
162
  }
 
163
 
 
164
  retval = CreateProfile(m_profileNameEdit->text().toUtf8().constData(),
 
165
                         m_usernameEdit->text().toUtf8().constData(),
 
166
                         m_passwordEdit->text().toUtf8().constData(), 0);
 
167
 
 
168
  if (retval != MAPI_E_SUCCESS) {
 
169
    mapi_errstr("CreateProfile", GetLastError());
 
170
    return;
 
171
  }
 
172
 
 
173
  mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
 
174
                               "binding",
 
175
                               m_addressEdit->text().toUtf8().constData() );
 
176
 
 
177
  mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
 
178
                               "workstation",
 
179
                               m_workstationEdit->text().toUtf8().constData() );
 
180
 
 
181
  mapi_profile_add_string_attr(m_profileNameEdit->text().toUtf8().constData(),
 
182
                               "domain",
 
183
                               m_domainEdit->text().toUtf8().constData() );
 
184
 
 
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(),
 
191
                               "method", "0x409");
 
192
 
 
193
 
 
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
 
201
  }
 
202
 
 
203
 
 
204
  retval = ProcessNetworkProfile(session, m_usernameEdit->text().toUtf8().constData(), (mapi_profile_callback_t) ProfileEditDialog::callback,
 
205
                                 "Select a user id");
 
206
 
 
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());
 
212
    }
 
213
    exit (1);
 
214
  }
 
215
 
 
216
 
 
217
  // TODO: add in KWallet support
 
218
  close(); // only if we added correctly.
 
219
}
 
220