1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_FILLER_HXX
23 #define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_FILLER_HXX
24 
25 #include "MasterPageContainer.hxx"
26 #include "MasterPageDescriptor.hxx"
27 #include "tools/AsynchronousTask.hxx"
28 
29 namespace sd {
30 class TemplateScanner;
31 class TemplateEntry;
32 }
33 
34 namespace sd { namespace sidebar {
35 
36 /** Fill a MasterPageContainer with information about the available master
37     pages.  These are provided by one default page and from the existing
38     Impress templates.  This is done asynchronously.
39 */
40 class MasterPageContainerFiller
41     : public ::sd::tools::AsynchronousTask
42 {
43 public:
44     class ContainerAdapter
45     {
46     public:
47         virtual MasterPageContainer::Token PutMasterPage (
48             const SharedMasterPageDescriptor& rpDescriptor) = 0;
49         /** This method is called when all Impress templates have been added
50             to the container via the PutMasterPage() method.
51         */
52         virtual void FillingDone (void) = 0;
53     };
54 
55     MasterPageContainerFiller (ContainerAdapter& rContainerAdapter);
56     virtual ~MasterPageContainerFiller (void);
57 
58     /** Run the next step of the task.  After HasNextStep() returns false
59         this method should ignore further calls.
60     */
61     virtual void RunNextStep (void);
62 
63     /** Return <TRUE/> when there is at least one more step to execute.
64         When the task has been executed completely then <FALSE/> is
65         returned.
66     */
67     virtual bool HasNextStep (void);
68 
69 private:
70     ContainerAdapter& mrContainerAdapter;
71     // Remember what the next step has to do.
72     enum State {
73         INITIALIZE_TEMPLATE_SCANNER,
74         SCAN_TEMPLATE,
75         ADD_TEMPLATE,
76         ERROR,
77         DONE
78     } meState;
79     ::std::auto_ptr<TemplateScanner> mpScannerTask;
80     const TemplateEntry* mpLastAddedEntry;
81     int mnIndex;
82 
83     State ScanTemplate (void);
84     State AddTemplate (void);
85 };
86 
87 } } // end of namespace sd::sidebar
88 
89 #endif
90