LCOV - code coverage report
Current view: top level - sfx2/source/control - templatelocalview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 368 0.0 %
Date: 2012-08-25 Functions: 0 27 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 504 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Copyright 2012 LibreOffice contributors.
       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/templatelocalview.hxx>
      11                 :            : 
      12                 :            : #include <comphelper/processfactory.hxx>
      13                 :            : #include <sfx2/doctempl.hxx>
      14                 :            : #include <sfx2/templatelocalviewitem.hxx>
      15                 :            : #include <sfx2/templateview.hxx>
      16                 :            : #include <sfx2/templateviewitem.hxx>
      17                 :            : #include <svl/inettype.hxx>
      18                 :            : #include <svtools/imagemgr.hxx>
      19                 :            : #include <tools/urlobj.hxx>
      20                 :            : #include <unotools/ucbstreamhelper.hxx>
      21                 :            : #include <vcl/pngread.hxx>
      22                 :            : 
      23                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      24                 :            : #include <com/sun/star/embed/XStorage.hpp>
      25                 :            : #include <com/sun/star/frame/DocumentTemplates.hpp>
      26                 :            : #include <com/sun/star/lang/XComponent.hpp>
      27                 :            : #include <com/sun/star/frame/XDocumentTemplates.hpp>
      28                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29                 :            : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      30                 :            : 
      31                 :            : using namespace ::com::sun::star;
      32                 :            : using namespace ::com::sun::star::frame;
      33                 :            : 
      34                 :            : void lcl_updateThumbnails (TemplateLocalViewItem *pItem);
      35                 :            : 
      36                 :            : class FolderFilter_Application
      37                 :            : {
      38                 :            : public:
      39                 :            : 
      40                 :          0 :     FolderFilter_Application (FILTER_APPLICATION eApp)
      41                 :          0 :         : meApp(eApp)
      42                 :            :     {
      43                 :          0 :     }
      44                 :            : 
      45                 :          0 :     bool operator () (const ThumbnailViewItem *pItem)
      46                 :            :     {
      47                 :          0 :         TemplateLocalViewItem *pFolderItem = (TemplateLocalViewItem*)pItem;
      48                 :            : 
      49                 :          0 :         std::vector<TemplateItemProperties> &rTemplates = pFolderItem->maTemplates;
      50                 :            : 
      51                 :          0 :         size_t nVisCount = 0;
      52                 :            : 
      53                 :            :         // Clear thumbnails
      54                 :          0 :         pFolderItem->maPreview1.Clear();
      55                 :          0 :         pFolderItem->maPreview2.Clear();
      56                 :            : 
      57         [ #  # ]:          0 :         for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
      58                 :            :         {
      59         [ #  # ]:          0 :             if (isValid(rTemplates[i].aType))
      60                 :            :             {
      61                 :          0 :                 ++nVisCount;
      62                 :            : 
      63                 :            :                 // Update the thumbnails
      64         [ #  # ]:          0 :                 if (nVisCount == 1)
      65                 :          0 :                     pFolderItem->maPreview1 = rTemplates[i].aThumbnail;
      66         [ #  # ]:          0 :                 else if (nVisCount == 2)
      67                 :          0 :                     pFolderItem->maPreview2 = rTemplates[i].aThumbnail;
      68                 :            :             }
      69                 :            :         }
      70                 :            : 
      71 [ #  # ][ #  # ]:          0 :         return meApp != FILTER_APP_NONE ? nVisCount : true ;
      72                 :            :     }
      73                 :            : 
      74                 :          0 :     bool isValid (const OUString &rType) const
      75                 :            :     {
      76                 :          0 :         bool bRet = true;
      77                 :            : 
      78         [ #  # ]:          0 :         if (meApp == FILTER_APP_WRITER)
      79                 :            :         {
      80 [ #  # ][ #  # ]:          0 :             bRet = rType == "OpenDocument Text" || rType == "OpenDocument Text Template";
      81                 :            :         }
      82         [ #  # ]:          0 :         else if (meApp == FILTER_APP_CALC)
      83                 :            :         {
      84 [ #  # ][ #  # ]:          0 :             bRet = rType == "OpenDocument Spreadsheet" || rType == "OpenDocument Spreadsheet Template";
      85                 :            :         }
      86         [ #  # ]:          0 :         else if (meApp == FILTER_APP_IMPRESS)
      87                 :            :         {
      88 [ #  # ][ #  # ]:          0 :             bRet = rType == "OpenDocument Presentation" || rType == "OpenDocument Presentation Template";
      89                 :            :         }
      90         [ #  # ]:          0 :         else if (meApp == FILTER_APP_DRAW)
      91                 :            :         {
      92 [ #  # ][ #  # ]:          0 :             bRet = rType == "OpenDocument Drawing" || rType == "OpenDocument Drawing Template";
      93                 :            :         }
      94                 :            : 
      95                 :          0 :         return bRet;
      96                 :            :     }
      97                 :            : 
      98                 :            : private:
      99                 :            : 
     100                 :            :     FILTER_APPLICATION meApp;
     101                 :            : };
     102                 :            : 
     103                 :          0 : TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren)
     104                 :            :     : TemplateAbstractView(pParent,rResId,bDisableTransientChildren),
     105                 :            :       mbFilteredResults(false),
     106                 :            :       meFilterOption(FILTER_APP_NONE),
     107 [ #  # ][ #  # ]:          0 :       mpDocTemplates(new SfxDocumentTemplates)
     108                 :            : {
     109         [ #  # ]:          0 :     mpItemView->SetColor(Color(COL_WHITE));
     110         [ #  # ]:          0 :     mpItemView->setChangeNameHdl(LINK(this,TemplateLocalView,ChangeNameHdl));
     111                 :          0 : }
     112                 :            : 
     113                 :          0 : TemplateLocalView::~TemplateLocalView()
     114                 :            : {
     115 [ #  # ][ #  # ]:          0 :     delete mpDocTemplates;
     116         [ #  # ]:          0 : }
     117                 :            : 
     118                 :          0 : void TemplateLocalView::Populate ()
     119                 :            : {
     120                 :          0 :     sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
     121         [ #  # ]:          0 :     for (sal_uInt16 i = 0; i < nCount; ++i)
     122                 :            :     {
     123 [ #  # ][ #  # ]:          0 :         OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
                 [ #  # ]
     124                 :            : 
     125         [ #  # ]:          0 :         if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
     126                 :            :         {
     127                 :          0 :             aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
     128                 :          0 :             aRegionName += "...";
     129                 :            :         }
     130                 :            : 
     131 [ #  # ][ #  # ]:          0 :         TemplateLocalViewItem* pItem = new TemplateLocalViewItem( *this, this );
     132                 :          0 :         pItem->mnId = i+1;
     133                 :          0 :         pItem->maTitle = aRegionName;
     134 [ #  # ][ #  # ]:          0 :         pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     135                 :            : 
     136         [ #  # ]:          0 :         sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
     137                 :            : 
     138         [ #  # ]:          0 :         for (sal_uInt16 j = 0; j < nEntries; ++j)
     139                 :            :         {
     140 [ #  # ][ #  # ]:          0 :             OUString aName = mpDocTemplates->GetName(i,j);
     141 [ #  # ][ #  # ]:          0 :             OUString aURL = mpDocTemplates->GetPath(i,j);
                 [ #  # ]
     142 [ #  # ][ #  # ]:          0 :             OUString aType = SvFileInformationManager::GetDescription(INetURLObject(aURL));
         [ #  # ][ #  # ]
                 [ #  # ]
     143                 :            : 
     144         [ #  # ]:          0 :             if ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
     145                 :            :             {
     146                 :          0 :                 aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
     147                 :          0 :                 aName += "...";
     148                 :            :             }
     149                 :            : 
     150         [ #  # ]:          0 :             TemplateItemProperties aProperties;;
     151                 :          0 :             aProperties.nId = j+1;
     152                 :          0 :             aProperties.nDocId = j;
     153                 :          0 :             aProperties.nRegionId = i;
     154                 :          0 :             aProperties.aName = aName;
     155                 :          0 :             aProperties.aPath = aURL;
     156                 :          0 :             aProperties.aType = aType;
     157                 :            :             aProperties.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,
     158                 :            :                                                                           TEMPLATE_THUMBNAIL_MAX_WIDTH,
     159 [ #  # ][ #  # ]:          0 :                                                                           TEMPLATE_THUMBNAIL_MAX_HEIGHT);
                 [ #  # ]
     160                 :            : 
     161         [ #  # ]:          0 :             pItem->maTemplates.push_back(aProperties);
     162         [ #  # ]:          0 :         }
     163                 :            : 
     164         [ #  # ]:          0 :         lcl_updateThumbnails(pItem);
     165                 :            : 
     166         [ #  # ]:          0 :         mItemList.push_back(pItem);
     167                 :          0 :     }
     168                 :            : 
     169                 :          0 :     CalculateItemPositions();
     170                 :            : 
     171 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     172                 :          0 :         Invalidate();
     173                 :          0 : }
     174                 :            : 
     175                 :          0 : void TemplateLocalView::reload ()
     176                 :            : {
     177                 :          0 :     mpDocTemplates->Update();
     178                 :            : 
     179                 :          0 :     Clear();
     180                 :            : 
     181                 :          0 :     Populate();
     182                 :            : 
     183         [ #  # ]:          0 :     if (mpItemView->IsVisible())
     184                 :            :     {
     185                 :          0 :         sal_uInt16 nItemId = mpItemView->getId() + 1;
     186                 :            : 
     187         [ #  # ]:          0 :         for (size_t i = 0; i < mItemList.size(); ++i)
     188                 :            :         {
     189         [ #  # ]:          0 :             if (mItemList[i]->mnId == nItemId)
     190                 :            :             {
     191                 :          0 :                 mpItemView->Clear();
     192                 :          0 :                 mpItemView->InsertItems(static_cast<TemplateLocalViewItem*>(mItemList[i])->maTemplates);
     193                 :          0 :                 break;
     194                 :            :             }
     195                 :            :         }
     196                 :            :     }
     197                 :          0 : }
     198                 :            : 
     199                 :          0 : std::vector<OUString> TemplateLocalView::getFolderNames()
     200                 :            : {
     201                 :          0 :     size_t n = mItemList.size();
     202                 :          0 :     std::vector<OUString> ret(n);
     203                 :            : 
     204         [ #  # ]:          0 :     for (size_t i = 0; i < n; ++i)
     205         [ #  # ]:          0 :         ret[i] = mItemList[i]->maTitle;
     206                 :            : 
     207                 :          0 :     return ret;
     208                 :            : }
     209                 :            : 
     210                 :          0 : void TemplateLocalView::showOverlay (bool bVisible)
     211                 :            : {
     212                 :          0 :     mpItemView->Show(bVisible);
     213                 :            : 
     214                 :            :     // Clear items is the overlay is closed.
     215         [ #  # ]:          0 :     if (!bVisible)
     216                 :            :     {
     217                 :            :         // Check if the folder view needs to be filtered
     218         [ #  # ]:          0 :         if (mbFilteredResults)
     219                 :            :         {
     220 [ #  # ][ #  # ]:          0 :             filterItems(FolderFilter_Application(meFilterOption));
                 [ #  # ]
     221                 :            : 
     222                 :          0 :             mbFilteredResults = false;
     223                 :          0 :             meFilterOption = FILTER_APP_NONE;
     224                 :            :         }
     225                 :            : 
     226                 :          0 :         mpItemView->Clear();
     227                 :            : 
     228                 :          0 :         setSelectionMode(mbSelectionMode);
     229                 :            :     }
     230                 :          0 : }
     231                 :            : 
     232                 :          0 : void TemplateLocalView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
     233                 :            : {
     234                 :          0 :     meFilterOption = eApp;
     235                 :            : 
     236         [ #  # ]:          0 :     if (mpItemView->IsVisible())
     237                 :            :     {
     238                 :          0 :         mbFilteredResults = true;
     239 [ #  # ][ #  # ]:          0 :         mpItemView->filterItems(ViewFilter_Application(eApp));
                 [ #  # ]
     240                 :            :     }
     241                 :            :     else
     242                 :            :     {
     243 [ #  # ][ #  # ]:          0 :         filterItems(FolderFilter_Application(eApp));
                 [ #  # ]
     244                 :            :     }
     245                 :          0 : }
     246                 :            : 
     247                 :            : std::vector<TemplateItemProperties>
     248                 :          0 : TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateItemProperties&) > &rFunc) const
     249                 :            : {
     250                 :          0 :     std::vector<TemplateItemProperties> aItems;
     251                 :            : 
     252         [ #  # ]:          0 :     for (size_t i = 0; i < mItemList.size(); ++i)
     253                 :            :     {
     254         [ #  # ]:          0 :         TemplateLocalViewItem *pFolderItem = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     255                 :            : 
     256         [ #  # ]:          0 :         for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
     257                 :            :         {
     258 [ #  # ][ #  # ]:          0 :             if (rFunc(pFolderItem->maTemplates[j]))
     259         [ #  # ]:          0 :                 aItems.push_back(pFolderItem->maTemplates[j]);
     260                 :            :         }
     261                 :            :     }
     262                 :            : 
     263                 :          0 :     return aItems;
     264                 :            : }
     265                 :            : 
     266                 :          0 : sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
     267                 :            : {
     268         [ #  # ]:          0 :     sal_uInt16 nRegionId = mpDocTemplates->GetRegionCount();    // Next regionId
     269                 :            : 
     270 [ #  # ][ #  # ]:          0 :     if (!mpDocTemplates->InsertDir(rName,nRegionId))
         [ #  # ][ #  # ]
     271                 :          0 :         return false;
     272                 :            : 
     273                 :          0 :     OUString aRegionName = rName;
     274                 :            : 
     275         [ #  # ]:          0 :     if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
     276                 :            :     {
     277                 :          0 :         aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
     278                 :          0 :         aRegionName += "...";
     279                 :            :     }
     280                 :            : 
     281 [ #  # ][ #  # ]:          0 :     TemplateLocalViewItem* pItem = new TemplateLocalViewItem( *this, this );
     282                 :          0 :     pItem->mnId = nRegionId+1;
     283                 :          0 :     pItem->maTitle = aRegionName;
     284 [ #  # ][ #  # ]:          0 :     pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     285                 :            : 
     286         [ #  # ]:          0 :     mItemList.push_back(pItem);
     287                 :            : 
     288         [ #  # ]:          0 :     CalculateItemPositions();
     289                 :            : 
     290 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
         [ #  # ][ #  # ]
                 [ #  # ]
     291         [ #  # ]:          0 :         Invalidate();
     292                 :            : 
     293                 :          0 :     return pItem->mnId;
     294                 :            : }
     295                 :            : 
     296                 :          0 : bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
     297                 :            : {
     298                 :          0 :     sal_uInt16 nRegionId = nItemId - 1;
     299                 :            : 
     300         [ #  # ]:          0 :     if (!mpDocTemplates->Delete(nRegionId,USHRT_MAX))
     301                 :          0 :         return false;
     302                 :            : 
     303                 :          0 :     RemoveItem(nItemId);
     304                 :            : 
     305                 :          0 :     return true;
     306                 :            : }
     307                 :            : 
     308                 :          0 : bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId)
     309                 :            : {
     310                 :          0 :     sal_uInt16 nRegionId = nSrcItemId - 1;
     311                 :            : 
     312         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     313                 :            :     {
     314         [ #  # ]:          0 :         if (mItemList[i]->mnId == nSrcItemId)
     315                 :            :         {
     316         [ #  # ]:          0 :             TemplateLocalViewItem *pItem = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     317                 :          0 :             std::vector<TemplateItemProperties>::iterator pIter;
     318 [ #  # ][ #  # ]:          0 :             for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter)
     319                 :            :             {
     320         [ #  # ]:          0 :                 if (pIter->nId == nItemId)
     321                 :            :                 {
     322 [ #  # ][ #  # ]:          0 :                     if (!mpDocTemplates->Delete(nRegionId,pIter->nDocId))
     323                 :          0 :                         return false;
     324                 :            : 
     325         [ #  # ]:          0 :                     pIter = pItem->maTemplates.erase(pIter);
     326                 :            : 
     327         [ #  # ]:          0 :                     mpItemView->RemoveItem(nItemId);
     328                 :            : 
     329                 :            :                     // Update Doc Idx for all templates that follow
     330 [ #  # ][ #  # ]:          0 :                     for (; pIter != pItem->maTemplates.end(); ++pIter)
     331                 :          0 :                         pIter->nDocId = pIter->nDocId - 1;
     332                 :            : 
     333                 :          0 :                     break;
     334                 :            :                 }
     335                 :            :             }
     336                 :            : 
     337         [ #  # ]:          0 :             lcl_updateThumbnails(pItem);
     338                 :            : 
     339         [ #  # ]:          0 :             CalculateItemPositions();
     340                 :            : 
     341                 :            :             break;
     342                 :            :         }
     343                 :            :     }
     344                 :            : 
     345                 :          0 :     return true;
     346                 :            : }
     347                 :            : 
     348                 :          0 : bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem,
     349                 :            :                                        const sal_uInt16 nTargetItem, bool bCopy)
     350                 :            : {
     351                 :          0 :     bool bRet = true;
     352                 :          0 :     bool bRefresh = false;
     353                 :            : 
     354                 :          0 :     TemplateLocalViewItem *pTarget = NULL;
     355                 :          0 :     TemplateLocalViewItem *pSrc = NULL;
     356                 :            : 
     357         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     358                 :            :     {
     359         [ #  # ]:          0 :         if (mItemList[i]->mnId == nTargetItem)
     360                 :          0 :             pTarget = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     361         [ #  # ]:          0 :         else if (mItemList[i]->mnId == nSrcItem)
     362                 :          0 :             pSrc = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     363                 :            :     }
     364                 :            : 
     365 [ #  # ][ #  # ]:          0 :     if (pTarget && pSrc)
     366                 :            :     {
     367                 :          0 :         sal_uInt16 nSrcRegionId = nSrcItem-1;
     368                 :          0 :         sal_uInt16 nTargetRegion = pTarget->mnId-1;
     369         [ #  # ]:          0 :         sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion);    // Next Idx
     370                 :            : 
     371                 :          0 :         const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
     372                 :            : 
     373                 :            :         bool bOK;
     374                 :            : 
     375         [ #  # ]:          0 :         if (bCopy)
     376         [ #  # ]:          0 :             bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
     377                 :            :         else
     378         [ #  # ]:          0 :             bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
     379                 :            : 
     380         [ #  # ]:          0 :         if (!bOK)
     381                 :          0 :             return false;
     382                 :            : 
     383                 :            :         // move template to destination
     384                 :            : 
     385         [ #  # ]:          0 :         TemplateItemProperties aTemplateItem;
     386                 :          0 :         aTemplateItem.nId = nTargetIdx + 1;
     387                 :          0 :         aTemplateItem.nDocId = nTargetIdx;
     388                 :          0 :         aTemplateItem.nRegionId = nTargetRegion;
     389                 :          0 :         aTemplateItem.aName = pViewItem->maTitle;
     390                 :          0 :         aTemplateItem.aPath = pViewItem->getPath();
     391                 :          0 :         aTemplateItem.aType = pViewItem->getFileType();
     392         [ #  # ]:          0 :         aTemplateItem.aThumbnail = pViewItem->maPreview1;
     393                 :            : 
     394         [ #  # ]:          0 :         pTarget->maTemplates.push_back(aTemplateItem);
     395                 :            : 
     396         [ #  # ]:          0 :         if (!bCopy)
     397                 :            :         {
     398                 :            :             // remove template from overlay and from cached data
     399                 :            : 
     400                 :          0 :             std::vector<TemplateItemProperties>::iterator aIter;
     401 [ #  # ][ #  # ]:          0 :             for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter)
     402                 :            :             {
     403         [ #  # ]:          0 :                 if (aIter->nId == pViewItem->mnId)
     404                 :            :                 {
     405         [ #  # ]:          0 :                     pSrc->maTemplates.erase(aIter);
     406                 :            : 
     407         [ #  # ]:          0 :                     mpItemView->RemoveItem(pViewItem->mnId);
     408                 :          0 :                     break;
     409                 :            :                 }
     410                 :            :             }
     411                 :            :         }
     412                 :            : 
     413         [ #  # ]:          0 :         bRefresh = true;
     414                 :            :     }
     415                 :            :     else
     416                 :          0 :         bRet = false;
     417                 :            : 
     418         [ #  # ]:          0 :     if (bRefresh)
     419                 :            :     {
     420                 :          0 :         lcl_updateThumbnails(pSrc);
     421                 :          0 :         lcl_updateThumbnails(pTarget);
     422                 :            : 
     423                 :          0 :         CalculateItemPositions();
     424                 :            : 
     425 [ #  # ][ #  # ]:          0 :         if (IsReallyVisible() && IsUpdateMode())
                 [ #  # ]
     426                 :            :         {
     427                 :          0 :             Invalidate();
     428                 :          0 :             mpItemView->Invalidate();
     429                 :            :         }
     430                 :            :     }
     431                 :            : 
     432                 :          0 :     return bRet;
     433                 :            : }
     434                 :            : 
     435                 :          0 : bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems,
     436                 :            :                                        const sal_uInt16 nTargetItem, bool bCopy)
     437                 :            : {
     438                 :          0 :     bool ret = true;
     439                 :          0 :     bool refresh = false;
     440                 :            : 
     441                 :          0 :     sal_uInt16 nSrcRegionId = mpItemView->getId();
     442                 :          0 :     sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
     443                 :            : 
     444                 :          0 :     TemplateLocalViewItem *pTarget = NULL;
     445                 :          0 :     TemplateLocalViewItem *pSrc = NULL;
     446                 :            : 
     447         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     448                 :            :     {
     449         [ #  # ]:          0 :         if (mItemList[i]->mnId == nTargetItem)
     450                 :          0 :             pTarget = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     451         [ #  # ]:          0 :         else if (mItemList[i]->mnId == nSrcRegionItemId)
     452                 :          0 :             pSrc = static_cast<TemplateLocalViewItem*>(mItemList[i]);
     453                 :            :     }
     454                 :            : 
     455 [ #  # ][ #  # ]:          0 :     if (pTarget && pSrc)
     456                 :            :     {
     457                 :          0 :         sal_uInt16 nTargetRegion = pTarget->mnId-1;
     458         [ #  # ]:          0 :         sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion);    // Next Idx
     459                 :            : 
     460         [ #  # ]:          0 :         std::set<const ThumbnailViewItem*>::iterator aSelIter;
     461 [ #  # ][ #  # ]:          0 :         for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
                 [ #  # ]
     462                 :            :         {
     463         [ #  # ]:          0 :             const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
     464                 :            : 
     465                 :            :             bool bOK;
     466                 :            : 
     467         [ #  # ]:          0 :             if (bCopy)
     468         [ #  # ]:          0 :                 bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
     469                 :            :             else
     470         [ #  # ]:          0 :                 bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
     471                 :            : 
     472         [ #  # ]:          0 :             if (!bOK)
     473                 :            :             {
     474                 :          0 :                 ret = false;
     475                 :          0 :                 continue;
     476                 :            :             }
     477                 :            : 
     478                 :            :             // move template to destination
     479                 :            : 
     480         [ #  # ]:          0 :             TemplateItemProperties aTemplateItem;
     481                 :          0 :             aTemplateItem.nId = nTargetIdx + 1;
     482                 :          0 :             aTemplateItem.nDocId = nTargetIdx;
     483                 :          0 :             aTemplateItem.nRegionId = nTargetRegion;
     484                 :          0 :             aTemplateItem.aName = pViewItem->maTitle;
     485                 :          0 :             aTemplateItem.aPath = pViewItem->getPath();
     486                 :          0 :             aTemplateItem.aType = pViewItem->getFileType();
     487         [ #  # ]:          0 :             aTemplateItem.aThumbnail = pViewItem->maPreview1;
     488                 :            : 
     489         [ #  # ]:          0 :             pTarget->maTemplates.push_back(aTemplateItem);
     490                 :            : 
     491         [ #  # ]:          0 :             if (!bCopy)
     492                 :            :             {
     493                 :            :                 // remove template from overlay and from cached data
     494                 :            : 
     495                 :          0 :                 std::vector<TemplateItemProperties>::iterator pIter;
     496 [ #  # ][ #  # ]:          0 :                 for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter)
     497                 :            :                 {
     498         [ #  # ]:          0 :                     if (pIter->nId == pViewItem->mnId)
     499                 :            :                     {
     500         [ #  # ]:          0 :                         pSrc->maTemplates.erase(pIter);
     501                 :            : 
     502         [ #  # ]:          0 :                         mpItemView->RemoveItem(pViewItem->mnId);
     503                 :          0 :                         break;
     504                 :            :                     }
     505                 :            :                 }
     506                 :            :             }
     507                 :            : 
     508                 :          0 :             refresh = true;
     509         [ #  # ]:          0 :         }
     510                 :            :     }
     511                 :            :     else
     512                 :          0 :         ret = false;
     513                 :            : 
     514         [ #  # ]:          0 :     if (refresh)
     515                 :            :     {
     516                 :          0 :         lcl_updateThumbnails(pSrc);
     517                 :          0 :         lcl_updateThumbnails(pTarget);
     518                 :            : 
     519                 :          0 :         CalculateItemPositions();
     520                 :            : 
     521                 :          0 :         Invalidate();
     522                 :          0 :         mpItemView->Invalidate();
     523                 :            :     }
     524                 :            : 
     525                 :          0 :     return ret;
     526                 :            : }
     527                 :            : 
     528                 :          0 : bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail,
     529                 :            :                                   const OUString &rPath)
     530                 :            : {
     531                 :          0 :     sal_uInt16 nRegionId = nRegionItemId - 1;
     532                 :            : 
     533         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     534                 :            :     {
     535         [ #  # ]:          0 :         if (mItemList[i]->mnId == nRegionItemId)
     536                 :            :         {
     537                 :          0 :             sal_uInt16 nId = 0;
     538                 :          0 :             sal_uInt16 nDocId = 0;
     539                 :            : 
     540                 :            :             TemplateLocalViewItem *pRegionItem =
     541         [ #  # ]:          0 :                     static_cast<TemplateLocalViewItem*>(mItemList[i]);
     542                 :            : 
     543         [ #  # ]:          0 :             if (!pRegionItem->maTemplates.empty())
     544                 :            :             {
     545         [ #  # ]:          0 :                 nId = (pRegionItem->maTemplates.back()).nId+1;
     546         [ #  # ]:          0 :                 nDocId = (pRegionItem->maTemplates.back()).nDocId+1;
     547                 :            :             }
     548                 :            : 
     549         [ #  # ]:          0 :             String aPath(rPath);
     550                 :            : 
     551 [ #  # ][ #  # ]:          0 :             if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath))
     552                 :            :             {
     553         [ #  # ]:          0 :                 TemplateItemProperties aTemplate;
     554                 :          0 :                 aTemplate.nId = nId;
     555                 :          0 :                 aTemplate.nDocId = nDocId;
     556                 :          0 :                 aTemplate.nRegionId = nRegionId;
     557         [ #  # ]:          0 :                 aTemplate.aName = aPath;
     558         [ #  # ]:          0 :                 aTemplate.aThumbnail = rThumbnail;
     559 [ #  # ][ #  # ]:          0 :                 aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nDocId);
                 [ #  # ]
     560 [ #  # ][ #  # ]:          0 :                 aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(aTemplate.aPath));
         [ #  # ][ #  # ]
                 [ #  # ]
     561                 :            : 
     562                 :            :                 TemplateLocalViewItem *pItem =
     563         [ #  # ]:          0 :                         static_cast<TemplateLocalViewItem*>(mItemList[i]);
     564                 :            : 
     565         [ #  # ]:          0 :                 pItem->maTemplates.push_back(aTemplate);
     566                 :            : 
     567         [ #  # ]:          0 :                 lcl_updateThumbnails(pItem);
     568                 :            : 
     569         [ #  # ]:          0 :                 return true;
     570                 :            :             }
     571                 :            : 
     572 [ #  # ][ #  # ]:          0 :             break;
     573                 :            :         }
     574                 :            :     }
     575                 :            : 
     576                 :          0 :     return false;
     577                 :            : }
     578                 :            : 
     579                 :          0 : bool TemplateLocalView::copyFrom (TemplateLocalViewItem *pItem, const OUString &rPath)
     580                 :            : {
     581                 :          0 :     sal_uInt16 nId = 0;
     582                 :          0 :     sal_uInt16 nDocId = 0;
     583                 :          0 :     sal_uInt16 nRegionId = pItem->mnId - 1;
     584         [ #  # ]:          0 :     String aPath(rPath);
     585                 :            : 
     586         [ #  # ]:          0 :     if (!pItem->maTemplates.empty())
     587                 :            :     {
     588         [ #  # ]:          0 :         nId = (pItem->maTemplates.back()).nId+1;
     589         [ #  # ]:          0 :         nDocId = (pItem->maTemplates.back()).nDocId+1;
     590                 :            :     }
     591                 :            : 
     592 [ #  # ][ #  # ]:          0 :     if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath))
     593                 :            :     {
     594         [ #  # ]:          0 :         TemplateItemProperties aTemplate;
     595                 :          0 :         aTemplate.nId = nId;
     596                 :          0 :         aTemplate.nDocId = nDocId;
     597                 :          0 :         aTemplate.nRegionId = nRegionId;
     598         [ #  # ]:          0 :         aTemplate.aName = aPath;
     599                 :            :         aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,
     600                 :            :                                                                     TEMPLATE_THUMBNAIL_MAX_WIDTH,
     601 [ #  # ][ #  # ]:          0 :                                                                     TEMPLATE_THUMBNAIL_MAX_HEIGHT);
                 [ #  # ]
     602                 :          0 :         aTemplate.aPath = rPath;
     603 [ #  # ][ #  # ]:          0 :         aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(rPath));
         [ #  # ][ #  # ]
                 [ #  # ]
     604                 :            : 
     605         [ #  # ]:          0 :         pItem->maTemplates.push_back(aTemplate);
     606                 :            : 
     607         [ #  # ]:          0 :         lcl_updateThumbnails(pItem);
     608                 :            : 
     609         [ #  # ]:          0 :         CalculateItemPositions();
     610                 :            : 
     611         [ #  # ]:          0 :         return true;
     612                 :            :     }
     613                 :            : 
     614         [ #  # ]:          0 :     return false;
     615                 :            : }
     616                 :            : 
     617                 :          0 : bool TemplateLocalView::exportTo(const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName)
     618                 :            : {
     619                 :          0 :     sal_uInt16 nRegionId = nRegionItemId - 1;
     620                 :            : 
     621         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     622                 :            :     {
     623         [ #  # ]:          0 :         if (mItemList[i]->mnId == nRegionItemId)
     624                 :            :         {
     625                 :            :             TemplateLocalViewItem *pRegItem =
     626         [ #  # ]:          0 :                     static_cast<TemplateLocalViewItem*>(mItemList[i]);
     627                 :            : 
     628                 :          0 :             std::vector<TemplateItemProperties>::iterator aIter;
     629 [ #  # ][ #  # ]:          0 :             for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
     630                 :            :             {
     631         [ #  # ]:          0 :                 if (aIter->nId == nItemId)
     632                 :            :                 {
     633 [ #  # ][ #  # ]:          0 :                     if (!mpDocTemplates->CopyTo(nRegionId,aIter->nDocId,rName))
         [ #  # ][ #  # ]
     634                 :          0 :                         return false;
     635                 :            : 
     636                 :          0 :                     return true;
     637                 :            :                 }
     638                 :            :             }
     639                 :            : 
     640                 :            :             break;
     641                 :            :         }
     642                 :            :     }
     643                 :            : 
     644                 :          0 :     return false;
     645                 :            : }
     646                 :            : 
     647                 :          0 : bool TemplateLocalView::saveTemplateAs (sal_uInt16 nItemId,
     648                 :            :                                         com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
     649                 :            :                                         const OUString &rName)
     650                 :            : {
     651                 :          0 :     bool bRet = false;
     652                 :            : 
     653         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     654                 :            :     {
     655         [ #  # ]:          0 :         if (mItemList[i]->mnId == nItemId)
     656                 :            :         {
     657                 :          0 :             bRet = saveTemplateAs((const TemplateLocalViewItem*)mItemList[i],rModel,rName);
     658                 :          0 :             break;
     659                 :            :         }
     660                 :            :     }
     661                 :            : 
     662                 :          0 :     return bRet;
     663                 :            : }
     664                 :            : 
     665                 :          0 : bool TemplateLocalView::saveTemplateAs(const TemplateLocalViewItem *pDstItem,
     666                 :            :                                        com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
     667                 :            :                                        const OUString &rName)
     668                 :            : {
     669         [ #  # ]:          0 :     uno::Reference< frame::XStorable > xStorable(rModel, uno::UNO_QUERY_THROW );
     670                 :            : 
     671                 :            :     uno::Reference< frame::XDocumentTemplates > xTemplates(
     672 [ #  # ][ #  # ]:          0 :                     frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
     673                 :            : 
     674                 :          0 :     sal_uInt16 nRegionId = pDstItem->mnId-1;
     675                 :            : 
     676 [ #  # ][ #  # ]:          0 :     if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(nRegionId),rName, xStorable ))
         [ #  # ][ #  # ]
                 [ #  # ]
     677                 :          0 :         return false;
     678                 :            : 
     679                 :          0 :     return true;
     680                 :            : }
     681                 :            : 
     682                 :          0 : bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, const OUString &rName) const
     683                 :            : {
     684         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     685                 :            :     {
     686         [ #  # ]:          0 :         if (mItemList[i]->mnId == nRegionItemId)
     687                 :            :         {
     688                 :            :             TemplateLocalViewItem *pRegItem =
     689         [ #  # ]:          0 :                     static_cast<TemplateLocalViewItem*>(mItemList[i]);
     690                 :            : 
     691                 :          0 :             std::vector<TemplateItemProperties>::iterator aIter;
     692 [ #  # ][ #  # ]:          0 :             for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
     693                 :            :             {
     694         [ #  # ]:          0 :                 if (aIter->aName == rName)
     695                 :          0 :                     return false;
     696                 :            :             }
     697                 :            : 
     698                 :            :             break;
     699                 :            :         }
     700                 :            :     }
     701                 :            : 
     702                 :          0 :     return true;
     703                 :            : }
     704                 :            : 
     705                 :          0 : void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pRegionItem)
     706                 :            : {
     707                 :            :     // Fill templates
     708                 :          0 :     sal_uInt16 nRegionId = pRegionItem->mnId-1;
     709                 :            : 
     710                 :          0 :     mpItemView->setId(nRegionId);
     711         [ #  # ]:          0 :     mpItemView->setName(mpDocTemplates->GetRegionName(nRegionId));
     712                 :          0 :     mpItemView->InsertItems(static_cast<TemplateLocalViewItem*>(pRegionItem)->maTemplates);
     713                 :            : 
     714         [ #  # ]:          0 :     if (mbSelectionMode)
     715                 :          0 :         mpItemView->setSelectionMode(true);
     716                 :            : 
     717 [ #  # ][ #  # ]:          0 :     mpItemView->filterItems(ViewFilter_Application(meFilterOption));
                 [ #  # ]
     718                 :            : 
     719                 :          0 :     mpItemView->Show();
     720                 :          0 : }
     721                 :            : 
     722                 :          0 : IMPL_LINK(TemplateLocalView, ChangeNameHdl, TemplateView*, pView)
     723                 :            : {
     724                 :          0 :     sal_uInt16 nRegionId = pView->getId();
     725                 :          0 :     sal_uInt16 nItemId = nRegionId + 1;
     726                 :            : 
     727 [ #  # ][ #  # ]:          0 :     if (!mpDocTemplates->SetName(pView->getName(),nRegionId,USHRT_MAX))
     728                 :          0 :         return false;
     729                 :            : 
     730         [ #  # ]:          0 :     for (size_t i = 0; i < mItemList.size(); ++i)
     731                 :            :     {
     732         [ #  # ]:          0 :         if (mItemList[i]->mnId == nItemId)
     733                 :            :         {
     734                 :          0 :             mItemList[i]->maTitle = pView->getName();
     735                 :          0 :             mItemList[i]->calculateItemsPosition(mnThumbnailHeight,mnDisplayHeight,
     736                 :          0 :                                                  mnItemPadding,mpItemAttrs->nMaxTextLenght,mpItemAttrs);
     737                 :          0 :             Invalidate();
     738                 :          0 :             break;
     739                 :            :         }
     740                 :            :     }
     741                 :            : 
     742                 :          0 :     return true;
     743                 :            : }
     744                 :            : 
     745                 :          0 : void lcl_updateThumbnails (TemplateLocalViewItem *pItem)
     746                 :            : {
     747                 :          0 :     pItem->maPreview1.Clear();
     748                 :          0 :     pItem->maPreview2.Clear();
     749                 :            : 
     750                 :            :     // Update folder thumbnails
     751 [ #  # ][ #  # ]:          0 :     for (size_t i = 0, n = pItem->maTemplates.size(); i < 2 && i < n; ++i)
                 [ #  # ]
     752                 :            :     {
     753         [ #  # ]:          0 :         if (i == 0)
     754                 :            :         {
     755                 :          0 :             pItem->maPreview1 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
     756                 :            :                                                                TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
     757         [ #  # ]:          0 :                                                                TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
     758                 :            :         }
     759                 :            :         else
     760                 :            :         {
     761                 :          0 :             pItem->maPreview2 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
     762                 :            :                                                                TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
     763         [ #  # ]:          0 :                                                                TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
     764                 :            :         }
     765                 :            :     }
     766                 :          0 : }
     767                 :            : 
     768                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10