Commit aa453c80 authored by Alessandro Portale's avatar Alessandro Portale

Implemented "import" and "Url" options for html5 app wizard

parent 2eb2f61c
......@@ -8,8 +8,11 @@ int main(int argc, char *argv[])
Html5ApplicationViewer viewer;
viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto); // ORIENTATION
viewer.showExpanded();
viewer.loadFile(QLatin1String("html/index.html")); // HTMLFILE
// viewer.loadUrl(QUrl(QLatin1String("http://dev.sencha.com/deploy/touch/examples/kitchensink/")));
#if 1 // DELETE_LINE
viewer.loadFile(QLatin1String("html/index.html")); // MAINHTMLFILE
#else // DELETE_LINE
viewer.loadUrl(QUrl(QLatin1String("http://dev.sencha.com/deploy/touch/examples/kitchensink/"))); // MAINHTMLURL
#endif // DELETE_LINE
return app.exec();
}
......@@ -219,6 +219,8 @@ QByteArray AbstractMobileApp::generateMainCpp(QString *errorMessage) const
}
insertParameter(line, mainWindowClassName() + QLatin1String("::")
+ QLatin1String(orientationString));
} else if (line.contains(QLatin1String("// DELETE_LINE"))) {
continue; // omit this line in the output
} else {
adaptLine = adaptCurrentMainCppTemplateLine(line);
}
......
......@@ -54,6 +54,7 @@ const QString appViewerOriginsSubDir(appViewerBaseName + QLatin1Char('/'));
Html5App::Html5App()
: AbstractMobileApp()
, m_mainHtmlMode(ModeGenerate)
{
}
......@@ -61,30 +62,36 @@ Html5App::~Html5App()
{
}
void Html5App::setIndexHtmlFile(const QString &qmlFile)
void Html5App::setMainHtml(Mode mode, const QString &data)
{
m_indexHtmlFile.setFile(qmlFile);
Q_ASSERT(mode != ModeGenerate || data.isEmpty());
m_mainHtmlMode = mode;
m_mainHtmlData = data;
}
QString Html5App::indexHtmlFile() const
Html5App::Mode Html5App::mainHtmlMode() const
{
return path(IndexHtml);
return m_mainHtmlMode;
}
QString Html5App::pathExtended(int fileType) const
{
const QString htmlSubDir = QLatin1String("html/");
const QString appViewerTargetSubDir = appViewerOriginsSubDir;
const QString indexHtml = QLatin1String("index.html");
const QString pathBase = outputPathBase();
const QDir appProFilePath(pathBase);
const bool generateHtml = m_mainHtmlMode == ModeGenerate;
const bool importHtml = m_mainHtmlMode == ModeImport;
const QFileInfo importedHtmlFile(m_mainHtmlData);
const QString htmlSubDir = importHtml ? importedHtmlFile.canonicalPath().split(QLatin1Char('/')).last() + QLatin1Char('/')
: QString::fromLatin1("html/");
switch (fileType) {
case IndexHtml: return useExistingIndexHtml() ? m_indexHtmlFile.canonicalFilePath()
: pathBase + htmlSubDir + indexHtml;
case IndexHtmlDeployed: return useExistingIndexHtml() ? htmlSubDir + m_indexHtmlFile.fileName()
: QString(htmlSubDir + indexHtml);
case IndexHtmlOrigin: return originsRoot() + QLatin1String("html/") + indexHtml;
case MainHtml: return generateHtml ? pathBase + htmlSubDir + indexHtml
: importedHtmlFile.canonicalFilePath();
case MainHtmlDeployed: return generateHtml ? QString(htmlSubDir + indexHtml)
: htmlSubDir + importedHtmlFile.fileName();
case MainHtmlOrigin: return originsRoot() + QLatin1String("html/") + indexHtml;
case AppViewerPri: return pathBase + appViewerTargetSubDir + appViewerPriFileName;
case AppViewerPriOrigin: return originsRoot() + appViewerOriginsSubDir + appViewerPriFileName;
case AppViewerCpp: return pathBase + appViewerTargetSubDir + appViewerCppFileName;
......@@ -92,8 +99,8 @@ QString Html5App::pathExtended(int fileType) const
case AppViewerH: return pathBase + appViewerTargetSubDir + appViewerHFileName;
case AppViewerHOrigin: return originsRoot() + appViewerOriginsSubDir + appViewerHFileName;
case HtmlDir: return pathBase + htmlSubDir;
case HtmlDirProFileRelative: return useExistingIndexHtml() ? appProFilePath.relativeFilePath(m_indexHtmlFile.canonicalPath())
: QString(htmlSubDir).remove(htmlSubDir.length() - 1, 1);
case HtmlDirProFileRelative: return generateHtml ? QString(htmlSubDir).remove(htmlSubDir.length() - 1, 1)
: appProFilePath.relativeFilePath(importedHtmlFile.canonicalPath());
default: qFatal("Html5App::pathExtended() needs more work");
}
return QString();
......@@ -113,8 +120,16 @@ bool Html5App::adaptCurrentMainCppTemplateLine(QString &line) const
{
const QLatin1Char quote('"');
bool adaptLine = true;
if (line.contains(QLatin1String("// MAINHTML"))) {
insertParameter(line, quote + path(IndexHtmlDeployed) + quote);
if (line.contains(QLatin1String("// MAINHTMLFILE"))) {
if (m_mainHtmlMode != ModeUrl)
insertParameter(line, quote + path(MainHtmlDeployed) + quote);
else
adaptLine = false;
} else if (line.contains(QLatin1String("// MAINHTMLURL"))) {
if (m_mainHtmlMode == ModeUrl)
insertParameter(line, quote + m_mainHtmlData + quote);
else
adaptLine = false;
}
return adaptLine;
}
......@@ -133,10 +148,10 @@ void Html5App::handleCurrentProFileTemplateLine(const QString &line,
Core::GeneratedFiles Html5App::generateFiles(QString *errorMessage) const
{
Core::GeneratedFiles files = AbstractMobileApp::generateFiles(errorMessage);
// if (!useExistingMainQml()) {
files.append(file(generateFile(Html5AppGeneratedFileInfo::IndexHtmlFile, errorMessage), path(IndexHtml)));
if (m_mainHtmlMode == ModeGenerate) {
files.append(file(generateFile(Html5AppGeneratedFileInfo::MainHtmlFile, errorMessage), path(MainHtml)));
files.last().setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// }
}
files.append(file(generateFile(Html5AppGeneratedFileInfo::AppViewerPriFile, errorMessage), path(AppViewerPri)));
files.append(file(generateFile(Html5AppGeneratedFileInfo::AppViewerCppFile, errorMessage), path(AppViewerCpp)));
......@@ -146,18 +161,13 @@ Core::GeneratedFiles Html5App::generateFiles(QString *errorMessage) const
}
#endif // CREATORLESSTEST
bool Html5App::useExistingIndexHtml() const
{
return !m_indexHtmlFile.filePath().isEmpty();
}
QByteArray Html5App::generateFileExtended(int fileType,
bool *versionAndCheckSum, QString *comment, QString *errorMessage) const
{
QByteArray data;
switch (fileType) {
case Html5AppGeneratedFileInfo::IndexHtmlFile:
data = readBlob(path(IndexHtmlOrigin), errorMessage);
case Html5AppGeneratedFileInfo::MainHtmlFile:
data = readBlob(path(MainHtmlOrigin), errorMessage);
break;
case Html5AppGeneratedFileInfo::AppViewerPriFile:
data = readBlob(path(AppViewerPriOrigin), errorMessage);
......@@ -215,7 +225,8 @@ QList<AbstractGeneratedFileInfo> Html5App::updateableFiles(const QString &mainPr
QList<DeploymentFolder> Html5App::deploymentFolders() const
{
QList<DeploymentFolder> result;
result.append(DeploymentFolder(path(HtmlDirProFileRelative), QLatin1String(".")));
if (m_mainHtmlMode != ModeUrl)
result.append(DeploymentFolder(path(HtmlDirProFileRelative), QLatin1String(".")));
return result;
}
......
......@@ -45,7 +45,7 @@ namespace Internal {
struct Html5AppGeneratedFileInfo : public AbstractGeneratedFileInfo
{
enum ExtendedFileType {
IndexHtmlFile = ExtendedFile,
MainHtmlFile = ExtendedFile,
AppViewerPriFile,
AppViewerCppFile,
AppViewerHFile
......@@ -60,9 +60,9 @@ class Html5App : public AbstractMobileApp
{
public:
enum ExtendedFileType {
IndexHtml = ExtendedFile,
IndexHtmlDeployed,
IndexHtmlOrigin,
MainHtml = ExtendedFile,
MainHtmlDeployed,
MainHtmlOrigin,
AppViewerPri,
AppViewerPriOrigin,
AppViewerCpp,
......@@ -74,18 +74,23 @@ public:
ModulesDir
};
enum Mode {
ModeGenerate,
ModeImport,
ModeUrl
};
Html5App();
virtual ~Html5App();
void setIndexHtmlFile(const QString &qmlFile);
QString indexHtmlFile() const;
void setMainHtml(Mode mode, const QString &data = QString());
Mode mainHtmlMode() const;
#ifndef CREATORLESSTEST
virtual Core::GeneratedFiles generateFiles(QString *errorMessage) const;
#else
bool generateFiles(QString *errorMessage) const;
#endif // CREATORLESSTEST
bool useExistingIndexHtml() const;
static const int StubVersion;
......@@ -104,6 +109,8 @@ private:
QList<DeploymentFolder> deploymentFolders() const;
QFileInfo m_indexHtmlFile;
Mode m_mainHtmlMode;
QString m_mainHtmlData;
};
} // namespace Internal
......
......@@ -130,18 +130,18 @@ void Html5AppWizard::prepareGenerateFiles(const QWizard *w,
{
Q_UNUSED(errorMessage)
const Html5AppWizardDialog *wizard = qobject_cast<const Html5AppWizardDialog*>(w);
const QString mainQmlFile = wizard->m_htmlSourcesPage->mainHtmlFile();
m_d->app->setIndexHtmlFile(mainQmlFile);
m_d->app->setMainHtml(wizard->m_htmlSourcesPage->mainHtmlMode(),
wizard->m_htmlSourcesPage->mainHtmlData());
}
bool Html5AppWizard::postGenerateFilesInternal(const Core::GeneratedFiles &l,
QString *errorMessage)
{
const bool success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
if (success && !m_d->app->indexHtmlFile().isEmpty()) {
ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, m_d->app->indexHtmlFile());
Core::EditorManager::instance()->openEditor(m_d->app->indexHtmlFile(),
QString(), Core::EditorManager::ModeSwitch);
const QString mainHtmlFile = m_d->app->path(Html5App::MainHtml);
if (success && !mainHtmlFile.isEmpty()) {
ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, mainHtmlFile);
Core::EditorManager::instance()->openEditor(mainHtmlFile, QString(), Core::EditorManager::ModeSwitch);
}
return success;
}
......
......@@ -54,15 +54,16 @@ Html5AppWizardSourcesPage::Html5AppWizardSourcesPage(QWidget *parent)
, m_d(new Html5AppWizardSourcesPagePrivate)
{
m_d->ui.setupUi(this);
m_d->ui.mainHtmlFileLineEdit->setExpectedKind(Utils::PathChooser::File);
m_d->ui.mainHtmlFileLineEdit->setPromptDialogFilter(QLatin1String("*.html"));
m_d->ui.mainHtmlFileLineEdit->setPromptDialogTitle(tr("Select Html File"));
connect(m_d->ui.mainHtmlFileLineEdit, SIGNAL(changed(QString)), SIGNAL(completeChanged()));
connect(m_d->ui.importExistingHtmlRadioButton,
m_d->ui.importLineEdit->setExpectedKind(Utils::PathChooser::File);
m_d->ui.importLineEdit->setPromptDialogFilter(QLatin1String("*.html"));
m_d->ui.importLineEdit->setPromptDialogTitle(tr("Select Html File"));
connect(m_d->ui.importLineEdit, SIGNAL(changed(QString)), SIGNAL(completeChanged()));
connect(m_d->ui.importRadioButton,
SIGNAL(toggled(bool)), SIGNAL(completeChanged()));
connect(m_d->ui.newHtmlRadioButton, SIGNAL(toggled(bool)),
m_d->ui.mainHtmlFileLineEdit, SLOT(setDisabled(bool)));
m_d->ui.newHtmlRadioButton->setChecked(true);
connect(m_d->ui.generateRadioButton, SIGNAL(toggled(bool)), SLOT(setLineEditsEnabled()));
connect(m_d->ui.importRadioButton, SIGNAL(toggled(bool)), SLOT(setLineEditsEnabled()));
connect(m_d->ui.urlRadioButton, SIGNAL(toggled(bool)), SLOT(setLineEditsEnabled()));
m_d->ui.generateRadioButton->setChecked(true);
}
Html5AppWizardSourcesPage::~Html5AppWizardSourcesPage()
......@@ -70,16 +71,35 @@ Html5AppWizardSourcesPage::~Html5AppWizardSourcesPage()
delete m_d;
}
QString Html5AppWizardSourcesPage::mainHtmlFile() const
Html5App::Mode Html5AppWizardSourcesPage::mainHtmlMode() const
{
return m_d->ui.importExistingHtmlRadioButton->isChecked() ?
m_d->ui.mainHtmlFileLineEdit->path() : QString();
Html5App::Mode result = Html5App::ModeGenerate;
if (m_d->ui.importRadioButton->isChecked())
result = Html5App::ModeImport;
else if (m_d->ui.urlRadioButton->isChecked())
result = Html5App::ModeUrl;
return result;
}
QString Html5AppWizardSourcesPage::mainHtmlData() const
{
switch (mainHtmlMode()) {
case Html5App::ModeImport: return m_d->ui.importLineEdit->path();
case Html5App::ModeUrl: return m_d->ui.urlLineEdit->text();
default:
case Html5App::ModeGenerate: return QString();
}
}
bool Html5AppWizardSourcesPage::isComplete() const
{
return !m_d->ui.importExistingHtmlRadioButton->isChecked()
|| m_d->ui.mainHtmlFileLineEdit->isValid();
return mainHtmlMode() != Html5App::ModeImport || m_d->ui.importLineEdit->isValid();
}
void Html5AppWizardSourcesPage::setLineEditsEnabled()
{
m_d->ui.importLineEdit->setEnabled(m_d->ui.importRadioButton->isChecked());
m_d->ui.urlLineEdit->setEnabled(m_d->ui.urlRadioButton->isChecked());
}
} // namespace Internal
......
......@@ -49,9 +49,13 @@ public:
explicit Html5AppWizardSourcesPage(QWidget *parent = 0);
virtual ~Html5AppWizardSourcesPage();
QString mainHtmlFile() const;
Html5App::Mode mainHtmlMode() const;
QString mainHtmlData() const;
virtual bool isComplete() const;
private slots:
void setLineEditsEnabled();
private:
class Html5AppWizardSourcesPagePrivate *m_d;
};
......
......@@ -21,16 +21,16 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="newHtmlRadioButton">
<widget class="QRadioButton" name="generateRadioButton">
<property name="text">
<string>Generate an index.html file</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="importExistingHtmlRadioButton">
<widget class="QRadioButton" name="importRadioButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Import an existing .html file</string>
......@@ -38,9 +38,9 @@
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="mainHtmlFileLineEdit">
<widget class="Utils::PathChooser" name="importLineEdit">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
......@@ -61,9 +61,9 @@
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="loadAUrlRadioButton">
<widget class="QRadioButton" name="urlRadioButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Load a URL</string>
......@@ -71,9 +71,12 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="loadAUrlLineEdit">
<widget class="QLineEdit" name="urlLineEdit">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>http://</string>
</property>
</widget>
</item>
......@@ -105,7 +108,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Note: Unless you chose to load an URL, all files and directories that reside in the same directory as the main Html file are deployed. You can modify the contents of the directory any time before deploying.</string>
<string>Note: Unless you chose to load a URL, all files and directories that reside in the same directory as the main Html file are deployed. You can modify the contents of the directory any time before deploying.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
......
......@@ -31,7 +31,7 @@ bool Html5App::generateFiles(QString *errorMessage) const
{
return writeFile(generateFile(Html5AppGeneratedFileInfo::MainCppFile, errorMessage), path(MainCpp))
&& writeFile(generateFile(Html5AppGeneratedFileInfo::AppProFile, errorMessage), path(AppPro))
&& (useExistingIndexHtml() ? true : writeFile(generateFile(Html5AppGeneratedFileInfo::IndexHtmlFile, errorMessage), path(IndexHtml)))
&& (mainHtmlMode() != ModeGenerate ? true : writeFile(generateFile(Html5AppGeneratedFileInfo::MainHtmlFile, errorMessage), path(MainHtml)))
&& writeFile(generateFile(Html5AppGeneratedFileInfo::AppViewerPriFile, errorMessage), path(AppViewerPri))
&& writeFile(generateFile(Html5AppGeneratedFileInfo::AppViewerCppFile, errorMessage), path(AppViewerCpp))
&& writeFile(generateFile(Html5AppGeneratedFileInfo::AppViewerHFile, errorMessage), path(AppViewerH))
......
......@@ -84,6 +84,27 @@ int main(int argc, char *argv[])
Html5App sAppNew;
sAppNew.setProjectPath(projectPath);
sAppNew.setProjectName(QLatin1String("new_html5_app"));
qDebug() << sAppNew.path(Html5App::MainHtml);
if (!sAppNew.generateFiles(&errorMessage))
return 1;
}
{
Html5App sAppNew;
sAppNew.setProjectPath(projectPath);
sAppNew.setProjectName(QLatin1String("html5_imported_scenario_01"));
sAppNew.setMainHtml(Html5App::ModeImport, QLatin1String("../appwizards/htmlimportscenario_01/themainhtml.html"));
qDebug() << sAppNew.path(Html5App::MainHtml);
if (!sAppNew.generateFiles(&errorMessage))
return 1;
}
{
Html5App sAppNew;
sAppNew.setProjectPath(projectPath);
sAppNew.setProjectName(QLatin1String("html5_url"));
sAppNew.setMainHtml(Html5App::ModeUrl, QLatin1String("http://www.jqtouch.com/preview/demos/main/"));
qDebug() << sAppNew.path(Html5App::MainHtml);
if (!sAppNew.generateFiles(&errorMessage))
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment