BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
templatefactory.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef TEMPLATEFACTORY_H
32 #define TEMPLATEFACTORY_H
33 
34 #include <QObject>
35 
36 #include <QHash>
37 #include <QDomDocument>
38 
39 /// \brief Finds root data element in basic XML bundle header
40 /// and exports it as target_name argument.
41 #define FIND_DATA_ELEMENT(target_name, source_document) \
42  QStringList way_to_data_element = QString(XML_BUNDLE_ROOT_DATA_ELEMENT).split('/'); \
43  QDomElement target_name = source_document.documentElement(); \
44  \
45  while (!way_to_data_element.isEmpty()) { \
46  QDomNode child_item = data_element.namedItem(way_to_data_element.at(0)); \
47  \
48  if (!child_item.isNull() && child_item.isElement()) { \
49  target_name = child_item.toElement(); \
50  way_to_data_element.removeFirst(); \
51  } \
52  else { \
53  return QString(); \
54  } \
55  } \
56 
57 
58 class TemplateEntryPoint;
59 class TemplateCore;
60 class TemplateGenerator;
61 
62 /// \brief The top-level manager of templates.
63 ///
64 /// This class is used in a singleton-like fashion from main Application
65 /// object via Application::templateManager(). It contains all available
66 /// template entry points.
67 /// \see TemplateEntryPoint, TemplateCore, Application
68 /// \ingroup template-interfaces
69 class TemplateFactory : public QObject {
70  Q_OBJECT
71 
72  public:
73  // Constructors and destructors.
74  explicit TemplateFactory(QObject *parent = 0);
75  virtual ~TemplateFactory();
76 
77  /// \brief Access to available templates.
78  /// \see TemplateEntryPoint
79  /// \return Method returns list of available templates. Templates
80  /// are not sorted in any particular order.
81  QList<TemplateEntryPoint*> availableTemplates();
82 
83  /// \brief Access to temporary directory used throughout APK generation process.
84  /// \return Returns temporary directory used throughout APK generation process.
85  QString tempDirectory() const;
86 
87  void setTempDirectory(const QString &temp_directory);
88 
89  /// \brief Access to directory used throughout APK generation process.
90  /// \return Returns output directory used throughout APK generation process.
91  QString outputDirectory() const;
92 
93  void setOutputDirectory(const QString &output_directory);
94 
95  /// \brief Access to pattern used for name of output APK file.
96  /// \return Returns pattern used for name of output APK file.
97  QString applicationFileNamePattern() const;
98 
99  void setApplicationFileNamePattern(const QString &file_name_pattern);
100 
101  /// \brief Generates file name for output APK file.
102  /// \param project_name Name of source project.
103  /// \return Access to output APK application file name pattern.
104  QString applicationFileName(const QString &project_name);
105 
106  /// \brief Access to active entry point.
107  /// \return Returns pointer to active entry point or NULL if no entry
108  /// point is active.
110  return m_activeEntryPoint;
111  }
112 
113  /// \brief Access to active core.
114  /// \return Returns pointer to active core or NULL if not core is active.
116  return m_activeCore;
117  }
118 
119  /// \brief Generates common XML bundle.
120  /// \return Returns XML bundle structure.
121  QDomDocument generateBundleHeader(const QString &template_type,
122  const QString &author_name,
123  const QString &author_email,
124  const QString &project_title,
125  const QString &project_description,
126  const QString &template_version);
127 
128  /// \brief Access to component which supervises generating of APK files.
129  /// \return Returns pointer to generator.
130  TemplateGenerator *generator() const;
131 
132  /// \brief Decides which entry point raw XML bundle data belong to.
133  /// \param bundle_data Raw XML bundle data.
134  /// \return Returns pointer to appropriate entry point or NULL
135  /// if no correct entry point exists.
136  TemplateEntryPoint *entryPointForBundle(const QString &bundle_data);
137 
138  /// \brief Performs lexicographical comparison of two entry points.
139  /// \note This is used for sorting entry points in FormNewProject class.
140  /// \param s1 First entry point.
141  /// \param s2 Second entry point.
142  /// \return Returns true if s1 is less than s2, otherwise
143  /// returns false.
145 
146  public slots:
147  /// \brief Quits running actions of template manager.
148  void quit();
149 
150  /// \brief Starts new project core from given entry point.
151  /// \param entry_point Entry point to be started.
152  bool startNewProject(TemplateEntryPoint *entry_point);
153 
154  /// \brief Loads stored project and initializes new core according to it.
155  /// \param bundle_file_name XML bundle file name of saved project.
156  bool loadProject(const QString &bundle_file_name);
157 
158  /// \brief Saves current project to given file.
159  /// \param bundle_file_name File to save project XML bundle to.
160  /// \return Returns true if project was saved, otherwise returns false.
161  bool saveCurrentProjectAs(const QString &bundle_file_name);
162 
163  /// \brief Saves current project to assigned file if there is any.
164  /// \return Returns true if project was saved, otherwise returns false.
165  bool saveCurrentProject();
166 
167  signals:
168  /// \brief Emitted if new project using some template core is started.
169  /// \param core Core object pointer.
171 
172  private:
173  void clearEntryAndCore();
174  void setupTemplates();
175 
176  QHash<QString, TemplateEntryPoint*> m_availableTemplates;
177  TemplateEntryPoint *m_activeEntryPoint;
178  TemplateCore *m_activeCore;
179  TemplateGenerator *m_generator;
180 };
181 
182 #endif // TEMPLATEFACTORY_H
TemplateEntryPoint * entryPointForBundle(const QString &bundle_data)
Decides which entry point raw XML bundle data belong to.
void newTemplateCoreCreated(TemplateCore *core)
Emitted if new project using some template core is started.
QString applicationFileName(const QString &project_name)
Generates file name for output APK file.
static bool entryPointIsLessThan(TemplateEntryPoint *s1, TemplateEntryPoint &s2)
Performs lexicographical comparison of two entry points.
TemplateGenerator * generator() const
Access to component which supervises generating of APK files.
bool saveCurrentProject()
Saves current project to assigned file if there is any.
QString outputDirectory() const
Access to directory used throughout APK generation process.
QDomDocument generateBundleHeader(const QString &template_type, const QString &author_name, const QString &author_email, const QString &project_title, const QString &project_description, const QString &template_version)
Generates common XML bundle.
QString applicationFileNamePattern() const
Access to pattern used for name of output APK file.
TemplateCore * activeCore() const
Access to active core.
bool startNewProject(TemplateEntryPoint *entry_point)
Starts new project core from given entry point.
bool loadProject(const QString &bundle_file_name)
Loads stored project and initializes new core according to it.
TemplateEntryPoint * activeEntryPoint() const
Access to active entry point.
The top-level manager of templates.
bool saveCurrentProjectAs(const QString &bundle_file_name)
Saves current project to given file.
QList< TemplateEntryPoint * > availableTemplates()
Access to available templates.
Generator responsible for generating APK mobile applications.
void quit()
Quits running actions of template manager.
The entry point for a template.
The core class container for single template.
Definition: templatecore.h:43
QString tempDirectory() const
Access to temporary directory used throughout APK generation process.