xref: /trunk/main/cui/source/dialogs/multifil.cxx (revision 2ee96f1c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <sfx2/filedlghelper.hxx>
31 
32 #include <tools/urlobj.hxx>
33 
34 #include "multipat.hxx"
35 #include "multifil.hxx"
36 #include <dialmgr.hxx>
37 
38 #include "multipat.hrc"
39 #include <cuires.hrc>
40 
41 // #97807# -------------
42 #include <com/sun/star/ucb/XContentProvider.hpp>
43 #include <ucbhelper/contentbroker.hxx>
44 
45 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
46 
47 using namespace com::sun::star::ucb;
48 using namespace com::sun::star::uno;
49 
50 // class SvxMultiFileDialog ----------------------------------------------
51 
IMPL_LINK(SvxMultiFileDialog,AddHdl_Impl,PushButton *,pBtn)52 IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn )
53 {
54     sfx2::FileDialogHelper aDlg(
55         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
56 
57 	if ( IsClassPathMode() )
58 	{
59 		aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
60 		aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
61 	}
62 
63 	if ( aDlg.Execute() == ERRCODE_NONE )
64     {
65 		// #97807# URL content comparison of entries -----------
66 		INetURLObject aFile( aDlg.GetPath() );
67 		String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT );
68 		::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
69 		Reference< XContent > xContent = aContent.get();
70 		OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" );
71 		Reference< XContentIdentifier > xID = xContent->getIdentifier();
72 		OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" );
73 		// ensure the content of files are valid
74 
75 		sal_uInt16 nCount = aPathLB.GetEntryCount();
76 		sal_Bool bDuplicated = sal_False;
77 		try
78 		{
79 			if( nCount > 0 ) // start comparison
80 			{
81 				sal_uInt16 i;
82 				::ucbhelper::Content & VContent = aContent; // temporary Content reference
83 				Reference< XContent > xVContent;
84 				Reference< XContentIdentifier > xVID;
85 				for( i = 0; i < nCount; i++ )
86 				{
87 					String sVFile = aPathLB.GetEntry( i );
88 					std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile );
89 					if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it.
90 					{
91 						INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT );
92 						aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
93 						VContent = aFileContentMap.find( sVFile )->second;
94 					}
95 					else
96 						VContent = aCur->second;
97 					xVContent = VContent.get();
98 					OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" );
99 					xVID = xVContent->getIdentifier();
100 					OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" );
101 					if ( xID.is() && xVID.is() )
102 					{
103 						// get a generic content provider
104 						::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
105 						Reference< XContentProvider > xProvider;
106 						if ( pBroker )
107 							xProvider = pBroker->getContentProviderInterface();
108 						if ( xProvider.is() )
109 						{
110 							if ( 0 == xProvider->compareContentIds( xID, xVID ) )
111 							{
112 								bDuplicated = sal_True;
113 								break;
114 							}
115 						}
116 					}
117 				}
118 			} // end of if the entries are more than zero.
119 		} // end of try(}
120 		catch( const Exception& ) // catch every exception of comparison
121    		{
122 			OSL_ENSURE( sal_False, "AddHdl_Impl: caught an unexpected exception!" );
123    		}
124 
125 		if ( bDuplicated ) // #97807# --------------------
126 		{
127 			String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
128 			sMsg.SearchAndReplaceAscii( "%1", sInsFile );
129 			InfoBox( pBtn, sMsg ).Execute();
130 		}
131 		else
132 		{
133 			sal_uInt16 nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND );
134 			aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) );
135 		}
136 
137 	} // end of if ( aDlg.Execute() == ERRCODE_NONE )
138 	return 0;
139 }
140 
141 // -----------------------------------------------------------------------
142 
IMPL_LINK(SvxMultiFileDialog,DelHdl_Impl,PushButton *,EMPTYARG)143 IMPL_LINK( SvxMultiFileDialog, DelHdl_Impl, PushButton *, EMPTYARG )
144 {
145 	sal_uInt16 nPos = aPathLB.GetSelectEntryPos();
146 	aPathLB.RemoveEntry( nPos );
147 	sal_uInt16 nCnt = aPathLB.GetEntryCount();
148 
149 	if ( nCnt )
150 	{
151 		nCnt--;
152 
153 		if ( nPos > nCnt )
154 			nPos = nCnt;
155 		aPathLB.SelectEntryPos( nPos );
156 	}
157 	return 0;
158 }
159 
160 // -----------------------------------------------------------------------
161 
SvxMultiFileDialog(Window * pParent,sal_Bool bEmptyAllowed)162 SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, sal_Bool bEmptyAllowed ) :
163 
164 	SvxMultiPathDialog( pParent, bEmptyAllowed )
165 
166 {
167 	aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) );
168 	aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) );
169 	SetText( CUI_RES( RID_SVXSTR_FILE_TITLE ) );
170     aPathFL.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE ) );
171 	aDelBtn.Enable();
172 }
173 
174 // -----------------------------------------------------------------------
175 
~SvxMultiFileDialog()176 SvxMultiFileDialog::~SvxMultiFileDialog()
177 {
178 }
179 
180 
181