Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "doclinkdialog.hxx"
30 : : #include "doclinkdialog.hrc"
31 : :
32 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 : :
34 : : #include <cuires.hrc>
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 : : //......................................................................
43 : : namespace svx
44 : : {
45 : : //......................................................................
46 : :
47 : : using namespace ::com::sun::star;
48 : : using namespace ::com::sun::star::uno;
49 : : using namespace ::com::sun::star::ucb;
50 : : using namespace ::svt;
51 : :
52 : : //==================================================================
53 : : //= ODocumentLinkDialog
54 : : //==================================================================
55 : : //------------------------------------------------------------------
56 : 0 : ODocumentLinkDialog::ODocumentLinkDialog( Window* _pParent, sal_Bool _bCreateNew )
57 : 0 : :ModalDialog( _pParent, CUI_RES(DLG_DOCUMENTLINK) )
58 [ # # ]: 0 : ,m_aURLLabel (this, CUI_RES(FT_URL))
59 [ # # ]: 0 : ,m_aURL (this, CUI_RES(CMB_URL))
60 [ # # ]: 0 : ,m_aBrowseFile (this, CUI_RES(PB_BROWSEFILE))
61 [ # # ]: 0 : ,m_aNameLabel (this, CUI_RES(FT_NAME))
62 [ # # ]: 0 : ,m_aName (this, CUI_RES(ET_NAME))
63 [ # # ]: 0 : ,m_aBottomLine (this, CUI_RES(FL_BOTTOM))
64 [ # # ]: 0 : ,m_aOK (this, CUI_RES(BTN_OK))
65 [ # # ]: 0 : ,m_aCancel (this, CUI_RES(BTN_CANCEL))
66 [ # # ]: 0 : ,m_aHelp (this, CUI_RES(BTN_HELP))
67 [ # # ][ # # ]: 0 : ,m_bCreatingNew(_bCreateNew)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
68 : : {
69 [ # # ][ # # ]: 0 : String sText = String( CUI_RES( m_bCreatingNew ? STR_NEW_LINK : STR_EDIT_LINK ) );
[ # # ]
70 [ # # ]: 0 : SetText(sText);
71 : :
72 [ # # ]: 0 : FreeResource();
73 : :
74 : 0 : rtl::OUString sTemp("*.odb");
75 [ # # ][ # # ]: 0 : m_aURL.SetFilter(sTemp);
[ # # ]
76 : :
77 [ # # ]: 0 : m_aName.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
78 [ # # ]: 0 : m_aURL.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
79 [ # # ]: 0 : m_aBrowseFile.SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) );
80 [ # # ]: 0 : m_aOK.SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) );
81 : :
82 [ # # ]: 0 : m_aURL.SetDropDownLineCount(10);
83 : :
84 [ # # ]: 0 : validate();
85 : :
86 [ # # ][ # # ]: 0 : m_aURL.SetDropDownLineCount( 5 );
87 : 0 : }
88 : :
89 : : //------------------------------------------------------------------
90 : 0 : void ODocumentLinkDialog::set( const String& _rName, const String& _rURL )
91 : : {
92 : 0 : m_aName.SetText(_rName);
93 : 0 : m_aURL.SetText(_rURL);
94 : 0 : validate();
95 : 0 : }
96 : :
97 : : //------------------------------------------------------------------
98 : 0 : void ODocumentLinkDialog::get( String& _rName, String& _rURL ) const
99 : : {
100 [ # # ]: 0 : _rName = m_aName.GetText();
101 [ # # ]: 0 : _rURL = m_aURL.GetText();
102 : 0 : }
103 : :
104 : : //------------------------------------------------------------------
105 : 0 : void ODocumentLinkDialog::validate( )
106 : : {
107 : :
108 [ # # ][ # # ]: 0 : m_aOK.Enable( (0 != m_aName.GetText().Len()) && ( 0 != m_aURL.GetText().Len() ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
109 : 0 : }
110 : :
111 : : //------------------------------------------------------------------
112 : 0 : IMPL_LINK_NOARG(ODocumentLinkDialog, OnOk)
113 : : {
114 : : // get the current URL
115 [ # # ][ # # ]: 0 : ::rtl::OUString sURL = m_aURL.GetText();
[ # # ]
116 [ # # ]: 0 : OFileNotation aTransformer(sURL);
117 [ # # ]: 0 : sURL = aTransformer.get(OFileNotation::N_URL);
118 : :
119 : : // check for the existence of the selected file
120 : 0 : sal_Bool bFileExists = sal_False;
121 : : try
122 : : {
123 [ # # ]: 0 : ::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >());
124 [ # # ][ # # ]: 0 : if (aFile.isDocument())
125 [ # # ][ # # ]: 0 : bFileExists = sal_True;
126 : : }
127 [ # # ]: 0 : catch(Exception&)
128 : : {
129 : : }
130 : :
131 [ # # ]: 0 : if (!bFileExists)
132 : : {
133 [ # # ][ # # ]: 0 : String sMsg = String(CUI_RES(STR_LINKEDDOC_DOESNOTEXIST));
134 [ # # ][ # # ]: 0 : sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText());
[ # # ]
135 [ # # ]: 0 : ErrorBox aError(this, WB_OK , sMsg);
136 [ # # ]: 0 : aError.Execute();
137 [ # # ][ # # ]: 0 : return 0L;
138 : : } // if (!bFileExists)
139 [ # # ]: 0 : INetURLObject aURL( sURL );
140 [ # # ]: 0 : if ( aURL.GetProtocol() != INET_PROT_FILE )
141 : : {
142 [ # # ][ # # ]: 0 : String sMsg = String(CUI_RES(STR_LINKEDDOC_NO_SYSTEM_FILE));
143 [ # # ][ # # ]: 0 : sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText());
[ # # ]
144 [ # # ]: 0 : ErrorBox aError(this, WB_OK , sMsg);
145 [ # # ]: 0 : aError.Execute();
146 [ # # ][ # # ]: 0 : return 0L;
147 : : }
148 : :
149 [ # # ]: 0 : String sCurrentText = m_aName.GetText();
150 [ # # ][ # # ]: 0 : if ( m_aNameValidator.IsSet() )
151 : : {
152 [ # # ][ # # ]: 0 : if ( !m_aNameValidator.Call( &sCurrentText ) )
153 : : {
154 [ # # ][ # # ]: 0 : String sMsg = String(CUI_RES(STR_NAME_CONFLICT));
155 [ # # ]: 0 : sMsg.SearchAndReplaceAscii("$file$", sCurrentText);
156 [ # # ]: 0 : InfoBox aError(this, sMsg);
157 [ # # ]: 0 : aError.Execute();
158 : :
159 [ # # ]: 0 : m_aName.SetSelection(Selection(0,sCurrentText.Len()));
160 [ # # ]: 0 : m_aName.GrabFocus();
161 [ # # ][ # # ]: 0 : return 0L;
162 : : }
163 : : }
164 : :
165 [ # # ]: 0 : EndDialog(RET_OK);
166 [ # # ][ # # ]: 0 : return 0L;
[ # # ]
167 : : }
168 : :
169 : : //------------------------------------------------------------------
170 : 0 : IMPL_LINK_NOARG(ODocumentLinkDialog, OnBrowseFile)
171 : : {
172 : : ::sfx2::FileDialogHelper aFileDlg(
173 [ # # ]: 0 : ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION, 0);
174 [ # # ][ # # ]: 0 : const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
[ # # ]
175 [ # # ]: 0 : if ( pFilter )
176 : : {
177 [ # # ][ # # ]: 0 : aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
[ # # ]
178 [ # # ]: 0 : aFileDlg.SetCurrentFilter(pFilter->GetUIName());
179 : : }
180 : :
181 [ # # ]: 0 : String sPath = m_aURL.GetText();
182 [ # # ]: 0 : if (sPath.Len())
183 : : {
184 [ # # ][ # # ]: 0 : OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM );
185 [ # # ][ # # ]: 0 : aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) );
[ # # ][ # # ]
[ # # ]
186 : : }
187 : :
188 [ # # ][ # # ]: 0 : if (0 != aFileDlg.Execute())
189 : 0 : return 0L;
190 : :
191 [ # # ][ # # ]: 0 : if (0 == m_aName.GetText().Len())
[ # # ]
192 : : { // default the name to the base of the chosen URL
193 [ # # ]: 0 : INetURLObject aParser;
194 : :
195 : 0 : aParser.SetSmartProtocol(INET_PROT_FILE);
196 [ # # ][ # # ]: 0 : aParser.SetSmartURL(aFileDlg.GetPath());
[ # # ][ # # ]
197 : :
198 [ # # ][ # # ]: 0 : m_aName.SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET));
[ # # ][ # # ]
199 : :
200 [ # # ][ # # ]: 0 : m_aName.SetSelection(Selection(0,m_aName.GetText().Len()));
[ # # ]
201 [ # # ][ # # ]: 0 : m_aName.GrabFocus();
202 : : }
203 : : else
204 [ # # ]: 0 : m_aURL.GrabFocus();
205 : :
206 : : // get the path in system notation
207 [ # # ][ # # ]: 0 : OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL);
[ # # ][ # # ]
208 [ # # ][ # # ]: 0 : m_aURL.SetText(aTransformer.get(OFileNotation::N_SYSTEM));
[ # # ][ # # ]
209 : :
210 [ # # ]: 0 : validate();
211 [ # # ][ # # ]: 0 : return 0L;
[ # # ]
212 : : }
213 : :
214 : : //------------------------------------------------------------------
215 : 0 : IMPL_LINK_NOARG(ODocumentLinkDialog, OnTextModified)
216 : : {
217 : 0 : validate( );
218 : 0 : return 0L;
219 : : }
220 : :
221 : : //......................................................................
222 : : } // namespace svx
223 : : //......................................................................
224 : :
225 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|