1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sfx2/templateremoteview.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/templaterepository.hxx>
#include <sfx2/templateviewitem.hxx>
#include <svtools/imagemgr.hxx>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <vcl/builderfactory.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/XDynamicResultSet.hpp>
using namespace com::sun::star;
using namespace com::sun::star::lang;
using namespace com::sun::star::task;
using namespace com::sun::star::sdbc;
using namespace com::sun::star::ucb;
using namespace com::sun::star::uno;
enum
{
ROW_TITLE = 1,
ROW_SIZE,
ROW_DATE_MOD,
ROW_DATE_CREATE,
ROW_TARGET_URL,
ROW_IS_HIDDEN,
ROW_IS_REMOTE,
ROW_IS_REMOVABLE
};
TemplateRemoteView::TemplateRemoteView (vcl::Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
: TemplateAbstractView(pParent,nWinStyle,bDisableTransientChildren)
{
Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
Reference< XInteractionHandler > xGlobalInteractionHandler(
InteractionHandler::createWithParent(xContext, nullptr), UNO_QUERY_THROW );
m_xCmdEnv = new ucbhelper::CommandEnvironment( xGlobalInteractionHandler, Reference< XProgressHandler >() );
}
VCL_BUILDER_DECL_FACTORY(TemplateRemoteView)
{
(void)rMap;
rRet = VclPtr<TemplateRemoteView>::Create(pParent, WB_VSCROLL, false);
}
void TemplateRemoteView::showRegion(TemplateContainerItem * /*pItem*/)
{
//TODO:
}
void TemplateRemoteView::showAllTemplates()
{
//TODO:
}
bool TemplateRemoteView::loadRepository (TemplateRepository* pItem)
{
if (!pItem)
return false;
if (!pItem->getTemplates().empty())
{
insertItems(pItem->getTemplates());
return true;
}
mnCurRegionId = pItem->mnId;
maCurRegionName = pItem->maTitle;
OUString aURL = pItem->getURL();
try
{
uno::Sequence<OUString> aProps(8);
aProps[0] = "Title";
aProps[1] = "Size";
aProps[2] = "DateModified";
aProps[3] = "DateCreated";
aProps[4] = "TargetURL";
aProps[5] = "IsHidden";
aProps[6] = "IsRemote";
aProps[7] = "IsRemoveable";
ucbhelper::Content aContent(aURL, m_xCmdEnv, comphelper::getProcessComponentContext());
uno::Reference< XResultSet > xResultSet;
uno::Reference< XDynamicResultSet > xDynResultSet;
ucbhelper::ResultSetInclude eInclude = ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
xDynResultSet = aContent.createDynamicCursor( aProps, eInclude );
if ( xDynResultSet.is() )
xResultSet = xDynResultSet->getStaticResultSet();
if ( xResultSet.is() )
{
pItem->clearTemplates();
uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
std::vector<TemplateItemProperties> aItems;
sal_uInt16 nIdx = 0;
while ( xResultSet->next() )
{
bool bIsHidden = xRow->getBoolean( ROW_IS_HIDDEN );
// don't show hidden files or anything besides documents
if ( !bIsHidden || xRow->wasNull() )
{
OUString aContentURL = xContentAccess->queryContentIdentifierString();
OUString aTargetURL = xRow->getString( ROW_TARGET_URL );
bool bHasTargetURL = !xRow->wasNull() && !aTargetURL.isEmpty();
OUString sRealURL = bHasTargetURL ? aTargetURL : aContentURL;
TemplateItemProperties aTemplateItem;
aTemplateItem.nId = nIdx+1;
aTemplateItem.nRegionId = pItem->mnId-1;
aTemplateItem.aPath = sRealURL;
aTemplateItem.aThumbnail = TemplateAbstractView::fetchThumbnail(sRealURL,
TEMPLATE_THUMBNAIL_MAX_WIDTH,
TEMPLATE_THUMBNAIL_MAX_HEIGHT);
aTemplateItem.aName = xRow->getString( ROW_TITLE );
pItem->insertTemplate(aTemplateItem);
aItems.push_back(aTemplateItem);
++nIdx;
}
}
insertItems(aItems);
}
}
catch( ucb::CommandAbortedException& )
{
}
catch( uno::RuntimeException& )
{
}
catch( uno::Exception& )
{
}
return true;
}
sal_uInt16 TemplateRemoteView::createRegion(const OUString &/*rName*/)
{
// TODO: Create new folder in current remote repository
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|