LCOV - code coverage report
Current view: top level - sfx2/source/control - templateremoteview.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 75 1.3 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11