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
BasicmLearningCore Class Reference
Collaboration diagram for BasicmLearningCore:
Collaboration graph

Public Member Functions

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

Definition at line 40 of file basicmlearningcore.h.

Member Function Documentation

TemplateCore::GenerationResult BasicmLearningCore::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 56 of file basicmlearningcore.cpp.

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