LCOV - code coverage report
Current view: top level - sd/source/ui/inc - TemplateScanner.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 11 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 9 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SD_SOURCE_UI_INC_TEMPLATESCANNER_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_INC_TEMPLATESCANNER_HXX
      22             : 
      23             : #include "tools/AsynchronousTask.hxx"
      24             : #include "sddllapi.h"
      25             : #include <ucbhelper/content.hxx>
      26             : #include "com/sun/star/uno/Reference.hxx"
      27             : 
      28             : #include <vector>
      29             : #include <boost/scoped_ptr.hpp>
      30             : #include <boost/shared_ptr.hpp>
      31             : 
      32             : namespace com { namespace sun { namespace star { namespace ucb {
      33             : class XContent;
      34             : class XCommandEnvironment;
      35             : } } } }
      36             : 
      37             : namespace com { namespace sun { namespace star { namespace sdbc {
      38             : class XResultSet;
      39             : } } } }
      40             : 
      41             : namespace comphelper { namespace string {
      42             : class NaturalStringSorter;
      43             : } }
      44             : 
      45             : namespace sd {
      46             : 
      47             : /** Representation of a template or layout file.
      48             : */
      49           0 : class TemplateEntry
      50             : {
      51             : public:
      52           0 :     TemplateEntry   (const OUString& rsTitle, const OUString& rsPath)
      53           0 :         :   msTitle(rsTitle), msPath(rsPath) {}
      54             : 
      55             :     OUString msTitle;
      56             :     OUString msPath;
      57             : };
      58             : 
      59             : /** Functor that compares two TemplateEntries based on their titles
      60             : */
      61           0 : class TemplateEntryCompare
      62             : {
      63             : public:
      64             :     TemplateEntryCompare();
      65             :     bool operator()(TemplateEntry* pA, TemplateEntry* pB) const;
      66             : 
      67             : private:
      68             :     ::boost::shared_ptr<comphelper::string::NaturalStringSorter> mpStringSorter;
      69             : };
      70             : 
      71             : /** Representation of a template or layout folder.
      72             : */
      73           0 : class TemplateDir
      74             : {
      75             : public:
      76           0 :     TemplateDir (const OUString& rsRegion, const OUString& rsUrl )
      77             :         :   msRegion(rsRegion), msUrl(rsUrl), maEntries(),
      78           0 :             mbSortingEnabled(false), mpEntryCompare(NULL) {}
      79             : 
      80             :     OUString msRegion;
      81             :     OUString msUrl;
      82             :     ::std::vector<TemplateEntry*> maEntries;
      83             : 
      84             :     void EnableSorting(bool bSortingEnabled = true);
      85             :     void InsertEntry(TemplateEntry* pNewEntry);
      86             : 
      87             : private:
      88             :     bool mbSortingEnabled;
      89             :     ::boost::scoped_ptr<TemplateEntryCompare> mpEntryCompare;
      90             : };
      91             : 
      92             : /** This class scans the template folders for impress templates.  There are
      93             :     two ways to use this class.
      94             :     1. The old and deprecated way is to call Scan() to scan all templates
      95             :     and collect the supported ones in a tree structure.  This structure is
      96             :     returned by GetFolderList().
      97             :     2. The new way implements the AsynchronousTask interface.  Call
      98             :     RunNextStep() as long HasNextStep() returns <TRUE/>.  After every step
      99             :     GetLastAddedEntry() returns the template that was scanned (and has a
     100             :     supported format) last.  When a step does not add a new template then
     101             :     the value of the previous step is returned.
     102             : */
     103             : class SD_DLLPUBLIC TemplateScanner
     104             :     : public ::sd::tools::AsynchronousTask
     105             : {
     106             : public:
     107             :     /** Create a new template scanner and prepare but do not execute the scanning.
     108             :     */
     109             :     TemplateScanner();
     110             : 
     111             :     /** The destructor deletes any remaining entries of the local list of
     112             :         templates.
     113             :     */
     114             :     virtual ~TemplateScanner();
     115             : 
     116             :     /** Execute the actual scanning of templates.  When this method
     117             :         terminates the result can be obtained by calling the
     118             :         <member>GetTemplateList</member> method.
     119             :     */
     120             :     void Scan();
     121             : 
     122             :     /** Return the list of template folders.  It lies in the responsibility
     123             :         of the caller to take ownership of some or all entries and remove
     124             :         them from the returned list.  All entries that remain until the
     125             :         destructor is called will be destroyed.
     126             :     */
     127           0 :     std::vector<TemplateDir*>& GetFolderList() { return maFolderList;}
     128             : 
     129             :     /** Implementation of the AsynchronousTask interface method.
     130             :     */
     131             :     virtual void RunNextStep() SAL_OVERRIDE;
     132             : 
     133             :     /** Implementation of the AsynchronousTask interface method.
     134             :     */
     135             :     virtual bool HasNextStep() SAL_OVERRIDE;
     136             : 
     137             :     /** Return the TemplateDir object that was last added to
     138             :         mpTemplateDirectory.
     139             :         @return
     140             :             <NULL/> is returned either before the template scanning is
     141             :             started or after it has ended.
     142             :     */
     143           0 :     const TemplateEntry* GetLastAddedEntry() const { return mpLastAddedEntry;}
     144             : 
     145             :     /** Set whether to sort the template entries inside the regions.
     146             :     */
     147           0 :     void EnableEntrySorting (bool isEntrySortingEnabled = true)
     148           0 :         {mbEntrySortingEnabled = isEntrySortingEnabled;}
     149             : 
     150             : private:
     151             :     /** The current state determines which step will be executed next by
     152             :         RunNextStep().
     153             :     */
     154             :     enum State {
     155             :         INITIALIZE_SCANNING,
     156             :         INITIALIZE_FOLDER_SCANNING,
     157             :         GATHER_FOLDER_LIST,
     158             :         SCAN_FOLDER,
     159             :         INITIALIZE_ENTRY_SCAN,
     160             :         SCAN_ENTRY,
     161             :         DONE,
     162             :         ERROR
     163             :     };
     164             :     State meState;
     165             : 
     166             :     ::ucbhelper::Content maFolderContent;
     167             :     TemplateDir* mpTemplateDirectory;
     168             : 
     169             :     /** The data structure that is to be filled with information about the
     170             :         template files.
     171             :     */
     172             :      std::vector<TemplateDir*> maFolderList;
     173             : 
     174             :     /** Whether the template entries have to be sorted.
     175             :     */
     176             :     bool mbEntrySortingEnabled;
     177             : 
     178             :     /** This member points into the maFolderList to the member that was most
     179             :         recently added.
     180             :     */
     181             :     TemplateEntry* mpLastAddedEntry;
     182             : 
     183             :     /** The folders that are collected by GatherFolderList().
     184             :     */
     185             :     class FolderDescriptorList;
     186             :     ::boost::scoped_ptr<FolderDescriptorList> mpFolderDescriptors;
     187             : 
     188             :     /** Set of state variables used by the methods
     189             :         InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
     190             :         InitializeEntryScanning(), and ScanEntry().
     191             :     */
     192             :     com::sun::star::uno::Reference<com::sun::star::ucb::XContent> mxTemplateRoot;
     193             :     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxFolderEnvironment;
     194             :     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxEntryEnvironment;
     195             :     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxFolderResultSet;
     196             :     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxEntryResultSet;
     197             : 
     198             :     /** Obtain the root folder of the template folder hierarchy.  The result
     199             :         is stored in mxTemplateRoot for later use.
     200             :     */
     201             :     State GetTemplateRoot();
     202             : 
     203             :     /** Initialize the scanning of folders.  This is called exactly once.
     204             :         @return
     205             :             Returns one of the two states ERROR or GATHER_FOLDER_LIST.
     206             :     */
     207             :     State InitializeFolderScanning();
     208             : 
     209             :     /** Collect all available top-level folders in an ordered list which can
     210             :         then be processed by ScanFolder().
     211             :         @return
     212             :             Returns one of the two states ERROR or SCAN_FOLDER.
     213             :     */
     214             :     State GatherFolderList();
     215             : 
     216             :     /** From the list of top-level folders collected by GatherFolderList()
     217             :         the one with highest priority is processed.
     218             :         @return
     219             :             Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
     220             :     */
     221             :     State ScanFolder();
     222             : 
     223             :     /** Initialize the scanning of entries of a top-level folder.
     224             :         @return
     225             :             Returns one of the states ERROR or SCAN_ENTRY.
     226             :     */
     227             :     State InitializeEntryScanning();
     228             : 
     229             :     /** Scan one entry.  When this entry matches the recognized template
     230             :         types it is appended to the result set.
     231             :         @return
     232             :             Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
     233             :     */
     234             :     State ScanEntry();
     235             : };
     236             : 
     237             : } // end of namespace sd
     238             : 
     239             : #endif
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11