Changeset View
Changeset View
Standalone View
Standalone View
document/kpDocument_Save.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
68 | 68 | | |||
69 | 69 | | |||
70 | bool kpDocument::save (bool overwritePrompt, bool lossyPrompt) | 70 | bool kpDocument::save (bool overwritePrompt, bool lossyPrompt) | ||
71 | { | 71 | { | ||
72 | qCDebug(kpLogDocument) << "kpDocument::save(" | 72 | qCDebug(kpLogDocument) << "kpDocument::save(" | ||
73 | << "overwritePrompt=" << overwritePrompt | 73 | << "overwritePrompt=" << overwritePrompt | ||
74 | << ",lossyPrompt=" << lossyPrompt | 74 | << ",lossyPrompt=" << lossyPrompt | ||
75 | << ") url=" << m_url | 75 | << ") url=" << m_url | ||
76 | << " savedAtLeastOnceBefore=" << savedAtLeastOnceBefore () | 76 | << " savedAtLeastOnceBefore=" << savedAtLeastOnceBefore (); | ||
77 | << endl; | | |||
78 | 77 | | |||
79 | // TODO: check feels weak | 78 | // TODO: check feels weak | ||
80 | if (m_url.isEmpty () || m_saveOptions->mimeType ().isEmpty ()) | 79 | if (m_url.isEmpty () || m_saveOptions->mimeType ().isEmpty ()) | ||
81 | { | 80 | { | ||
82 | KMessageBox::detailedError (d->environ->dialogParent (), | 81 | KMessageBox::detailedError (d->environ->dialogParent (), | ||
83 | i18n ("Could not save image - insufficient information."), | 82 | i18n ("Could not save image - insufficient information."), | ||
84 | i18n ("URL: %1\n" | 83 | i18n ("URL: %1\n" | ||
85 | "Mimetype: %2", | 84 | "Mimetype: %2", | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
163 | bool kpDocument::savePixmapToDevice (const QImage &image, | 162 | bool kpDocument::savePixmapToDevice (const QImage &image, | ||
164 | QIODevice *device, | 163 | QIODevice *device, | ||
165 | const kpDocumentSaveOptions &saveOptions, | 164 | const kpDocumentSaveOptions &saveOptions, | ||
166 | const kpDocumentMetaInfo &metaInfo, | 165 | const kpDocumentMetaInfo &metaInfo, | ||
167 | bool lossyPrompt, | 166 | bool lossyPrompt, | ||
168 | QWidget *parent, | 167 | QWidget *parent, | ||
169 | bool *userCancelled) | 168 | bool *userCancelled) | ||
170 | { | 169 | { | ||
171 | if (userCancelled) | 170 | if (userCancelled) { | ||
172 | *userCancelled = false; | 171 | *userCancelled = false; | ||
172 | } | ||||
173 | 173 | | |||
174 | QStringList types = KImageIO::typeForMime (saveOptions.mimeType ()); | 174 | QStringList types = KImageIO::typeForMime (saveOptions.mimeType ()); | ||
175 | qCDebug(kpLogDocument) << "\ttypes=" << types; | 175 | qCDebug(kpLogDocument) << "\ttypes=" << types; | ||
176 | if (types.isEmpty ()) | 176 | if (types.isEmpty ()) { | ||
177 | return false; | 177 | return false; | ||
178 | 178 | } | |||
179 | // It's safe to arbitrarily choose the 0th type as any type in the list | 179 | // It's safe to arbitrarily choose the 0th type as any type in the list | ||
180 | // should invoke the same KImageIO image loader. | 180 | // should invoke the same KImageIO image loader. | ||
181 | const QString type = types [0]; | 181 | const QString type = types [0]; | ||
182 | 182 | | |||
183 | qCDebug(kpLogDocument) << "\tmimeType=" << saveOptions.mimeType () | 183 | qCDebug(kpLogDocument) << "\tmimeType=" << saveOptions.mimeType () | ||
184 | << " type=" << type << endl; | 184 | << " type=" << type; | ||
185 | 185 | | |||
186 | if (lossyPrompt && !lossyPromptContinue (image, saveOptions, parent)) | 186 | if (lossyPrompt && !lossyPromptContinue (image, saveOptions, parent)) | ||
187 | { | 187 | { | ||
188 | if (userCancelled) | 188 | if (userCancelled) { | ||
189 | *userCancelled = true; | 189 | *userCancelled = true; | ||
190 | } | ||||
190 | 191 | | |||
191 | qCDebug(kpLogDocument) << "\treturning false because of lossyPrompt"; | 192 | qCDebug(kpLogDocument) << "\treturning false because of lossyPrompt"; | ||
192 | return false; | 193 | return false; | ||
193 | } | 194 | } | ||
194 | 195 | | |||
195 | 196 | | |||
196 | // TODO: fix dup with kpDocumentSaveOptions::isLossyForSaving() | 197 | // TODO: fix dup with kpDocumentSaveOptions::isLossyForSaving() | ||
197 | const bool useSaveOptionsColorDepth = | 198 | const bool useSaveOptionsColorDepth = | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
246 | 247 | | |||
247 | 248 | | |||
248 | // | 249 | // | ||
249 | // Save at required quality | 250 | // Save at required quality | ||
250 | // | 251 | // | ||
251 | 252 | | |||
252 | int quality = -1; // default | 253 | int quality = -1; // default | ||
253 | 254 | | |||
254 | if (useSaveOptionsQuality) | 255 | if (useSaveOptionsQuality) { | ||
255 | quality = saveOptions.quality (); | 256 | quality = saveOptions.quality (); | ||
257 | } | ||||
256 | 258 | | |||
257 | qCDebug(kpLogDocument) << "\tsaving"; | 259 | qCDebug(kpLogDocument) << "\tsaving"; | ||
258 | if (!imageToSave.save (device, type.toLatin1 (), quality)) | 260 | if (!imageToSave.save (device, type.toLatin1 (), quality)) | ||
259 | { | 261 | { | ||
260 | qCDebug(kpLogDocument) << "\tQImage::save() returned false"; | 262 | qCDebug(kpLogDocument) << "\tQImage::save() returned false"; | ||
261 | return false; | 263 | return false; | ||
262 | } | 264 | } | ||
263 | qCDebug(kpLogDocument) << "\tsave OK"; | 265 | qCDebug(kpLogDocument) << "\tsave OK"; | ||
Show All 31 Lines | |||||
295 | { | 297 | { | ||
296 | // TODO: Use KIO::NetAccess:mostLocalURL() for accessing home:/ (and other | 298 | // TODO: Use KIO::NetAccess:mostLocalURL() for accessing home:/ (and other | ||
297 | // such local URLs) for efficiency and because only local writes | 299 | // such local URLs) for efficiency and because only local writes | ||
298 | // are atomic. | 300 | // are atomic. | ||
299 | qCDebug(kpLogDocument) << "kpDocument::savePixmapToFile (" | 301 | qCDebug(kpLogDocument) << "kpDocument::savePixmapToFile (" | ||
300 | << url | 302 | << url | ||
301 | << ",overwritePrompt=" << overwritePrompt | 303 | << ",overwritePrompt=" << overwritePrompt | ||
302 | << ",lossyPrompt=" << lossyPrompt | 304 | << ",lossyPrompt=" << lossyPrompt | ||
303 | << ")" << endl; | 305 | << ")"; | ||
304 | saveOptions.printDebug (QLatin1String ("\tsaveOptions")); | 306 | saveOptions.printDebug (QLatin1String ("\tsaveOptions")); | ||
305 | metaInfo.printDebug (QLatin1String ("\tmetaInfo")); | 307 | metaInfo.printDebug (QLatin1String ("\tmetaInfo")); | ||
306 | 308 | | |||
307 | if (overwritePrompt && | 309 | if (overwritePrompt && | ||
308 | KIO::NetAccess::exists (url, KIO::NetAccess::DestinationSide/*write*/, parent)) | 310 | KIO::NetAccess::exists (url, KIO::NetAccess::DestinationSide/*write*/, parent)) | ||
309 | { | 311 | { | ||
310 | int result = KMessageBox::warningContinueCancel (parent, | 312 | int result = KMessageBox::warningContinueCancel (parent, | ||
311 | i18n ("A document called \"%1\" already exists.\n" | 313 | i18n ("A document called \"%1\" already exists.\n" | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 452 | { | |||
452 | *m_saveOptions = saveOptions; | 454 | *m_saveOptions = saveOptions; | ||
453 | m_modified = false; | 455 | m_modified = false; | ||
454 | 456 | | |||
455 | m_savedAtLeastOnceBefore = true; | 457 | m_savedAtLeastOnceBefore = true; | ||
456 | 458 | | |||
457 | emit documentSaved (); | 459 | emit documentSaved (); | ||
458 | return true; | 460 | return true; | ||
459 | } | 461 | } | ||
460 | else | 462 | | ||
461 | { | | |||
462 | return false; | 463 | return false; | ||
463 | } | 464 | } | ||
464 | } | | |||
465 | 465 | | |||
466 | //--------------------------------------------------------------------- | 466 | //--------------------------------------------------------------------- |