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
QuizCore Class Reference

Main core of Quiz template. More...

#include <quizcore.h>

Collaboration diagram for QuizCore:
Collaboration graph

Public Member Functions

 QuizCore (TemplateEntryPoint *entry_point, QObject *parent=0)
 
GenerationResult generateMobileApplication (const QString &input_apk_file, QString &output_file)
 Generates APK file from current project with active settings. More...
 
- Public Member Functions inherited from TemplateCore
 TemplateCore (TemplateEntryPoint *entry_point, QObject *parent=0)
 
virtual void launch ()
 Called after this template is fully loaded in toolkit. More...
 
virtual TemplateEntryPointentryPoint () const
 Access to entry point of the template. More...
 
virtual TemplateEditoreditor () const
 Access to editor widget of the template. More...
 
virtual TemplateSimulatorsimulator () const
 Access to simulator widget of the template. More...
 
QString assignedFile () const
 Access to assigned XML "bundle" file. More...
 
void setAssignedFile (const QString &assigned_file)
 Sets new assigned file. More...
 

Additional Inherited Members

- Public Types inherited from TemplateCore
enum  GenerationResult {
  Success, ZipProblem, SignApkProblem, JavaProblem,
  BundleProblem, CopyProblem, Aborted, OtherProblem
}
 Possible results of generation of bundle data.
 
- Signals inherited from TemplateCore
void generationProgress (int percent_completed, const QString &progress_info)
 Emitted when there is something new concerning generating of mobile APK application. More...
 
- Protected Attributes inherited from TemplateCore
TemplateEntryPointm_entryPoint
 
TemplateEditorm_editor
 
TemplateSimulatorm_simulator
 
QString m_assignedFile
 

Detailed Description

Main core of Quiz template.

Definition at line 47 of file quizcore.h.

Member Function Documentation

TemplateCore::GenerationResult QuizCore::generateMobileApplication ( const QString &  input_apk_file,
QString &  output_file 
)
virtual

Generates APK file from current project with active settings.

Returns
Returns true on success, otherwise returns false.
Warning
This is used only if template can actually generate mobile application, so that editor of the template must contain sufficient data for doing so.

Implements TemplateCore.

Definition at line 59 of file quizcore.cpp.

59  {
60  emit generationProgress(5, tr("Preparing workspace..."));
61 
62  qApp->templateManager()->generator()->cleanWorkspace();
63 
64  emit generationProgress(10, tr("Extracting raw data from editor..."));
65 
66  // We need data which will be imported into apk/zip file.
67  QString quiz_data = editor()->generateBundleData();
68 
69  if (quiz_data.isEmpty()) {
70  // No date received, this is big problem.
71  return BundleProblem;
72  }
73 
74  QString temp_folder = qApp->templateManager()->tempDirectory();
75  QDir temp_directory(temp_folder);
76  QString base_folder = temp_folder + "/" + APP_LOW_NAME;
77  QDir base_directory(base_folder);
78 
79  // Preparation of target bundle file
80  emit generationProgress(20, tr("Creating base temporary folder..."));
81 
82  temp_directory.mkdir(APP_LOW_NAME);
83  base_directory.mkdir("assets");
84 
85  QFile index_file(base_folder + "/assets/quiz_content.xml");
86  index_file.open(QIODevice::WriteOnly | QIODevice::Text);
87 
88  emit generationProgress(30, tr("Writting quiz data into file..."));
89 
90  QTextStream out(&index_file);
91  out << quiz_data;
92 
93  out.flush();
94  index_file.close();
95 
96  emit generationProgress(40, tr("Copying template apk file..."));
97 
98  // Copying of target apk file.
99  QString new_apk_name = input_apk_file;
100  if (!QFile::copy(APP_TEMPLATES_PATH + "/" + entryPoint()->baseFolder() + "/" + entryPoint()->mobileApplicationApkFile(),
101  base_folder + "/" + new_apk_name)) {
102  qApp->templateManager()->generator()->cleanWorkspace();
103  return CopyProblem;
104  }
105 
106  emit generationProgress(60, tr("Inserting data into apk file..."));
107 
108  // Inserting bundle file into apk file.
109  QProcess zip;
110 
111  zip.setWorkingDirectory(base_folder);
112  zip.start(qApp->zipUtilityPath(), QStringList() << "-m" << "-r" << new_apk_name << "assets");
113  zip.waitForFinished();
114 
115  if (zip.exitCode() != EXIT_STATUS_ZIP_NORMAL) {
116  // Error during inserting quiz data via zip.
117  qApp->templateManager()->generator()->cleanWorkspace();
118  return ZipProblem;
119  }
120 
121  emit generationProgress(70, tr("Signing apk file..."));
122 
123  // Signing and renaming target file.
124  QString pem_certificate = QDir::toNativeSeparators(APP_CERT_PATH + "/" + CERTIFICATE_PATH);
125  QString pk_certificate = QDir::toNativeSeparators(APP_CERT_PATH + "/" + KEY_PATH);
126  QProcess signapk;
127 
128  signapk.setWorkingDirectory(base_folder);
129  signapk.start(qApp->javaInterpreterPath(), QStringList() << "-jar" << qApp->signApkUtlityPath() <<
130  pem_certificate << pk_certificate << new_apk_name <<
131  QDir::toNativeSeparators(new_apk_name + ".new"));
132  signapk.waitForFinished();
133 
134  if (signapk.exitCode() != EXIT_STATUS_SIGNAPK_WORKING) {
135  qApp->templateManager()->generator()->cleanWorkspace();
136  return SignApkProblem;
137  }
138 
139  emit generationProgress(90, tr("Copying final apk file to output directory..."));
140 
141  // Now, our file is created. We need to move it to target directory.
142  if (!IOFactory::copyFile(base_folder + "/" + new_apk_name + ".new",
143  qApp->templateManager()->outputDirectory() + "/" + new_apk_name)) {
144  qApp->templateManager()->generator()->cleanWorkspace();
145  return CopyProblem;
146  }
147 
148  output_file = QDir(qApp->templateManager()->outputDirectory()).filePath(new_apk_name);
149 
150  // Removing temporary files and exit.
151  qApp->templateManager()->generator()->cleanWorkspace();
152  return Success;
153 }
virtual TemplateEditor * editor() const
Access to editor widget of the template.
Definition: templatecore.h:84
static bool copyFile(const QString &source, const QString &destination)
Copies source file into destination path.
Definition: iofactory.cpp:69
void generationProgress(int percent_completed, const QString &progress_info)
Emitted when there is something new concerning generating of mobile APK application.
virtual TemplateEntryPoint * entryPoint() const
Access to entry point of the template.
Definition: templatecore.h:78
virtual QString generateBundleData()=0
Generates RAW data which represent data of this template.

Here is the call graph for this function:


The documentation for this class was generated from the following files: