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
templategenerator.cpp
1 #include "core/templategenerator.h"
2 
3 #include "definitions/definitions.h"
4 #include "core/templatecore.h"
5 #include "core/templatefactory.h"
6 #include "core/templateeditor.h"
7 #include "gui/formmain.h"
8 #include "miscellaneous/application.h"
9 #include "miscellaneous/iofactory.h"
10 
11 #include <QMutex>
12 #include <QInputDialog>
13 
14 
15 TemplateGenerator::TemplateGenerator(QObject *parent) : QObject(parent) {
16 }
17 
18 TemplateGenerator::~TemplateGenerator() {
19 }
20 
22  if (qApp->closeLock()->tryLock()) {
23  bool ok;
24  QString input_file_name = QInputDialog::getText(qApp->mainForm(), tr("Specify application output file name"),
25  tr("Type here custom output application file name or leave the default value intact if you are satisfied with it."),
26  QLineEdit::Normal,
27  qApp->templateManager()->applicationFileName(core->editor()->projectName()), &ok);
28 
29  if (!ok || input_file_name.isEmpty()) {
30  // User aborted the process or entered empty file name.
31  //emit generationFinished(TemplateCore::Aborted);
32  qApp->closeLock()->unlock();
33  return;
34  }
35 
36  // Append necessary suffix.
37  if (!input_file_name.endsWith(".apk")) {
38  input_file_name += ".apk";
39  }
40 
41  connect(core, SIGNAL(generationProgress(int,QString)), this, SIGNAL(generationProgress(int,QString)));
42  emit generationStarted();
43 
44  // TODO: upravit signaturu metody generationMobileApplication,
45  // aby brala i ten vstupni nazev ciloveho apk souboru.
46 
47  QString output_file;
48  TemplateCore::GenerationResult result = core->generateMobileApplication(input_file_name, output_file);
49 
50  disconnect(core, SIGNAL(generationProgress(int,QString)), this, SIGNAL(generationProgress(int,QString)));
51 
52  if (result == TemplateCore::Success) {
53  emit generationFinished(result, output_file);
54  }
55  else {
56  emit generationFinished(result);
57  }
58 
59  qApp->closeLock()->unlock();
60  }
61  else {
62  qApp->trayIcon()->showMessage(tr("Cannot generate application"),
63  tr("Master generation lock is locked, try to\ngenerate application later."),
64  QSystemTrayIcon::Warning);
65  }
66 }
67 
69  IOFactory::removeDirectory(qApp->templateManager()->tempDirectory() + "/" + APP_LOW_NAME);
70 }
71 
74  QDir().mkpath(qApp->templateManager()->tempDirectory() + "/" + APP_LOW_NAME);
75 }
virtual QString projectName()=0
Access to project name of current editor.
virtual TemplateEditor * editor() const
Access to editor widget of the template.
Definition: templatecore.h:84
void generateMobileApplication(TemplateCore *core)
Generates new APK application using given core.
void refreshWorkspace()
Cleans and recreates base workspace path.
void cleanWorkspace()
Cleans workspace used for generating applications.
void generationProgress(int progress, const QString &message)
Emitted when there is some progress in generating APK application.
virtual GenerationResult generateMobileApplication(const QString &input_apk_file, QString &output_file)=0
Generates APK file from current project with active settings.
void generationFinished(TemplateCore::GenerationResult result_code, const QString &output_file=QString())
Emitted if generating process is finished.
void generationStarted()
Emitted if generating process is started.
The core class container for single template.
Definition: templatecore.h:43
GenerationResult
Possible results of generation of bundle data.
Definition: templatecore.h:48
static bool removeDirectory(const QString &directory_name, const QStringList &exception_file_list=QStringList(), const QStringList &exception_folder_list=QStringList())
Removes given directory and all its contents if not exceptions are given.
Definition: iofactory.cpp:85