~neon/kdesdk-thumbnailers/master

« back to all changes in this revision

Viewing changes to po_thumbnailer/pocreator.cpp

  • Committer: Nicolas Fella
  • Date: 2023-11-04 20:35:19 UTC
  • Revision ID: git-v1:940b8aec0dcc656881d798e32563c8a26b1743ab
Make it build against KF6

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include <QLatin1String>
13
13
#include <QPainter>
14
14
#include <QWidget>
 
15
 
15
16
#include <KLocalizedString>
 
17
#include <KPluginFactory>
16
18
 
17
19
#include "pocreatorsettings.h"
18
20
#include "ui_pocreatorform.h"
19
21
 
20
 
extern "C" {
21
 
    Q_DECL_EXPORT ThumbCreator* new_creator() {
22
 
        return new PoCreator;
23
 
    }
24
 
}
25
 
 
26
 
class KIOPluginForMetaData : public QObject
27
 
{
28
 
    Q_OBJECT
29
 
    Q_PLUGIN_METADATA(IID "KIOPluginForMetaData" FILE "pothumbnail.json")
30
 
};
31
 
 
 
22
K_PLUGIN_CLASS_WITH_JSON(PoCreator, "pothumbnail.json")
32
23
 
33
24
static bool readerror = false;
34
25
 
91
82
    return true;
92
83
}
93
84
 
94
 
PoCreator::PoCreator()
 
85
PoCreator::PoCreator(QObject *parent, const QVariantList &args)
 
86
    : KIO::ThumbnailCreator(parent, args)
95
87
{
96
88
}
97
89
 
99
91
{
100
92
}
101
93
 
102
 
bool PoCreator::create( const QString& path, int width, int height, QImage& img )
 
94
KIO::ThumbnailResult PoCreator::create( const KIO::ThumbnailRequest &request )
103
95
{
104
96
    int translate = 0;
105
97
    int untranslate = 0;
106
98
    int fuzzy = 0;
107
99
    int obsolete = 0;
108
100
 
109
 
    if ( !get_po_info( path.toLocal8Bit().constData(), translate, untranslate, fuzzy, obsolete ) )
110
 
        return false;
 
101
    if ( !get_po_info( request.url().toLocalFile().toLocal8Bit().constData(), translate, untranslate, fuzzy, obsolete ) )
 
102
        return KIO::ThumbnailResult::fail();
111
103
 
112
104
    int total = translate + untranslate + fuzzy + obsolete;
113
105
 
114
106
    if (total == 0) {
115
107
        // Treat a .po file with no strings as an invalid file
116
 
        return false;
 
108
        return KIO::ThumbnailResult::fail();
117
109
    }
118
110
 
119
 
    int d = ( width < height ) ? width - 2 : height - 2;
 
111
    int d = ( request.targetSize().width() < request.targetSize().height() ) ? request.targetSize().width() - 2 : request.targetSize().height() - 2;
120
112
 
121
113
    QImage pix( d + 2, d + 2, QImage::Format_ARGB32_Premultiplied );
122
114
    pix.fill( Qt::transparent ); /// transparent background
159
151
            p.drawPie( 1, 1, d, d, -fuzzyAngle-untranslateAngle-obsoleteAngle, -translateAngle );
160
152
    }
161
153
 
162
 
    img = pix;
163
 
 
164
 
    return true;
165
 
}
166
 
 
167
 
#if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 87)
168
 
 
169
 
class PoCreatorFormWidget : public QWidget, public Ui::PoCreatorForm
170
 
{
171
 
public:
172
 
    PoCreatorFormWidget() { setupUi( this ); }
173
 
};
174
 
 
175
 
QWidget* PoCreator::createConfigurationWidget()
176
 
{
177
 
    PoCreatorFormWidget* cw = new PoCreatorFormWidget;
178
 
    cw->translatedButton->setColor( PoCreatorSettings::self()->translatedColor() );
179
 
    cw->fuzzyButton->setColor( PoCreatorSettings::self()->fuzzyColor() );
180
 
    cw->untranslatedButton->setColor( PoCreatorSettings::self()->untranslatedColor() );
181
 
    cw->obsoletedButton->setColor( PoCreatorSettings::self()->obsoletedColor() );
182
 
    return cw;
183
 
}
184
 
 
185
 
void PoCreator::writeConfiguration( const QWidget* configurationWidget )
186
 
{
187
 
    const PoCreatorFormWidget* cw = static_cast<const PoCreatorFormWidget*>(configurationWidget);
188
 
    PoCreatorSettings::self()->setTranslatedColor( cw->translatedButton->color() );
189
 
    PoCreatorSettings::self()->setFuzzyColor( cw->fuzzyButton->color() );
190
 
    PoCreatorSettings::self()->setUntranslatedColor( cw->untranslatedButton->color() );
191
 
    PoCreatorSettings::self()->setObsoletedColor( cw->obsoletedButton->color() );
192
 
    PoCreatorSettings::self()->save();
193
 
}
194
 
 
195
 
#endif
 
154
    return KIO::ThumbnailResult::pass(pix);
 
155
}
196
156
 
197
157
#include "pocreator.moc"