1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "pluginfilefactory.h"
35 #include "projectexplorer.h"
37 #include "projectexplorerconstants.h"
38 #include "iprojectmanager.h"
41 #include <extensionsystem/pluginmanager.h>
42 #include <coreplugin/icore.h>
43 #include <coreplugin/mimedatabase.h>
44 #include <coreplugin/messagemanager.h>
46 #include <QtCore/QDebug>
48 using namespace ProjectExplorer;
49 using namespace ProjectExplorer::Internal;
51 ProjectFileFactory::ProjectFileFactory(IProjectManager *manager)
52 : m_mimeTypes(manager->mimeType()),
57 QStringList ProjectFileFactory::mimeTypes() const
62 QString ProjectFileFactory::id() const
64 return QLatin1String(Constants::FILE_FACTORY_ID);
67 QString ProjectFileFactory::displayName() const
69 return tr("Project File Factory", "ProjectExplorer::ProjectFileFactory display name.");
72 Core::IFile *ProjectFileFactory::open(const QString &fileName)
74 Core::IFile *fIFace = 0;
76 ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
77 if (!pe->openProject(fileName)) {
78 Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not open the following project: '%1'").arg(fileName));
79 } else if (pe->session()) {
80 SessionManager *session = pe->session();
81 if (session->projects().count() == 1)
82 fIFace = session->projects().first()->file();
87 QList<ProjectFileFactory *> ProjectFileFactory::createFactories(QString *filterString)
89 // Register factories for all project managers
90 QList<Internal::ProjectFileFactory*> rc;
91 QList<IProjectManager*> projectManagers =
92 ExtensionSystem::PluginManager::instance()->getObjects<IProjectManager>();
94 QList<Core::MimeGlobPattern> allGlobPatterns;
96 const QString filterSeparator = QLatin1String(";;");
97 filterString->clear();
98 foreach (IProjectManager *manager, projectManagers) {
99 rc.push_back(new ProjectFileFactory(manager));
100 if (!filterString->isEmpty())
101 *filterString += filterSeparator;
102 const QString mimeType = manager->mimeType();
103 Core::MimeType mime = Core::ICore::instance()->mimeDatabase()->findByType(mimeType);
104 const QString pFilterString = mime.filterString();
105 allGlobPatterns.append(mime.globPatterns());
106 *filterString += pFilterString;
108 QString allProjectFilter = Core::MimeType::formatFilterString(tr("All Projects"), allGlobPatterns);
109 allProjectFilter.append(filterSeparator);
110 filterString->prepend(allProjectFilter);