[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdegraphics/kolourpaint
From: Clarence Dang <dang () kde ! org>
Date: 2007-05-11 11:49:04
Message-ID: 1178884144.295620.2425.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 663465 by dang:
Implement rudimentary global session management. It saves the URLs, which
is the most I dare implement in the stable branch so as to not break anything.
Local session save/restore is not implemented, although some psuedo-code exists for \
it. I don't intend to implement this since I don't think any other KDE app does.
CCMAIL: 94651@bugs.kde.org
M +4 -0 kolourpaint.cpp
M +15 -0 kpdefs.h
M +164 -1 kpmainwindow.cpp
M +24 -0 kpmainwindow.h
M +27 -11 kpmainwindow_file.cpp
--- branches/KDE/3.5/kdegraphics/kolourpaint/kolourpaint.cpp #663464:663465
@@ -220,7 +220,11 @@
if (app.isRestored ())
+ {
+ // Creates a kpMainWindow using the default constructor and then
+ // calls kpMainWindow::readProperties().
RESTORE (kpMainWindow)
+ }
else
{
kpMainWindow *mainWindow;
--- branches/KDE/3.5/kdegraphics/kolourpaint/kpdefs.h #663464:663465
@@ -132,5 +132,20 @@
#define kpSettingFlattenEffectColor2 QString::fromLatin1 ("Color2")
+//
+// Session Restore Setting
+//
+
+// URL of the document in the main window.
+//
+// This key only exists if the document does. If it exists, it can be empty.
+// The URL need not point to a file that exists e.g. "kolourpaint doesnotexist.png".
+#define kpSessionSettingDocumentUrl QString::fromLatin1 ("Session Document Url")
+
+// The size of a document which is not from a URL e.g. "kolourpaint \
doesnotexist.png". +// This key does not exist for documents from URLs.
+#define kpSessionSettingNotFromUrlDocumentSize QString::fromLatin1 ("Session \
Not-From-Url Document Size") +
+
#endif // __kp_defs_h__
--- branches/KDE/3.5/kdegraphics/kolourpaint/kpmainwindow.cpp #663464:663465
@@ -310,6 +310,170 @@
#endif
}
+
+// private virtual [base KMainWindow]
+void kpMainWindow::readProperties (KConfig *cfg)
+{
+#if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "kpMainWindow<" << this << ">::readProperties()" << endl;
+#endif
+
+ // No document at all?
+ if (!cfg->hasKey (kpSessionSettingDocumentUrl))
+ {
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\tno url - no document" << endl;
+ #endif
+ setDocument (0);
+ }
+ // Have a document.
+ else
+ {
+ const KURL url (cfg->readEntry (kpSessionSettingDocumentUrl));
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\turl=" << url << endl;
+ #endif
+
+ const QSize notFromURLDocSize =
+ cfg->readSizeEntry (kpSessionSettingNotFromUrlDocumentSize);
+
+ // Is from URL?
+ if (notFromURLDocSize.isEmpty ())
+ {
+ // If this fails, the empty document that kpMainWindow::kpMainWindow()
+ // created is left untouched.
+ openInternal (url, defaultDocSize (),
+ false/*show error message if url !exist*/);
+ }
+ // Not from URL?
+ else
+ {
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\tnot from url; doc size=" << notFromURLDocSize << endl;
+ #endif
+ // Either we have an empty URL or we have a "kolourpaint \
doesnotexist.png" + // URL. Regarding the latter case, if a file now \
actually exists at that + // URL, we do open it - ignoring \
notFromURLDocSize - to avoid putting + // the user in a situation where he \
might accidentally overwrite an + // existing file.
+ openInternal (url, notFromURLDocSize,
+ true/*create an empty doc with the same url if url !exist*/);
+ }
+ }
+
+}
+
+// private virtual [base KMainWindow]
+// WARNING: KMainWindow API Doc says "No user interaction is allowed
+// in this function!"
+void kpMainWindow::saveProperties (KConfig *cfg)
+{
+#if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "kpMainWindow<" << this << ">::saveProperties()" << endl;
+#endif
+
+ // No document at all?
+ if (!m_document)
+ {
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\tno url - no document" << endl;
+ #endif
+ }
+ // Have a document.
+ else
+ {
+ // Save URL in all cases:
+ //
+ // a) m_document->isFromURL()
+ // b) !m_document->isFromURL() [save size in this case]
+ // i) No URL
+ // ii) URL (from "kolourpaint doesnotexist.png")
+
+ const KURL url = m_document->url ();
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\turl=" << url << endl;
+ #endif
+ cfg->writeEntry (kpSessionSettingDocumentUrl, url.url ());
+
+ // Not from URL e.g. "kolourpaint doesnotexist.png"?
+ //
+ // Note that "kolourpaint doesexist.png" is considered to be from
+ // a URL even if it was deleted in the background (hence the
+ // "false" arg to isFromURL()). This is because the user expects
+ // it to be from a URL, so when we session restore, we pop up a
+ // "cannot find file" dialog, instead of silently creating a new,
+ // blank document.
+ if (!m_document->isFromURL (false/*don't bother checking exists*/))
+ {
+ // If we don't have a URL either:
+ //
+ // a) it was not modified - so we can use either width() or
+ // constructorWidth() (they'll be equal).
+ // b) the changes were discarded so we use the initial width,
+ // constructorWidth().
+ //
+ // Similarly for height() and constructorHeight().
+ const QSize docSize (m_document->constructorWidth (),
+ m_document->constructorHeight ());
+ #if DEBUG_KP_MAIN_WINDOW
+ kdDebug () << "\tnot from url; doc size=" << docSize << endl;
+ #endif
+ cfg->writeEntry (kpSessionSettingNotFromUrlDocumentSize, docSize);
+ }
+
+
+ // Local session save i.e. queryClose() was not called beforehand
+ // (see QApplication::saveState())?
+ #if 0
+ if (m_document->isModified ())
+ {
+ // TODO: Implement by saving the current image to a persistent file.
+ // We do this instead of saving/mutating the backing image file
+ // as no one expects a file save on a session save without a
+ // "do you want to save" dialog first.
+ //
+ // I don't think any KDE application implements local session \
saving. + //
+ // --- The below code does not compile but shows you want to do \
--- +
+ // Create unique name for the document in this main window.
+ const KURL tempURL = homeDir +
+ "kolourpaint session " + sessionID +
+ mainWindowPtrToString + ".png";
+ // TODO: Use lossless PNG saving options.
+ kpDocumentSaveOptions pngSaveOptions;
+
+ if (kpDocument::savePixmapToFile (m_document->pixmapWithSelection (),
+ tempURL,
+ pngSaveOptions, *m_document->metaInfo (),
+ false/*no overwrite prompt*/,
+ false/*no lossy prompt*/,
+ this))
+ {
+ // readProperties() will still open kpSessionSettingDocumentUrl
+ // (as that's the expected URL) and will then add commands to:
+ //
+ // 1. Resize the document to the size of image at
+ // kpSessionSettingDocumentUnsavedContentsUrl, if the sizes
+ // differ.
+ // 2. Paste the kpSessionSettingDocumentUnsavedContentsUrl image
+ // (setting the main window's selection mode to opaque \
beforehand). + //
+ // It will then delete the file at
+ // kpSessionSettingDocumentUnsavedContentsUrl.
+ cfg->writeEntry (kpSessionSettingDocumentUnsavedContentsUrl,
+ tempURL.url ());
+ }
+ else
+ {
+ // Not much we can do - we aren't allowed to throw up a dialog.
+ }
+ }
+ #endif
+ }
+}
+
+
kpMainWindow::~kpMainWindow ()
{
m_isFullyConstructed = false;
@@ -885,4 +1049,3 @@
#include <kpmainwindow.moc>
-
--- branches/KDE/3.5/kdegraphics/kolourpaint/kpmainwindow.h #663464:663465
@@ -120,6 +120,15 @@
void readThumbnailSettings ();
void init ();
+ // (only called for restoring a previous session e.g. starting KDE with
+ // a previously saved session; it's not called on normal KolourPaint
+ // startup)
+ virtual void readProperties (KConfig *cfg);
+ // (only called for saving the current session e.g. logging out of KDE
+ // with the KolourPaint window open; it's not called on normal KolourPaint
+ // exit)
+ virtual void saveProperties (KConfig *cfg);
+
public:
~kpMainWindow ();
@@ -310,7 +319,22 @@
void setDocumentChoosingWindow (kpDocument *doc);
private:
+ kpDocument *openInternal (const KURL &url,
+ const QSize &fallbackDocSize,
+ bool newDocSameNameIfNotExist);
+ // Same as above except that it:
+ //
+ // 1. Assumes a default fallback document size.
+ // 2. If the URL is successfully opened (with the special exception of
+ // the "kolourpaint doesnotexist.png" case), it is bubbled up to the
+ // top in the Recent Files Action.
+ //
+ // As a result of this behavior, this should only be called in response
+ // to a user open request e.g. File / Open or "kolourpaint doesexist.png".
+ // It should not be used for session restore - in that case, it does not
+ // make sense to bubble the Recent Files list.
bool open (const KURL &url, bool newDocSameNameIfNotExist = false);
+
KURL::List askForOpenURLs (const QString &caption,
const QString &startURL,
bool allowMultipleURLs = true);
--- branches/KDE/3.5/kdegraphics/kolourpaint/kpmainwindow_file.cpp #663464:663465
@@ -283,29 +283,45 @@
// private
-bool kpMainWindow::open (const KURL &url, bool newDocSameNameIfNotExist)
+kpDocument *kpMainWindow::openInternal (const KURL &url,
+ const QSize &fallbackDocSize,
+ bool newDocSameNameIfNotExist)
{
- QSize docSize = defaultDocSize ();
-
// create doc
- kpDocument *newDoc = new kpDocument (docSize.width (), docSize.height (), this);
- if (newDoc->open (url, newDocSameNameIfNotExist))
+ kpDocument *newDoc = new kpDocument (fallbackDocSize.width (),
+ fallbackDocSize.height (),
+ this);
+ if (!newDoc->open (url, newDocSameNameIfNotExist))
{
+ delete newDoc;
+ return 0;
+ }
+
+ // Send document to current or new window.
+ setDocumentChoosingWindow (newDoc);
+
+ return newDoc;
+}
+
+// private
+bool kpMainWindow::open (const KURL &url, bool newDocSameNameIfNotExist)
+{
+ kpDocument *newDoc = openInternal (url,
+ defaultDocSize (),
+ newDocSameNameIfNotExist);
+ if (newDoc)
+ {
if (newDoc->isFromURL (false/*don't bother checking exists*/))
addRecentURL (url);
+ return true;
}
else
{
- delete newDoc;
return false;
}
+}
- // Send document to current or new window.
- setDocumentChoosingWindow (newDoc);
- return true;
-}
-
// private
KURL::List kpMainWindow::askForOpenURLs (const QString &caption, const QString \
&startURL, bool allowMultipleURLs)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic