thumbnailers: import po thunmbnaier

This commit is contained in:
Ivailo Monev 2015-01-24 20:43:27 +00:00
parent b4d03404c3
commit 8803d28274
11 changed files with 474 additions and 2 deletions

View file

@ -1,5 +1,7 @@
project(kdegraphics-thumbnailers)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules )
find_package(KDE4 4.14.3 REQUIRED)
include(KDE4Defaults)
include(MacroLibrary)
@ -10,14 +12,20 @@ include_directories(${KDE4_INCLUDES})
macro_optional_find_package(Kexiv2)
macro_optional_find_package(Kdcraw)
macro_optional_find_package(GettextPO)
macro_log_feature(KEXIV2_FOUND "libkexiv2" "A library for reading and writing image metadata" "www.kde.org" FALSE "" "Required to build the RAW thumbnailer")
macro_log_feature(KDCRAW_FOUND "libkdcraw" "A library for accessing raw files" "www.kde.org" FALSE "" "Required to build the RAW thumbnailer")
macro_log_feature(GETTEXTPO_FOUND "gettext-po" "A library for processing PO files" "www.gnu.org/software/gettext" FALSE "" "Required to build the PO thumbnailer")
macro_optional_add_subdirectory(ps)
if(KEXIV2_FOUND AND KDCRAW_FOUND)
macro_optional_add_subdirectory(raw)
macro_optional_add_subdirectory(raw)
endif()
macro_display_feature_log()
if(GETTEXTPO_FOUND)
macro_optional_add_subdirectory(po)
endif(GETTEXTPO_FOUND)
macro_display_feature_log()

View file

@ -0,0 +1,22 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,31 @@
# - Try to find GettextPO
#
# Once done this will define
#
# GETTEXTPO_FOUND - System has GETTEXTPO
# GETTEXTPO_INCLUDE_DIR - The GETTEXTPO include directory
# GETTEXTPO_LIBRARY - The library needed to use GETTEXTPO
# Copyright (c) 2012, Ni Hui <shuizhuyuanluo@126.com>
# Based off FindLibXml2.cmake from CMake 2.6.4 by Alexander Neundorf <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
if(GETTEXTPO_INCLUDE_DIR AND GETTEXTPO_LIBRARY)
# in cache already
set(GETTEXTPO_FIND_QUIETLY TRUE)
endif(GETTEXTPO_INCLUDE_DIR AND GETTEXTPO_LIBRARY)
find_path(GETTEXTPO_INCLUDE_DIR gettext-po.h)
find_library(GETTEXTPO_LIBRARY NAMES gettextpo)
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set GETTEXTPO_FOUND to TRUE if
# all listed variables are TRUE
find_package_handle_standard_args(GettextPO DEFAULT_MSG GETTEXTPO_LIBRARY GETTEXTPO_INCLUDE_DIR)
mark_as_advanced(GETTEXTPO_INCLUDE_DIR GETTEXTPO_LIBRARY)

View file

@ -0,0 +1,26 @@
project(kde-thumbnailer-po)
cmake_minimum_required(VERSION 2.6)
find_package(KDE4 REQUIRED)
find_package(GettextPO REQUIRED)
include(KDE4Defaults)
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories(${QT_INCLUDES} ${KDE4_INCLUDES})
set(pothumbnail_SRCS pocreator.cpp)
kde4_add_ui_files(pothumbnail_SRCS pocreatorform.ui)
kde4_add_kcfg_files(pothumbnail_SRCS pocreatorsettings.kcfgc)
kde4_add_plugin(pothumbnail ${pothumbnail_SRCS})
target_link_libraries(pothumbnail
${KDE4_KIO_LIBS}
${GETTEXTPO_LIBRARY}
)
install(TARGETS pothumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES pocreatorsettings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
install(FILES pothumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR})

View file

@ -0,0 +1,4 @@
#! /bin/bash
$EXTRACTRC *.ui *.kcfg >> rc.cpp
$XGETTEXT *.cpp *.h -o $podir/pothumbnail.pot
rm -f rc.cpp

View file

@ -0,0 +1,196 @@
/*
* This file is part of kde-thumbnailer-po
* Copyright (C) 2011-2012 Ni Hui <shuizhuyuanluo@126.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pocreator.h"
#include <gettext-po.h>
#include <QColor>
#include <QImage>
#include <QLatin1String>
#include <QPainter>
#include <QWidget>
#include <kdemacros.h>
#include <KLocale>
#include "pocreatorsettings.h"
#include "ui_pocreatorform.h"
extern "C" {
KDE_EXPORT ThumbCreator* new_creator() {
KGlobal::locale()->insertCatalog( QLatin1String( "pothumbnail" ) );
return new PoCreator;
}
}
static bool readerror = false;
static void xerror( int severity,
po_message_t /*message*/,
const char */*filename*/, size_t /*lineno*/, size_t /*column*/,
int /*multiline_p*/, const char */*message_text*/ )
{
if ( severity == PO_SEVERITY_ERROR || severity == PO_SEVERITY_FATAL_ERROR )
readerror = true;
}
static void xerror2( int severity,
po_message_t /*message1*/,
const char */*filename1*/, size_t /*lineno1*/, size_t /*column1*/,
int /*multiline_p1*/, const char */*message_text1*/,
po_message_t /*message2*/,
const char */*filename2*/, size_t /*lineno2*/, size_t /*column2*/,
int /*multiline_p2*/, const char */*message_text2*/ )
{
if ( severity == PO_SEVERITY_ERROR || severity == PO_SEVERITY_FATAL_ERROR )
readerror = true;
}
static bool get_po_info( const char* filepath, int& translate, int& untranslate, int& fuzzy, int& obsolete )
{
po_file_t pofile;
const struct po_xerror_handler handler = { xerror, xerror2 };
pofile = po_file_read( filepath, &handler );
if ( pofile == NULL || readerror )
return false;
po_message_iterator_t it;
it = po_message_iterator( pofile, NULL );
po_message_t msg;
const char* msgstr;
while ( ( msg = po_next_message( it ) ) != NULL ) {
if ( po_message_is_obsolete( msg ) )
++obsolete;
else if ( po_message_is_fuzzy( msg ) )
++fuzzy;
else {
msgstr = po_message_msgstr( msg );
if ( msgstr[0] == '\0' )
++untranslate;
else
++translate;
}
}
po_message_iterator_free( it );
/// do not count domain header as translated message
const char* header = po_file_domain_header( pofile, NULL );
if ( header != NULL )
--translate;
po_file_free( pofile );
return true;
}
PoCreator::PoCreator()
{
}
PoCreator::~PoCreator()
{
}
bool PoCreator::create( const QString& path, int width, int height, QImage& img )
{
int translate = 0;
int untranslate = 0;
int fuzzy = 0;
int obsolete = 0;
if ( !get_po_info( path.toLocal8Bit(), translate, untranslate, fuzzy, obsolete ) )
return false;
int total = translate + untranslate + fuzzy + obsolete;
int d = ( width < height ) ? width - 2 : height - 2;
QImage pix( d + 2, d + 2, QImage::Format_ARGB32_Premultiplied );
pix.fill( Qt::transparent ); /// transparent background
int circle = 16 * 360;
int untranslateAngle = untranslate * circle / total;
int fuzzyAngle = fuzzy * circle / total;
int obsoleteAngle = obsolete * circle / total;
int translateAngle = circle - untranslateAngle - fuzzyAngle - obsoleteAngle;
QPainter p( &pix );
p.setRenderHint( QPainter::Antialiasing );
if ( fuzzyAngle > 0 ) {
p.setBrush( PoCreatorSettings::self()->fuzzyColor() );
if ( fuzzy == total )
p.drawEllipse( 1, 1, d, d );
else
p.drawPie( 1, 1, d, d, 0, -fuzzyAngle );
}
if ( untranslateAngle > 0 ) {
p.setBrush( PoCreatorSettings::self()->untranslatedColor() );
if ( untranslate == total )
p.drawEllipse( 1, 1, d, d );
else
p.drawPie( 1, 1, d, d, -fuzzyAngle, -untranslateAngle );
}
if ( obsoleteAngle > 0 ) {
p.setBrush( PoCreatorSettings::self()->obsoletedColor() );
if ( obsolete == total )
p.drawEllipse( 1, 1, d, d );
else
p.drawPie( 1, 1, d, d, -fuzzyAngle-untranslateAngle, -obsoleteAngle );
}
if ( translateAngle > 0 ) {
p.setBrush( PoCreatorSettings::self()->translatedColor() );
if ( translate == total )
p.drawEllipse( 1, 1, d, d );
else
p.drawPie( 1, 1, d, d, -fuzzyAngle-untranslateAngle-obsoleteAngle, -translateAngle );
}
img = pix;
return true;
}
class PoCreatorFormWidget : public QWidget, public Ui::PoCreatorForm
{
public:
PoCreatorFormWidget() { setupUi( this ); }
};
QWidget* PoCreator::createConfigurationWidget()
{
PoCreatorFormWidget* cw = new PoCreatorFormWidget;
cw->translatedButton->setColor( PoCreatorSettings::self()->translatedColor() );
cw->fuzzyButton->setColor( PoCreatorSettings::self()->fuzzyColor() );
cw->untranslatedButton->setColor( PoCreatorSettings::self()->untranslatedColor() );
cw->obsoletedButton->setColor( PoCreatorSettings::self()->obsoletedColor() );
return cw;
}
void PoCreator::writeConfiguration( const QWidget* configurationWidget )
{
const PoCreatorFormWidget* cw = static_cast<const PoCreatorFormWidget*>(configurationWidget);
PoCreatorSettings::self()->setTranslatedColor( cw->translatedButton->color() );
PoCreatorSettings::self()->setFuzzyColor( cw->fuzzyButton->color() );
PoCreatorSettings::self()->setUntranslatedColor( cw->untranslatedButton->color() );
PoCreatorSettings::self()->setObsoletedColor( cw->obsoletedButton->color() );
PoCreatorSettings::self()->writeConfig();
}

View file

@ -0,0 +1,42 @@
/*
* This file is part of kde-thumbnailer-po
* Copyright (C) 2011-2012 Ni Hui <shuizhuyuanluo@126.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef POCREATOR_H
#define POCREATOR_H
#include <kdeversion.h>
#include <kio/thumbcreator.h>
#if KDE_IS_VERSION(4,7,0)
class PoCreator : public ThumbCreatorV2
#else
class PoCreator : public ThumbCreator
#endif
{
public:
explicit PoCreator();
virtual ~PoCreator();
virtual bool create( const QString& path, int width, int height, QImage& img );
virtual QWidget* createConfigurationWidget();
virtual void writeConfiguration( const QWidget* configurationWidget );
};
#endif // POCREATOR_H

View file

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PoCreatorForm</class>
<widget class="QWidget" name="PoCreatorForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>136</width>
<height>127</height>
</rect>
</property>
<layout class="QFormLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Translated: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KColorButton" name="translatedButton"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fuzzy: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KColorButton" name="fuzzyButton"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Untranslated: </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KColorButton" name="untranslatedButton"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Obsoleted: </string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KColorButton" name="obsoletedButton"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="pocreatorrc"/>
<group name="General">
<entry name="TranslatedColor" type="Color">
<default code="true">Qt::darkGreen</default>
</entry>
<entry name="FuzzyColor" type="Color">
<default code="true">Qt::blue</default>
</entry>
<entry name="UntranslatedColor" type="Color">
<default code="true">Qt::red</default>
</entry>
<entry name="ObsoletedColor" type="Color">
<default code="true">Qt::yellow</default>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,4 @@
File=pocreatorsettings.kcfg
ClassName=PoCreatorSettings
Singleton=true
Mutators=true

View file

@ -0,0 +1,50 @@
[Desktop Entry]
Type=Service
Name=Gettext Translation
Name[bs]=GetText prijevod
Name[ca]=Traducció del Gettext
Name[ca@valencia]=Traducció del Gettext
Name[cs]=Překlad Gettext
Name[da]=Gettext-oversættelse
Name[de]=Gettext-Übersetzung
Name[el]=Μετάφραση με gettext
Name[en_GB]=Gettext Translation
Name[es]=Traducción de Gettext
Name[et]=Gettexti tõlkefail
Name[fi]=Gettext-käännös
Name[fr]=Traduction de Gettext
Name[ga]=Aistriúchán Gettext
Name[gl]=Tradución Gettext
Name[hu]=Gettext fordítás
Name[it]=Traduzioni di Gettext
Name[kk]=Gettext аудармасы
Name[ko]=Gettext
Name[lt]=Gettext vertimas
Name[mr]=
Name[nb]=Gettext-oversetting
Name[nds]=Gettext-Översetten
Name[nl]=Gettext-vertaling
Name[pa]=Gettext
Name[pl]=Tłumaczenie Gettext
Name[pt]=Tradução do Gettext
Name[pt_BR]=Tradução gettext
Name[ro]=Traducere Gettext
Name[ru]=Переводы Gettext
Name[sk]=Preklad Gettext
Name[sl]=Prevod Gettext
Name[sr]=Геттекст превод
Name[sr@ijekavian]=Геттекст превод
Name[sr@ijekavianlatin]=Gettext prevod
Name[sr@latin]=Gettext prevod
Name[sv]=Översättning med Gettext
Name[tr]=Gettext Çevirisi
Name[uk]=Переклад Gettext
Name[x-test]=xxGettext Translationxx
Name[zh_CN]=Gettext
Name[zh_TW]=Gettext
X-KDE-ServiceTypes=ThumbCreator
MimeType=text/x-gettext-translation;text/x-gettext-translation-template;
CacheThumbnail=false
IgnoreMaximumSize=true
X-KDE-Library=pothumbnail
Configurable=true