Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <swmodule.hxx>
21 : #include <swtypes.hxx>
22 : #include <mailconfigpage.hxx>
23 : #include <sfx2/imgmgr.hxx>
24 : #include <svtools/svmedit.hxx>
25 : #include <svtools/stdctrl.hxx>
26 : #include <svtools/svtabbx.hxx>
27 : #include <svtools/headbar.hxx>
28 : #include <mmconfigitem.hxx>
29 : #include <mailmergehelper.hxx>
30 : #include <cmdid.h>
31 : #include <vcl/svapp.hxx>
32 : #include <comphelper/processfactory.hxx>
33 : #include "com/sun/star/mail/MailServiceType.hpp"
34 : #include "com/sun/star/mail/XMailService.hpp"
35 : #include "com/sun/star/mail/MailServiceProvider.hpp"
36 : #include <vcl/msgbox.hxx>
37 : #include <globals.hrc>
38 : #include <config.hrc>
39 : #include <helpid.h>
40 :
41 : using namespace ::com::sun::star;
42 : using namespace ::com::sun::star::lang;
43 : using namespace ::com::sun::star::mail;
44 : using namespace ::com::sun::star::beans;
45 :
46 0 : class SwTestAccountSettingsDialog : public SfxModalDialog
47 : {
48 : VclMultiLineEdit* m_pErrorsED;
49 :
50 : PushButton* m_pStopPB;
51 :
52 : FixedText* m_pEstablish;
53 : FixedText* m_pFind;
54 : FixedText* m_pResult1;
55 : FixedText* m_pResult2;
56 : FixedImage* m_pImage1;
57 : FixedImage* m_pImage2;
58 :
59 : Image m_aCompletedImg;
60 : Image m_aFailedImg;
61 : OUString m_sCompleted;
62 : OUString m_sFailed;
63 : OUString m_sErrorServer;
64 :
65 : SwMailConfigPage* m_pParent;
66 :
67 : bool m_bStop;
68 :
69 : void Test();
70 : DECL_LINK(StopHdl, void *);
71 : DECL_STATIC_LINK(SwTestAccountSettingsDialog, TestHdl, void*);
72 : public:
73 : SwTestAccountSettingsDialog(SwMailConfigPage* pParent);
74 : };
75 :
76 : class SwAuthenticationSettingsDialog : public SfxModalDialog
77 : {
78 : CheckBox* m_pAuthenticationCB;
79 :
80 : RadioButton* m_pSeparateAuthenticationRB;
81 : RadioButton* m_pSMTPAfterPOPRB;
82 :
83 : FixedText* m_pOutgoingServerFT;
84 : FixedText* m_pUserNameFT;
85 : Edit* m_pUserNameED;
86 : FixedText* m_pOutPasswordFT;
87 : Edit* m_pOutPasswordED;
88 :
89 : FixedText* m_pIncomingServerFT;
90 : FixedText* m_pServerFT;
91 : Edit* m_pServerED;
92 : FixedText* m_pPortFT;
93 : NumericField* m_pPortNF;
94 : FixedText* m_pProtocolFT;
95 : RadioButton* m_pPOP3RB;
96 : RadioButton* m_pIMAPRB;
97 : FixedText* m_pInUsernameFT;
98 : Edit* m_pInUsernameED;
99 : FixedText* m_pInPasswordFT;
100 : Edit* m_pInPasswordED;
101 :
102 : OKButton* m_pOKPB;
103 :
104 : SwMailMergeConfigItem& rConfigItem;
105 :
106 : DECL_LINK(OKHdl_Impl, void *);
107 : DECL_LINK( CheckBoxHdl_Impl, CheckBox*);
108 : DECL_LINK(RadioButtonHdl_Impl, void *);
109 :
110 : public:
111 : SwAuthenticationSettingsDialog(SwMailConfigPage* pParent, SwMailMergeConfigItem& rItem);
112 : virtual ~SwAuthenticationSettingsDialog();
113 : };
114 :
115 0 : SwMailConfigPage::SwMailConfigPage( Window* pParent, const SfxItemSet& rSet ) :
116 : SfxTabPage(pParent, "MailConfigPage" , "modules/swriter/ui/mailconfigpage.ui", rSet),
117 :
118 0 : m_pConfigItem( new SwMailMergeConfigItem )
119 : {
120 0 : get(m_pDisplayNameED,"displayname");
121 0 : get(m_pAddressED,"address");
122 0 : get(m_pReplyToCB,"replytocb");
123 0 : get(m_pReplyToFT,"replyto_label");
124 0 : get(m_pReplyToED,"replyto");
125 0 : get(m_pServerED,"server");
126 0 : get(m_pPortNF,"port");
127 0 : get(m_pSecureCB,"secure");
128 0 : get(m_pServerAuthenticationPB,"serverauthentication");
129 0 : get(m_pTestPB,"test");
130 :
131 0 : m_pReplyToCB->SetClickHdl(LINK(this, SwMailConfigPage, ReplyToHdl));
132 0 : m_pServerAuthenticationPB->SetClickHdl(LINK(this, SwMailConfigPage, AuthenticationHdl));
133 0 : m_pTestPB->SetClickHdl(LINK(this, SwMailConfigPage, TestHdl));
134 0 : }
135 :
136 0 : SwMailConfigPage::~SwMailConfigPage()
137 : {
138 0 : delete m_pConfigItem;
139 0 : }
140 :
141 0 : SfxTabPage* SwMailConfigPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
142 : {
143 0 : return new SwMailConfigPage(pParent, rAttrSet);
144 : }
145 :
146 0 : bool SwMailConfigPage::FillItemSet( SfxItemSet& /*rSet*/ )
147 : {
148 0 : if(m_pDisplayNameED->GetText() != m_pDisplayNameED->GetSavedValue())
149 0 : m_pConfigItem->SetMailDisplayName(m_pDisplayNameED->GetText());
150 0 : if(m_pAddressED->GetText() != m_pAddressED->GetSavedValue())
151 0 : m_pConfigItem->SetMailAddress(m_pAddressED->GetText());
152 0 : if( m_pReplyToCB->GetSavedValue() != TriState(m_pReplyToCB->IsChecked()))
153 0 : m_pConfigItem->SetMailReplyTo(m_pReplyToCB->IsChecked());
154 0 : if(m_pReplyToED->GetText() != m_pReplyToED->GetSavedValue())
155 0 : m_pConfigItem->SetMailReplyTo(m_pReplyToED->GetText());
156 0 : if(m_pServerED->GetText() != m_pServerED->GetSavedValue())
157 0 : m_pConfigItem->SetMailServer(m_pServerED->GetText());
158 :
159 0 : if(m_pPortNF->IsModified())
160 0 : m_pConfigItem->SetMailPort((sal_Int16)m_pPortNF->GetValue());
161 :
162 0 : m_pConfigItem->SetSecureConnection(m_pSecureCB->IsChecked());
163 :
164 0 : m_pConfigItem->Commit();
165 0 : return true;
166 : }
167 :
168 0 : void SwMailConfigPage::Reset( const SfxItemSet& /*rSet*/ )
169 : {
170 0 : m_pDisplayNameED->SetText(m_pConfigItem->GetMailDisplayName());
171 0 : m_pAddressED->SetText(m_pConfigItem->GetMailAddress());
172 :
173 0 : m_pReplyToED->SetText(m_pConfigItem->GetMailReplyTo()) ;
174 0 : m_pReplyToCB->Check(m_pConfigItem->IsMailReplyTo());
175 0 : m_pReplyToCB->GetClickHdl().Call(&m_pReplyToCB);
176 :
177 0 : m_pServerED->SetText(m_pConfigItem->GetMailServer());
178 0 : m_pPortNF->SetValue(m_pConfigItem->GetMailPort());
179 :
180 0 : m_pSecureCB->Check(m_pConfigItem->IsSecureConnection());
181 :
182 0 : m_pDisplayNameED->SaveValue();
183 0 : m_pAddressED ->SaveValue();
184 0 : m_pReplyToCB ->SaveValue();
185 0 : m_pReplyToED ->SaveValue();
186 0 : m_pServerED ->SaveValue();
187 0 : m_pPortNF ->SaveValue();
188 0 : m_pSecureCB ->SaveValue();
189 0 : }
190 :
191 0 : IMPL_LINK(SwMailConfigPage, ReplyToHdl, CheckBox*, pBox)
192 : {
193 0 : sal_Bool bEnable = pBox->IsChecked();
194 0 : m_pReplyToFT->Enable(bEnable);
195 0 : m_pReplyToED->Enable(bEnable);
196 0 : return 0;
197 : }
198 :
199 0 : IMPL_LINK_NOARG(SwMailConfigPage, AuthenticationHdl)
200 : {
201 0 : SwAuthenticationSettingsDialog aDlg(this, *m_pConfigItem);
202 0 : aDlg.Execute();
203 0 : return 0;
204 : }
205 :
206 0 : IMPL_LINK_NOARG(SwMailConfigPage, TestHdl)
207 : {
208 0 : SwTestAccountSettingsDialog(this).Execute();
209 0 : return 0;
210 : }
211 :
212 0 : SwTestAccountSettingsDialog::SwTestAccountSettingsDialog(SwMailConfigPage* pParent)
213 : : SfxModalDialog(pParent, "TestMailSettings", "modules/swriter/ui/testmailsettings.ui")
214 : , m_pParent(pParent)
215 0 : , m_bStop(false)
216 : {
217 0 : get(m_pStopPB, "stop");
218 0 : get(m_pErrorsED, "errors");
219 0 : m_pErrorsED->SetMaxTextWidth(80 * m_pErrorsED->approximate_char_width());
220 0 : m_pErrorsED->set_height_request(8 * m_pErrorsED->GetTextHeight());
221 0 : m_sErrorServer = m_pErrorsED->GetText();
222 0 : m_pErrorsED->SetText("");
223 0 : get(m_pEstablish, "establish");
224 0 : get(m_pFind, "find");
225 0 : get(m_pImage1, "image1");
226 0 : get(m_pResult1, "result1");
227 0 : get(m_pImage2, "image2");
228 0 : get(m_pResult2, "result2");
229 0 : m_sCompleted = m_pResult1->GetText();
230 0 : m_sFailed = m_pResult2->GetText();
231 :
232 0 : SfxImageManager* pManager = SfxImageManager::GetImageManager( SW_MOD() );
233 0 : m_aFailedImg = pManager->GetImage(FN_FORMULA_CANCEL);
234 0 : m_aCompletedImg = pManager->GetImage(FN_FORMULA_APPLY);
235 :
236 0 : m_pStopPB->SetClickHdl(LINK(this, SwTestAccountSettingsDialog, StopHdl));
237 :
238 0 : Application::PostUserEvent( STATIC_LINK( this, SwTestAccountSettingsDialog, TestHdl ), this );
239 0 : }
240 :
241 0 : IMPL_LINK_NOARG(SwTestAccountSettingsDialog, StopHdl)
242 : {
243 0 : m_bStop = true;
244 0 : return 0;
245 : }
246 :
247 0 : IMPL_STATIC_LINK(SwTestAccountSettingsDialog, TestHdl, void*, EMPTYARG)
248 : {
249 0 : pThis->EnterWait();
250 0 : pThis->Test();
251 0 : pThis->LeaveWait();
252 0 : return 0;
253 : }
254 :
255 0 : void SwTestAccountSettingsDialog::Test()
256 : {
257 0 : uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
258 :
259 0 : OUString sException;
260 :
261 0 : bool bIsLoggedIn = false;
262 0 : bool bIsServer = false;
263 : try
264 : {
265 0 : uno::Reference< mail::XMailService > xInMailService;
266 : uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
267 0 : mail::MailServiceProvider::create(xContext) );
268 : uno::Reference< mail::XMailService > xMailService =
269 0 : xMailServiceProvider->create(
270 0 : mail::MailServiceType_SMTP);
271 0 : if(m_bStop)
272 0 : return;
273 0 : uno::Reference<XConnectionListener> xConnectionListener(new SwConnectionListener());
274 :
275 0 : if(m_pParent->m_pConfigItem->IsAuthentication() &&
276 0 : m_pParent->m_pConfigItem->IsSMTPAfterPOP())
277 : {
278 0 : xInMailService = xMailServiceProvider->create(
279 0 : m_pParent->m_pConfigItem->IsInServerPOP() ?
280 0 : mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
281 0 : if(m_bStop)
282 0 : return;
283 : //authenticate at the POP or IMAP server first
284 : uno::Reference<XAuthenticator> xAuthenticator =
285 : new SwAuthenticator(
286 : m_pParent->m_pConfigItem->GetInServerUserName(),
287 : m_pParent->m_pConfigItem->GetInServerPassword(),
288 0 : this);
289 :
290 0 : xInMailService->addConnectionListener(xConnectionListener);
291 : //check connection
292 : uno::Reference< uno::XCurrentContext> xConnectionContext =
293 : new SwConnectionContext(
294 : m_pParent->m_pConfigItem->GetInServerName(),
295 0 : m_pParent->m_pConfigItem->GetInServerPort(),
296 0 : OUString("Insecure"));
297 0 : xInMailService->connect(xConnectionContext, xAuthenticator);
298 : }
299 0 : if(m_bStop)
300 0 : return;
301 0 : uno::Reference<XAuthenticator> xAuthenticator;
302 0 : if(m_pParent->m_pConfigItem->IsAuthentication() &&
303 0 : !m_pParent->m_pConfigItem->IsSMTPAfterPOP() &&
304 0 : !m_pParent->m_pConfigItem->GetMailUserName().isEmpty())
305 0 : xAuthenticator =
306 : new SwAuthenticator(
307 : m_pParent->m_pConfigItem->GetMailUserName(),
308 : m_pParent->m_pConfigItem->GetMailPassword(),
309 0 : this);
310 : else
311 0 : xAuthenticator = new SwAuthenticator();
312 :
313 0 : xMailService->addConnectionListener(xConnectionListener);
314 0 : if(m_bStop)
315 0 : return;
316 : //just to check if the server exists
317 0 : xMailService->getSupportedConnectionTypes();
318 0 : if(m_bStop)
319 0 : return;
320 0 : bIsServer = true;
321 : //check connection
322 : uno::Reference< uno::XCurrentContext> xConnectionContext =
323 : new SwConnectionContext(
324 0 : m_pParent->m_pServerED->GetText(),
325 0 : sal::static_int_cast< sal_Int16, sal_Int64 >(m_pParent->m_pPortNF->GetValue()),
326 0 : m_pParent->m_pSecureCB->IsChecked() ? OUString("Ssl") : OUString("Insecure"));
327 0 : xMailService->connect(xConnectionContext, xAuthenticator);
328 0 : bIsLoggedIn = xMailService->isConnected();
329 0 : if( xInMailService.is() )
330 0 : xInMailService->disconnect();
331 0 : if( xMailService->isConnected())
332 0 : xMailService->disconnect();
333 : }
334 0 : catch (const uno::Exception& e)
335 : {
336 0 : sException = e.Message;
337 : }
338 :
339 0 : m_pResult1->SetText(bIsServer ? m_sCompleted : m_sFailed);
340 0 : m_pImage1->SetImage(bIsServer ? m_aCompletedImg : m_aFailedImg);
341 :
342 0 : m_pResult2->SetText(bIsLoggedIn ? m_sCompleted : m_sFailed);
343 0 : m_pImage2->SetImage(bIsLoggedIn ? m_aCompletedImg : m_aFailedImg);
344 :
345 0 : if (!bIsServer || !bIsLoggedIn)
346 : {
347 0 : OUStringBuffer aErrorMessage(m_sErrorServer);
348 0 : if (!sException.isEmpty())
349 0 : aErrorMessage.append("\n--\n").append(sException);
350 0 : m_pErrorsED->SetText(aErrorMessage.makeStringAndClear());
351 0 : }
352 : }
353 :
354 0 : SwMailConfigDlg::SwMailConfigDlg(Window* pParent, SfxItemSet& rSet)
355 0 : : SfxSingleTabDialog(pParent, rSet)
356 : {
357 : // create TabPage
358 0 : SetTabPage(SwMailConfigPage::Create(get_content_area(), rSet));
359 0 : }
360 :
361 0 : SwAuthenticationSettingsDialog::SwAuthenticationSettingsDialog(
362 : SwMailConfigPage* pParent, SwMailMergeConfigItem& rItem)
363 : : SfxModalDialog(pParent, "AuthenticationSettingsDialog", "modules/swriter/ui/authenticationsettingsdialog.ui")
364 0 : , rConfigItem( rItem )
365 : {
366 0 : get(m_pAuthenticationCB,"authentication");
367 0 : get(m_pSeparateAuthenticationRB,"seperateauthentication");
368 0 : get(m_pSMTPAfterPOPRB,"smtpafterpop");
369 0 : get(m_pOutgoingServerFT,"label1");
370 0 : get(m_pUserNameFT,"username_label");
371 0 : get(m_pUserNameED,"username");
372 0 : get(m_pOutPasswordFT,"outpassword_label");
373 0 : get(m_pOutPasswordED,"outpassword");
374 0 : get(m_pIncomingServerFT,"label2");
375 0 : get(m_pServerFT,"server_label");
376 0 : get(m_pServerED,"server");
377 0 : get(m_pPortFT,"port_label");
378 0 : get(m_pPortNF,"port");
379 0 : get(m_pProtocolFT,"label3");
380 0 : get(m_pPOP3RB,"pop3");
381 0 : get(m_pIMAPRB,"imap");
382 0 : get(m_pInUsernameFT,"inusername_label");
383 0 : get(m_pInUsernameED,"inusername");
384 0 : get(m_pInPasswordFT,"inpassword_label");
385 0 : get(m_pInPasswordED,"inpassword");
386 :
387 0 : get(m_pOKPB,"ok");
388 :
389 0 : m_pAuthenticationCB->SetClickHdl( LINK( this, SwAuthenticationSettingsDialog, CheckBoxHdl_Impl));
390 0 : Link aRBLink = LINK( this, SwAuthenticationSettingsDialog, RadioButtonHdl_Impl );
391 0 : m_pSeparateAuthenticationRB->SetClickHdl( aRBLink );
392 0 : m_pSMTPAfterPOPRB->SetClickHdl( aRBLink );
393 0 : m_pOKPB->SetClickHdl( LINK( this, SwAuthenticationSettingsDialog, OKHdl_Impl));
394 :
395 0 : m_pAuthenticationCB->Check( rConfigItem.IsAuthentication() );
396 0 : if(rConfigItem.IsSMTPAfterPOP())
397 0 : m_pSMTPAfterPOPRB->Check();
398 : else
399 0 : m_pSeparateAuthenticationRB->Check();
400 0 : m_pUserNameED->SetText( rConfigItem.GetMailUserName() );
401 0 : m_pOutPasswordED->SetText( rConfigItem.GetMailPassword() );
402 :
403 0 : m_pServerED->SetText( rConfigItem.GetInServerName() );
404 0 : m_pPortNF->SetValue( rConfigItem.GetInServerPort() );
405 0 : if(rConfigItem.IsInServerPOP())
406 0 : m_pPOP3RB->Check();
407 : else
408 0 : m_pIMAPRB->Check();
409 0 : m_pInUsernameED->SetText( rConfigItem.GetInServerUserName());
410 0 : m_pInPasswordED->SetText( rConfigItem.GetInServerPassword() );
411 :
412 0 : CheckBoxHdl_Impl( m_pAuthenticationCB );
413 0 : }
414 :
415 0 : SwAuthenticationSettingsDialog::~SwAuthenticationSettingsDialog()
416 : {
417 0 : }
418 :
419 0 : IMPL_LINK_NOARG(SwAuthenticationSettingsDialog, OKHdl_Impl)
420 : {
421 0 : rConfigItem.SetAuthentication( m_pAuthenticationCB->IsChecked() );
422 0 : rConfigItem.SetSMTPAfterPOP(m_pSMTPAfterPOPRB->IsChecked());
423 0 : rConfigItem.SetMailUserName(m_pUserNameED->GetText());
424 0 : rConfigItem.SetMailPassword(m_pOutPasswordED->GetText());
425 0 : rConfigItem.SetInServerName(m_pServerED->GetText());
426 0 : rConfigItem.SetInServerPort(sal::static_int_cast< sal_Int16, sal_Int64 >(m_pPortNF->GetValue( ) ));
427 0 : rConfigItem.SetInServerPOP(m_pPOP3RB->IsChecked());
428 0 : rConfigItem.SetInServerUserName(m_pInUsernameED->GetText());
429 :
430 0 : rConfigItem.SetInServerPassword(m_pInPasswordED->GetText());
431 0 : EndDialog(RET_OK);
432 0 : return 0;
433 : }
434 :
435 0 : IMPL_LINK( SwAuthenticationSettingsDialog, CheckBoxHdl_Impl, CheckBox*, pBox)
436 : {
437 0 : sal_Bool bChecked = pBox->IsChecked();
438 0 : m_pSeparateAuthenticationRB->Enable(bChecked);
439 0 : m_pSMTPAfterPOPRB->Enable(bChecked);
440 0 : RadioButtonHdl_Impl( 0 );
441 :
442 0 : return 0;
443 : }
444 :
445 0 : IMPL_LINK_NOARG(SwAuthenticationSettingsDialog, RadioButtonHdl_Impl)
446 : {
447 0 : sal_Bool bSeparate = m_pSeparateAuthenticationRB->IsChecked();
448 0 : sal_Bool bIsEnabled = m_pSeparateAuthenticationRB->IsEnabled();
449 0 : sal_Bool bNotSeparate = !bSeparate && bIsEnabled;
450 0 : bSeparate &= bIsEnabled;
451 :
452 0 : m_pOutgoingServerFT->Enable(bSeparate);
453 0 : m_pUserNameFT->Enable(bSeparate);
454 0 : m_pUserNameED->Enable(bSeparate);
455 0 : m_pOutPasswordFT->Enable(bSeparate);
456 0 : m_pOutPasswordED->Enable(bSeparate);
457 :
458 0 : m_pIncomingServerFT->Enable(bNotSeparate);
459 0 : m_pServerFT->Enable(bNotSeparate);
460 0 : m_pServerED->Enable(bNotSeparate);
461 0 : m_pPortFT->Enable(bNotSeparate);
462 0 : m_pPortNF->Enable(bNotSeparate);
463 0 : m_pInUsernameFT->Enable(bNotSeparate);
464 0 : m_pInUsernameED->Enable(bNotSeparate);
465 0 : m_pProtocolFT->Enable(bNotSeparate);
466 0 : m_pPOP3RB->Enable(bNotSeparate);
467 0 : m_pIMAPRB->Enable(bNotSeparate);
468 0 : m_pInPasswordFT->Enable(bNotSeparate);
469 0 : m_pInPasswordED->Enable(bNotSeparate);
470 :
471 0 : return 0;
472 0 : }
473 :
474 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|