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

Core of Learn Spellings template. More...

#include <learnspellingscore.h>

Collaboration diagram for LearnSpellingsCore:
Collaboration graph

Public Member Functions

 LearnSpellingsCore (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

Core of Learn Spellings template.

Definition at line 43 of file learnspellingscore.h.

Member Function Documentation

TemplateCore::GenerationResult LearnSpellingsCore::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 57 of file learnspellingscore.cpp.

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