OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / pluginfilefactory.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "pluginfilefactory.h"
35 #include "projectexplorer.h"
36 #include "project.h"
37 #include "projectexplorerconstants.h"
38 #include "iprojectmanager.h"
39 #include "session.h"
40
41 #include <extensionsystem/pluginmanager.h>
42 #include <coreplugin/icore.h>
43 #include <coreplugin/mimedatabase.h>
44 #include <coreplugin/messagemanager.h>
45
46 #include <QtCore/QDebug>
47
48 using namespace ProjectExplorer;
49 using namespace ProjectExplorer::Internal;
50
51 ProjectFileFactory::ProjectFileFactory(IProjectManager *manager)
52   : m_mimeTypes(manager->mimeType()),
53     m_manager(manager)
54 {
55 }
56
57 QStringList ProjectFileFactory::mimeTypes() const
58 {
59     return m_mimeTypes;
60 }
61
62 QString ProjectFileFactory::id() const
63 {
64     return QLatin1String(Constants::FILE_FACTORY_ID);
65 }
66
67 QString ProjectFileFactory::displayName() const
68 {
69     return tr("Project File Factory", "ProjectExplorer::ProjectFileFactory display name.");
70 }
71
72 Core::IFile *ProjectFileFactory::open(const QString &fileName)
73 {
74     Core::IFile *fIFace = 0;
75
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();
83     }
84     return fIFace;
85 }
86
87 QList<ProjectFileFactory *> ProjectFileFactory::createFactories(QString *filterString)
88 {
89     // Register factories for all project managers
90     QList<Internal::ProjectFileFactory*> rc;
91     QList<IProjectManager*> projectManagers =
92         ExtensionSystem::PluginManager::instance()->getObjects<IProjectManager>();
93
94     QList<Core::MimeGlobPattern> allGlobPatterns;
95
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;
107     }
108     QString allProjectFilter = Core::MimeType::formatFilterString(tr("All Projects"), allGlobPatterns);
109     allProjectFilter.append(filterSeparator);
110     filterString->prepend(allProjectFilter);
111     return rc;
112 }