1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the tools applications of the Qt Toolkit.
|
|
7 **
|
|
8 ** Commercial Usage
|
|
9 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 ** accordance with the Qt Commercial License Agreement provided with the
|
|
11 ** Software or, alternatively, in accordance with the terms contained in
|
|
12 ** a written agreement between you and Nokia.
|
|
13 **
|
|
14 **
|
|
15 ** GNU General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU
|
|
17 ** General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 ** Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 ** the packaging of this file. Please review the following information
|
|
20 ** to ensure GNU General Public Licensing requirements will be met:
|
|
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 ** exception, Nokia gives you certain additional rights. These rights
|
|
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in
|
|
25 ** the file GPL_EXCEPTION.txt in this package.
|
|
26 **
|
|
27 ** Qt for Windows(R) Licensees
|
|
28 ** As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 ** right for the Qt/Eclipse Integration to link to functionality
|
|
31 ** provided by Qt Designer and its related libraries.
|
|
32 **
|
|
33 ** If you are unsure which license is appropriate for your use, please
|
|
34 ** contact the sales department at qt-sales@nokia.com.
|
|
35 **
|
|
36 ****************************************************************************/
|
|
37
|
|
38 #include "dextractimages.h"
|
|
39 #include "dwriteicondata.h"
|
|
40 #include "driver.h"
|
|
41 #include "ui4.h"
|
|
42 #include "utils.h"
|
|
43 #include "uic.h"
|
|
44
|
|
45 #include <QtCore/QDataStream>
|
|
46 #include <QtCore/QTextStream>
|
|
47 #include <QtCore/QTextCodec>
|
|
48 #include <QtCore/QDir>
|
|
49 #include <QtCore/QFile>
|
|
50 #include <QtCore/QFileInfo>
|
|
51
|
|
52 QT_BEGIN_NAMESPACE
|
|
53
|
|
54 namespace D {
|
|
55
|
|
56 ExtractImages::ExtractImages(const Option &opt)
|
|
57 : m_output(0), m_option(opt)
|
|
58 {
|
|
59 }
|
|
60
|
|
61 void ExtractImages::acceptUI(DomUI *node)
|
|
62 {
|
|
63 if (!m_option.extractImages)
|
|
64 return;
|
|
65
|
|
66 if (node->elementImages() == 0)
|
|
67 return;
|
|
68
|
|
69 QString className = node->elementClass() + m_option.postfix;
|
|
70
|
|
71 QFile f;
|
|
72 if (m_option.qrcOutputFile.size()) {
|
|
73 f.setFileName(m_option.qrcOutputFile);
|
|
74 if (!f.open(QIODevice::WriteOnly | QFile::Text)) {
|
|
75 fprintf(stderr, "Could not create resource file\n");
|
|
76 return;
|
|
77 }
|
|
78
|
|
79 QFileInfo fi(m_option.qrcOutputFile);
|
|
80 QDir dir = fi.absoluteDir();
|
|
81 if (!dir.exists(QLatin1String("images")) && !dir.mkdir(QLatin1String("images"))) {
|
|
82 fprintf(stderr, "Could not create image dir\n");
|
|
83 return;
|
|
84 }
|
|
85 dir.cd(QLatin1String("images"));
|
|
86 m_imagesDir = dir;
|
|
87
|
|
88 m_output = new QTextStream(&f);
|
|
89 m_output->setCodec(QTextCodec::codecForName("UTF-8"));
|
|
90
|
|
91 QTextStream &out = *m_output;
|
|
92
|
|
93 out << "<RCC>\n";
|
|
94 out << " <qresource prefix=\"/" << className << "\" >\n";
|
|
95 TreeWalker::acceptUI(node);
|
|
96 out << " </qresource>\n";
|
|
97 out << "</RCC>\n";
|
|
98
|
|
99 f.close();
|
|
100 delete m_output;
|
|
101 m_output = 0;
|
|
102 }
|
|
103 }
|
|
104
|
|
105 void ExtractImages::acceptImages(DomImages *images)
|
|
106 {
|
|
107 TreeWalker::acceptImages(images);
|
|
108 }
|
|
109
|
|
110 void ExtractImages::acceptImage(DomImage *image)
|
|
111 {
|
|
112 QString format = image->elementData()->attributeFormat();
|
|
113 QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower();
|
|
114 QString fname = m_imagesDir.absoluteFilePath(image->attributeName() + QLatin1Char('.') + extension);
|
|
115
|
|
116 *m_output << " <file>images/" << image->attributeName() << QLatin1Char('.') + extension << "</file>\n";
|
|
117
|
|
118 QFile f;
|
|
119 f.setFileName(fname);
|
|
120 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
121 fprintf(stderr, "Could not create image file\n");
|
|
122 return;
|
|
123 }
|
|
124
|
|
125 if (format == QLatin1String("XPM.GZ")) {
|
|
126 QTextStream *imageOut = new QTextStream(&f);
|
|
127 imageOut->setCodec(QTextCodec::codecForName("UTF-8"));
|
|
128
|
|
129 D::WriteIconData::writeImage(*imageOut, QString(), image);
|
|
130 delete imageOut;
|
|
131 } else {
|
|
132 D::WriteIconData::writeImage(f, image);
|
|
133 }
|
|
134
|
|
135 f.close();
|
|
136 }
|
|
137
|
|
138 } // namespace D
|
|
139
|
|
140 QT_END_NAMESPACE
|