1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _TEMPLATE_SCANNER_HXX
21 #define _TEMPLATE_SCANNER_HXX
23 #include "tools/AsynchronousTask.hxx"
25 #include <ucbhelper/content.hxx>
26 #include <tools/string.hxx>
27 #include "com/sun/star/uno/Reference.hxx"
30 #include <boost/scoped_ptr.hpp>
31 #include <boost/shared_ptr.hpp>
33 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
35 class XCommandEnvironment
;
38 namespace com
{ namespace sun
{ namespace star
{ namespace sdbc
{
42 namespace comphelper
{ namespace string
{
43 class NaturalStringSorter
;
48 /** Representation of a template or layout file.
53 TemplateEntry (const String
& rsTitle
, const String
& rsPath
)
54 : msTitle(rsTitle
), msPath(rsPath
) {}
63 /** Functor that compares two TemplateEntries based on their titles
65 class TemplateEntryCompare
68 TemplateEntryCompare();
69 bool operator()(TemplateEntry
* pA
, TemplateEntry
* pB
) const;
72 ::boost::shared_ptr
<comphelper::string::NaturalStringSorter
> mpStringSorter
;
78 /** Representation of a template or layout folder.
83 TemplateDir (const String
& rsRegion
, const String
& rsUrl
)
84 : msRegion(rsRegion
), msUrl(rsUrl
), maEntries(),
85 mbSortingEnabled(false), mpEntryCompare(NULL
) {}
89 ::std::vector
<TemplateEntry
*> maEntries
;
91 void EnableSorting(bool bSortingEnabled
= true);
92 void InsertEntry(TemplateEntry
* pNewEntry
);
95 bool mbSortingEnabled
;
96 ::boost::scoped_ptr
<TemplateEntryCompare
> mpEntryCompare
;
102 /** This class scans the template folders for impress templates. There are
103 two ways to use this class.
104 1. The old and deprecated way is to call Scan() to scan all templates
105 and collect the supported ones in a tree structure. This structure is
106 returned by GetFolderList().
107 2. The new way implements the AsynchronousTask interface. Call
108 RunNextStep() as long HasNextStep() returns <TRUE/>. After every step
109 GetLastAddedEntry() returns the template that was scanned (and has a
110 supported format) last. When a step does not add a new template then
111 the value of the previous step is returned.
113 class SD_DLLPUBLIC TemplateScanner
114 : public ::sd::tools::AsynchronousTask
117 /** Create a new template scanner and prepare but do not execute the scanning.
119 TemplateScanner (void);
121 /** The destructor deletes any remaining entries of the local list of
124 virtual ~TemplateScanner (void);
126 /** Execute the actual scanning of templates. When this method
127 terminates the result can be obtained by calling the
128 <member>GetTemplateList</member> method.
132 /** Return the list of template folders. It lies in the responsibility
133 of the caller to take ownership of some or all entries and remove
134 them from the returned list. All entries that remain until the
135 destructor is called will be destroyed.
137 std::vector
<TemplateDir
*>& GetFolderList (void);
139 /** Implementation of the AsynchronousTask interface method.
141 virtual void RunNextStep (void);
143 /** Implementation of the AsynchronousTask interface method.
145 virtual bool HasNextStep (void);
147 /** Return the TemplateDir object that was last added to
150 <NULL/> is returned either before the template scanning is
151 started or after it has ended.
153 const TemplateEntry
* GetLastAddedEntry (void) const;
155 /** Set whether to sort the template entries inside the regions.
157 void EnableEntrySorting (bool isEntrySortingEnabled
= true)
158 {mbEntrySortingEnabled
= isEntrySortingEnabled
;}
161 /** The current state determines which step will be executed next by
166 INITIALIZE_FOLDER_SCANNING
,
169 INITIALIZE_ENTRY_SCAN
,
176 ::ucbhelper::Content maFolderContent
;
177 TemplateDir
* mpTemplateDirectory
;
179 /** The data structure that is to be filled with information about the
182 std::vector
<TemplateDir
*> maFolderList
;
184 /** Whether the template entries have to be sorted.
186 bool mbEntrySortingEnabled
;
188 /** This member points into the maFolderList to the member that was most
191 TemplateEntry
* mpLastAddedEntry
;
193 /** The folders that are collected by GatherFolderList().
195 class FolderDescriptorList
;
196 ::boost::scoped_ptr
<FolderDescriptorList
> mpFolderDescriptors
;
198 /** Set of state variables used by the methods
199 InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
200 InitializeEntryScanning(), and ScanEntry().
202 com::sun::star::uno::Reference
<com::sun::star::ucb::XContent
> mxTemplateRoot
;
203 com::sun::star::uno::Reference
<com::sun::star::ucb::XCommandEnvironment
> mxFolderEnvironment
;
204 com::sun::star::uno::Reference
<com::sun::star::ucb::XCommandEnvironment
> mxEntryEnvironment
;
205 com::sun::star::uno::Reference
<com::sun::star::sdbc::XResultSet
> mxFolderResultSet
;
206 com::sun::star::uno::Reference
<com::sun::star::sdbc::XResultSet
> mxEntryResultSet
;
208 /** Obtain the root folder of the template folder hierarchy. The result
209 is stored in mxTemplateRoot for later use.
211 State
GetTemplateRoot (void);
213 /** Initialize the scanning of folders. This is called exactly once.
215 Returns one of the two states ERROR or GATHER_FOLDER_LIST.
217 State
InitializeFolderScanning (void);
219 /** Collect all available top-level folders in an ordered list which can
220 then be processed by ScanFolder().
222 Returns one of the two states ERROR or SCAN_FOLDER.
224 State
GatherFolderList (void);
226 /** From the list of top-level folders collected by GatherFolderList()
227 the one with highest priority is processed.
229 Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
231 State
ScanFolder (void);
233 /** Initialize the scanning of entries of a top-level folder.
235 Returns one of the states ERROR or SCAN_ENTRY.
237 State
InitializeEntryScanning (void);
239 /** Scan one entry. When this entry matches the recognized template
240 types it is appended to the result set.
242 Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
244 State
ScanEntry (void);
247 } // end of namespace sd
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */