LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/control - templateremoteview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 80 0.0 %
Date: 2012-12-27 Functions: 0 5 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/templateview.hxx>
      15             : #include <sfx2/templateviewitem.hxx>
      16             : #include <svtools/imagemgr.hxx>
      17             : #include <tools/urlobj.hxx>
      18             : #include <ucbhelper/content.hxx>
      19             : #include <ucbhelper/commandenvironment.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_REMOVEABLE
      45             : };
      46             : 
      47           0 : TemplateRemoteView::TemplateRemoteView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
      48           0 :     : TemplateAbstractView(pParent,nWinStyle,bDisableTransientChildren)
      49             : {
      50           0 :     mpItemView->SetColor(Color(COL_WHITE));
      51             : 
      52           0 :     Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
      53             :     Reference< XInteractionHandler > xGlobalInteractionHandler(
      54           0 :         InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
      55             : 
      56           0 :     m_xCmdEnv = new ucbhelper::CommandEnvironment( xGlobalInteractionHandler, Reference< XProgressHandler >() );
      57           0 : }
      58             : 
      59           0 : TemplateRemoteView::~TemplateRemoteView ()
      60             : {
      61           0 : }
      62             : 
      63           0 : void TemplateRemoteView::showOverlay (bool bVisible)
      64             : {
      65           0 :     mpItemView->Show(bVisible);
      66             : 
      67             :     // Clear items is the overlay is closed.
      68           0 :     if (!bVisible)
      69             :     {
      70           0 :         mpItemView->Clear();
      71             :     }
      72           0 : }
      73             : 
      74           0 : bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh)
      75             : {
      76           0 :     if (!pItem)
      77           0 :         return false;
      78             : 
      79           0 :     if (!pItem->getTemplates().empty() && !bRefresh)
      80             :     {
      81           0 :         mpItemView->InsertItems(pItem->getTemplates());
      82           0 :         return true;
      83             :     }
      84             : 
      85           0 :     mpItemView->Clear();
      86           0 :     mpItemView->setId(pItem->mnId);
      87           0 :     mpItemView->setName(pItem->maTitle);
      88             : 
      89           0 :     OUString aURL = pItem->getURL();
      90             : 
      91             :     try
      92             :     {
      93             : 
      94           0 :         uno::Sequence<OUString> aProps(8);
      95             : 
      96           0 :         aProps[0] = "Title";
      97           0 :         aProps[1] = "Size";
      98           0 :         aProps[2] = "DateModified";
      99           0 :         aProps[3] = "DateCreated";
     100           0 :         aProps[4] = "TargetURL";
     101           0 :         aProps[5] = "IsHidden";
     102           0 :         aProps[6] = "IsRemote";
     103           0 :         aProps[7] = "IsRemoveable";
     104             : 
     105           0 :         ucbhelper::Content aContent(aURL, m_xCmdEnv, comphelper::getProcessComponentContext());
     106             : 
     107           0 :         uno::Reference< XResultSet > xResultSet;
     108           0 :         uno::Reference< XDynamicResultSet > xDynResultSet;
     109             : 
     110           0 :         ucbhelper::ResultSetInclude eInclude = ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
     111           0 :         xDynResultSet = aContent.createDynamicCursor( aProps, eInclude );
     112             : 
     113           0 :         if ( xDynResultSet.is() )
     114           0 :             xResultSet = xDynResultSet->getStaticResultSet();
     115             : 
     116           0 :         if ( xResultSet.is() )
     117             :         {
     118           0 :             pItem->clearTemplates();
     119             : 
     120           0 :             uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
     121           0 :             uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
     122             : 
     123           0 :             util::DateTime aDT;
     124           0 :             std::vector<TemplateItemProperties> aItems;
     125             : 
     126           0 :             sal_uInt16 nIdx = 0;
     127           0 :             while ( xResultSet->next() )
     128             :             {
     129           0 :                 bool bIsHidden = xRow->getBoolean( ROW_IS_HIDDEN );
     130             : 
     131             :                 // don't show hidden files or anything besides documents
     132           0 :                 if ( !bIsHidden || xRow->wasNull() )
     133             :                 {
     134           0 :                     aDT = xRow->getTimestamp( ROW_DATE_MOD );
     135           0 :                     bool bContainsDate = !xRow->wasNull();
     136             : 
     137           0 :                     if ( !bContainsDate )
     138             :                     {
     139           0 :                         aDT = xRow->getTimestamp( ROW_DATE_CREATE );
     140           0 :                         bContainsDate = !xRow->wasNull();
     141             :                     }
     142             : 
     143           0 :                     OUString aContentURL = xContentAccess->queryContentIdentifierString();
     144           0 :                     OUString aTargetURL = xRow->getString( ROW_TARGET_URL );
     145           0 :                     bool bHasTargetURL = !xRow->wasNull() && !aTargetURL.isEmpty();
     146             : 
     147           0 :                     OUString sRealURL = bHasTargetURL ? aTargetURL : aContentURL;
     148             : 
     149           0 :                     TemplateItemProperties aTemplateItem;
     150           0 :                     aTemplateItem.nId = nIdx+1;
     151           0 :                     aTemplateItem.nRegionId = pItem->mnId-1;
     152           0 :                     aTemplateItem.aPath = sRealURL;
     153             :                     aTemplateItem.aThumbnail = TemplateAbstractView::fetchThumbnail(sRealURL,
     154             :                                                                                     TEMPLATE_THUMBNAIL_MAX_WIDTH,
     155           0 :                                                                                     TEMPLATE_THUMBNAIL_MAX_HEIGHT);
     156             : //                    pData->mbIsRemote = xRow->getBoolean( ROW_IS_REMOTE ) && !xRow->wasNull();
     157             : //                    pData->mbIsRemoveable = xRow->getBoolean( ROW_IS_REMOVEABLE ) && !xRow->wasNull();
     158           0 :                     aTemplateItem.aName = xRow->getString( ROW_TITLE );
     159             : //                    pData->maSize = xRow->getLong( ROW_SIZE );
     160             : 
     161           0 :                     if ( bHasTargetURL &&
     162           0 :                         INetURLObject( aContentURL ).GetProtocol() == INET_PROT_VND_SUN_STAR_HIER )
     163             :                     {
     164           0 :                         ucbhelper::Content aCnt( aTargetURL, m_xCmdEnv, comphelper::getProcessComponentContext() );
     165             : 
     166             :                         try
     167             :                         {
     168             : //                            aCnt.getPropertyValue("Size") >>= pData->maSize;
     169           0 :                             aCnt.getPropertyValue("DateModified") >>= aDT;
     170             :                         }
     171           0 :                         catch (...)
     172           0 :                         {}
     173             :                     }
     174             : 
     175           0 :                     pItem->insertTemplate(aTemplateItem);
     176           0 :                     aItems.push_back(aTemplateItem);
     177           0 :                     ++nIdx;
     178             :                 }
     179             :             }
     180             : 
     181           0 :             mpItemView->InsertItems(aItems);
     182           0 :         }
     183             :     }
     184           0 :     catch( ucb::CommandAbortedException& )
     185             :     {
     186             :     }
     187           0 :     catch( uno::RuntimeException& )
     188             :     {
     189             :     }
     190           0 :     catch( uno::Exception& )
     191             :     {
     192             :     }
     193             : 
     194           0 :     return true;
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10