Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sfx2/templateremoteview.hxx>
11 :
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 :
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>
26 :
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;
33 :
34 : enum
35 : {
36 : ROW_TITLE = 1,
37 : ROW_SIZE,
38 : ROW_DATE_MOD,
39 : ROW_DATE_CREATE,
40 : ROW_TARGET_URL,
41 : ROW_IS_HIDDEN,
42 : ROW_IS_REMOTE,
43 : ROW_IS_REMOVABLE
44 : };
45 :
46 0 : TemplateRemoteView::TemplateRemoteView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
47 0 : : TemplateAbstractView(pParent,nWinStyle,bDisableTransientChildren)
48 : {
49 0 : Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
50 : Reference< XInteractionHandler > xGlobalInteractionHandler(
51 0 : InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
52 :
53 0 : m_xCmdEnv = new ucbhelper::CommandEnvironment( xGlobalInteractionHandler, Reference< XProgressHandler >() );
54 0 : }
55 :
56 0 : TemplateRemoteView::~TemplateRemoteView ()
57 : {
58 0 : }
59 :
60 0 : void TemplateRemoteView::showRootRegion()
61 : {
62 : //TODO:
63 0 : }
64 :
65 0 : void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
66 : {
67 : //TODO:
68 0 : }
69 :
70 0 : bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh)
71 : {
72 0 : if (!pItem)
73 0 : return false;
74 :
75 0 : if (!pItem->getTemplates().empty() && !bRefresh)
76 : {
77 0 : insertItems(pItem->getTemplates());
78 0 : return true;
79 : }
80 :
81 0 : mnCurRegionId = pItem->mnId;
82 0 : maCurRegionName = pItem->maTitle;
83 0 : maFTName.SetText(maCurRegionName);
84 :
85 0 : OUString aURL = pItem->getURL();
86 :
87 : try
88 : {
89 :
90 0 : uno::Sequence<OUString> aProps(8);
91 :
92 0 : aProps[0] = "Title";
93 0 : aProps[1] = "Size";
94 0 : aProps[2] = "DateModified";
95 0 : aProps[3] = "DateCreated";
96 0 : aProps[4] = "TargetURL";
97 0 : aProps[5] = "IsHidden";
98 0 : aProps[6] = "IsRemote";
99 0 : aProps[7] = "IsRemoveable";
100 :
101 0 : ucbhelper::Content aContent(aURL, m_xCmdEnv, comphelper::getProcessComponentContext());
102 :
103 0 : uno::Reference< XResultSet > xResultSet;
104 0 : uno::Reference< XDynamicResultSet > xDynResultSet;
105 :
106 0 : ucbhelper::ResultSetInclude eInclude = ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
107 0 : xDynResultSet = aContent.createDynamicCursor( aProps, eInclude );
108 :
109 0 : if ( xDynResultSet.is() )
110 0 : xResultSet = xDynResultSet->getStaticResultSet();
111 :
112 0 : if ( xResultSet.is() )
113 : {
114 0 : pItem->clearTemplates();
115 :
116 0 : uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
117 0 : uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
118 :
119 0 : std::vector<TemplateItemProperties> aItems;
120 :
121 0 : sal_uInt16 nIdx = 0;
122 0 : while ( xResultSet->next() )
123 : {
124 0 : bool bIsHidden = xRow->getBoolean( ROW_IS_HIDDEN );
125 :
126 : // don't show hidden files or anything besides documents
127 0 : if ( !bIsHidden || xRow->wasNull() )
128 : {
129 0 : OUString aContentURL = xContentAccess->queryContentIdentifierString();
130 0 : OUString aTargetURL = xRow->getString( ROW_TARGET_URL );
131 0 : bool bHasTargetURL = !xRow->wasNull() && !aTargetURL.isEmpty();
132 :
133 0 : OUString sRealURL = bHasTargetURL ? aTargetURL : aContentURL;
134 :
135 0 : TemplateItemProperties aTemplateItem;
136 0 : aTemplateItem.nId = nIdx+1;
137 0 : aTemplateItem.nRegionId = pItem->mnId-1;
138 0 : aTemplateItem.aPath = sRealURL;
139 0 : aTemplateItem.aThumbnail = TemplateAbstractView::fetchThumbnail(sRealURL,
140 : TEMPLATE_THUMBNAIL_MAX_WIDTH,
141 0 : TEMPLATE_THUMBNAIL_MAX_HEIGHT);
142 0 : aTemplateItem.aName = xRow->getString( ROW_TITLE );
143 :
144 0 : pItem->insertTemplate(aTemplateItem);
145 0 : aItems.push_back(aTemplateItem);
146 0 : ++nIdx;
147 : }
148 : }
149 :
150 0 : insertItems(aItems);
151 0 : }
152 : }
153 0 : catch( ucb::CommandAbortedException& )
154 : {
155 : }
156 0 : catch( uno::RuntimeException& )
157 : {
158 : }
159 0 : catch( uno::Exception& )
160 : {
161 : }
162 :
163 0 : return true;
164 : }
165 :
166 0 : sal_uInt16 TemplateRemoteView::createRegion(const OUString &/*rName*/)
167 : {
168 : // TODO: Create new folder in current remote repository
169 0 : return 0;
170 : }
171 :
172 0 : bool TemplateRemoteView::isNestedRegionAllowed() const
173 : {
174 0 : return true;
175 : }
176 :
177 0 : bool TemplateRemoteView::isImportAllowed() const
178 : {
179 0 : return true;
180 408 : }
181 :
182 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|