2
* This file is part of kde-thumbnailer-po
3
* Copyright (C) 2011-2012 Ni Hui <shuizhuyuanluo@126.com>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of
8
* the License or (at your option) version 3 or any later version
9
* accepted by the membership of KDE e.V. (or its successor approved
10
* by the membership of KDE e.V.), which shall act as a proxy
11
* defined in Section 14 of version 3 of the license.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "pocreator.h"
24
#include <gettext-po.h>
27
#include <QLatin1String>
30
#include <kdemacros.h>
33
#include "pocreatorsettings.h"
34
#include "ui_pocreatorform.h"
37
KDE_EXPORT ThumbCreator* new_creator() {
38
KGlobal::locale()->insertCatalog( QLatin1String( "pothumbnail" ) );
43
static bool readerror = false;
45
static void xerror( int severity,
46
po_message_t /*message*/,
47
const char */*filename*/, size_t /*lineno*/, size_t /*column*/,
48
int /*multiline_p*/, const char */*message_text*/ )
50
if ( severity == PO_SEVERITY_ERROR || severity == PO_SEVERITY_FATAL_ERROR )
54
static void xerror2( int severity,
55
po_message_t /*message1*/,
56
const char */*filename1*/, size_t /*lineno1*/, size_t /*column1*/,
57
int /*multiline_p1*/, const char */*message_text1*/,
58
po_message_t /*message2*/,
59
const char */*filename2*/, size_t /*lineno2*/, size_t /*column2*/,
60
int /*multiline_p2*/, const char */*message_text2*/ )
62
if ( severity == PO_SEVERITY_ERROR || severity == PO_SEVERITY_FATAL_ERROR )
66
static bool get_po_info( const char* filepath, int& translate, int& untranslate, int& fuzzy, int& obsolete )
69
const struct po_xerror_handler handler = { xerror, xerror2 };
71
pofile = po_file_read( filepath, &handler );
72
if ( pofile == NULL || readerror )
75
po_message_iterator_t it;
76
it = po_message_iterator( pofile, NULL );
79
while ( ( msg = po_next_message( it ) ) != NULL ) {
80
if ( po_message_is_obsolete( msg ) )
82
else if ( po_message_is_fuzzy( msg ) )
85
msgstr = po_message_msgstr( msg );
86
if ( msgstr[0] == '\0' )
92
po_message_iterator_free( it );
94
/// do not count domain header as translated message
95
const char* header = po_file_domain_header( pofile, NULL );
99
po_file_free( pofile );
104
PoCreator::PoCreator()
108
PoCreator::~PoCreator()
112
bool PoCreator::create( const QString& path, int width, int height, QImage& img )
119
if ( !get_po_info( path.toLocal8Bit(), translate, untranslate, fuzzy, obsolete ) )
122
int total = translate + untranslate + fuzzy + obsolete;
124
int d = ( width < height ) ? width - 2 : height - 2;
126
QImage pix( d + 2, d + 2, QImage::Format_ARGB32_Premultiplied );
127
pix.fill( Qt::transparent ); /// transparent background
129
int circle = 16 * 360;
130
int untranslateAngle = untranslate * circle / total;
131
int fuzzyAngle = fuzzy * circle / total;
132
int obsoleteAngle = obsolete * circle / total;
133
int translateAngle = circle - untranslateAngle - fuzzyAngle - obsoleteAngle;
136
p.setRenderHint( QPainter::Antialiasing );
138
if ( fuzzyAngle > 0 ) {
139
p.setBrush( PoCreatorSettings::self()->fuzzyColor() );
140
if ( fuzzy == total )
141
p.drawEllipse( 1, 1, d, d );
143
p.drawPie( 1, 1, d, d, 0, -fuzzyAngle );
145
if ( untranslateAngle > 0 ) {
146
p.setBrush( PoCreatorSettings::self()->untranslatedColor() );
147
if ( untranslate == total )
148
p.drawEllipse( 1, 1, d, d );
150
p.drawPie( 1, 1, d, d, -fuzzyAngle, -untranslateAngle );
152
if ( obsoleteAngle > 0 ) {
153
p.setBrush( PoCreatorSettings::self()->obsoletedColor() );
154
if ( obsolete == total )
155
p.drawEllipse( 1, 1, d, d );
157
p.drawPie( 1, 1, d, d, -fuzzyAngle-untranslateAngle, -obsoleteAngle );
159
if ( translateAngle > 0 ) {
160
p.setBrush( PoCreatorSettings::self()->translatedColor() );
161
if ( translate == total )
162
p.drawEllipse( 1, 1, d, d );
164
p.drawPie( 1, 1, d, d, -fuzzyAngle-untranslateAngle-obsoleteAngle, -translateAngle );
172
class PoCreatorFormWidget : public QWidget, public Ui::PoCreatorForm
175
PoCreatorFormWidget() { setupUi( this ); }
178
QWidget* PoCreator::createConfigurationWidget()
180
PoCreatorFormWidget* cw = new PoCreatorFormWidget;
181
cw->translatedButton->setColor( PoCreatorSettings::self()->translatedColor() );
182
cw->fuzzyButton->setColor( PoCreatorSettings::self()->fuzzyColor() );
183
cw->untranslatedButton->setColor( PoCreatorSettings::self()->untranslatedColor() );
184
cw->obsoletedButton->setColor( PoCreatorSettings::self()->obsoletedColor() );
188
void PoCreator::writeConfiguration( const QWidget* configurationWidget )
190
const PoCreatorFormWidget* cw = static_cast<const PoCreatorFormWidget*>(configurationWidget);
191
PoCreatorSettings::self()->setTranslatedColor( cw->translatedButton->color() );
192
PoCreatorSettings::self()->setFuzzyColor( cw->fuzzyButton->color() );
193
PoCreatorSettings::self()->setUntranslatedColor( cw->untranslatedButton->color() );
194
PoCreatorSettings::self()->setObsoletedColor( cw->obsoletedButton->color() );
195
PoCreatorSettings::self()->writeConfig();