From f29b95cef0441958050c86d3544cdfde32e9e62e Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 7 Jan 2011 11:07:08 +0000 Subject: Using QFile open by RFile and take ownership of handle QFileOpenEvent's open method now opens the QFile with an RFile handle if possible. It takes a duplicate of the handle and transfers ownership to the QFile, so that the QFile can be used many times and outside of the lifetime of the QFileOpenEvent. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/corelib/kernel/qcore_symbian_p.h | 16 ++++++++++++++++ src/gui/kernel/qevent.cpp | 18 ++++++++++++------ src/gui/kernel/qevent.h | 2 +- src/gui/s60framework/qs60maindocument.cpp | 18 ++++++++++++------ src/s60installs/bwins/QtGuiu.def | 4 +++- src/s60installs/eabi/QtGuiu.def | 8 ++++---- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h index 3ef71e0..5b48689 100644 --- a/src/corelib/kernel/qcore_symbian_p.h +++ b/src/corelib/kernel/qcore_symbian_p.h @@ -158,6 +158,22 @@ Q_CORE_EXPORT RFs& qt_s60GetRFs(); // Defined in qlocale_symbian.cpp. Q_CORE_EXPORT QByteArray qt_symbianLocaleName(int code); +template +struct QScopedPointerRCloser +{ + static inline void cleanup(R *rPointer) + { + // Enforce a complete type. + // If you get a compile error here, read the section on forward declared + // classes in the QScopedPointer documentation. + typedef char IsIncompleteType[ sizeof(R) ? 1 : -1 ]; + (void) sizeof(IsIncompleteType); + + if (rPointer) + rPointer->Close(); + } +}; + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8f2e6cb..17bcbfb 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3099,9 +3099,11 @@ QUrl QFileOpenEvent::url() const } /*! - \fn void openFile(QFile &file, QIODevice::OpenMode flags) const + \fn bool openFile(QFile &file, QIODevice::OpenMode flags) const Opens a QFile on the file referenced by this event. + Returns true if successful; otherwise returns false. + This is necessary as some files cannot be opened with the filename alone, but require specific information stored in this event. For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, @@ -3109,18 +3111,22 @@ QUrl QFileOpenEvent::url() const \since 4.8 */ -void QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const +bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const { file.setFileName(f); #ifdef Q_OS_SYMBIAN const QFileOpenEventPrivate *priv = reinterpret_cast(d); if (priv->file.SubSessionHandle()) { - // TODO return a QFile opened from the file handle - file.open(flags); - return; + RFile dup; + if (dup.Duplicate(priv->file) == KErrNone) { + QScopedPointer > dupCloser(&dup); + bool open = file.open(dup, flags, QFile::AutoCloseHandle); + dupCloser.take(); + return open; + } } #endif - file.open(flags); + return file.open(flags); } #ifndef QT_NO_TOOLBAR diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 88a7a8a..997ac0c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -657,7 +657,7 @@ public: inline QString file() const { return f; } QUrl url() const; - void openFile(QFile &file, QIODevice::OpenMode flags) const; + bool openFile(QFile &file, QIODevice::OpenMode flags) const; private: QString f; }; diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index d53aac1..37bd55f 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -113,10 +113,12 @@ CEikAppUi *QS60MainDocument::CreateAppUiL() */ CFileStore *QS60MainDocument::OpenFileL(TBool /*aDoOpen*/, const TDesC &aFilename, RFs &/*aFs*/) { - QCoreApplication* app = QCoreApplication::instance(); - QString qname = qt_TDesC2QString(aFilename); - QFileOpenEvent* event = new QFileOpenEvent(qname); - app->postEvent(app, event); + QT_TRYCATCH_LEAVING( { + QCoreApplication* app = QCoreApplication::instance(); + QString qname = qt_TDesC2QString(aFilename); + QFileOpenEvent* event = new QFileOpenEvent(qname); + app->postEvent(app, event); + }) return 0; } @@ -125,8 +127,12 @@ CFileStore *QS60MainDocument::OpenFileL(TBool /*aDoOpen*/, const TDesC &aFilenam */ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { - QCoreApplication* app = QCoreApplication::instance(); - QFileOpenEvent* event = new QFileOpenEvent(aFile); + QT_TRYCATCH_LEAVING( { + QCoreApplication* app = QCoreApplication::instance(); + QFileOpenEvent* event = new QFileOpenEvent(aFile); + app->postEvent(app, event); + aFileStore = 0; + }) } QT_END_NAMESPACE diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 322d88b..9475728 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -13142,4 +13142,6 @@ EXPORTS ?viewportSize@QScrollPrepareEvent@@QBE?AVQSizeF@@XZ @ 13141 NONAME ; class QSizeF QScrollPrepareEvent::viewportSize(void) const ?staticMetaObject@QScroller@@2UQMetaObject@@B @ 13142 NONAME ; struct QMetaObject const QScroller::staticMetaObject ?staticMetaObject@QFlickGesture@@2UQMetaObject@@B @ 13143 NONAME ; struct QMetaObject const QFlickGesture::staticMetaObject - + ?ProcessCommandParametersL@QS60MainAppUi@@UAEHW4TApaCommand@@AAV?$TBuf@$0BAA@@@ABVTDesC8@@@Z @ 13144 NONAME ; int QS60MainAppUi::ProcessCommandParametersL(enum TApaCommand, class TBuf<256> &, class TDesC8 const &) + ?openFile@QFileOpenEvent@@QBE_NAAVQFile@@V?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z @ 13145 NONAME ; bool QFileOpenEvent::openFile(class QFile &, class QFlags) const + ??0QFileOpenEvent@@QAE@ABVRFile@@@Z @ 13146 NONAME ; QFileOpenEvent::QFileOpenEvent(class RFile const &) diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index 8064fa3..a4937a7 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12227,10 +12227,10 @@ EXPORTS _ZTV19QBlitterPaintEngine @ 12226 NONAME _ZTV20QBlittablePixmapData @ 12227 NONAME _Zls6QDebugPK13QSymbianEvent @ 12228 NONAME - _ZN13QS60MainAppUi25ProcessCommandParametersLE11TApaCommandR4TBufILi256EERK6TDesC8 @ 12229 NONAME ABSENT - _ZN14QFileOpenEventC1ERK5RFile @ 12230 NONAME ABSENT - _ZN14QFileOpenEventC2ERK5RFile @ 12231 NONAME ABSENT - _ZNK14QFileOpenEvent8openFileER5QFile6QFlagsIN9QIODevice12OpenModeFlagEE @ 12232 NONAME ABSENT + _ZN13QS60MainAppUi25ProcessCommandParametersLE11TApaCommandR4TBufILi256EERK6TDesC8 @ 12229 NONAME + _ZN14QFileOpenEventC1ERK5RFile @ 12230 NONAME + _ZN14QFileOpenEventC2ERK5RFile @ 12231 NONAME + _ZNK14QFileOpenEvent8openFileER5QFile6QFlagsIN9QIODevice12OpenModeFlagEE @ 12232 NONAME _ZN11QFontEngine16alphaMapForGlyphEj6QFixed @ 12233 NONAME _ZN11QFontEngine16alphaMapForGlyphEj6QFixedRK10QTransform @ 12234 NONAME _Z32qGamma_correct_back_to_linear_csP6QImage @ 12235 NONAME -- cgit v0.12