1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
22 #include <comphelper/processfactory.hxx>
23 #include <tools/shl.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <sfx2/filedlghelper.hxx>
27 #include <tools/urlobj.hxx>
29 #include "multipat.hxx"
30 #include "multifil.hxx"
31 #include <dialmgr.hxx>
33 #include "multipat.hrc"
36 // #97807# -------------
37 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
39 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
41 using namespace com::sun::star::ucb
;
42 using namespace com::sun::star::uno
;
44 // class SvxMultiFileDialog ----------------------------------------------
46 IMPL_LINK( SvxMultiFileDialog
, AddHdl_Impl
, PushButton
*, pBtn
)
48 sfx2::FileDialogHelper
aDlg(
49 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0 );
51 if ( IsClassPathMode() )
53 aDlg
.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE
) );
54 aDlg
.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE
), OUString("*.jar;*.zip") );
57 if ( aDlg
.Execute() == ERRCODE_NONE
)
59 // #97807# URL content comparison of entries -----------
60 INetURLObject
aFile( aDlg
.GetPath() );
61 String sInsFile
= aFile
.getFSysPath( INetURLObject::FSYS_DETECT
);
62 ::ucbhelper::Content
aContent( aFile
.GetMainURL( INetURLObject::NO_DECODE
), Reference
< XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
63 Reference
< XContent
> xContent
= aContent
.get();
64 OSL_ENSURE( xContent
.is(), "AddHdl_Impl: invalid content interface!" );
65 Reference
< XContentIdentifier
> xID
= xContent
->getIdentifier();
66 OSL_ENSURE( xID
.is(), "AddHdl_Impl: invalid ID interface!" );
67 // ensure the content of files are valid
69 sal_uInt16 nCount
= aPathLB
.GetEntryCount();
70 sal_Bool bDuplicated
= sal_False
;
73 if( nCount
> 0 ) // start comparison
76 ::ucbhelper::Content
& VContent
= aContent
; // temporary Content reference
77 Reference
< XContent
> xVContent
;
78 Reference
< XContentIdentifier
> xVID
;
79 for( i
= 0; i
< nCount
; i
++ )
81 String sVFile
= aPathLB
.GetEntry( i
);
82 std::map
< String
, ::ucbhelper::Content
>::iterator aCur
= aFileContentMap
.find( sVFile
);
83 if( aCur
== aFileContentMap
.end() ) // look for File Content in aFileContentMap, but not find it.
85 INetURLObject
aVFile( sVFile
, INetURLObject::FSYS_DETECT
);
86 aFileContentMap
[sVFile
] = ::ucbhelper::Content( aVFile
.GetMainURL( INetURLObject::NO_DECODE
), Reference
< XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
87 VContent
= aFileContentMap
.find( sVFile
)->second
;
90 VContent
= aCur
->second
;
91 xVContent
= VContent
.get();
92 OSL_ENSURE( xVContent
.is(), "AddHdl_Impl: invalid content interface!" );
93 xVID
= xVContent
->getIdentifier();
94 OSL_ENSURE( xVID
.is(), "AddHdl_Impl: invalid ID interface!" );
95 if ( xID
.is() && xVID
.is()
96 && ( UniversalContentBroker::create(
97 comphelper::getProcessComponentContext() )->
98 compareContentIds( xID
, xVID
) == 0 ) )
100 bDuplicated
= sal_True
;
104 } // end of if the entries are more than zero.
106 catch( const Exception
& ) // catch every exception of comparison
108 OSL_FAIL( "AddHdl_Impl: caught an unexpected exception!" );
111 if ( bDuplicated
) // #97807# --------------------
113 String
sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR
) );
114 sMsg
.SearchAndReplaceAscii( "%1", sInsFile
);
115 InfoBox( pBtn
, sMsg
).Execute();
119 sal_uInt16 nPos
= aPathLB
.InsertEntry( sInsFile
, LISTBOX_APPEND
);
120 aPathLB
.SetEntryData( nPos
, (void*) new String( sInsFile
) );
123 } // end of if ( aDlg.Execute() == ERRCODE_NONE )
127 // -----------------------------------------------------------------------
129 IMPL_LINK_NOARG(SvxMultiFileDialog
, DelHdl_Impl
)
131 sal_uInt16 nPos
= aPathLB
.GetSelectEntryPos();
132 aPathLB
.RemoveEntry( nPos
);
133 sal_uInt16 nCnt
= aPathLB
.GetEntryCount();
141 aPathLB
.SelectEntryPos( nPos
);
146 // -----------------------------------------------------------------------
148 SvxMultiFileDialog::SvxMultiFileDialog( Window
* pParent
, sal_Bool bEmptyAllowed
) :
150 SvxMultiPathDialog( pParent
, bEmptyAllowed
)
153 aAddBtn
.SetClickHdl( LINK( this, SvxMultiFileDialog
, AddHdl_Impl
) );
154 aDelBtn
.SetClickHdl( LINK( this, SvxMultiFileDialog
, DelHdl_Impl
) );
155 SetText( CUI_RES( RID_SVXSTR_FILE_TITLE
) );
156 aPathFL
.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE
) );
160 // -----------------------------------------------------------------------
162 SvxMultiFileDialog::~SvxMultiFileDialog()
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */