00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qstring.h>
00013 #include <qimage.h>
00014 #include <qapplication.h>
00015 #include <qdir.h>
00016 #include <qprocess.h>
00017 #include <qfile.h>
00018 #include <qdir.h>
00019
00020
00021 #if defined(Q_OS_WIN)
00022 #include <windows.h>
00023 #endif //Q_OS_WIN
00024
00025
00026 #include "wallpaperTools.h"
00027 #include "fileTools.h"
00028 #include "../album.h"
00029 #include "../photo.h"
00030 #include "../../gui/window.h"
00031 #include "../../gui/titleWidget.h"
00032
00033
00034 void setWallpaper( Photo* phto )
00035 {
00036
00037 int imageW, imageH;
00038 getImageSize( phto->getImageFilename(), imageW, imageH );
00039
00040
00041 int screenW = qApp->desktop()->screenGeometry().size().width();
00042 int screenH = qApp->desktop()->screenGeometry().size().height();
00043
00044
00045 QImage scaledImage;
00046 if( imageW > screenW || imageH > screenH )
00047 {
00048 scaleImage( phto->getImageFilename(), scaledImage, screenW, screenH );
00049 imageW = scaledImage.width();
00050 imageH = scaledImage.height();
00051 }
00052
00053
00054
00055 #ifndef Q_OS_MACX
00056 const bool centerImage = (imageW < 0.75*screenW) || (imageH < 0.75*screenH);
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #if defined(Q_OS_WIN)
00072
00073
00074 QString outFilename;
00075 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, outFilename) )
00076 {
00077 outFilename = getenv("USERPROFILE") + QString("/Local Settings/Application Data");
00078 }
00079 outFilename = QDir::convertSeparators( outFilename + "/Album Shaper/Album Shaper Wallpaper.bmp" );
00080
00081
00082
00083 if( scaledImage.isNull() )
00084 { scaledImage.load( phto->getImageFilename() ); }
00085
00086
00087 scaledImage.save( outFilename, "BMP" );
00088
00089
00090 #else
00091
00092
00093 #if defined(Q_OS_MACX)
00094 QString outFilename1 = QDir::homeDirPath() + QString("/Pictures/Album Shaper Wallpaper.jpg");
00095 QString outFilename2 = QDir::homeDirPath() + QString("/Pictures/Album_Shaper_Wallpaper.jpg");
00096 #else
00097 QString outFilename1 = QDir::homeDirPath() + QString("/.albumShaper/Album Shaper Wallpaper.jpg");
00098 QString outFilename2 = QDir::homeDirPath() + QString("/.albumShaper/Album_Shaper_Wallpaper.jpg");
00099 #endif
00100
00101 QString chosenFilename;
00102 QString oldFilename;
00103
00104
00105
00106
00107 QDir tmpDir;
00108 if(tmpDir.exists( outFilename1 ) )
00109 {
00110 chosenFilename = outFilename2;
00111 oldFilename = outFilename1;
00112 }
00113 else if( tmpDir.exists( outFilename2 ) )
00114 {
00115 chosenFilename = outFilename1;
00116 oldFilename = outFilename2;
00117 }
00118 else
00119 {
00120 chosenFilename = outFilename1;
00121 }
00122
00123
00124 if( !scaledImage.isNull() )
00125 {
00126 scaledImage.save( chosenFilename, "JPEG", 95 );
00127 }
00128 else
00129 {
00130 copyFile( phto->getImageFilename(), chosenFilename );
00131 }
00132
00133 #endif
00134
00135
00136
00137
00138
00139
00140
00141
00142 #if defined(Q_OS_WIN)
00143
00144
00145 HKEY key;
00146 char data[8];
00147 if( RegOpenKeyExA( HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS)
00148 {
00149
00150 itoa( centerImage ? 0 : 2, data, 10);
00151 RegSetValueExA(key, "WallpaperStyle", NULL, REG_SZ, (UCHAR*)data, 8);
00152
00153
00154 itoa(0, data, 10);
00155 RegSetValueExA(key, "TileWallpaper", NULL, REG_SZ, (UCHAR*)data, 8);
00156
00157
00158 RegCloseKey(key);
00159 }
00160
00161
00162 SystemParametersInfoA( SPI_SETDESKWALLPAPER, 0,
00163 (void*) outFilename.ascii(),
00164 SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
00165
00166
00167 #elif defined(Q_OS_MACX)
00168
00169
00170 QString scriptFilename = ((Window*)qApp->mainWidget())->getTitle()->getAlbum()->getTmpDir() +
00171 "/tmpBackgroundScript";
00172
00173 QFile file( scriptFilename );
00174 if(file.open(IO_WriteOnly))
00175 {
00176
00177 QTextStream stream;
00178 stream.setDevice( &file );
00179 stream.setEncoding( QTextStream::UnicodeUTF8 );
00180
00181 stream << "tell application \"Finder\"\n";
00182 stream << "set pFile to POSIX file \"" << chosenFilename.ascii() << "\"\n";
00183 stream << "set desktop picture to file pFile\n";
00184 stream << "end tell";
00185 }
00186 file.close();
00187
00188
00189 QProcess p;
00190 p.addArgument( "/usr/bin/osascript" );
00191 p.addArgument( scriptFilename );
00192 p.start();
00193
00194
00195 if(!oldFilename.isNull())
00196 { tmpDir.remove( oldFilename ); }
00197
00198
00199
00200 #else
00201
00202
00203 {
00204 QProcess p;
00205 p.clearArguments();
00206 p.addArgument( "dcop" );
00207 p.addArgument( "kdesktop" );
00208 p.addArgument( "KBackgroundIface" );
00209 p.addArgument( "setWallpaper" );
00210 p.addArgument( chosenFilename.ascii() );
00211
00212
00213
00214
00215
00216 const int CENTERED = 1;
00217 const int CENTER_MAXPECT = 4;
00218 int positionOption = centerImage ? CENTERED : CENTER_MAXPECT;
00219 p.addArgument( QString("%1").arg(positionOption) );
00220
00221
00222 p.start();
00223 }
00224
00225
00226 {
00227 QProcess p;
00228 p.clearArguments();
00229 p.addArgument( "gconftool-2" );
00230 p.addArgument( "-t" );
00231 p.addArgument( "string" );
00232 p.addArgument( "-s" );
00233 p.addArgument( "/desktop/gnome/background/picture_filename" );
00234 p.addArgument( chosenFilename.ascii() );
00235 p.start();
00236 }
00237
00238
00239 {
00240 QProcess p;
00241 p.clearArguments();
00242 p.addArgument( "wmsetbg" );
00243 p.addArgument( "--maxscale" );
00244 p.addArgument( "-u" );
00245 p.addArgument( chosenFilename.ascii() );
00246 p.start();
00247 }
00248
00249
00250 if(!oldFilename.isNull())
00251 { tmpDir.remove( oldFilename ); }
00252
00253 #endif
00254 }
00255
00256 bool setWallpaperSupported()
00257 {
00258
00259 #if defined(Q_OS_MACX)
00260 return true;
00261
00262
00263 #elif defined(Q_OS_WIN)
00264 return true;
00265
00266
00267 #else
00268 QProcess p;
00269
00270 p.addArgument( "dcop" );
00271 bool DCOP_Present = p.start();
00272
00273 p.clearArguments();
00274 p.addArgument( "gconftool-2" );
00275 bool gconftool_Present = p.start();
00276
00277 p.clearArguments();
00278 p.addArgument( "wmsetbg" );
00279 bool wmsetbg_Present = p.start();
00280
00281 return ( DCOP_Present || gconftool_Present || wmsetbg_Present );
00282
00283 #endif
00284 }
00285
00286