Files
libreoffice/cui/source/dialogs/hldocntp.cxx

460 lines
16 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 "hldocntp.hxx"
#include <sfx2/viewfrm.hxx>
#include <sfx2/docfac.hxx>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/uno/Exception.hpp>
#include <unotools/localfilehelper.hxx>
#include <vcl/image.hxx>
#include <tools/urlobj.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/dynamicmenuoptions.hxx>
#include <sfx2/filedlghelper.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/dialogs/FolderPicker.hpp>
2009-10-31 00:36:06 +01:00
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;
/*************************************************************************
|*
|* Data-struct for documenttypes in listbox
|*
|************************************************************************/
struct DocumentTypeData
{
OUString aStrURL;
OUString aStrExt;
DocumentTypeData (const OUString& aURL, const OUString& aExt) : aStrURL(aURL), aStrExt(aExt)
2009-10-31 00:36:06 +01:00
{}
};
bool SvxHyperlinkNewDocTp::ImplGetURLObject( const OUString& rPath, const OUString& rBase, INetURLObject& aURLObject ) const
2009-10-31 00:36:06 +01:00
{
bool bIsValidURL = !rPath.isEmpty();
2009-10-31 00:36:06 +01:00
if ( bIsValidURL )
{
aURLObject.SetURL( rPath );
if ( aURLObject.GetProtocol() == INET_PROT_NOT_VALID ) // test if the source is already a valid url
{ // if not we have to create a url from a physical file name
bool wasAbs;
INetURLObject base(rBase);
base.setFinalSlash();
aURLObject = base.smartRel2Abs(
rPath, wasAbs, true, INetURLObject::ENCODE_ALL,
RTL_TEXTENCODING_UTF8, true);
}
bIsValidURL = aURLObject.GetProtocol() != INET_PROT_NOT_VALID;
if ( bIsValidURL )
{
OUString aBase( aURLObject.getName( INetURLObject::LAST_SEGMENT, false ) );
if ( aBase.isEmpty() || ( aBase[0] == '.' ) )
bIsValidURL = false;
2009-10-31 00:36:06 +01:00
}
if ( bIsValidURL )
{
sal_Int32 nPos = m_pLbDocTypes->GetSelectEntryPos();
2009-10-31 00:36:06 +01:00
if ( nPos != LISTBOX_ENTRY_NOTFOUND )
aURLObject.SetExtension( ((DocumentTypeData*)m_pLbDocTypes->GetEntryData( nPos ))->aStrExt );
2009-10-31 00:36:06 +01:00
}
}
return bIsValidURL;
}
/*************************************************************************
|*
|* Contructor / Destructor
|*
|************************************************************************/
SvxHyperlinkNewDocTp::SvxHyperlinkNewDocTp ( vcl::Window *pParent, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet)
: SvxHyperlinkTabPageBase ( pParent, pDlg, "HyperlinkNewDocPage", "cui/ui/hyperlinknewdocpage.ui", rItemSet )
2009-10-31 00:36:06 +01:00
{
get(m_pRbtEditNow, "editnow");
get(m_pRbtEditLater, "editlater");
get(m_pCbbPath, "path");
m_pCbbPath->SetSmartProtocol(INET_PROT_FILE);
get(m_pBtCreate, "create");
m_pBtCreate->SetModeImage(Image(CUI_RES(RID_SVXBMP_NEWDOC)));
get(m_pLbDocTypes, "types");
m_pLbDocTypes->set_height_request(m_pLbDocTypes->GetTextHeight() * 5);
2009-10-31 00:36:06 +01:00
// Set HC bitmaps and disable display of bitmap names.
m_pBtCreate->EnableTextDisplay (false);
2009-10-31 00:36:06 +01:00
InitStdControls();
SetExchangeSupport ();
m_pCbbPath->Show();
m_pCbbPath->SetBaseURL(SvtPathOptions().GetWorkPath());
2009-10-31 00:36:06 +01:00
// set defaults
m_pRbtEditNow->Check();
2009-10-31 00:36:06 +01:00
m_pBtCreate->SetClickHdl ( LINK ( this, SvxHyperlinkNewDocTp, ClickNewHdl_Impl ) );
2009-10-31 00:36:06 +01:00
FillDocumentList ();
}
SvxHyperlinkNewDocTp::~SvxHyperlinkNewDocTp ()
{
for ( sal_uInt16 n=0; n<m_pLbDocTypes->GetEntryCount(); n++ )
2009-10-31 00:36:06 +01:00
{
DocumentTypeData* pTypeData = (DocumentTypeData*)
m_pLbDocTypes->GetEntryData ( n );
2009-10-31 00:36:06 +01:00
delete pTypeData;
}
}
/*************************************************************************
|*
|* Fill the all dialog-controls except controls in groupbox "more..."
|*
|************************************************************************/
void SvxHyperlinkNewDocTp::FillDlgFields(const OUString& /*rStrURL*/)
2009-10-31 00:36:06 +01:00
{
}
void SvxHyperlinkNewDocTp::FillDocumentList ()
{
EnterWait();
uno::Sequence< uno::Sequence< beans::PropertyValue > >
aDynamicMenuEntries( SvtDynamicMenuOptions().GetMenu( E_NEWMENU ) );
sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
for ( i = 0; i < nCount; i++ )
{
uno::Sequence< beans::PropertyValue >& rDynamicMenuEntry = aDynamicMenuEntries[ i ];
OUString aDocumentUrl, aTitle, aImageId, aTargetName;
2009-10-31 00:36:06 +01:00
for ( int e = 0; e < rDynamicMenuEntry.getLength(); e++ )
{
if ( rDynamicMenuEntry[ e ].Name == DYNAMICMENU_PROPERTYNAME_URL )
rDynamicMenuEntry[ e ].Value >>= aDocumentUrl;
else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
rDynamicMenuEntry[e].Value >>= aTitle;
else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
rDynamicMenuEntry[e].Value >>= aImageId;
else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
rDynamicMenuEntry[e].Value >>= aTargetName;
}
//#i96822# business cards, labels and database should not be inserted here
if( aDocumentUrl == "private:factory/swriter?slot=21051" ||
aDocumentUrl == "private:factory/swriter?slot=21052" ||
aDocumentUrl == "private:factory/sdatabase?Interactive" )
2009-10-31 00:36:06 +01:00
continue;
// Insert into listbox
if ( !aDocumentUrl.isEmpty() )
2009-10-31 00:36:06 +01:00
{
if ( aDocumentUrl == "private:factory/simpress?slot=6686" ) // SJ: #106216# do not start
aDocumentUrl = "private:factory/simpress"; // the AutoPilot for impress
2009-10-31 00:36:06 +01:00
// insert private-url and default-extension as user-data
const SfxFilter* pFilter = SfxFilter::GetDefaultFilterFromFactory( aDocumentUrl );
if ( pFilter )
{
// insert doc-name and image
OUString aTitleName( aTitle );
aTitleName = aTitleName.replaceFirst( "~", "" );
2009-10-31 00:36:06 +01:00
sal_Int16 nPos = m_pLbDocTypes->InsertEntry ( aTitleName );
OUString aStrDefExt( pFilter->GetDefaultExtension () );
DocumentTypeData *pTypeData = new DocumentTypeData ( aDocumentUrl, aStrDefExt.copy( 2 ) );
m_pLbDocTypes->SetEntryData ( nPos, pTypeData );
2009-10-31 00:36:06 +01:00
}
}
}
m_pLbDocTypes->SelectEntryPos ( 0 );
2009-10-31 00:36:06 +01:00
LeaveWait();
}
/*************************************************************************
|*
|* retrieve and prepare data from dialog-fields
|*
|************************************************************************/
void SvxHyperlinkNewDocTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
OUString& aStrIntName, OUString& aStrFrame,
2009-10-31 00:36:06 +01:00
SvxLinkInsertMode& eMode )
{
// get data from dialog-controls
rStrURL = m_pCbbPath->GetText();
2009-10-31 00:36:06 +01:00
INetURLObject aURL;
if ( ImplGetURLObject( rStrURL, m_pCbbPath->GetBaseURL(), aURL ) )
2009-10-31 00:36:06 +01:00
{
rStrURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
2009-10-31 00:36:06 +01:00
}
GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
}
/*************************************************************************
|*
|* static method to create Tabpage
|*
|************************************************************************/
IconChoicePage* SvxHyperlinkNewDocTp::Create( vcl::Window* pWindow, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet )
2009-10-31 00:36:06 +01:00
{
return( new SvxHyperlinkNewDocTp( pWindow, pDlg, rItemSet ) );
2009-10-31 00:36:06 +01:00
}
/*************************************************************************
|*
|* Set initial focus
|*
|************************************************************************/
void SvxHyperlinkNewDocTp::SetInitFocus()
{
m_pCbbPath->GrabFocus();
2009-10-31 00:36:06 +01:00
}
/*************************************************************************
|*
|* Ask page whether an insert is possible
|*
\************************************************************************/
bool SvxHyperlinkNewDocTp::AskApply()
2009-10-31 00:36:06 +01:00
{
INetURLObject aINetURLObject;
bool bRet = ImplGetURLObject( m_pCbbPath->GetText(), m_pCbbPath->GetBaseURL(), aINetURLObject );
2009-10-31 00:36:06 +01:00
if ( !bRet )
{
WarningBox aWarning( this, WB_OK, CUI_RESSTR(RID_SVXSTR_HYPDLG_NOVALIDFILENAME) );
2009-10-31 00:36:06 +01:00
aWarning.Execute();
}
return bRet;
}
/*************************************************************************
|*
|* Any action to do after apply-button is pressed
|*
\************************************************************************/
void SvxHyperlinkNewDocTp::DoApply ()
{
EnterWait();
// get data from dialog-controls
OUString aStrNewName = m_pCbbPath->GetText();
2009-10-31 00:36:06 +01:00
if ( aStrNewName == aEmptyStr )
aStrNewName = maStrInitURL;
2009-10-31 00:36:06 +01:00
// create a real URL-String
INetURLObject aURL;
if ( ImplGetURLObject( aStrNewName, m_pCbbPath->GetBaseURL(), aURL ) )
2009-10-31 00:36:06 +01:00
{
2009-10-31 00:36:06 +01:00
// create Document
aStrNewName = aURL.GetURLPath( INetURLObject::NO_DECODE );
SfxViewFrame *pViewFrame = NULL;
try
{
bool bCreate = true;
// check if file exists, warn before we overwrite it
{
com::sun::star::uno::Reference < com::sun::star::task::XInteractionHandler > xHandler;
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ, xHandler );
bool bOk = pIStm && ( pIStm->GetError() == 0);
2009-10-31 00:36:06 +01:00
if( pIStm )
delete pIStm;
if( bOk )
{
WarningBox aWarning( this, WB_YES_NO, CUI_RESSTR(RID_SVXSTR_HYPERDLG_QUERYOVERWRITE) );
2009-10-31 00:36:06 +01:00
bCreate = aWarning.Execute() == BUTTON_YES;
}
}
if( bCreate )
{
// current document
SfxViewFrame* pCurrentDocFrame = SfxViewFrame::Current();
if ( aStrNewName != aEmptyStr )
{
// get private-url
sal_Int32 nPos = m_pLbDocTypes->GetSelectEntryPos();
2009-10-31 00:36:06 +01:00
if( nPos == LISTBOX_ENTRY_NOTFOUND )
nPos=0;
OUString aStrDocName ( ( ( DocumentTypeData* )
m_pLbDocTypes->GetEntryData( nPos ) )->aStrURL );
2009-10-31 00:36:06 +01:00
// create items
SfxStringItem aName( SID_FILE_NAME, aStrDocName );
SfxStringItem aReferer( SID_REFERER, OUString("private:user") );
SfxStringItem aFrame( SID_TARGETNAME, OUString("_blank") );
2009-10-31 00:36:06 +01:00
OUString aStrFlags('S');
if ( m_pRbtEditLater->IsChecked() )
2009-10-31 00:36:06 +01:00
{
aStrFlags += OUString('H');
2009-10-31 00:36:06 +01:00
}
SfxStringItem aFlags (SID_OPTIONS, aStrFlags);
// open url
const SfxPoolItem* pReturn = GetDispatcher()->Execute( SID_OPENDOC,
SfxCallMode::SYNCHRON,
2009-10-31 00:36:06 +01:00
&aName, &aFlags,
&aFrame, &aReferer, 0L );
// save new doc
const SfxViewFrameItem *pItem = PTR_CAST( SfxViewFrameItem, pReturn ); // SJ: pReturn is NULL if the Hyperlink
if ( pItem ) // creation is cancelled #106216#
{
pViewFrame = pItem->GetFrame();
if (pViewFrame)
{
SfxStringItem aNewName( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
pViewFrame->GetDispatcher()->Execute( SID_SAVEASDOC,
SfxCallMode::SYNCHRON,
2009-10-31 00:36:06 +01:00
&aNewName, 0L );
}
}
}
if ( m_pRbtEditNow->IsChecked() && pCurrentDocFrame )
2009-10-31 00:36:06 +01:00
{
pCurrentDocFrame->ToTop();
}
}
}
2011-06-18 00:05:06 +01:00
catch (const uno::Exception&)
2009-10-31 00:36:06 +01:00
{
}
if ( pViewFrame && m_pRbtEditLater->IsChecked() )
2009-10-31 00:36:06 +01:00
{
SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
pObjShell->DoClose();
}
}
LeaveWait();
}
/*************************************************************************
|*
|* Click on imagebutton : new
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHyperlinkNewDocTp, ClickNewHdl_Impl)
2009-10-31 00:36:06 +01:00
{
uno::Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
uno::Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
2009-10-31 00:36:06 +01:00
OUString aStrURL;
OUString aTempStrURL( m_pCbbPath->GetText() );
utl::LocalFileHelper::ConvertSystemPathToURL( aTempStrURL, m_pCbbPath->GetBaseURL(), aStrURL );
2009-10-31 00:36:06 +01:00
OUString aStrPath = aStrURL;
bool bZeroPath = aStrPath.isEmpty();
bool bHandleFileName = bZeroPath; // when path has length of 0, then the rest should always be handled
2009-10-31 00:36:06 +01:00
// as file name, otherwise we do not yet know
if( bZeroPath )
aStrPath = SvtPathOptions().GetWorkPath();
else if( !::utl::UCBContentHelper::IsFolder( aStrURL ) )
bHandleFileName = true;
2009-10-31 00:36:06 +01:00
xFolderPicker->setDisplayDirectory( aStrPath );
DisableClose( true );
2009-10-31 00:36:06 +01:00
sal_Int16 nResult = xFolderPicker->execute();
DisableClose( false );
2009-10-31 00:36:06 +01:00
if( ExecutableDialogResults::OK == nResult )
{
sal_Char const sSlash[] = "/";
INetURLObject aURL( aStrURL, INET_PROT_FILE );
OUString aStrName;
2009-10-31 00:36:06 +01:00
if( bHandleFileName )
aStrName = bZeroPath? aTempStrURL : OUString(aURL.getName());
2009-10-31 00:36:06 +01:00
m_pCbbPath->SetBaseURL( xFolderPicker->getDirectory() );
OUString aStrTmp( xFolderPicker->getDirectory() );
2009-10-31 00:36:06 +01:00
if( aStrTmp[ aStrTmp.getLength() - 1 ] != sSlash[0] )
aStrTmp += OUString( sSlash );
2009-10-31 00:36:06 +01:00
// append old file name
if( bHandleFileName )
aStrTmp += aStrName;
INetURLObject aNewURL( aStrTmp );
if( !aStrName.isEmpty() && !aNewURL.getExtension().isEmpty() &&
m_pLbDocTypes->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
2009-10-31 00:36:06 +01:00
{
// get private-url
sal_uInt16 nPos = m_pLbDocTypes->GetSelectEntryPos();
aNewURL.setExtension( ( ( DocumentTypeData* ) m_pLbDocTypes->GetEntryData( nPos ) )->aStrExt );
2009-10-31 00:36:06 +01:00
}
if( aNewURL.GetProtocol() == INET_PROT_FILE )
{
utl::LocalFileHelper::ConvertURLToSystemPath( aNewURL.GetMainURL( INetURLObject::NO_DECODE ), aStrTmp );
}
else
{
aStrTmp = aNewURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
}
m_pCbbPath->SetText ( aStrTmp );
2009-10-31 00:36:06 +01:00
}
return( 0L );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */