~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksplash/ksplashx/scale/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <unistd.h>
 
2
#include <QImage>
 
3
#include <QFile>
 
4
#include <kcomponentdata.h>
 
5
#include <kstandarddirs.h>
 
6
#include <utime.h>
 
7
#include <stdlib.h>
 
8
#include <stdio.h>
 
9
 
 
10
int main( int argc, char* argv[] )
 
11
    {
 
12
    if( argc != 10 )
 
13
        return 1;
 
14
    QString theme = argv[ 1 ];
 
15
    QString file = argv[ 2 ];
 
16
    QString real_file = argv[ 3 ];
 
17
    int width = atoi( argv[ 4 ] );
 
18
    int height = atoi( argv[ 5 ] );
 
19
    int res_w = atoi( argv[ 6 ] );
 
20
    int res_h = atoi( argv[ 7 ] );
 
21
    time_t timestamp = atol( argv[ 8 ] );
 
22
    bool locolor = strcmp( argv[ 9 ], "locolor" ) == 0;
 
23
    KComponentData k( "ksplashx_scale" );
 
24
    QString outfile = QString( "ksplashx/%1-%2x%3%4-%5" ).arg( theme ).arg( res_w ).arg( res_h )
 
25
        .arg( locolor ? "-locolor" : "" ).arg( file );
 
26
    outfile = KStandardDirs::locateLocal( "cache", outfile );
 
27
    QImage img( real_file );
 
28
    if( img.isNull())
 
29
        return 2;
 
30
    QImage img2 = img.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
 
31
    if( img2.save( outfile + ".tmp", "PNG" ))
 
32
        {
 
33
        rename( QFile::encodeName( outfile + ".tmp" ), QFile::encodeName( outfile ));
 
34
        utimbuf tm;
 
35
        tm.actime = tm.modtime = timestamp;
 
36
        utime( QFile::encodeName( outfile ), &tm );
 
37
        }
 
38
    else
 
39
        {
 
40
        unlink( QFile::encodeName( outfile ));
 
41
        unlink( QFile::encodeName( outfile + ".tmp" ));
 
42
        return 3;
 
43
        }
 
44
    return 0;
 
45
    }