1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: doclinkdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include "doclinkdialog.hxx"
38 #ifndef _SVX_DOCLINKDIALOG_HRC_
39 #include "doclinkdialog.hrc"
41 #include <svx/dialogs.hrc>
42 #include <svx/svxids.hrc>
43 #include <tools/debug.hxx>
44 #ifndef SVTOOLS_FILENOTATION_HXX_
45 #include <svtools/filenotation.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <ucbhelper/content.hxx>
49 #include <svx/dialmgr.hxx>
50 #include <tools/urlobj.hxx>
51 #include <sfx2/filedlghelper.hxx>
52 #include <sfx2/docfilt.hxx>
53 //......................................................................
56 //......................................................................
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::ucb
;
60 using namespace ::svt
;
62 //==================================================================
63 //= ODocumentLinkDialog
64 //==================================================================
65 //------------------------------------------------------------------
66 ODocumentLinkDialog::ODocumentLinkDialog( Window
* _pParent
, sal_Bool _bCreateNew
)
67 :ModalDialog( _pParent
, SVX_RES(DLG_DOCUMENTLINK
) )
68 ,m_aURLLabel (this, SVX_RES(FT_URL
))
69 ,m_aURL (this, SVX_RES(CMB_URL
))
70 ,m_aBrowseFile (this, SVX_RES(PB_BROWSEFILE
))
71 ,m_aNameLabel (this, SVX_RES(FT_NAME
))
72 ,m_aName (this, SVX_RES(ET_NAME
))
73 ,m_aBottomLine (this, SVX_RES(FL_BOTTOM
))
74 ,m_aOK (this, SVX_RES(BTN_OK
))
75 ,m_aCancel (this, SVX_RES(BTN_CANCEL
))
76 ,m_aHelp (this, SVX_RES(BTN_HELP
))
77 ,m_bCreatingNew(_bCreateNew
)
79 String sText
= String( SVX_RES( m_bCreatingNew
? STR_NEW_LINK
: STR_EDIT_LINK
) );
84 String sTemp
= String::CreateFromAscii("*.odb");
85 m_aURL
.SetFilter(sTemp
);
87 m_aName
.SetModifyHdl( LINK(this, ODocumentLinkDialog
, OnTextModified
) );
88 m_aURL
.SetModifyHdl( LINK(this, ODocumentLinkDialog
, OnTextModified
) );
89 m_aBrowseFile
.SetClickHdl( LINK(this, ODocumentLinkDialog
, OnBrowseFile
) );
90 m_aOK
.SetClickHdl( LINK(this, ODocumentLinkDialog
, OnOk
) );
92 m_aURL
.SetDropDownLineCount(10);
96 // m_aURL.SetHelpId( HID_DOCLINKEDIT_URL );
97 m_aURL
.SetDropDownLineCount( 5 );
100 //------------------------------------------------------------------
101 void ODocumentLinkDialog::set( const String
& _rName
, const String
& _rURL
)
103 m_aName
.SetText(_rName
);
104 m_aURL
.SetText(_rURL
);
108 //------------------------------------------------------------------
109 void ODocumentLinkDialog::get( String
& _rName
, String
& _rURL
) const
111 _rName
= m_aName
.GetText();
112 _rURL
= m_aURL
.GetText();
115 //------------------------------------------------------------------
116 void ODocumentLinkDialog::validate( )
119 m_aOK
.Enable( (0 != m_aName
.GetText().Len()) && ( 0 != m_aURL
.GetText().Len() ) );
122 //------------------------------------------------------------------
123 IMPL_LINK( ODocumentLinkDialog
, OnOk
, void*, EMPTYARG
)
125 // get the current URL
126 ::rtl::OUString sURL
= m_aURL
.GetText();
127 OFileNotation
aTransformer(sURL
);
128 sURL
= aTransformer
.get(OFileNotation::N_URL
);
130 // check for the existence of the selected file
131 sal_Bool bFileExists
= sal_False
;
134 ::ucbhelper::Content
aFile(sURL
, Reference
< XCommandEnvironment
>());
135 if (aFile
.isDocument())
136 bFileExists
= sal_True
;
144 String sMsg
= String(SVX_RES(STR_LINKEDDOC_DOESNOTEXIST
));
145 sMsg
.SearchAndReplaceAscii("$file$", m_aURL
.GetText());
146 ErrorBox
aError(this, WB_OK
, sMsg
);
149 } // if (!bFileExists)
150 INetURLObject
aURL( sURL
);
151 if ( aURL
.GetProtocol() != INET_PROT_FILE
)
153 String sMsg
= String(SVX_RES(STR_LINKEDDOC_NO_SYSTEM_FILE
));
154 sMsg
.SearchAndReplaceAscii("$file$", m_aURL
.GetText());
155 ErrorBox
aError(this, WB_OK
, sMsg
);
160 String sCurrentText
= m_aName
.GetText();
161 if ( m_aNameValidator
.IsSet() )
163 if ( !m_aNameValidator
.Call( &sCurrentText
) )
165 String sMsg
= String(SVX_RES(STR_NAME_CONFLICT
));
166 sMsg
.SearchAndReplaceAscii("$file$", sCurrentText
);
167 InfoBox
aError(this, sMsg
);
170 m_aName
.SetSelection(Selection(0,sCurrentText
.Len()));
180 //------------------------------------------------------------------
181 IMPL_LINK( ODocumentLinkDialog
, OnBrowseFile
, void*, EMPTYARG
)
183 ::sfx2::FileDialogHelper
aFileDlg(WB_3DLOOK
| WB_STDMODAL
| WB_OPEN
);
184 static const String s_sDatabaseType
= String::CreateFromAscii("StarOffice XML (Base)");
185 const SfxFilter
* pFilter
= SfxFilter::GetFilterByName( s_sDatabaseType
);
188 aFileDlg
.AddFilter(pFilter
->GetUIName(),pFilter
->GetDefaultExtension());
189 aFileDlg
.SetCurrentFilter(pFilter
->GetUIName());
192 String sPath
= m_aURL
.GetText();
195 OFileNotation
aTransformer( sPath
, OFileNotation::N_SYSTEM
);
196 aFileDlg
.SetDisplayDirectory( aTransformer
.get( OFileNotation::N_URL
) );
199 if (0 != aFileDlg
.Execute())
202 if (0 == m_aName
.GetText().Len())
203 { // default the name to the base of the chosen URL
204 INetURLObject aParser
;
206 aParser
.SetSmartProtocol(INET_PROT_FILE
);
207 aParser
.SetSmartURL(aFileDlg
.GetPath());
209 m_aName
.SetText(aParser
.getBase(INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
));
211 m_aName
.SetSelection(Selection(0,m_aName
.GetText().Len()));
217 // get the path in system notation
218 OFileNotation
aTransformer(aFileDlg
.GetPath(), OFileNotation::N_URL
);
219 m_aURL
.SetText(aTransformer
.get(OFileNotation::N_SYSTEM
));
225 //------------------------------------------------------------------
226 IMPL_LINK( ODocumentLinkDialog
, OnTextModified
, Control
*, EMPTYARG
)
232 //......................................................................
234 //......................................................................