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>
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/task/InteractionHandler.hpp>
22 #include <com/sun/star/sdbc/XResultSet.hpp>
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <com/sun/star/ucb/XContentAccess.hpp>
25 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
27 using namespace com::sun::star
;
28 using namespace com::sun::star::lang
;
29 using namespace com::sun::star::task
;
30 using namespace com::sun::star::sdbc
;
31 using namespace com::sun::star::ucb
;
32 using namespace com::sun::star::uno
;
46 TemplateRemoteView::TemplateRemoteView (Window
*pParent
, WinBits nWinStyle
, bool bDisableTransientChildren
)
47 : TemplateAbstractView(pParent
,nWinStyle
,bDisableTransientChildren
)
49 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
50 Reference
< XInteractionHandler
> xGlobalInteractionHandler(
51 InteractionHandler::createWithParent(xContext
, 0), UNO_QUERY_THROW
);
53 m_xCmdEnv
= new ucbhelper::CommandEnvironment( xGlobalInteractionHandler
, Reference
< XProgressHandler
>() );
56 TemplateRemoteView::~TemplateRemoteView ()
60 void TemplateRemoteView::showRootRegion()
65 void TemplateRemoteView::showRegion(ThumbnailViewItem
* /*pItem*/)
70 bool TemplateRemoteView::loadRepository (TemplateRepository
* pItem
, bool bRefresh
)
75 if (!pItem
->getTemplates().empty() && !bRefresh
)
77 insertItems(pItem
->getTemplates());
81 mnCurRegionId
= pItem
->mnId
;
82 maCurRegionName
= pItem
->maTitle
;
83 maFTName
.SetText(maCurRegionName
);
85 OUString aURL
= pItem
->getURL();
90 uno::Sequence
<OUString
> aProps(8);
94 aProps
[2] = "DateModified";
95 aProps
[3] = "DateCreated";
96 aProps
[4] = "TargetURL";
97 aProps
[5] = "IsHidden";
98 aProps
[6] = "IsRemote";
99 aProps
[7] = "IsRemoveable";
101 ucbhelper::Content
aContent(aURL
, m_xCmdEnv
, comphelper::getProcessComponentContext());
103 uno::Reference
< XResultSet
> xResultSet
;
104 uno::Reference
< XDynamicResultSet
> xDynResultSet
;
106 ucbhelper::ResultSetInclude eInclude
= ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS
;
107 xDynResultSet
= aContent
.createDynamicCursor( aProps
, eInclude
);
109 if ( xDynResultSet
.is() )
110 xResultSet
= xDynResultSet
->getStaticResultSet();
112 if ( xResultSet
.is() )
114 pItem
->clearTemplates();
116 uno::Reference
< XRow
> xRow( xResultSet
, UNO_QUERY
);
117 uno::Reference
< XContentAccess
> xContentAccess( xResultSet
, UNO_QUERY
);
119 std::vector
<TemplateItemProperties
> aItems
;
122 while ( xResultSet
->next() )
124 bool bIsHidden
= xRow
->getBoolean( ROW_IS_HIDDEN
);
126 // don't show hidden files or anything besides documents
127 if ( !bIsHidden
|| xRow
->wasNull() )
129 OUString aContentURL
= xContentAccess
->queryContentIdentifierString();
130 OUString aTargetURL
= xRow
->getString( ROW_TARGET_URL
);
131 bool bHasTargetURL
= !xRow
->wasNull() && !aTargetURL
.isEmpty();
133 OUString sRealURL
= bHasTargetURL
? aTargetURL
: aContentURL
;
135 TemplateItemProperties aTemplateItem
;
136 aTemplateItem
.nId
= nIdx
+1;
137 aTemplateItem
.nRegionId
= pItem
->mnId
-1;
138 aTemplateItem
.aPath
= sRealURL
;
139 aTemplateItem
.aThumbnail
= TemplateAbstractView::fetchThumbnail(sRealURL
,
140 TEMPLATE_THUMBNAIL_MAX_WIDTH
,
141 TEMPLATE_THUMBNAIL_MAX_HEIGHT
);
142 aTemplateItem
.aName
= xRow
->getString( ROW_TITLE
);
144 pItem
->insertTemplate(aTemplateItem
);
145 aItems
.push_back(aTemplateItem
);
153 catch( ucb::CommandAbortedException
& )
156 catch( uno::RuntimeException
& )
159 catch( uno::Exception
& )
166 sal_uInt16
TemplateRemoteView::createRegion(const OUString
&/*rName*/)
168 // TODO: Create new folder in current remote repository
172 bool TemplateRemoteView::isNestedRegionAllowed() const
177 bool TemplateRemoteView::isImportAllowed() const
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */