fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / CollectionView.cxx
blob1ceb8a62931dc8b60928f9f6e14af1d78c92a1fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "CollectionView.hxx"
21 #include <tools/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include "moduledbu.hxx"
24 #include "dbu_dlg.hrc"
25 #include <comphelper/processfactory.hxx>
26 #include <comphelper/interaction.hxx>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/container/XChild.hpp>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <vcl/msgbox.hxx>
34 #include "dbustrings.hrc"
35 #include "UITools.hxx"
36 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
37 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
38 #include <com/sun/star/ucb/IOErrorCode.hpp>
39 #include <com/sun/star/task/InteractionHandler.hpp>
40 #include <com/sun/star/task/InteractionClassification.hpp>
41 #include <com/sun/star/sdbc/SQLException.hpp>
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <unotools/viewoptions.hxx>
44 #include <osl/thread.h>
45 #include <connectivity/dbexception.hxx>
47 namespace dbaui
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::ucb;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::container;
55 using namespace ::com::sun::star::task;
56 using namespace ::com::sun::star::sdbc;
57 using namespace comphelper;
58 OCollectionView::OCollectionView( vcl::Window * pParent
59 ,const Reference< XContent>& _xContent
60 ,const OUString& _sDefaultName
61 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
62 : ModalDialog( pParent, "CollectionView", "dbaccess/ui/collectionviewdialog.ui")
63 , m_xContent(_xContent)
64 , m_xContext(_rxContext)
65 , m_bCreateForm(true)
67 get(m_pFTCurrentPath, "currentPathLabel");
68 get(m_pNewFolder, "newFolderButton");
69 get(m_pUp, "upButton");
70 get(m_pView, "viewTreeview");
71 get(m_pName, "fileNameEntry");
72 get(m_pPB_OK, "ok");
74 OSL_ENSURE(m_xContent.is(),"No valid content!");
75 m_pView->Initialize(m_xContent,OUString());
76 m_pFTCurrentPath->SetStyle( m_pFTCurrentPath->GetStyle() | WB_PATHELLIPSIS );
77 initCurrentPath();
79 m_pName->SetText(_sDefaultName);
80 m_pName->GrabFocus();
82 m_pNewFolder->SetStyle( m_pNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
83 m_pUp->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_BTN_UP_SC)));
84 m_pNewFolder->SetModeImage(Image(ModuleRes(IMG_NAVIGATION_CREATEFOLDER_SC)));
86 m_pView->SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) );
87 m_pView->EnableAutoResize();
88 m_pView->EnableDelete(true);
89 m_pUp->SetClickHdl( LINK( this, OCollectionView, Up_Click ) );
90 m_pNewFolder->SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) );
91 m_pPB_OK->SetClickHdl( LINK( this, OCollectionView, Save_Click ) );
94 OCollectionView::~OCollectionView()
96 disposeOnce();
99 void OCollectionView::dispose()
101 m_pFTCurrentPath.clear();
102 m_pNewFolder.clear();
103 m_pUp.clear();
104 m_pView.clear();
105 m_pName.clear();
106 m_pPB_OK.clear();
107 ModalDialog::dispose();
110 IMPL_LINK_NOARG(OCollectionView, Save_Click)
112 OUString sName = m_pName->GetText();
113 if ( sName.isEmpty() )
114 return 0;
117 OUString sSubFolder = m_pView->GetCurrentURL();
118 sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
119 if ( nIndex )
121 if ( nIndex == 1 ) // special handling for root
123 Reference<XChild> xChild(m_xContent,UNO_QUERY);
124 Reference<XNameAccess> xNameAccess(xChild,UNO_QUERY);
125 while( xNameAccess.is() )
127 xNameAccess.set(xChild->getParent(),UNO_QUERY);
128 if ( xNameAccess.is() )
130 m_xContent.set(xNameAccess,UNO_QUERY);
131 xChild.set(m_xContent,UNO_QUERY);
134 m_pView->Initialize(m_xContent,OUString());
135 initCurrentPath();
137 sSubFolder = sName.copy(0,nIndex-1);
138 sName = sName.copy(nIndex);
139 Reference<XHierarchicalNameContainer> xHier(m_xContent,UNO_QUERY);
140 OSL_ENSURE(xHier.is(),"XHierarchicalNameContainer not supported!");
141 if ( !sSubFolder.isEmpty() && xHier.is() )
143 if ( xHier->hasByHierarchicalName(sSubFolder) )
145 m_xContent.set(xHier->getByHierarchicalName(sSubFolder),UNO_QUERY);
147 else // sub folder doesn't exist
149 Sequence< Any > aValues(2);
150 PropertyValue aValue;
151 aValue.Name = "ResourceName";
152 aValue.Value <<= sSubFolder;
153 aValues[0] <<= aValue;
155 aValue.Name = "ResourceType";
156 aValue.Value <<= OUString("folder");
157 aValues[1] <<= aValue;
159 InteractionClassification eClass = InteractionClassification_ERROR;
160 ::com::sun::star::ucb::IOErrorCode eError = IOErrorCode_NOT_EXISTING_PATH;
161 OUString sTemp;
162 InteractiveAugmentedIOException aException(sTemp,Reference<XInterface>(),eClass,eError,aValues);
164 Reference<XInteractionHandler2> xHandler(
165 InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this )));
166 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException));
167 Reference< XInteractionRequest > xRequest(pRequest);
169 OInteractionApprove* pApprove = new OInteractionApprove;
170 pRequest->addContinuation(pApprove);
171 xHandler->handle(xRequest);
173 return 0;
177 Reference<XNameContainer> xNameContainer(m_xContent,UNO_QUERY);
178 if ( xNameContainer.is() )
180 Reference< XContent> xContent;
181 if ( xNameContainer->hasByName(sName) )
183 ScopedVclPtrInstance< QueryBox > aBox( this, WB_YES_NO, ModuleRes( STR_ALREADYEXISTOVERWRITE ) );
184 if ( aBox->Execute() != RET_YES )
185 return 0;
187 m_pName->SetText(sName);
188 EndDialog( RET_OK );
191 catch( const Exception& )
193 DBG_UNHANDLED_EXCEPTION();
195 return 0;
198 IMPL_LINK_NOARG(OCollectionView, NewFolder_Click)
202 Reference<XHierarchicalNameContainer> xNameContainer(m_xContent,UNO_QUERY);
203 if ( dbaui::insertHierachyElement(this,m_xContext,xNameContainer,OUString(),m_bCreateForm) )
204 m_pView->Initialize(m_xContent,OUString());
206 catch( const SQLException& )
208 showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), this, m_xContext );
210 catch( const Exception& )
212 DBG_UNHANDLED_EXCEPTION();
214 return 0;
217 IMPL_LINK_NOARG(OCollectionView, Up_Click)
221 Reference<XChild> xChild(m_xContent,UNO_QUERY);
222 if ( xChild.is() )
224 Reference<XNameAccess> xNameAccess(xChild->getParent(),UNO_QUERY);
225 if ( xNameAccess.is() )
227 m_xContent.set(xNameAccess,UNO_QUERY);
228 m_pView->Initialize(m_xContent,OUString());
229 initCurrentPath();
231 else
232 m_pUp->Disable();
235 catch( const Exception& )
237 DBG_UNHANDLED_EXCEPTION();
239 return 0;
242 IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView)
246 Reference<XNameAccess> xNameAccess(m_xContent,UNO_QUERY);
247 if ( xNameAccess.is() )
249 OUString sSubFolder = m_pView->GetCurrentURL();
250 sal_Int32 nIndex = sSubFolder.lastIndexOf('/') + 1;
251 sSubFolder = sSubFolder.getToken(0,'/',nIndex);
252 if ( !sSubFolder.isEmpty() )
254 Reference< XContent> xContent;
255 if ( xNameAccess->hasByName(sSubFolder) )
256 xContent.set(xNameAccess->getByName(sSubFolder),UNO_QUERY);
257 if ( xContent.is() )
259 m_xContent = xContent;
260 m_pView->Initialize(m_xContent,OUString());
261 initCurrentPath();
266 catch( const Exception& )
268 DBG_UNHANDLED_EXCEPTION();
270 return 0;
273 void OCollectionView::initCurrentPath()
275 bool bEnable = false;
278 if ( m_xContent.is() )
280 const OUString sCID = m_xContent->getIdentifier()->getContentIdentifier();
281 static const char s_sFormsCID[] = "private:forms";
282 static const char s_sReportsCID[] = "private:reports";
283 m_bCreateForm = s_sFormsCID == sCID;
284 OUString sPath("/");
285 if ( m_bCreateForm && sCID.getLength() != (sal_Int32)strlen(s_sFormsCID))
286 sPath = sCID.copy(strlen(s_sFormsCID));
287 else if ( !m_bCreateForm && sCID.getLength() != (sal_Int32)strlen(s_sReportsCID) )
288 sPath = sCID.copy(strlen(s_sReportsCID) - 2);
290 m_pFTCurrentPath->SetText(sPath);
291 Reference<XChild> xChild(m_xContent,UNO_QUERY);
292 bEnable = xChild.is() && Reference<XNameAccess>(xChild->getParent(),UNO_QUERY).is();
295 catch( const Exception& )
297 DBG_UNHANDLED_EXCEPTION();
299 m_pUp->Enable(bEnable);
302 OUString OCollectionView::getName() const
304 return m_pName->GetText();
307 } // namespace dbaui
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */