not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / ksplash / ksplashx / scale / main.cpp
blob167d484446c8e46e7ea57b55c3e6ad44c6b6025c
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>
10 int main( int argc, char* argv[] )
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" ))
33 rename( QFile::encodeName( outfile + ".tmp" ), QFile::encodeName( outfile ));
34 utimbuf tm;
35 tm.actime = tm.modtime = timestamp;
36 utime( QFile::encodeName( outfile ), &tm );
38 else
40 unlink( QFile::encodeName( outfile ));
41 unlink( QFile::encodeName( outfile + ".tmp" ));
42 return 3;
44 return 0;