bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / control / templateremoteview.cxx
blob310dead385084d0d69fde068de85fc20fc54caa5
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/.
8 */
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;
35 enum
37 ROW_TITLE = 1,
38 ROW_SIZE,
39 ROW_DATE_MOD,
40 ROW_DATE_CREATE,
41 ROW_TARGET_URL,
42 ROW_IS_HIDDEN,
43 ROW_IS_REMOTE,
44 ROW_IS_REMOVABLE
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)
59 (void)rMap;
60 rRet = VclPtr<TemplateRemoteView>::Create(pParent, WB_VSCROLL, false);
63 void TemplateRemoteView::showRootRegion()
65 //TODO:
68 void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
70 //TODO:
73 bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh)
75 if (!pItem)
76 return false;
78 if (!pItem->getTemplates().empty() && !bRefresh)
80 insertItems(pItem->getTemplates());
81 return true;
84 mnCurRegionId = pItem->mnId;
85 maCurRegionName = pItem->maTitle;
86 maFTName->SetText(maCurRegionName);
88 OUString aURL = pItem->getURL();
90 try
93 uno::Sequence<OUString> aProps(8);
95 aProps[0] = "Title";
96 aProps[1] = "Size";
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;
124 sal_uInt16 nIdx = 0;
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);
149 ++nIdx;
153 insertItems(aItems);
156 catch( ucb::CommandAbortedException& )
159 catch( uno::RuntimeException& )
162 catch( uno::Exception& )
166 return true;
169 sal_uInt16 TemplateRemoteView::createRegion(const OUString &/*rName*/)
171 // TODO: Create new folder in current remote repository
172 return 0;
175 bool TemplateRemoteView::isNestedRegionAllowed() const
177 return true;
180 bool TemplateRemoteView::isImportAllowed() const
182 return true;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */