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/.
10 #include <sfx2/templateremoteview.hxx>
12 #include <comphelper/processfactory.hxx>
13 #include <sfx2/templaterepository.hxx>
14 #include <sfx2/templateviewitem.hxx>
15 #include <svtools/imagemgr.hxx>
16 #include <tools/urlobj.hxx>
17 #include <ucbhelper/content.hxx>
18 #include <ucbhelper/commandenvironment.hxx>
19 #include <vcl/builderfactory.hxx>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/task/InteractionHandler.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/ucb/XContentAccess.hpp>
26 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
28 using namespace com::sun::star
;
29 using namespace com::sun::star::lang
;
30 using namespace com::sun::star::task
;
31 using namespace com::sun::star::sdbc
;
32 using namespace com::sun::star::ucb
;
33 using namespace com::sun::star::uno
;
47 TemplateRemoteView::TemplateRemoteView (vcl::Window
*pParent
, WinBits nWinStyle
, bool bDisableTransientChildren
)
48 : TemplateAbstractView(pParent
,nWinStyle
,bDisableTransientChildren
)
50 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
51 Reference
< XInteractionHandler
> xGlobalInteractionHandler(
52 InteractionHandler::createWithParent(xContext
, 0), UNO_QUERY_THROW
);
54 m_xCmdEnv
= new ucbhelper::CommandEnvironment( xGlobalInteractionHandler
, Reference
< XProgressHandler
>() );
57 VCL_BUILDER_DECL_FACTORY(TemplateRemoteView
)
60 rRet
= VclPtr
<TemplateRemoteView
>::Create(pParent
, WB_VSCROLL
, false);
63 void TemplateRemoteView::showRootRegion()
68 void TemplateRemoteView::showRegion(ThumbnailViewItem
* /*pItem*/)
73 bool TemplateRemoteView::loadRepository (TemplateRepository
* pItem
, bool bRefresh
)
78 if (!pItem
->getTemplates().empty() && !bRefresh
)
80 insertItems(pItem
->getTemplates());
84 mnCurRegionId
= pItem
->mnId
;
85 maCurRegionName
= pItem
->maTitle
;
86 maFTName
->SetText(maCurRegionName
);
88 OUString aURL
= pItem
->getURL();
93 uno::Sequence
<OUString
> aProps(8);
97 aProps
[2] = "DateModified";
98 aProps
[3] = "DateCreated";
99 aProps
[4] = "TargetURL";
100 aProps
[5] = "IsHidden";
101 aProps
[6] = "IsRemote";
102 aProps
[7] = "IsRemoveable";
104 ucbhelper::Content
aContent(aURL
, m_xCmdEnv
, comphelper::getProcessComponentContext());
106 uno::Reference
< XResultSet
> xResultSet
;
107 uno::Reference
< XDynamicResultSet
> xDynResultSet
;
109 ucbhelper::ResultSetInclude eInclude
= ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS
;
110 xDynResultSet
= aContent
.createDynamicCursor( aProps
, eInclude
);
112 if ( xDynResultSet
.is() )
113 xResultSet
= xDynResultSet
->getStaticResultSet();
115 if ( xResultSet
.is() )
117 pItem
->clearTemplates();
119 uno::Reference
< XRow
> xRow( xResultSet
, UNO_QUERY
);
120 uno::Reference
< XContentAccess
> xContentAccess( xResultSet
, UNO_QUERY
);
122 std::vector
<TemplateItemProperties
> aItems
;
125 while ( xResultSet
->next() )
127 bool bIsHidden
= xRow
->getBoolean( ROW_IS_HIDDEN
);
129 // don't show hidden files or anything besides documents
130 if ( !bIsHidden
|| xRow
->wasNull() )
132 OUString aContentURL
= xContentAccess
->queryContentIdentifierString();
133 OUString aTargetURL
= xRow
->getString( ROW_TARGET_URL
);
134 bool bHasTargetURL
= !xRow
->wasNull() && !aTargetURL
.isEmpty();
136 OUString sRealURL
= bHasTargetURL
? aTargetURL
: aContentURL
;
138 TemplateItemProperties aTemplateItem
;
139 aTemplateItem
.nId
= nIdx
+1;
140 aTemplateItem
.nRegionId
= pItem
->mnId
-1;
141 aTemplateItem
.aPath
= sRealURL
;
142 aTemplateItem
.aThumbnail
= TemplateAbstractView::fetchThumbnail(sRealURL
,
143 TEMPLATE_THUMBNAIL_MAX_WIDTH
,
144 TEMPLATE_THUMBNAIL_MAX_HEIGHT
);
145 aTemplateItem
.aName
= xRow
->getString( ROW_TITLE
);
147 pItem
->insertTemplate(aTemplateItem
);
148 aItems
.push_back(aTemplateItem
);
156 catch( ucb::CommandAbortedException
& )
159 catch( uno::RuntimeException
& )
162 catch( uno::Exception
& )
169 sal_uInt16
TemplateRemoteView::createRegion(const OUString
&/*rName*/)
171 // TODO: Create new folder in current remote repository
175 bool TemplateRemoteView::isNestedRegionAllowed() const
180 bool TemplateRemoteView::isImportAllowed() const
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */