CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / inc / TemplateScanner.hxx
blob1c5f0cfe6f11566d620cbf5083a6c567971adcf4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _TEMPLATE_SCANNER_HXX
29 #define _TEMPLATE_SCANNER_HXX
31 #include "tools/AsynchronousTask.hxx"
32 #include "sddllapi.h"
33 #include <ucbhelper/content.hxx>
34 #include <tools/string.hxx>
35 #include "com/sun/star/uno/Reference.hxx"
37 #include <vector>
38 #include <boost/scoped_ptr.hpp>
40 namespace com { namespace sun { namespace star { namespace ucb {
41 class XContent;
42 class XCommandEnvironment;
43 } } } }
45 namespace com { namespace sun { namespace star { namespace sdbc {
46 class XResultSet;
47 } } } }
49 namespace sd {
51 /** Representation of a template or layout file.
53 class TemplateEntry
55 public:
56 TemplateEntry (const String& rsTitle, const String& rsPath)
57 : msTitle(rsTitle), msPath(rsPath) {}
59 String msTitle;
60 String msPath;
66 /** Representation of a template or layout folder.
68 class TemplateDir
70 public:
71 TemplateDir (const String& rsRegion, const String& rsUrl )
72 : msRegion(rsRegion), msUrl(rsUrl), maEntries() {}
74 String msRegion;
75 String msUrl;
76 ::std::vector<TemplateEntry*> maEntries;
82 /** This class scans the template folders for impress templates. There are
83 two ways to use this class.
84 1. The old and deprecated way is to call Scan() to scan all templates
85 and collect the supported ones in a tree structure. This structure is
86 returned by GetFolderList().
87 2. The new way implements the AsynchronousTask interface. Call
88 RunNextStep() as long HasNextStep() returns <TRUE/>. After every step
89 GetLastAddedEntry() returns the template that was scanned (and has a
90 supported format) last. When a step does not add a new template then
91 the value of the previous step is returned.
93 class SD_DLLPUBLIC TemplateScanner
94 : public ::sd::tools::AsynchronousTask
96 public:
97 /** Create a new template scanner and prepare but do not execute the scanning.
99 TemplateScanner (void);
101 /** The destructor deletes any remaining entries of the local list of
102 templates.
104 virtual ~TemplateScanner (void);
106 /** Execute the actual scanning of templates. When this method
107 terminates the result can be obtained by calling the
108 <member>GetTemplateList</member> method.
110 void Scan (void);
112 /** Return the list of template folders. It lies in the responsibility
113 of the caller to take ownership of some or all entries and remove
114 them from the returned list. All entries that remain until the
115 destructor is called will be destroyed.
117 std::vector<TemplateDir*>& GetFolderList (void);
119 /** Implementation of the AsynchronousTask interface method.
121 virtual void RunNextStep (void);
123 /** Implementation of the AsynchronousTask interface method.
125 virtual bool HasNextStep (void);
127 /** Return the TemplateDir object that was last added to
128 mpTemplateDirectory.
129 @return
130 <NULL/> is returned either before the template scanning is
131 started or after it has ended.
133 const TemplateEntry* GetLastAddedEntry (void) const;
135 private:
136 /** The current state determines which step will be executed next by
137 RunNextStep().
139 enum State {
140 INITIALIZE_SCANNING,
141 INITIALIZE_FOLDER_SCANNING,
142 GATHER_FOLDER_LIST,
143 SCAN_FOLDER,
144 INITIALIZE_ENTRY_SCAN,
145 SCAN_ENTRY,
146 DONE,
147 ERROR
149 State meState;
151 ::ucbhelper::Content maFolderContent;
152 TemplateDir* mpTemplateDirectory;
154 /** The data structure that is to be filled with information about the
155 template files.
157 std::vector<TemplateDir*> maFolderList;
159 /** This member points into the maFolderList to the member that was most
160 recently added.
162 TemplateEntry* mpLastAddedEntry;
164 /** The folders that are collected by GatherFolderList().
166 class FolderDescriptorList;
167 ::boost::scoped_ptr<FolderDescriptorList> mpFolderDescriptors;
169 /** Set of state variables used by the methods
170 InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
171 InitializeEntryScanning(), and ScanEntry().
173 com::sun::star::uno::Reference<com::sun::star::ucb::XContent> mxTemplateRoot;
174 com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxFolderEnvironment;
175 com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxEntryEnvironment;
176 com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxFolderResultSet;
177 com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxEntryResultSet;
179 /** Obtain the root folder of the template folder hierarchy. The result
180 is stored in mxTemplateRoot for later use.
182 State GetTemplateRoot (void);
184 /** Initialize the scanning of folders. This is called exactly once.
185 @return
186 Returns one of the two states ERROR or GATHER_FOLDER_LIST.
188 State InitializeFolderScanning (void);
190 /** Collect all available top-level folders in an ordered list which can
191 then be processed by ScanFolder().
192 @return
193 Returns one of the two states ERROR or SCAN_FOLDER.
195 State GatherFolderList (void);
197 /** From the list of top-level folders collected by GatherFolderList()
198 the one with highest priority is processed.
199 @return
200 Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
202 State ScanFolder (void);
204 /** Initialize the scanning of entries of a top-level folder.
205 @return
206 Returns one of the states ERROR or SCAN_ENTRY.
208 State InitializeEntryScanning (void);
210 /** Scan one entry. When this entry matches the recognized template
211 types it is appended to the result set.
212 @return
213 Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
215 State ScanEntry (void);
218 } // end of namespace sd
220 #endif