From f3cf0c36cbdbd111c47cd0d87cbad73620bd08fb Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Tue, 26 Jan 2010 22:03:17 +0100
Subject: [PATCH] Adjust .qmlproject files generated by wizards to new format

---
 .../qmlprojectmanager/qmlnewprojectwizard.cpp | 46 ++++++++-----
 .../qmlprojectmanager/qmlprojectwizard.cpp    | 65 ++++---------------
 .../qmlprojectmanager/qmlprojectwizard.h      |  7 --
 3 files changed, 44 insertions(+), 74 deletions(-)

diff --git a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
index 2e88ca154ea..b7df8f15c3d 100644
--- a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
+++ b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
@@ -103,26 +103,40 @@ Core::GeneratedFiles QmlNewProjectWizard::generateFiles(const QWizard *w,
                                                                      QLatin1String("qml"));
 
     QString contents;
-    QTextStream out(&contents);
-
-    out
-        << "import Qt 4.6" << endl
-        << endl
-        << "Rectangle {" << endl
-        << "    width: 200" << endl
-        << "    height: 200" << endl
-        << "    Text {" << endl
-        << "        x: 66" << endl
-        << "        y: 93" << endl
-        << "        text: \"Hello World\"" << endl
-        << "    }" << endl
-        << "}" << endl;
-
+    {
+        QTextStream out(&contents);
+
+        out
+            << "import Qt 4.6" << endl
+            << endl
+            << "Rectangle {" << endl
+            << "    width: 200" << endl
+            << "    height: 200" << endl
+            << "    Text {" << endl
+            << "        x: 66" << endl
+            << "        y: 93" << endl
+            << "        text: \"Hello World\"" << endl
+            << "    }" << endl
+            << "}" << endl;
+    }
     Core::GeneratedFile generatedMainFile(mainFileName);
     generatedMainFile.setContents(contents);
 
+    QString projectContents;
+    {
+        QTextStream out(&projectContents);
+
+        out
+            << "import QmlProject 1.0" << endl
+            << "Project {" << endl
+            << "    QmlFiles {" << endl
+            << "        directory: \".\"" << endl
+            << "    }" << endl
+            << "}" << endl;
+    }
     Core::GeneratedFile generatedCreatorFile(creatorFileName);
-    generatedCreatorFile.setContents(projectName + QLatin1String(".qml\n"));
+
+    generatedCreatorFile.setContents(projectContents);
 
     Core::GeneratedFiles files;
     files.append(generatedMainFile);
diff --git a/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp b/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
index bb555357b6c..53089d7798d 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
@@ -117,48 +117,6 @@ QWizard *QmlProjectWizard::createWizardDialog(QWidget *parent,
     return wizard;
 }
 
-void QmlProjectWizard::getFileList(const QDir &dir, const QString &projectRoot,
-                                       const QStringList &suffixes,
-                                       QStringList *files, QStringList *paths) const
-{
-    const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files |
-                                                         QDir::Dirs |
-                                                         QDir::NoDotAndDotDot |
-                                                         QDir::NoSymLinks);
-
-    foreach (const QFileInfo &fileInfo, fileInfoList) {
-        QString filePath = fileInfo.absoluteFilePath();
-        filePath = filePath.mid(projectRoot.length() + 1);
-
-        if (fileInfo.isDir() && isValidDir(fileInfo)) {
-            getFileList(QDir(fileInfo.absoluteFilePath()), projectRoot,
-                        suffixes, files, paths);
-
-            if (! paths->contains(filePath))
-                paths->append(filePath);
-        }
-
-        else if (suffixes.contains(fileInfo.suffix()))
-            files->append(filePath);
-    }
-}
-
-bool QmlProjectWizard::isValidDir(const QFileInfo &fileInfo) const
-{
-    const QString fileName = fileInfo.fileName();
-    const QString suffix = fileInfo.suffix();
-
-    if (fileName.startsWith(QLatin1Char('.')))
-        return false;
-
-    else if (fileName == QLatin1String("CVS"))
-        return false;    
-
-    // ### user include/exclude
-
-    return true;
-}
-
 Core::GeneratedFiles QmlProjectWizard::generateFiles(const QWizard *w,
                                                      QString *errorMessage) const
 {
@@ -170,16 +128,21 @@ Core::GeneratedFiles QmlProjectWizard::generateFiles(const QWizard *w,
     const QString projectName = wizard->projectName();
     const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".qmlproject")).absoluteFilePath();
 
-    Core::ICore *core = Core::ICore::instance();
-    Core::MimeDatabase *mimeDatabase = core->mimeDatabase();
-
-    const QStringList suffixes = mimeDatabase->suffixes();
-
-    QStringList sources, paths;
-    getFileList(dir, projectPath, suffixes, &sources, &paths);
-
+    QString projectContents;
+    {
+        QTextStream out(&projectContents);
+
+        out
+            << "import QmlProject 1.0" << endl
+            << "Project {" << endl
+            << "    QmlFiles {" << endl
+            << "        directory: \".\"" << endl
+            << "        recursive: true" << endl
+            << "    }" << endl
+            << "}" << endl;
+    }
     Core::GeneratedFile generatedCreatorFile(creatorFileName);
-    generatedCreatorFile.setContents(sources.join(QLatin1String("\n")));
+    generatedCreatorFile.setContents(projectContents);
 
     Core::GeneratedFiles files;
     files.append(generatedCreatorFile);
diff --git a/src/plugins/qmlprojectmanager/qmlprojectwizard.h b/src/plugins/qmlprojectmanager/qmlprojectwizard.h
index 865a69512a8..1b59cce86bc 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectwizard.h
+++ b/src/plugins/qmlprojectmanager/qmlprojectwizard.h
@@ -84,13 +84,6 @@ protected:
                                                QString *errorMessage) const;
 
     virtual bool postGenerateFiles(const Core::GeneratedFiles &l, QString *errorMessage);
-
-    bool isValidDir(const QFileInfo &fileInfo) const;
-
-    void getFileList(const QDir &dir, const QString &projectRoot,
-                     const QStringList &suffixes,
-                     QStringList *files,
-                     QStringList *paths) const;
 };
 
 } // end of namespace Internal
-- 
GitLab