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 INCLUDED_SD_SOURCE_UI_INC_TEMPLATESCANNER_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_TEMPLATESCANNER_HXX
23 #include "tools/AsynchronousTask.hxx"
25 #include <ucbhelper/content.hxx>
26 #include "com/sun/star/uno/Reference.hxx"
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/shared_ptr.hpp>
32 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
34 class XCommandEnvironment
;
37 namespace com
{ namespace sun
{ namespace star
{ namespace sdbc
{
41 namespace comphelper
{ namespace string
{
42 class NaturalStringSorter
;
47 /** Representation of a template or layout file.
52 TemplateEntry (const OUString
& rsTitle
, const OUString
& rsPath
)
53 : msTitle(rsTitle
), msPath(rsPath
) {}
59 /** Functor that compares two TemplateEntries based on their titles
61 class TemplateEntryCompare
64 TemplateEntryCompare();
65 bool operator()(TemplateEntry
* pA
, TemplateEntry
* pB
) const;
68 ::boost::shared_ptr
<comphelper::string::NaturalStringSorter
> mpStringSorter
;
71 /** Representation of a template or layout folder.
76 TemplateDir (const OUString
& rsRegion
, const OUString
& rsUrl
)
77 : msRegion(rsRegion
), msUrl(rsUrl
), maEntries(),
78 mbSortingEnabled(false), mpEntryCompare(NULL
) {}
82 ::std::vector
<TemplateEntry
*> maEntries
;
84 void EnableSorting(bool bSortingEnabled
= true);
85 void InsertEntry(TemplateEntry
* pNewEntry
);
88 bool mbSortingEnabled
;
89 ::boost::scoped_ptr
<TemplateEntryCompare
> mpEntryCompare
;
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.
103 class SD_DLLPUBLIC TemplateScanner
104 : public ::sd::tools::AsynchronousTask
107 /** Create a new template scanner and prepare but do not execute the scanning.
111 /** The destructor deletes any remaining entries of the local list of
114 virtual ~TemplateScanner();
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.
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.
127 std::vector
<TemplateDir
*>& GetFolderList() { return maFolderList
;}
129 /** Implementation of the AsynchronousTask interface method.
131 virtual void RunNextStep() SAL_OVERRIDE
;
133 /** Implementation of the AsynchronousTask interface method.
135 virtual bool HasNextStep() SAL_OVERRIDE
;
137 /** Return the TemplateDir object that was last added to
140 <NULL/> is returned either before the template scanning is
141 started or after it has ended.
143 const TemplateEntry
* GetLastAddedEntry() const { return mpLastAddedEntry
;}
145 /** Set whether to sort the template entries inside the regions.
147 void EnableEntrySorting (bool isEntrySortingEnabled
= true)
148 {mbEntrySortingEnabled
= isEntrySortingEnabled
;}
151 /** The current state determines which step will be executed next by
156 INITIALIZE_FOLDER_SCANNING
,
159 INITIALIZE_ENTRY_SCAN
,
166 ::ucbhelper::Content maFolderContent
;
167 TemplateDir
* mpTemplateDirectory
;
169 /** The data structure that is to be filled with information about the
172 std::vector
<TemplateDir
*> maFolderList
;
174 /** Whether the template entries have to be sorted.
176 bool mbEntrySortingEnabled
;
178 /** This member points into the maFolderList to the member that was most
181 TemplateEntry
* mpLastAddedEntry
;
183 /** The folders that are collected by GatherFolderList().
185 class FolderDescriptorList
;
186 ::boost::scoped_ptr
<FolderDescriptorList
> mpFolderDescriptors
;
188 /** Set of state variables used by the methods
189 InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
190 InitializeEntryScanning(), and ScanEntry().
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
;
198 /** Obtain the root folder of the template folder hierarchy. The result
199 is stored in mxTemplateRoot for later use.
201 State
GetTemplateRoot();
203 /** Initialize the scanning of folders. This is called exactly once.
205 Returns one of the two states ERROR or GATHER_FOLDER_LIST.
207 State
InitializeFolderScanning();
209 /** Collect all available top-level folders in an ordered list which can
210 then be processed by ScanFolder().
212 Returns one of the two states ERROR or SCAN_FOLDER.
214 State
GatherFolderList();
216 /** From the list of top-level folders collected by GatherFolderList()
217 the one with highest priority is processed.
219 Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
223 /** Initialize the scanning of entries of a top-level folder.
225 Returns one of the states ERROR or SCAN_ENTRY.
227 State
InitializeEntryScanning();
229 /** Scan one entry. When this entry matches the recognized template
230 types it is appended to the result set.
232 Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
237 } // end of namespace sd
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */