bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / inc / TemplateScanner.hxx
blob552159e0b89aab07787f7c96eadf11c419cf9970
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include <sddllapi.h>
25 #include <ucbhelper/content.hxx>
26 #include <com/sun/star/uno/Reference.h>
28 #include <memory>
29 #include <vector>
31 namespace com { namespace sun { namespace star { namespace ucb {
32 class XContent;
33 class XCommandEnvironment;
34 } } } }
36 namespace com { namespace sun { namespace star { namespace sdbc {
37 class XResultSet;
38 } } } }
40 namespace sd {
42 /** Representation of a template or layout file.
44 class TemplateEntry
46 public:
47 TemplateEntry (const OUString& rsTitle, const OUString& rsPath)
48 : msTitle(rsTitle), msPath(rsPath) {}
50 OUString const msTitle;
51 OUString const msPath;
54 /** This class scans the template folders for impress templates. There are
55 two ways to use this class.
56 1. The old and deprecated way is to call Scan() to scan all templates
57 and collect the supported ones in a tree structure. This structure is
58 returned by GetFolderList().
59 2. The new way implements the AsynchronousTask interface. Call
60 RunNextStep() as long HasNextStep() returns <TRUE/>. After every step
61 GetLastAddedEntry() returns the template that was scanned (and has a
62 supported format) last. When a step does not add a new template then
63 the value of the previous step is returned.
65 class SD_DLLPUBLIC TemplateScanner
66 : public ::sd::tools::AsynchronousTask
68 public:
69 /** Create a new template scanner and prepare but do not execute the scanning.
71 TemplateScanner();
73 /** The destructor deletes any remaining entries of the local list of
74 templates.
76 virtual ~TemplateScanner();
78 /** Implementation of the AsynchronousTask interface method.
80 virtual void RunNextStep() override;
82 /** Implementation of the AsynchronousTask interface method.
84 virtual bool HasNextStep() override;
86 /** Return the TemplateDir object that was last added to
87 mpTemplateEntries.
88 @return
89 <nullptr/> is returned either before the template scanning is
90 started or after it has ended.
92 const TemplateEntry* GetLastAddedEntry() const { return mpTemplateEntries.empty()?nullptr:mpTemplateEntries.back().get();}
94 private:
95 /** The current state determines which step will be executed next by
96 RunNextStep().
98 enum State {
99 INITIALIZE_SCANNING,
100 INITIALIZE_FOLDER_SCANNING,
101 GATHER_FOLDER_LIST,
102 SCAN_FOLDER,
103 INITIALIZE_ENTRY_SCAN,
104 SCAN_ENTRY,
105 DONE,
106 ERROR
108 State meState;
110 ::ucbhelper::Content maFolderContent;
111 ::std::vector< std::unique_ptr<TemplateEntry> > mpTemplateEntries;
113 /** The folders that are collected by GatherFolderList().
115 class FolderDescriptorList;
116 std::unique_ptr<FolderDescriptorList> mpFolderDescriptors;
118 /** Set of state variables used by the methods
119 InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
120 InitializeEntryScanning(), and ScanEntry().
122 css::uno::Reference<css::ucb::XContent> mxTemplateRoot;
123 css::uno::Reference<css::ucb::XCommandEnvironment> mxFolderEnvironment;
124 css::uno::Reference<css::ucb::XCommandEnvironment> mxEntryEnvironment;
125 css::uno::Reference<css::sdbc::XResultSet> mxFolderResultSet;
126 css::uno::Reference<css::sdbc::XResultSet> mxEntryResultSet;
128 /** Obtain the root folder of the template folder hierarchy. The result
129 is stored in mxTemplateRoot for later use.
131 State GetTemplateRoot();
133 /** Initialize the scanning of folders. This is called exactly once.
134 @return
135 Returns one of the two states ERROR or GATHER_FOLDER_LIST.
137 State InitializeFolderScanning();
139 /** Collect all available top-level folders in an ordered list which can
140 then be processed by ScanFolder().
141 @return
142 Returns one of the two states ERROR or SCAN_FOLDER.
144 State GatherFolderList();
146 /** From the list of top-level folders collected by GatherFolderList()
147 the one with highest priority is processed.
148 @return
149 Returns one of the states ERROR, DONE, or INITIALIZE_ENTRY_SCAN.
151 State ScanFolder();
153 /** Initialize the scanning of entries of a top-level folder.
154 @return
155 Returns one of the states ERROR or SCAN_ENTRY.
157 State InitializeEntryScanning();
159 /** Scan one entry. When this entry matches the recognized template
160 types it is appended to the result set.
161 @return
162 Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
164 State ScanEntry();
167 } // end of namespace sd
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */