1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include "doclinkdialog.hxx"
32 #include "doclinkdialog.hrc"
34 #include <tools/debug.hxx>
35 #include <svl/filenotation.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <ucbhelper/content.hxx>
38 #include <dialmgr.hxx>
39 #include <tools/urlobj.hxx>
40 #include <sfx2/filedlghelper.hxx>
41 #include <sfx2/docfilt.hxx>
42 //......................................................................
45 //......................................................................
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::ucb
;
49 using namespace ::svt
;
51 //==================================================================
52 //= ODocumentLinkDialog
53 //==================================================================
54 //------------------------------------------------------------------
55 ODocumentLinkDialog::ODocumentLinkDialog( Window
* _pParent
, sal_Bool _bCreateNew
)
56 :ModalDialog( _pParent
, CUI_RES(DLG_DOCUMENTLINK
) )
57 ,m_aURLLabel (this, CUI_RES(FT_URL
))
58 ,m_aURL (this, CUI_RES(CMB_URL
))
59 ,m_aBrowseFile (this, CUI_RES(PB_BROWSEFILE
))
60 ,m_aNameLabel (this, CUI_RES(FT_NAME
))
61 ,m_aName (this, CUI_RES(ET_NAME
))
62 ,m_aBottomLine (this, CUI_RES(FL_BOTTOM
))
63 ,m_aOK (this, CUI_RES(BTN_OK
))
64 ,m_aCancel (this, CUI_RES(BTN_CANCEL
))
65 ,m_aHelp (this, CUI_RES(BTN_HELP
))
66 ,m_bCreatingNew(_bCreateNew
)
68 String sText
= String( CUI_RES( m_bCreatingNew
? STR_NEW_LINK
: STR_EDIT_LINK
) );
73 String sTemp
= String::CreateFromAscii("*.odb");
74 m_aURL
.SetFilter(sTemp
);
76 m_aName
.SetModifyHdl( LINK(this, ODocumentLinkDialog
, OnTextModified
) );
77 m_aURL
.SetModifyHdl( LINK(this, ODocumentLinkDialog
, OnTextModified
) );
78 m_aBrowseFile
.SetClickHdl( LINK(this, ODocumentLinkDialog
, OnBrowseFile
) );
79 m_aOK
.SetClickHdl( LINK(this, ODocumentLinkDialog
, OnOk
) );
81 m_aURL
.SetDropDownLineCount(10);
85 // m_aURL.SetHelpId( HID_DOCLINKEDIT_URL );
86 m_aURL
.SetDropDownLineCount( 5 );
89 //------------------------------------------------------------------
90 void ODocumentLinkDialog::set( const String
& _rName
, const String
& _rURL
)
92 m_aName
.SetText(_rName
);
93 m_aURL
.SetText(_rURL
);
97 //------------------------------------------------------------------
98 void ODocumentLinkDialog::get( String
& _rName
, String
& _rURL
) const
100 _rName
= m_aName
.GetText();
101 _rURL
= m_aURL
.GetText();
104 //------------------------------------------------------------------
105 void ODocumentLinkDialog::validate( )
108 m_aOK
.Enable( (0 != m_aName
.GetText().Len()) && ( 0 != m_aURL
.GetText().Len() ) );
111 //------------------------------------------------------------------
112 IMPL_LINK( ODocumentLinkDialog
, OnOk
, void*, EMPTYARG
)
114 // get the current URL
115 ::rtl::OUString sURL
= m_aURL
.GetText();
116 OFileNotation
aTransformer(sURL
);
117 sURL
= aTransformer
.get(OFileNotation::N_URL
);
119 // check for the existence of the selected file
120 sal_Bool bFileExists
= sal_False
;
123 ::ucbhelper::Content
aFile(sURL
, Reference
< XCommandEnvironment
>());
124 if (aFile
.isDocument())
125 bFileExists
= sal_True
;
133 String sMsg
= String(CUI_RES(STR_LINKEDDOC_DOESNOTEXIST
));
134 sMsg
.SearchAndReplaceAscii("$file$", m_aURL
.GetText());
135 ErrorBox
aError(this, WB_OK
, sMsg
);
138 } // if (!bFileExists)
139 INetURLObject
aURL( sURL
);
140 if ( aURL
.GetProtocol() != INET_PROT_FILE
)
142 String sMsg
= String(CUI_RES(STR_LINKEDDOC_NO_SYSTEM_FILE
));
143 sMsg
.SearchAndReplaceAscii("$file$", m_aURL
.GetText());
144 ErrorBox
aError(this, WB_OK
, sMsg
);
149 String sCurrentText
= m_aName
.GetText();
150 if ( m_aNameValidator
.IsSet() )
152 if ( !m_aNameValidator
.Call( &sCurrentText
) )
154 String sMsg
= String(CUI_RES(STR_NAME_CONFLICT
));
155 sMsg
.SearchAndReplaceAscii("$file$", sCurrentText
);
156 InfoBox
aError(this, sMsg
);
159 m_aName
.SetSelection(Selection(0,sCurrentText
.Len()));
169 //------------------------------------------------------------------
170 IMPL_LINK( ODocumentLinkDialog
, OnBrowseFile
, void*, EMPTYARG
)
172 ::sfx2::FileDialogHelper
aFileDlg(WB_3DLOOK
| WB_STDMODAL
| WB_OPEN
);
173 static const String s_sDatabaseType
= String::CreateFromAscii("StarOffice XML (Base)");
174 const SfxFilter
* pFilter
= SfxFilter::GetFilterByName( s_sDatabaseType
);
177 aFileDlg
.AddFilter(pFilter
->GetUIName(),pFilter
->GetDefaultExtension());
178 aFileDlg
.SetCurrentFilter(pFilter
->GetUIName());
181 String sPath
= m_aURL
.GetText();
184 OFileNotation
aTransformer( sPath
, OFileNotation::N_SYSTEM
);
185 aFileDlg
.SetDisplayDirectory( aTransformer
.get( OFileNotation::N_URL
) );
188 if (0 != aFileDlg
.Execute())
191 if (0 == m_aName
.GetText().Len())
192 { // default the name to the base of the chosen URL
193 INetURLObject aParser
;
195 aParser
.SetSmartProtocol(INET_PROT_FILE
);
196 aParser
.SetSmartURL(aFileDlg
.GetPath());
198 m_aName
.SetText(aParser
.getBase(INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
));
200 m_aName
.SetSelection(Selection(0,m_aName
.GetText().Len()));
206 // get the path in system notation
207 OFileNotation
aTransformer(aFileDlg
.GetPath(), OFileNotation::N_URL
);
208 m_aURL
.SetText(aTransformer
.get(OFileNotation::N_SYSTEM
));
214 //------------------------------------------------------------------
215 IMPL_LINK( ODocumentLinkDialog
, OnTextModified
, Control
*, EMPTYARG
)
221 //......................................................................
223 //......................................................................