Files
libreoffice/cui/source/options/doclinkdialog.cxx

210 lines
7.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +01:00
/*
* 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 .
*/
2009-10-31 00:36:06 +01:00
#include "doclinkdialog.hxx"
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <comphelper/processfactory.hxx>
#include <cuires.hrc>
2009-10-31 00:36:06 +01:00
#include <svl/filenotation.hxx>
#include <vcl/msgbox.hxx>
#include <ucbhelper/content.hxx>
#include <dialmgr.hxx>
2009-10-31 00:36:06 +01:00
#include <tools/urlobj.hxx>
#include <sfx2/filedlghelper.hxx>
#include <sfx2/docfilt.hxx>
//......................................................................
namespace svx
{
//......................................................................
using namespace ::com::sun::star;
2009-10-31 00:36:06 +01:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::svt;
//==================================================================
//= ODocumentLinkDialog
//==================================================================
//------------------------------------------------------------------
ODocumentLinkDialog::ODocumentLinkDialog( Window* _pParent, sal_Bool _bCreateNew )
: ModalDialog(_pParent, "DatabaseLinkDialog",
"cui/ui/databaselinkdialog.ui")
2009-10-31 00:36:06 +01:00
,m_bCreatingNew(_bCreateNew)
{
get(m_pURL, "url");
get(m_pOK, "ok");
get(m_pName, "name");
get(m_pBrowseFile, "browse");
2009-10-31 00:36:06 +01:00
if (!m_bCreatingNew)
SetText(get<FixedText>("alttitle")->GetText());
2009-10-31 00:36:06 +01:00
m_pURL->SetFilter("*.odb");
2009-10-31 00:36:06 +01:00
m_pName->SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
m_pURL->SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
m_pBrowseFile->SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) );
m_pOK->SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) );
2009-10-31 00:36:06 +01:00
m_pURL->SetDropDownLineCount(10);
2009-10-31 00:36:06 +01:00
validate();
m_pURL->SetDropDownLineCount( 5 );
2009-10-31 00:36:06 +01:00
}
//------------------------------------------------------------------
void ODocumentLinkDialog::setLink( const OUString& _rName, const OUString& _rURL )
2009-10-31 00:36:06 +01:00
{
m_pName->SetText(_rName);
m_pURL->SetText(_rURL);
2009-10-31 00:36:06 +01:00
validate();
}
//------------------------------------------------------------------
void ODocumentLinkDialog::getLink( OUString& _rName, OUString& _rURL ) const
2009-10-31 00:36:06 +01:00
{
_rName = m_pName->GetText();
_rURL = m_pURL->GetText();
2009-10-31 00:36:06 +01:00
}
//------------------------------------------------------------------
void ODocumentLinkDialog::validate( )
{
m_pOK->Enable( ( !m_pName->GetText().isEmpty()) && ( !m_pURL->GetText().isEmpty() ) );
2009-10-31 00:36:06 +01:00
}
//------------------------------------------------------------------
IMPL_LINK_NOARG(ODocumentLinkDialog, OnOk)
2009-10-31 00:36:06 +01:00
{
// get the current URL
OUString sURL = m_pURL->GetText();
2009-10-31 00:36:06 +01:00
OFileNotation aTransformer(sURL);
sURL = aTransformer.get(OFileNotation::N_URL);
// check for the existence of the selected file
sal_Bool bFileExists = sal_False;
try
{
::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
2009-10-31 00:36:06 +01:00
if (aFile.isDocument())
bFileExists = sal_True;
}
catch(Exception&)
{
}
if (!bFileExists)
{
OUString sMsg = CUI_RES(STR_LINKEDDOC_DOESNOTEXIST);
sMsg = sMsg.replaceFirst("$file$", m_pURL->GetText());
2009-10-31 00:36:06 +01:00
ErrorBox aError(this, WB_OK , sMsg);
aError.Execute();
return 0L;
} // if (!bFileExists)
INetURLObject aURL( sURL );
if ( aURL.GetProtocol() != INET_PROT_FILE )
{
OUString sMsg = CUI_RES(STR_LINKEDDOC_NO_SYSTEM_FILE);
sMsg = sMsg.replaceFirst("$file$", m_pURL->GetText());
2009-10-31 00:36:06 +01:00
ErrorBox aError(this, WB_OK , sMsg);
aError.Execute();
return 0L;
}
OUString sCurrentText = m_pName->GetText();
2009-10-31 00:36:06 +01:00
if ( m_aNameValidator.IsSet() )
{
if ( !m_aNameValidator.Call( &sCurrentText ) )
{
OUString sMsg = CUI_RES(STR_NAME_CONFLICT);
sMsg = sMsg.replaceFirst("$file$", sCurrentText);
2009-10-31 00:36:06 +01:00
InfoBox aError(this, sMsg);
aError.Execute();
m_pName->SetSelection(Selection(0,sCurrentText.getLength()));
m_pName->GrabFocus();
2009-10-31 00:36:06 +01:00
return 0L;
}
}
EndDialog(RET_OK);
return 0L;
}
//------------------------------------------------------------------
IMPL_LINK_NOARG(ODocumentLinkDialog, OnBrowseFile)
2009-10-31 00:36:06 +01:00
{
::sfx2::FileDialogHelper aFileDlg(
ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION, 0);
const SfxFilter* pFilter = SfxFilter::GetFilterByName(OUString("StarOffice XML (Base)"));
2009-10-31 00:36:06 +01:00
if ( pFilter )
{
aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
aFileDlg.SetCurrentFilter(pFilter->GetUIName());
}
OUString sPath = m_pURL->GetText();
if (!sPath.isEmpty())
2009-10-31 00:36:06 +01:00
{
OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM );
aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) );
}
if (0 != aFileDlg.Execute())
return 0L;
if (m_pName->GetText().isEmpty())
2009-10-31 00:36:06 +01:00
{ // default the name to the base of the chosen URL
INetURLObject aParser;
aParser.SetSmartProtocol(INET_PROT_FILE);
aParser.SetSmartURL(aFileDlg.GetPath());
m_pName->SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET));
2009-10-31 00:36:06 +01:00
m_pName->SetSelection(Selection(0,m_pName->GetText().getLength()));
m_pName->GrabFocus();
2009-10-31 00:36:06 +01:00
}
else
m_pURL->GrabFocus();
2009-10-31 00:36:06 +01:00
// get the path in system notation
OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL);
m_pURL->SetText(aTransformer.get(OFileNotation::N_SYSTEM));
2009-10-31 00:36:06 +01:00
validate();
return 0L;
}
//------------------------------------------------------------------
IMPL_LINK_NOARG(ODocumentLinkDialog, OnTextModified)
2009-10-31 00:36:06 +01:00
{
validate( );
return 0L;
}
//......................................................................
} // namespace svx
//......................................................................
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */