Sets desktop wallpaper using specified photo.
38{
39
40 int imageW, imageH;
42
43
44 int screenW = qApp->desktop()->screenGeometry().size().width();
45 int screenH = qApp->desktop()->screenGeometry().size().height();
46
47
48 QImage scaledImage;
49 if( imageW > screenW || imageH > screenH )
50 {
52 imageW = scaledImage.width();
53 imageH = scaledImage.height();
54 }
55
56
57
58 #ifndef Q_OS_MACX
59 const bool centerImage = (imageW < 0.75*screenW) || (imageH < 0.75*screenH);
60 #endif
61
62
63
64
65
66
67
68
69
70
71
72
73
74 #if defined(Q_OS_WIN)
75
76
77 QString outFilename;
78 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, outFilename) )
79 {
80 outFilename = getenv("USERPROFILE") + QString("/Local Settings/Application Data");
81 }
82 outFilename = QDir::convertSeparators( outFilename + "/Album Shaper/Album Shaper Wallpaper.bmp" );
83
84
85
86 if( scaledImage.isNull() )
88
89
90 scaledImage.save( outFilename, "BMP" );
91
92
93 #else
94
95
96 #if defined(Q_OS_MACX)
97 QString outFilename1 = QDir::homeDirPath() + QString("/Pictures/Album Shaper Wallpaper.jpg");
98 QString outFilename2 = QDir::homeDirPath() + QString("/Pictures/Album_Shaper_Wallpaper.jpg");
99 #else
100 QString outFilename1 = QDir::homeDirPath() + QString("/.albumShaper/Album Shaper Wallpaper.jpg");
101 QString outFilename2 = QDir::homeDirPath() + QString("/.albumShaper/Album_Shaper_Wallpaper.jpg");
102 #endif
103
104 QString chosenFilename;
105 QString oldFilename;
106
107
108
109
110 QDir tmpDir;
111 if(tmpDir.exists( outFilename1 ) )
112 {
113 chosenFilename = outFilename2;
114 oldFilename = outFilename1;
115 }
116 else if( tmpDir.exists( outFilename2 ) )
117 {
118 chosenFilename = outFilename1;
119 oldFilename = outFilename2;
120 }
121 else
122 {
123 chosenFilename = outFilename1;
124 }
125
126
127 if( !scaledImage.isNull() )
128 {
129 scaledImage.save( chosenFilename, "JPEG", 95 );
130 }
131 else
132 {
134 }
135
136 #endif
137
138
139
140
141
142
143
144
145 #if defined(Q_OS_WIN)
146
147
148 HKEY key;
149 char data[8];
150 if( RegOpenKeyExA( HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS)
151 {
152
153 itoa( centerImage ? 0 : 2, data, 10);
154 RegSetValueExA(key, "WallpaperStyle", NULL, REG_SZ, (UCHAR*)data, 8);
155
156
157 itoa(0, data, 10);
158 RegSetValueExA(key, "TileWallpaper", NULL, REG_SZ, (UCHAR*)data, 8);
159
160
161 RegCloseKey(key);
162 }
163
164
165 SystemParametersInfoA( SPI_SETDESKWALLPAPER, 0,
166 (void*) outFilename.ascii(),
167 SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
168
169
170 #elif defined(Q_OS_MACX)
171
172
173 QString scriptFilename = ((
Window*)qApp->mainWidget())->getTitle()->getAlbum()->getTmpDir() +
174 "/tmpBackgroundScript";
175
176 QFile file( scriptFilename );
177 if(file.open(QIODevice::WriteOnly))
178 {
179
180 Q3TextStream stream;
181 stream.setDevice( &file );
182 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
183
184 stream << "tell application \"Finder\"\n";
185 stream << "set pFile to POSIX file \"" << chosenFilename.ascii() << "\"\n";
186 stream << "set desktop picture to file pFile\n";
187 stream << "end tell";
188 }
189 file.close();
190
191
192 Q3Process p;
193 p.addArgument( "/usr/bin/osascript" );
194 p.addArgument( scriptFilename );
195 p.start();
196
197
198 if(!oldFilename.isNull())
199 { tmpDir.remove( oldFilename ); }
200
201
202
203 #else
204
205
206 {
207 Q3Process p;
208 p.clearArguments();
209 p.addArgument( "dcop" );
210 p.addArgument( "kdesktop" );
211 p.addArgument( "KBackgroundIface" );
212 p.addArgument( "setWallpaper" );
213 p.addArgument( chosenFilename.ascii() );
214
215
216
217
218
219 const int CENTERED = 1;
220 const int CENTER_MAXPECT = 4;
221 int positionOption = centerImage ? CENTERED : CENTER_MAXPECT;
222 p.addArgument( QString("%1").arg(positionOption) );
223
224
225 p.start();
226 }
227
228
229 {
230 Q3Process p;
231 p.clearArguments();
232 p.addArgument( "gconftool-2" );
233 p.addArgument( "-t" );
234 p.addArgument( "string" );
235 p.addArgument( "-s" );
236 p.addArgument( "/desktop/gnome/background/picture_filename" );
237 p.addArgument( chosenFilename.ascii() );
238 p.start();
239 }
240
241
242 {
243 Q3Process p;
244 p.clearArguments();
245 p.addArgument( "wmsetbg" );
246 p.addArgument( "--maxscale" );
247 p.addArgument( "-u" );
248 p.addArgument( chosenFilename.ascii() );
249 p.start();
250 }
251
252
253 if(!oldFilename.isNull())
254 { tmpDir.remove( oldFilename ); }
255
256 #endif
257}
QString getImageFilename()
Gets the image filename.
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget.