OSDN Git Service

5092ba8dc4b84ddbff5c3e09314583ea83160f54
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / coreplugin.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 "coreplugin.h"
35 #include "editmode.h"
36 #include "editormanager.h"
37 #include "mainwindow.h"
38 #include "modemanager.h"
39 #include "fileiconprovider.h"
40 #include "designmode.h"
41 #include "mimedatabase.h"
42
43 #include <extensionsystem/pluginmanager.h>
44
45 #include <QtCore/QtPlugin>
46 #include <QtCore/QDebug>
47
48 using namespace Core;
49 using namespace Core::Internal;
50
51 CorePlugin::CorePlugin() :
52     m_mainWindow(new MainWindow), m_editMode(0)
53 {
54 }
55
56 CorePlugin::~CorePlugin()
57 {
58     if (m_editMode) {
59         removeObject(m_editMode);
60         delete m_editMode;
61     }
62
63     if (m_designMode) {
64         removeObject(m_designMode);
65         delete m_designMode;
66     }
67
68     // delete FileIconProvider singleton
69     delete FileIconProvider::instance();
70
71     delete m_mainWindow;
72 }
73
74 void CorePlugin::parseArguments(const QStringList &arguments)
75 {
76     for (int i = 0; i < arguments.size() - 1; i++) {
77         if (arguments.at(i) == QLatin1String("-color")) {
78             const QString colorcode(arguments.at(i + 1));
79             m_mainWindow->setOverrideColor(QColor(colorcode));
80             i++; // skip the argument
81         }
82     }
83 }
84
85 bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
86 {
87     parseArguments(arguments);
88     const bool success = m_mainWindow->init(errorMessage);
89     if (success) {
90         EditorManager *editorManager = m_mainWindow->editorManager();
91         m_editMode = new EditMode(editorManager);
92         addObject(m_editMode);
93         m_mainWindow->modeManager()->activateMode(m_editMode->id());
94
95         m_designMode = new DesignMode(editorManager);
96         addObject(m_designMode);
97     }
98     return success;
99 }
100
101 void CorePlugin::extensionsInitialized()
102 {
103     m_mainWindow->mimeDatabase()->syncUserModifiedMimeTypes();
104     m_mainWindow->extensionsInitialized();
105 }
106
107 void CorePlugin::remoteCommand(const QStringList & /* options */, const QStringList &args)
108 {
109     m_mainWindow->openFiles(args, ICore::SwitchMode);
110     m_mainWindow->activateWindow();
111 }
112
113 void CorePlugin::fileOpenRequest(const QString &f)
114 {
115     remoteCommand(QStringList(), QStringList(f));
116 }
117
118 ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
119 {
120     m_mainWindow->aboutToShutdown();
121     return SynchronousShutdown;
122 }
123
124 Q_EXPORT_PLUGIN(CorePlugin)