OSDN Git Service

48613806c05388a8a116bef96b5cb879d63a2858
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / wizards / qtprojectparameters.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 "qtprojectparameters.h"
35 #include <utils/codegeneration.h>
36
37 #include <QtCore/QTextStream>
38 #include <QtCore/QDir>
39 #include <QtCore/QCoreApplication>
40 #include <QtCore/QDateTime>
41 #include <QtCore/QDebug>
42
43 namespace Qt4ProjectManager {
44 namespace Internal {
45
46 // ----------- QtProjectParameters
47 QtProjectParameters::QtProjectParameters()
48   : type(ConsoleApp)
49 {
50 }
51
52 QString QtProjectParameters::projectPath() const
53 {
54     QString rc = path;
55     if (!rc.isEmpty())
56         rc += QDir::separator();
57     rc += fileName;
58     return rc;
59 }
60
61 void QtProjectParameters::writeProFile(QTextStream &str) const
62 {
63     if (!selectedModules.isEmpty())
64         str << "QT       += " << selectedModules << "\n\n";
65     if (!deselectedModules.isEmpty())
66         str << "QT       -= " << deselectedModules << "\n\n";
67     const QString &effectiveTarget = target.isEmpty() ? fileName : target;
68     if (!effectiveTarget.isEmpty())
69         str << "TARGET = " <<  effectiveTarget << '\n';
70     switch (type) {
71     case ConsoleApp:
72         // Mac: Command line apps should not be bundles
73         str << "CONFIG   += console\nCONFIG   -= app_bundle\n\n";
74     case GuiApp:
75         str << "TEMPLATE = app\n";
76         break;
77     case StaticLibrary:
78         str << "TEMPLATE = lib\nCONFIG += staticlib\n";
79         break;
80     case SharedLibrary:
81         str << "TEMPLATE = lib\n\nDEFINES += " << libraryMacro(fileName) << '\n';
82         break;
83     case Qt4Plugin:
84         str << "TEMPLATE = lib\nCONFIG += plugin\n";
85         break;
86     default:
87         break;
88     }
89
90     if (!targetDirectory.isEmpty())
91         str << "\nDESTDIR = " << targetDirectory << '\n';
92 }
93
94 void QtProjectParameters::writeProFileHeader(QTextStream &str)
95 {
96     const QChar hash = QLatin1Char ('#');
97     const QChar nl = QLatin1Char('\n');
98     const QChar blank = QLatin1Char(' ');
99     // Format as '#-------\n# <Header> \n#---------'
100     QString header = QLatin1String(" Project created by ");
101     header += QCoreApplication::applicationName();
102     header += blank;
103     header += QDateTime::currentDateTime().toString(Qt::ISODate);
104     const QString line = QString(header.size(), QLatin1Char('-'));
105     str << hash << line << nl << hash << nl << hash << header << nl
106         << hash <<nl << hash << line << nl << nl;
107 }
108
109
110 QString createMacro(const QString &name, const QString &suffix)
111 {
112     QString rc = name.toUpper();
113     const int extensionPosition = rc.indexOf(QLatin1Char('.'));
114     if (extensionPosition != -1)
115         rc.truncate(extensionPosition);
116     rc += suffix;
117     return Utils::fileNameToCppIdentifier(rc);
118 }
119
120 QString QtProjectParameters::exportMacro(const QString &projectName)
121 {
122     return createMacro(projectName, QLatin1String("SHARED_EXPORT"));
123 }
124
125 QString QtProjectParameters::libraryMacro(const QString &projectName)
126 {
127      return createMacro(projectName, QLatin1String("_LIBRARY"));
128 }
129
130 } // namespace Internal
131 } // namespace Qt4ProjectManager