LCOV - code coverage report
Current view: top level - sd/source/ui/inc - TemplateScanner.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 9 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 10 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _TEMPLATE_SCANNER_HXX
      30                 :            : #define _TEMPLATE_SCANNER_HXX
      31                 :            : 
      32                 :            : #include "tools/AsynchronousTask.hxx"
      33                 :            : #include "sddllapi.h"
      34                 :            : #include <ucbhelper/content.hxx>
      35                 :            : #include <tools/string.hxx>
      36                 :            : #include "com/sun/star/uno/Reference.hxx"
      37                 :            : 
      38                 :            : #include <vector>
      39                 :            : #include <boost/scoped_ptr.hpp>
      40                 :            : #include <boost/shared_ptr.hpp>
      41                 :            : 
      42                 :            : namespace com { namespace sun { namespace star { namespace ucb {
      43                 :            : class XContent;
      44                 :            : class XCommandEnvironment;
      45                 :            : } } } }
      46                 :            : 
      47                 :            : namespace com { namespace sun { namespace star { namespace sdbc {
      48                 :            : class XResultSet;
      49                 :            : } } } }
      50                 :            : 
      51                 :            : namespace comphelper { namespace string {
      52                 :            : class NaturalStringSorter;
      53                 :            : } }
      54                 :            : 
      55                 :            : namespace sd {
      56                 :            : 
      57                 :            : /** Representation of a template or layout file.
      58                 :            : */
      59                 :          0 : class TemplateEntry
      60                 :            : {
      61                 :            : public:
      62                 :          0 :     TemplateEntry   (const String& rsTitle, const String& rsPath)
      63         [ #  # ]:          0 :         :   msTitle(rsTitle), msPath(rsPath) {}
      64                 :            : 
      65                 :            :     String msTitle;
      66                 :            :     String msPath;
      67                 :            : };
      68                 :            : 
      69                 :            : 
      70                 :            : 
      71                 :            : 
      72                 :            : /** Functor that compares two TemplateEntries based on their titles
      73                 :            : */
      74                 :          0 : class TemplateEntryCompare
      75                 :            : {
      76                 :            : public:
      77                 :            :     TemplateEntryCompare();
      78                 :            :     bool operator()(TemplateEntry* pA, TemplateEntry* pB) const;
      79                 :            : 
      80                 :            : private:
      81                 :            :     ::boost::shared_ptr<comphelper::string::NaturalStringSorter> mpStringSorter;
      82                 :            : };
      83                 :            : 
      84                 :            : 
      85                 :            : 
      86                 :            : 
      87                 :            : /** Representation of a template or layout folder.
      88                 :            : */
      89 [ #  # ][ #  # ]:          0 : class TemplateDir
      90                 :            : {
      91                 :            : public:
      92                 :          0 :     TemplateDir (const String& rsRegion, const String& rsUrl )
      93                 :            :         :   msRegion(rsRegion), msUrl(rsUrl), maEntries(),
      94 [ #  # ][ #  # ]:          0 :             mbSortingEnabled(false), mpEntryCompare(NULL) {}
      95                 :            : 
      96                 :            :     String msRegion;
      97                 :            :     String msUrl;
      98                 :            :     ::std::vector<TemplateEntry*> maEntries;
      99                 :            : 
     100                 :            :     void EnableSorting(bool bSortingEnabled = true);
     101                 :            :     void InsertEntry(TemplateEntry* pNewEntry);
     102                 :            : 
     103                 :            : private:
     104                 :            :     bool mbSortingEnabled;
     105                 :            :     ::boost::scoped_ptr<TemplateEntryCompare> mpEntryCompare;
     106                 :            : };
     107                 :            : 
     108                 :            : 
     109                 :            : 
     110                 :            : 
     111                 :            : /** This class scans the template folders for impress templates.  There are
     112                 :            :     two ways to use this class.
     113                 :            :     1. The old and deprecated way is to call Scan() to scan all templates
     114                 :            :     and collect the supported ones in a tree structure.  This structure is
     115                 :            :     returned by GetFolderList().
     116                 :            :     2. The new way implements the AsynchronousTask interface.  Call
     117                 :            :     RunNextStep() as long HasNextStep() returns <TRUE/>.  After every step
     118                 :            :     GetLastAddedEntry() returns the template that was scanned (and has a
     119                 :            :     supported format) last.  When a step does not add a new template then
     120                 :            :     the value of the previous step is returned.
     121                 :            : */
     122                 :            : class SD_DLLPUBLIC TemplateScanner
     123                 :            :     : public ::sd::tools::AsynchronousTask
     124                 :            : {
     125                 :            : public:
     126                 :            :     /** Create a new template scanner and prepare but do not execute the scanning.
     127                 :            :     */
     128                 :            :     TemplateScanner (void);
     129                 :            : 
     130                 :            :     /** The destructor deletes any remaining entries of the local list of
     131                 :            :         templates.
     132                 :            :     */
     133                 :            :     virtual ~TemplateScanner (void);
     134                 :            : 
     135                 :            :     /** Execute the actual scanning of templates.  When this method
     136                 :            :         terminates the result can be obtained by calling the
     137                 :            :         <member>GetTemplateList</member> method.
     138                 :            :     */
     139                 :            :     void Scan (void);
     140                 :            : 
     141                 :            :     /** Return the list of template folders.  It lies in the responsibility
     142                 :            :         of the caller to take ownership of some or all entries and remove
     143                 :            :         them from the returned list.  All entries that remain until the
     144                 :            :         destructor is called will be destroyed.
     145                 :            :     */
     146                 :            :     std::vector<TemplateDir*>& GetFolderList (void);
     147                 :            : 
     148                 :            :     /** Implementation of the AsynchronousTask interface method.
     149                 :            :     */
     150                 :            :     virtual void RunNextStep (void);
     151                 :            : 
     152                 :            :     /** Implementation of the AsynchronousTask interface method.
     153                 :            :     */
     154                 :            :     virtual bool HasNextStep (void);
     155                 :            : 
     156                 :            :     /** Return the TemplateDir object that was last added to
     157                 :            :         mpTemplateDirectory.
     158                 :            :         @return
     159                 :            :             <NULL/> is returned either before the template scanning is
     160                 :            :             started or after it has ended.
     161                 :            :     */
     162                 :            :     const TemplateEntry* GetLastAddedEntry (void) const;
     163                 :            : 
     164                 :            :     /** Set whether to sort the template entries inside the regions.
     165                 :            :     */
     166                 :          0 :     void EnableEntrySorting (bool isEntrySortingEnabled = true)
     167                 :          0 :         {mbEntrySortingEnabled = isEntrySortingEnabled;}
     168                 :            : 
     169                 :            : private:
     170                 :            :     /** The current state determines which step will be executed next by
     171                 :            :         RunNextStep().
     172                 :            :     */
     173                 :            :     enum State {
     174                 :            :         INITIALIZE_SCANNING,
     175                 :            :         INITIALIZE_FOLDER_SCANNING,
     176                 :            :         GATHER_FOLDER_LIST,
     177                 :            :         SCAN_FOLDER,
     178                 :            :         INITIALIZE_ENTRY_SCAN,
     179                 :            :         SCAN_ENTRY,
     180                 :            :         DONE,
     181                 :            :         ERROR
     182                 :            :     };
     183                 :            :     State meState;
     184                 :            : 
     185                 :            :     ::ucbhelper::Content maFolderContent;
     186                 :            :     TemplateDir* mpTemplateDirectory;
     187                 :            : 
     188                 :            :     /** The data structure that is to be filled with information about the
     189                 :            :         template files.
     190                 :            :     */
     191                 :            :      std::vector<TemplateDir*> maFolderList;
     192                 :            : 
     193                 :            :     /** Whether the template entries have to be sorted.
     194                 :            :     */
     195                 :            :     bool mbEntrySortingEnabled;
     196                 :            : 
     197                 :            :     /** This member points into the maFolderList to the member that was most
     198                 :            :         recently added.
     199                 :            :     */
     200                 :            :     TemplateEntry* mpLastAddedEntry;
     201                 :            : 
     202                 :            :     /** The folders that are collected by GatherFolderList().
     203                 :            :     */
     204                 :            :     class FolderDescriptorList;
     205                 :            :     ::boost::scoped_ptr<FolderDescriptorList> mpFolderDescriptors;
     206                 :            : 
     207                 :            :     /** Set of state variables used by the methods
     208                 :            :         InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
     209                 :            :         InitializeEntryScanning(), and ScanEntry().
     210                 :            :     */
     211                 :            :     com::sun::star::uno::Reference<com::sun::star::ucb::XContent> mxTemplateRoot;
     212                 :            :     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxFolderEnvironment;
     213                 :            :     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxEntryEnvironment;
     214                 :            :     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxFolderResultSet;
     215                 :            :     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxEntryResultSet;
     216                 :            : 
     217                 :            :     /** Obtain the root folder of the template folder hierarchy.  The result
     218                 :            :         is stored in mxTemplateRoot for later use.
     219                 :            :     */
     220                 :            :     State GetTemplateRoot (void);
     221                 :            : 
     222                 :            :     /** Initialize the scanning of folders.  This is called exactly once.
     223                 :            :         @return
     224                 :            :             Returns one of the two states ERROR or GATHER_FOLDER_LIST.
     225                 :            :     */
     226                 :            :     State InitializeFolderScanning (void);
     227                 :            : 
     228                 :            :     /** Collect all available top-level folders in an ordered list which can
     229                 :            :         then be processed by ScanFolder().
     230                 :            :         @return
     231                 :            :             Returns one of the two states ERROR or SCAN_FOLDER.
     232                 :            :     */
     233                 :            :     State GatherFolderList (void);
     234                 :            : 
     235                 :            :     /** From the list of top-level folders collected by GatherFolderList()
     236                 :            :         the one with highest priority is processed.
     237                 :            :         @return
     238                 :            :             Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
     239                 :            :     */
     240                 :            :     State ScanFolder (void);
     241                 :            : 
     242                 :            :     /** Initialize the scanning of entries of a top-level folder.
     243                 :            :         @return
     244                 :            :             Returns one of the states ERROR or SCAN_ENTRY.
     245                 :            :     */
     246                 :            :     State InitializeEntryScanning (void);
     247                 :            : 
     248                 :            :     /** Scan one entry.  When this entry matches the recognized template
     249                 :            :         types it is appended to the result set.
     250                 :            :         @return
     251                 :            :             Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
     252                 :            :     */
     253                 :            :     State ScanEntry (void);
     254                 :            : };
     255                 :            : 
     256                 :            : } // end of namespace sd
     257                 :            : 
     258                 :            : #endif
     259                 :            : 
     260                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10