LCOV - code coverage report
Current view: top level - sfx2/source/control - templateremoteview.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 75 0.0 %
Date: 2014-04-14 Functions: 0 10 0.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/builder.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 (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 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeTemplateRemoteView(Window *pParent, VclBuilder::stringmap &)
      58             : {
      59           0 :     return new TemplateRemoteView(pParent, WB_VSCROLL, false);
      60             : }
      61             : 
      62           0 : TemplateRemoteView::~TemplateRemoteView ()
      63             : {
      64           0 : }
      65             : 
      66           0 : void TemplateRemoteView::showRootRegion()
      67             : {
      68             :     //TODO:
      69           0 : }
      70             : 
      71           0 : void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
      72             : {
      73             :     //TODO:
      74           0 : }
      75             : 
      76           0 : bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh)
      77             : {
      78           0 :     if (!pItem)
      79           0 :         return false;
      80             : 
      81           0 :     if (!pItem->getTemplates().empty() && !bRefresh)
      82             :     {
      83           0 :         insertItems(pItem->getTemplates());
      84           0 :         return true;
      85             :     }
      86             : 
      87           0 :     mnCurRegionId = pItem->mnId;
      88           0 :     maCurRegionName = pItem->maTitle;
      89           0 :     maFTName.SetText(maCurRegionName);
      90             : 
      91           0 :     OUString aURL = pItem->getURL();
      92             : 
      93             :     try
      94             :     {
      95             : 
      96           0 :         uno::Sequence<OUString> aProps(8);
      97             : 
      98           0 :         aProps[0] = "Title";
      99           0 :         aProps[1] = "Size";
     100           0 :         aProps[2] = "DateModified";
     101           0 :         aProps[3] = "DateCreated";
     102           0 :         aProps[4] = "TargetURL";
     103           0 :         aProps[5] = "IsHidden";
     104           0 :         aProps[6] = "IsRemote";
     105           0 :         aProps[7] = "IsRemoveable";
     106             : 
     107           0 :         ucbhelper::Content aContent(aURL, m_xCmdEnv, comphelper::getProcessComponentContext());
     108             : 
     109           0 :         uno::Reference< XResultSet > xResultSet;
     110           0 :         uno::Reference< XDynamicResultSet > xDynResultSet;
     111             : 
     112           0 :         ucbhelper::ResultSetInclude eInclude = ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
     113           0 :         xDynResultSet = aContent.createDynamicCursor( aProps, eInclude );
     114             : 
     115           0 :         if ( xDynResultSet.is() )
     116           0 :             xResultSet = xDynResultSet->getStaticResultSet();
     117             : 
     118           0 :         if ( xResultSet.is() )
     119             :         {
     120           0 :             pItem->clearTemplates();
     121             : 
     122           0 :             uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
     123           0 :             uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
     124             : 
     125           0 :             std::vector<TemplateItemProperties> aItems;
     126             : 
     127           0 :             sal_uInt16 nIdx = 0;
     128           0 :             while ( xResultSet->next() )
     129             :             {
     130           0 :                 bool bIsHidden = xRow->getBoolean( ROW_IS_HIDDEN );
     131             : 
     132             :                 // don't show hidden files or anything besides documents
     133           0 :                 if ( !bIsHidden || xRow->wasNull() )
     134             :                 {
     135           0 :                     OUString aContentURL = xContentAccess->queryContentIdentifierString();
     136           0 :                     OUString aTargetURL = xRow->getString( ROW_TARGET_URL );
     137           0 :                     bool bHasTargetURL = !xRow->wasNull() && !aTargetURL.isEmpty();
     138             : 
     139           0 :                     OUString sRealURL = bHasTargetURL ? aTargetURL : aContentURL;
     140             : 
     141           0 :                     TemplateItemProperties aTemplateItem;
     142           0 :                     aTemplateItem.nId = nIdx+1;
     143           0 :                     aTemplateItem.nRegionId = pItem->mnId-1;
     144           0 :                     aTemplateItem.aPath = sRealURL;
     145           0 :                     aTemplateItem.aThumbnail = TemplateAbstractView::fetchThumbnail(sRealURL,
     146             :                                                                                     TEMPLATE_THUMBNAIL_MAX_WIDTH,
     147           0 :                                                                                     TEMPLATE_THUMBNAIL_MAX_HEIGHT);
     148           0 :                     aTemplateItem.aName = xRow->getString( ROW_TITLE );
     149             : 
     150           0 :                     pItem->insertTemplate(aTemplateItem);
     151           0 :                     aItems.push_back(aTemplateItem);
     152           0 :                     ++nIdx;
     153             :                 }
     154             :             }
     155             : 
     156           0 :             insertItems(aItems);
     157           0 :         }
     158             :     }
     159           0 :     catch( ucb::CommandAbortedException& )
     160             :     {
     161             :     }
     162           0 :     catch( uno::RuntimeException& )
     163             :     {
     164             :     }
     165           0 :     catch( uno::Exception& )
     166             :     {
     167             :     }
     168             : 
     169           0 :     return true;
     170             : }
     171             : 
     172           0 : sal_uInt16 TemplateRemoteView::createRegion(const OUString &/*rName*/)
     173             : {
     174             :     // TODO: Create new folder in current remote repository
     175           0 :     return 0;
     176             : }
     177             : 
     178           0 : bool TemplateRemoteView::isNestedRegionAllowed() const
     179             : {
     180           0 :     return true;
     181             : }
     182             : 
     183           0 : bool TemplateRemoteView::isImportAllowed() const
     184             : {
     185           0 :     return true;
     186             : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10