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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <unotools/pathoptions.hxx>
#include <unotools/useroptions.hxx>
#include <svl/adrparse.hxx>
#include "hlinettp.hxx"
#include "hlmarkwn_def.hxx"
sal_Char const sAnonymous[] = "anonymous";
sal_Char const sHTTPScheme[] = INET_HTTP_SCHEME;
sal_Char const sFTPScheme[] = INET_FTP_SCHEME;
/*************************************************************************
|*
|* Constructor / Destructor
|*
|************************************************************************/
SvxHyperlinkInternetTp::SvxHyperlinkInternetTp ( vcl::Window *pParent,
IconChoiceDialog* pDlg,
const SfxItemSet& rItemSet)
: SvxHyperlinkTabPageBase ( pParent, pDlg, "HyperlinkInternetPage", "cui/ui/hyperlinkinternetpage.ui",
rItemSet ) ,
mbMarkWndOpen ( false )
{
get(m_pRbtLinktypInternet, "linktyp_internet");
get(m_pRbtLinktypFTP, "linktyp_ftp");
get(m_pCbbTarget, "target");
m_pCbbTarget->SetSmartProtocol(INetProtocol::Http);
get(m_pBtBrowse, "browse");
m_pBtBrowse->SetModeImage(Image(CUI_RES (RID_SVXBMP_BROWSE)));
get(m_pFtLogin, "login_label");
get(m_pEdLogin, "login");
get(m_pFtPassword, "password_label");
get(m_pEdPassword, "password");
get(m_pCbAnonymous, "anonymous");
// Disable display of bitmap names.
m_pBtBrowse->EnableTextDisplay (false);
InitStdControls();
m_pCbbTarget->Show();
m_pCbbTarget->SetHelpId( HID_HYPERDLG_INET_PATH );
SetExchangeSupport ();
// set defaults
m_pRbtLinktypInternet->Check ();
m_pBtBrowse->Enable( true );
// set handlers
Link<Button*, void> aLink( LINK ( this, SvxHyperlinkInternetTp, Click_SmartProtocol_Impl ) );
m_pRbtLinktypInternet->SetClickHdl( aLink );
m_pRbtLinktypFTP->SetClickHdl ( aLink );
m_pCbAnonymous->SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl ) );
m_pBtBrowse->SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp, ClickBrowseHdl_Impl ) );
m_pEdLogin->SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl ) );
m_pCbbTarget->SetLoseFocusHdl ( LINK ( this, SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl ) );
m_pCbbTarget->SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl ) );
maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkInternetTp, TimeoutHdl_Impl ) );
}
SvxHyperlinkInternetTp::~SvxHyperlinkInternetTp()
{
disposeOnce();
}
void SvxHyperlinkInternetTp::dispose()
{
m_pRbtLinktypInternet.clear();
m_pRbtLinktypFTP.clear();
m_pCbbTarget.clear();
m_pBtBrowse.clear();
m_pFtLogin.clear();
m_pEdLogin.clear();
m_pFtPassword.clear();
m_pEdPassword.clear();
m_pCbAnonymous.clear();
SvxHyperlinkTabPageBase::dispose();
}
/*************************************************************************
|*
|* Fill the all dialog-controls except controls in groupbox "more..."
|*
|************************************************************************/
void SvxHyperlinkInternetTp::FillDlgFields(const OUString& rStrURL)
{
INetURLObject aURL(rStrURL);
OUString aStrScheme(GetSchemeFromURL(rStrURL));
// set additional controls for FTP: Username / Password
if (aStrScheme.startsWith(sFTPScheme))
{
if ( aURL.GetUser().toAsciiLowerCase().startsWith( sAnonymous ) )
setAnonymousFTPUser();
else
setFTPUser(aURL.GetUser(), aURL.GetPass());
//do not show password and user in url
if(!aURL.GetUser().isEmpty() || !aURL.GetPass().isEmpty() )
aURL.SetUserAndPass(aEmptyStr,aEmptyStr);
}
// set URL-field
// Show the scheme, #72740
if ( aURL.GetProtocol() != INetProtocol::NotValid )
m_pCbbTarget->SetText( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
else
m_pCbbTarget->SetText(rStrURL); // #77696#
SetScheme(aStrScheme);
}
void SvxHyperlinkInternetTp::setAnonymousFTPUser()
{
m_pEdLogin->SetText(OUString(sAnonymous));
SvAddressParser aAddress( SvtUserOptions().GetEmail() );
m_pEdPassword->SetText( aAddress.Count() ? aAddress.GetEmailAddress(0) : OUString() );
m_pFtLogin->Disable ();
m_pFtPassword->Disable ();
m_pEdLogin->Disable ();
m_pEdPassword->Disable ();
m_pCbAnonymous->Check();
}
void SvxHyperlinkInternetTp::setFTPUser(const OUString& rUser, const OUString& rPassword)
{
m_pEdLogin->SetText ( rUser );
m_pEdPassword->SetText ( rPassword );
m_pFtLogin->Enable ();
m_pFtPassword->Enable ();
m_pEdLogin->Enable ();
m_pEdPassword->Enable ();
m_pCbAnonymous->Check(false);
}
/*************************************************************************
|*
|* retrieve and prepare data from dialog-fields
|*
|************************************************************************/
void SvxHyperlinkInternetTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
OUString& aStrIntName, OUString& aStrFrame,
SvxLinkInsertMode& eMode )
{
rStrURL = CreateAbsoluteURL();
GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
}
OUString SvxHyperlinkInternetTp::CreateAbsoluteURL() const
{
// erase leading and trailing whitespaces
OUString aStrURL( m_pCbbTarget->GetText().trim() );
INetURLObject aURL(aStrURL);
if( aURL.GetProtocol() == INetProtocol::NotValid )
{
aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
aURL.SetSmartURL(aStrURL);
}
// username and password for ftp-url
if( aURL.GetProtocol() == INetProtocol::Ftp && !m_pEdLogin->GetText().isEmpty() )
aURL.SetUserAndPass ( m_pEdLogin->GetText(), m_pEdPassword->GetText() );
if ( aURL.GetProtocol() != INetProtocol::NotValid )
return aURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
else //#105788# always create a URL even if it is not valid
return aStrURL;
}
/*************************************************************************
|*
|* static method to create Tabpage
|*
|************************************************************************/
VclPtr<IconChoicePage> SvxHyperlinkInternetTp::Create( vcl::Window* pWindow, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet )
{
return VclPtr<SvxHyperlinkInternetTp>::Create( pWindow, pDlg, rItemSet );
}
/*************************************************************************
|*
|* Set initial focus
|*
|************************************************************************/
void SvxHyperlinkInternetTp::SetInitFocus()
{
m_pCbbTarget->GrabFocus();
}
/*************************************************************************
|*
|* Contents of editfield "Target" modified
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl)
{
OUString aScheme = GetSchemeFromURL( m_pCbbTarget->GetText() );
if( !aScheme.isEmpty() )
SetScheme( aScheme );
// start timer
maTimer.SetTimeout( 2500 );
maTimer.Start();
return 0L;
}
/*************************************************************************
|*
|* If target-field was modify, to browse the new doc after timeout
|*
|************************************************************************/
IMPL_LINK_NOARG_TYPED(SvxHyperlinkInternetTp, TimeoutHdl_Impl, Timer *, void)
{
RefreshMarkWindow();
}
/*************************************************************************
|*
|* Contents of editfield "Login" modified
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl)
{
OUString aStrLogin ( m_pEdLogin->GetText() );
if ( aStrLogin.equalsIgnoreAsciiCase( sAnonymous ) )
{
m_pCbAnonymous->Check();
ClickAnonymousHdl_Impl(NULL);
}
return 0L;
}
void SvxHyperlinkInternetTp::SetScheme(const OUString& rScheme)
{
//if rScheme is empty or unknown the default behaviour is like it where HTTP
bool bFTP = rScheme.startsWith(sFTPScheme);
bool bInternet = !(bFTP);
//update protocol button selection:
m_pRbtLinktypFTP->Check(bFTP);
m_pRbtLinktypInternet->Check(bInternet);
//update target:
RemoveImproperProtocol(rScheme);
m_pCbbTarget->SetSmartProtocol( GetSmartProtocolFromButtons() );
//show/hide special fields for FTP:
m_pFtLogin->Show( bFTP );
m_pFtPassword->Show( bFTP );
m_pEdLogin->Show( bFTP );
m_pEdPassword->Show( bFTP );
m_pCbAnonymous->Show( bFTP );
//update 'link target in document'-window and opening-button
if (rScheme.startsWith(sHTTPScheme) || rScheme.isEmpty())
{
if ( mbMarkWndOpen )
ShowMarkWnd ();
}
else
{
//disable for https and ftp
if ( mbMarkWndOpen )
HideMarkWnd ();
}
}
/*************************************************************************
|*
|* Remove protocol if it does not fit to the current button selection
|*
|************************************************************************/
void SvxHyperlinkInternetTp::RemoveImproperProtocol(const OUString& aProperScheme)
{
OUString aStrURL ( m_pCbbTarget->GetText() );
if ( aStrURL != aEmptyStr )
{
OUString aStrScheme(GetSchemeFromURL(aStrURL));
if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
{
aStrURL = aStrURL.copy( aStrScheme.getLength() );
m_pCbbTarget->SetText ( aStrURL );
}
}
}
OUString SvxHyperlinkInternetTp::GetSchemeFromButtons() const
{
if( m_pRbtLinktypFTP->IsChecked() )
return OUString(INET_FTP_SCHEME);
return OUString(INET_HTTP_SCHEME);
}
INetProtocol SvxHyperlinkInternetTp::GetSmartProtocolFromButtons() const
{
if( m_pRbtLinktypFTP->IsChecked() )
{
return INetProtocol::Ftp;
}
return INetProtocol::Http;
}
/*************************************************************************
|*
|* Click on Radiobutton : Internet or FTP
|*
|************************************************************************/
IMPL_LINK_NOARG_TYPED(SvxHyperlinkInternetTp, Click_SmartProtocol_Impl, Button*, void)
{
OUString aScheme = GetSchemeFromButtons();
SetScheme(aScheme);
}
/*************************************************************************
|*
|* Click on Checkbox : Anonymous user
|*
|************************************************************************/
IMPL_LINK_NOARG_TYPED(SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl, Button*, void)
{
// disable login-editfields if checked
if ( m_pCbAnonymous->IsChecked() )
{
if ( m_pEdLogin->GetText().toAsciiLowerCase().startsWith( sAnonymous ) )
{
maStrOldUser = aEmptyStr;
maStrOldPassword = aEmptyStr;
}
else
{
maStrOldUser = m_pEdLogin->GetText();
maStrOldPassword = m_pEdPassword->GetText();
}
setAnonymousFTPUser();
}
else
setFTPUser(maStrOldUser, maStrOldPassword);
}
/*************************************************************************
|*
|* Combobox Target lost the focus
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl)
{
RefreshMarkWindow();
return 0L;
}
/*************************************************************************
|*
|* Click on imagebutton : Browse
|*
|************************************************************************/
IMPL_LINK_NOARG_TYPED(SvxHyperlinkInternetTp, ClickBrowseHdl_Impl, Button*, void)
{
// Open URL if available
SfxStringItem aName( SID_FILE_NAME, OUString("http://") );
SfxStringItem aRefererItem( SID_REFERER, OUString("private:user") );
SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, true );
SfxBoolItem aSilent( SID_SILENT, true );
SfxBoolItem aReadOnly( SID_DOC_READONLY, true );
SfxBoolItem aBrowse( SID_BROWSE, true );
const SfxPoolItem *ppItems[] = { &aName, &aNewView, &aSilent, &aReadOnly, &aRefererItem, &aBrowse, NULL };
static_cast<SvxHpLinkDlg*>(mpDialog.get())->GetBindings()->Execute( SID_OPENDOC, ppItems, 0, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
}
void SvxHyperlinkInternetTp::RefreshMarkWindow()
{
if ( m_pRbtLinktypInternet->IsChecked() && IsMarkWndVisible() )
{
EnterWait();
OUString aStrURL( CreateAbsoluteURL() );
if ( aStrURL != aEmptyStr )
mpMarkWnd->RefreshTree ( aStrURL );
else
mpMarkWnd->SetError( LERR_DOCNOTOPEN );
LeaveWait();
}
}
/*************************************************************************
|*
|* Get String from Bookmark-Wnd
|*
|************************************************************************/
void SvxHyperlinkInternetTp::SetMarkStr ( const OUString& aStrMark )
{
OUString aStrURL ( m_pCbbTarget->GetText() );
const sal_Unicode sUHash = '#';
sal_Int32 nPos = aStrURL.lastIndexOf( sUHash );
if( nPos != -1 )
aStrURL = aStrURL.copy(0, nPos);
aStrURL += OUStringLiteral1<sUHash>() + aStrMark;
m_pCbbTarget->SetText ( aStrURL );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|