1*2ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2ee96f1cSAndrew Rist * distributed with this work for additional information 6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10*2ee96f1cSAndrew Rist * 11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2ee96f1cSAndrew Rist * 13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an 15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations 18*2ee96f1cSAndrew Rist * under the License. 19*2ee96f1cSAndrew Rist * 20*2ee96f1cSAndrew Rist *************************************************************/ 21*2ee96f1cSAndrew Rist 22*2ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "doclinkdialog.hxx" 28cdf0e10cSrcweir #include "doclinkdialog.hrc" 29cdf0e10cSrcweir #include <cuires.hrc> 30cdf0e10cSrcweir #include <tools/debug.hxx> 31cdf0e10cSrcweir #include <svl/filenotation.hxx> 32cdf0e10cSrcweir #include <vcl/msgbox.hxx> 33cdf0e10cSrcweir #include <ucbhelper/content.hxx> 34cdf0e10cSrcweir #include <dialmgr.hxx> 35cdf0e10cSrcweir #include <tools/urlobj.hxx> 36cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 37cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 38cdf0e10cSrcweir //...................................................................... 39cdf0e10cSrcweir namespace svx 40cdf0e10cSrcweir { 41cdf0e10cSrcweir //...................................................................... 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star::uno; 44cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 45cdf0e10cSrcweir using namespace ::svt; 46cdf0e10cSrcweir 47cdf0e10cSrcweir //================================================================== 48cdf0e10cSrcweir //= ODocumentLinkDialog 49cdf0e10cSrcweir //================================================================== 50cdf0e10cSrcweir //------------------------------------------------------------------ ODocumentLinkDialog(Window * _pParent,sal_Bool _bCreateNew)51cdf0e10cSrcweir ODocumentLinkDialog::ODocumentLinkDialog( Window* _pParent, sal_Bool _bCreateNew ) 52cdf0e10cSrcweir :ModalDialog( _pParent, CUI_RES(DLG_DOCUMENTLINK) ) 53cdf0e10cSrcweir ,m_aURLLabel (this, CUI_RES(FT_URL)) 54cdf0e10cSrcweir ,m_aURL (this, CUI_RES(CMB_URL)) 55cdf0e10cSrcweir ,m_aBrowseFile (this, CUI_RES(PB_BROWSEFILE)) 56cdf0e10cSrcweir ,m_aNameLabel (this, CUI_RES(FT_NAME)) 57cdf0e10cSrcweir ,m_aName (this, CUI_RES(ET_NAME)) 58cdf0e10cSrcweir ,m_aBottomLine (this, CUI_RES(FL_BOTTOM)) 59cdf0e10cSrcweir ,m_aOK (this, CUI_RES(BTN_OK)) 60cdf0e10cSrcweir ,m_aCancel (this, CUI_RES(BTN_CANCEL)) 61cdf0e10cSrcweir ,m_aHelp (this, CUI_RES(BTN_HELP)) 62cdf0e10cSrcweir ,m_bCreatingNew(_bCreateNew) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir String sText = String( CUI_RES( m_bCreatingNew ? STR_NEW_LINK : STR_EDIT_LINK ) ); 65cdf0e10cSrcweir SetText(sText); 66cdf0e10cSrcweir 67cdf0e10cSrcweir FreeResource(); 68cdf0e10cSrcweir 69cdf0e10cSrcweir String sTemp = String::CreateFromAscii("*.odb"); 70cdf0e10cSrcweir m_aURL.SetFilter(sTemp); 71cdf0e10cSrcweir 72cdf0e10cSrcweir m_aName.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) ); 73cdf0e10cSrcweir m_aURL.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) ); 74cdf0e10cSrcweir m_aBrowseFile.SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) ); 75cdf0e10cSrcweir m_aOK.SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir m_aURL.SetDropDownLineCount(10); 78cdf0e10cSrcweir 79cdf0e10cSrcweir validate(); 80cdf0e10cSrcweir 81cdf0e10cSrcweir // m_aURL.SetHelpId( HID_DOCLINKEDIT_URL ); 82cdf0e10cSrcweir m_aURL.SetDropDownLineCount( 5 ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir //------------------------------------------------------------------ set(const String & _rName,const String & _rURL)86cdf0e10cSrcweir void ODocumentLinkDialog::set( const String& _rName, const String& _rURL ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir m_aName.SetText(_rName); 89cdf0e10cSrcweir m_aURL.SetText(_rURL); 90cdf0e10cSrcweir validate(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir //------------------------------------------------------------------ get(String & _rName,String & _rURL) const94cdf0e10cSrcweir void ODocumentLinkDialog::get( String& _rName, String& _rURL ) const 95cdf0e10cSrcweir { 96cdf0e10cSrcweir _rName = m_aName.GetText(); 97cdf0e10cSrcweir _rURL = m_aURL.GetText(); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir //------------------------------------------------------------------ validate()101cdf0e10cSrcweir void ODocumentLinkDialog::validate( ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir 104cdf0e10cSrcweir m_aOK.Enable( (0 != m_aName.GetText().Len()) && ( 0 != m_aURL.GetText().Len() ) ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir //------------------------------------------------------------------ IMPL_LINK(ODocumentLinkDialog,OnOk,void *,EMPTYARG)108cdf0e10cSrcweir IMPL_LINK( ODocumentLinkDialog, OnOk, void*, EMPTYARG ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir // get the current URL 111cdf0e10cSrcweir ::rtl::OUString sURL = m_aURL.GetText(); 112cdf0e10cSrcweir OFileNotation aTransformer(sURL); 113cdf0e10cSrcweir sURL = aTransformer.get(OFileNotation::N_URL); 114cdf0e10cSrcweir 115cdf0e10cSrcweir // check for the existence of the selected file 116cdf0e10cSrcweir sal_Bool bFileExists = sal_False; 117cdf0e10cSrcweir try 118cdf0e10cSrcweir { 119cdf0e10cSrcweir ::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >()); 120cdf0e10cSrcweir if (aFile.isDocument()) 121cdf0e10cSrcweir bFileExists = sal_True; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch(Exception&) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir if (!bFileExists) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir String sMsg = String(CUI_RES(STR_LINKEDDOC_DOESNOTEXIST)); 130cdf0e10cSrcweir sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText()); 131cdf0e10cSrcweir ErrorBox aError(this, WB_OK , sMsg); 132cdf0e10cSrcweir aError.Execute(); 133cdf0e10cSrcweir return 0L; 134cdf0e10cSrcweir } // if (!bFileExists) 135cdf0e10cSrcweir INetURLObject aURL( sURL ); 136cdf0e10cSrcweir if ( aURL.GetProtocol() != INET_PROT_FILE ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir String sMsg = String(CUI_RES(STR_LINKEDDOC_NO_SYSTEM_FILE)); 139cdf0e10cSrcweir sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText()); 140cdf0e10cSrcweir ErrorBox aError(this, WB_OK , sMsg); 141cdf0e10cSrcweir aError.Execute(); 142cdf0e10cSrcweir return 0L; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir String sCurrentText = m_aName.GetText(); 146cdf0e10cSrcweir if ( m_aNameValidator.IsSet() ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir if ( !m_aNameValidator.Call( &sCurrentText ) ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir String sMsg = String(CUI_RES(STR_NAME_CONFLICT)); 151cdf0e10cSrcweir sMsg.SearchAndReplaceAscii("$file$", sCurrentText); 152cdf0e10cSrcweir InfoBox aError(this, sMsg); 153cdf0e10cSrcweir aError.Execute(); 154cdf0e10cSrcweir 155cdf0e10cSrcweir m_aName.SetSelection(Selection(0,sCurrentText.Len())); 156cdf0e10cSrcweir m_aName.GrabFocus(); 157cdf0e10cSrcweir return 0L; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir EndDialog(RET_OK); 162cdf0e10cSrcweir return 0L; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir //------------------------------------------------------------------ IMPL_LINK(ODocumentLinkDialog,OnBrowseFile,void *,EMPTYARG)166cdf0e10cSrcweir IMPL_LINK( ODocumentLinkDialog, OnBrowseFile, void*, EMPTYARG ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN); 169cdf0e10cSrcweir static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)"); 170cdf0e10cSrcweir const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType); 171cdf0e10cSrcweir if ( pFilter ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension()); 174cdf0e10cSrcweir aFileDlg.SetCurrentFilter(pFilter->GetUIName()); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir String sPath = m_aURL.GetText(); 178cdf0e10cSrcweir if (sPath.Len()) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM ); 181cdf0e10cSrcweir aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir if (0 != aFileDlg.Execute()) 185cdf0e10cSrcweir return 0L; 186cdf0e10cSrcweir 187cdf0e10cSrcweir if (0 == m_aName.GetText().Len()) 188cdf0e10cSrcweir { // default the name to the base of the chosen URL 189cdf0e10cSrcweir INetURLObject aParser; 190cdf0e10cSrcweir 191cdf0e10cSrcweir aParser.SetSmartProtocol(INET_PROT_FILE); 192cdf0e10cSrcweir aParser.SetSmartURL(aFileDlg.GetPath()); 193cdf0e10cSrcweir 194cdf0e10cSrcweir m_aName.SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET)); 195cdf0e10cSrcweir 196cdf0e10cSrcweir m_aName.SetSelection(Selection(0,m_aName.GetText().Len())); 197cdf0e10cSrcweir m_aName.GrabFocus(); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir else 200cdf0e10cSrcweir m_aURL.GrabFocus(); 201cdf0e10cSrcweir 202cdf0e10cSrcweir // get the path in system notation 203cdf0e10cSrcweir OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL); 204cdf0e10cSrcweir m_aURL.SetText(aTransformer.get(OFileNotation::N_SYSTEM)); 205cdf0e10cSrcweir 206cdf0e10cSrcweir validate(); 207cdf0e10cSrcweir return 0L; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir //------------------------------------------------------------------ IMPL_LINK(ODocumentLinkDialog,OnTextModified,Control *,EMPTYARG)211cdf0e10cSrcweir IMPL_LINK( ODocumentLinkDialog, OnTextModified, Control*, EMPTYARG ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir validate( ); 214cdf0e10cSrcweir return 0L; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir //...................................................................... 218cdf0e10cSrcweir } // namespace svx 219cdf0e10cSrcweir //...................................................................... 220cdf0e10cSrcweir 221