xref: /aoo41x/main/cui/source/dialogs/multifil.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 
36 #include <tools/urlobj.hxx>
37 
38 #include "multipat.hxx"
39 #include "multifil.hxx"
40 #include <dialmgr.hxx>
41 
42 #include "multipat.hrc"
43 #include <cuires.hrc>
44 
45 // #97807# -------------
46 #include <com/sun/star/ucb/XContentProvider.hpp>
47 #include <ucbhelper/contentbroker.hxx>
48 
49 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
50 
51 using namespace com::sun::star::ucb;
52 using namespace com::sun::star::uno;
53 
54 // class SvxMultiFileDialog ----------------------------------------------
55 
56 IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn )
57 {
58     sfx2::FileDialogHelper aDlg(
59         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
60 
61 	if ( IsClassPathMode() )
62 	{
63 		aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
64 		aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
65 	}
66 
67 	if ( aDlg.Execute() == ERRCODE_NONE )
68     {
69 		// #97807# URL content comparison of entries -----------
70 		INetURLObject aFile( aDlg.GetPath() );
71 		String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT );
72 		::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
73 		Reference< XContent > xContent = aContent.get();
74 		OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" );
75 		Reference< XContentIdentifier > xID = xContent->getIdentifier();
76 		OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" );
77 		// ensure the content of files are valid
78 
79 		sal_uInt16 nCount = aPathLB.GetEntryCount();
80 		sal_Bool bDuplicated = sal_False;
81 		try
82 		{
83 			if( nCount > 0 ) // start comparison
84 			{
85 				sal_uInt16 i;
86 				::ucbhelper::Content & VContent = aContent; // temporary Content reference
87 				Reference< XContent > xVContent;
88 				Reference< XContentIdentifier > xVID;
89 				for( i = 0; i < nCount; i++ )
90 				{
91 					String sVFile = aPathLB.GetEntry( i );
92 					std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile );
93 					if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it.
94 					{
95 						INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT );
96 						aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
97 						VContent = aFileContentMap.find( sVFile )->second;
98 					}
99 					else
100 						VContent = aCur->second;
101 					xVContent = VContent.get();
102 					OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" );
103 					xVID = xVContent->getIdentifier();
104 					OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" );
105 					if ( xID.is() && xVID.is() )
106 					{
107 						// get a generic content provider
108 						::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
109 						Reference< XContentProvider > xProvider;
110 						if ( pBroker )
111 							xProvider = pBroker->getContentProviderInterface();
112 						if ( xProvider.is() )
113 						{
114 							if ( 0 == xProvider->compareContentIds( xID, xVID ) )
115 							{
116 								bDuplicated = sal_True;
117 								break;
118 							}
119 						}
120 					}
121 				}
122 			} // end of if the entries are more than zero.
123 		} // end of try(}
124 		catch( const Exception& ) // catch every exception of comparison
125    		{
126 			OSL_ENSURE( sal_False, "AddHdl_Impl: caught an unexpected exception!" );
127    		}
128 
129 		if ( bDuplicated ) // #97807# --------------------
130 		{
131 			String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
132 			sMsg.SearchAndReplaceAscii( "%1", sInsFile );
133 			InfoBox( pBtn, sMsg ).Execute();
134 		}
135 		else
136 		{
137 			sal_uInt16 nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND );
138 			aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) );
139 		}
140 
141 	} // end of if ( aDlg.Execute() == ERRCODE_NONE )
142 	return 0;
143 }
144 
145 // -----------------------------------------------------------------------
146 
147 IMPL_LINK( SvxMultiFileDialog, DelHdl_Impl, PushButton *, EMPTYARG )
148 {
149 	sal_uInt16 nPos = aPathLB.GetSelectEntryPos();
150 	aPathLB.RemoveEntry( nPos );
151 	sal_uInt16 nCnt = aPathLB.GetEntryCount();
152 
153 	if ( nCnt )
154 	{
155 		nCnt--;
156 
157 		if ( nPos > nCnt )
158 			nPos = nCnt;
159 		aPathLB.SelectEntryPos( nPos );
160 	}
161 	return 0;
162 }
163 
164 // -----------------------------------------------------------------------
165 
166 SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, sal_Bool bEmptyAllowed ) :
167 
168 	SvxMultiPathDialog( pParent, bEmptyAllowed )
169 
170 {
171 	aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) );
172 	aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) );
173 	SetText( CUI_RES( RID_SVXSTR_FILE_TITLE ) );
174     aPathFL.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE ) );
175 	aDelBtn.Enable();
176 }
177 
178 // -----------------------------------------------------------------------
179 
180 SvxMultiFileDialog::~SvxMultiFileDialog()
181 {
182 }
183 
184 
185