Ticket #1585: pdiff

File pdiff, 1.6 KB (added by sbower@…, 20 years ago)

patch to previewgenerator.cpp

Line 
1Index: previewgenerator.cpp
2===================================================================
3--- previewgenerator.cpp (revision 9499)
4+++ previewgenerator.cpp (working copy)
5@@ -259,7 +259,22 @@
6
7 QImage small_img = img.smoothScale((int) ppw, (int) pph);
8
9- return small_img.save(filename.ascii(), "PNG");
10+ if (small_img.save(filename.ascii(), "PNG"))
11+ {
12+ chmod(filename.ascii(), 0666); // Let anybody update it
13+ return true;
14+ }
15+ // Save failed; if file exists, try saving to .new and moving over
16+ QString newfile=filename+".new";
17+ if (QFileInfo(filename.ascii()).exists() &&
18+ small_img.save(newfile.ascii(), "PNG"))
19+ {
20+ chmod(newfile.ascii(), 0666);
21+ rename(newfile.ascii(), filename.ascii());
22+ return true;
23+ }
24+ // Couldn't save, nothing else I can do?
25+ return false;
26 }
27
28 void PreviewGenerator::LocalPreviewRun(void)
29@@ -275,8 +290,9 @@
30 unsigned char *data = (unsigned char*)
31 GetScreenGrab(&programInfo, programInfo.pathname, secsin,
32 sz, width, height, aspect);
33-
34- if (SavePreview(programInfo.pathname+".png", data, width, height, aspect))
35+
36+ bool success=SavePreview(programInfo.pathname+".png", data, width, height, aspect);
37+ if (success)
38 {
39 QMutexLocker locker(&previewLock);
40 emit previewReady(&programInfo);
41@@ -286,6 +302,10 @@
42 delete[] data;
43
44 programInfo.MarkAsInUse(false);
45+ if (!success && !localOnly) // local update failed, try remote?
46+ {
47+ RemotePreviewRun();
48+ }
49 }
50
51 bool PreviewGenerator::IsLocal(void) const