[Ktutorial-commits] SF.net SVN: ktutorial:[217] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-30 03:16:13
|
Revision: 217 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=217&view=rev Author: danxuliu Date: 2010-03-30 03:16:07 +0000 (Tue, 30 Mar 2010) Log Message: ----------- Provide the main window to Serialization to be used in KIO::NetAccess operations. Serialization methods were changed from class methods to instance methods. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.h trunk/ktutorial/ktutorial-editor/tests/unit/serialization/SerializationTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 02:32:32 UTC (rev 216) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 03:16:07 UTC (rev 217) @@ -76,7 +76,7 @@ void KTutorialEditor::loadTutorialFromUrl(const KUrl& url) { Tutorial* tutorial; try { - tutorial = Serialization::loadTutorial(url); + tutorial = Serialization(this).loadTutorial(url); } catch (IOException e) { QString text = i18nc("@label", "There was a problem when trying to " "open the file:<nl/>%1", e.message()); @@ -452,7 +452,7 @@ } try { - Serialization::saveTutorial(mTutorial, mTutorialUrl); + Serialization(this).saveTutorial(mTutorial, mTutorialUrl); } catch (IOException e) { QString text = i18nc("@label", "There was a problem when trying to " "save the tutorial:<nl/>%1", e.message()); @@ -483,7 +483,7 @@ } try { - Serialization::saveTutorial(mTutorial, dialog->selectedUrl()); + Serialization(this).saveTutorial(mTutorial, dialog->selectedUrl()); } catch (IOException e) { QString text = i18nc("@label", "There was a problem when trying to " "save the tutorial:<nl/>%1", e.message()); @@ -509,7 +509,7 @@ dialog->setCaption(i18nc("@title", "Export Tutorial")); dialog->setOperationMode(KFileDialog::Saving); dialog->setConfirmOverwrite(true); - dialog->setFilter(Serialization::availableExporterTypes()); + dialog->setFilter(Serialization(this).availableExporterTypes()); dialog->filterWidget()->setEditable(false); if (dialog->exec() == QDialog::Rejected) { @@ -517,8 +517,8 @@ } try { - Serialization::exportTutorial(mTutorial, dialog->currentFilter(), - dialog->selectedUrl()); + Serialization(this).exportTutorial(mTutorial, dialog->currentFilter(), + dialog->selectedUrl()); } catch (IOException e) { QString text = i18nc("@label", "There was a problem when trying to " "save the exported tutorial:<nl/>%1", e.message()); Modified: trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp 2010-03-30 02:32:32 UTC (rev 216) +++ trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp 2010-03-30 03:16:07 UTC (rev 217) @@ -29,6 +29,10 @@ //public: +Serialization::Serialization(QWidget* window): + mWindow(window) { +} + Tutorial* Serialization::loadTutorial(const KUrl& url) throw (DeserializationException, IOException) { Q_ASSERT(url.isValid()); @@ -39,7 +43,7 @@ } QString temporaryFileName; - if (!KIO::NetAccess::download(url, temporaryFileName, 0)) { + if (!KIO::NetAccess::download(url, temporaryFileName, mWindow)) { throw IOException(KIO::NetAccess::lastErrorString()); } @@ -111,7 +115,7 @@ out.flush(); temporaryFile.close(); - if (!KIO::NetAccess::upload(temporaryFile.fileName(), url, 0)) { + if (!KIO::NetAccess::upload(temporaryFile.fileName(), url, mWindow)) { throw IOException(KIO::NetAccess::lastErrorString()); } } Modified: trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.h 2010-03-30 02:32:32 UTC (rev 216) +++ trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.h 2010-03-30 03:16:07 UTC (rev 217) @@ -25,6 +25,7 @@ #include "IOException.h" class KUrl; +class QWidget; class Tutorial; /** @@ -37,6 +38,17 @@ public: /** + * Creates a new Serialization. + * The given window will be used as the parent window if any dialog is shown + * to request some information (for example, the user password when saving a + * file in a remote computer). It will be also used to automatically cache + * and discard that information. + * + * @param window The window associated with the input/ouput jobs, if any. + */ + explicit Serialization(QWidget* window = 0); + + /** * Loads a tutorial from the file specified by the given url. * The file must be a XML file that validates against the W3C Schema in * Tutorial.xsd. The url can be local or remote. @@ -49,8 +61,8 @@ * file. * @see TutorialReader */ - static Tutorial* loadTutorial(const KUrl& url) - throw (DeserializationException, IOException); + Tutorial* loadTutorial(const KUrl& url) throw (DeserializationException, + IOException); /** * Saves the tutorial to the file specified by the given url. @@ -63,8 +75,7 @@ * file. * @see TutorialWriter */ - static void saveTutorial(Tutorial* tutorial, const KUrl& url) - throw (IOException); + void saveTutorial(Tutorial* tutorial, const KUrl& url) throw (IOException); /** * Returns the available exporter types. @@ -75,7 +86,7 @@ * * @return The available exporter types. */ - static QString availableExporterTypes(); + QString availableExporterTypes(); /** * Exports the tutorial to the file specified by the url using the given @@ -91,17 +102,19 @@ * @throw IOException If there was a problem writing the contents to the * file. */ - static void exportTutorial(const Tutorial* tutorial, const QString& type, - const KUrl& url) throw (IOException); + void exportTutorial(const Tutorial* tutorial, const QString& type, + const KUrl& url) throw (IOException); private: + QWidget* mWindow; + /** * Returns a list of strings with the available exporter types. * * @return A list with the available exporter types. */ - static QStringList availableExporterTypeList(); + QStringList availableExporterTypeList(); /** * Writes the data to the file specified by the given url. @@ -112,8 +125,7 @@ * @throw IOException If there was a problem writing the contents to the * file. */ - static void writeFile(const QString& data, const KUrl& url) - throw (IOException); + void writeFile(const QString& data, const KUrl& url) throw (IOException); }; Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/SerializationTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/SerializationTest.cpp 2010-03-30 02:32:32 UTC (rev 216) +++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/SerializationTest.cpp 2010-03-30 03:16:07 UTC (rev 217) @@ -94,8 +94,8 @@ KUrl url = KGlobal::dirs()->saveLocation("tmp") + "/SerializationTest.xml"; - Serialization::saveTutorial(&tutorial, url); - QScopedPointer<Tutorial> loadedTutorial(Serialization::loadTutorial(url)); + Serialization().saveTutorial(&tutorial, url); + QScopedPointer<Tutorial> loadedTutorial(Serialization().loadTutorial(url)); QVERIFY(loadedTutorial); QCOMPARE(loadedTutorial->name(), tutorial.name()); @@ -109,13 +109,13 @@ writeFile(mFile, "<tutorial name=\"The name\"></tutorial>"); QVERIFY(QFile::setPermissions(mFile->fileName(), 0)); - EXPECT_EXCEPTION(Serialization::loadTutorial(url), IOException); + EXPECT_EXCEPTION(Serialization().loadTutorial(url), IOException); } void SerializationTest::testLoadFromDirectory() { KUrl url = KGlobal::dirs()->saveLocation("tmp"); - EXPECT_EXCEPTION(Serialization::loadTutorial(url), IOException); + EXPECT_EXCEPTION(Serialization().loadTutorial(url), IOException); } void SerializationTest::testLoadNotAnXmlFile() { @@ -124,7 +124,7 @@ mFile->open(QIODevice::WriteOnly | QIODevice::Text); writeFile(mFile, "Not an XML file"); - EXPECT_EXCEPTION(Serialization::loadTutorial(url), + EXPECT_EXCEPTION(Serialization().loadTutorial(url), DeserializationException); } @@ -134,7 +134,7 @@ mFile->open(QIODevice::WriteOnly | QIODevice::Text); writeFile(mFile, "<tutorial><step></invalidEndElement></tutorial>"); - EXPECT_EXCEPTION(Serialization::loadTutorial(url), + EXPECT_EXCEPTION(Serialization().loadTutorial(url), DeserializationException); } @@ -144,7 +144,7 @@ mFile->open(QIODevice::WriteOnly | QIODevice::Text); writeFile(mFile, "<unknownRootElement></unknownRootElement>"); - EXPECT_EXCEPTION(Serialization::loadTutorial(url), + EXPECT_EXCEPTION(Serialization().loadTutorial(url), DeserializationException); } @@ -158,7 +158,7 @@ mFile->open(QIODevice::WriteOnly | QIODevice::Text); writeFile(mFile, "Hello world!"); - Serialization::saveTutorial(&tutorial, url); + Serialization().saveTutorial(&tutorial, url); QVERIFY(mFile->exists()); QVERIFY(mFile->open(QIODevice::ReadOnly | QIODevice::Text)); @@ -184,7 +184,7 @@ writeFile(mFile, "Hello world!"); QVERIFY(QFile::setPermissions(mFile->fileName(), 0)); - EXPECT_EXCEPTION(Serialization::saveTutorial(&tutorial, url), IOException); + EXPECT_EXCEPTION(Serialization().saveTutorial(&tutorial, url), IOException); } void SerializationTest::testSaveToDirectory() { @@ -194,11 +194,11 @@ KUrl url = KGlobal::dirs()->saveLocation("tmp"); - EXPECT_EXCEPTION(Serialization::saveTutorial(&tutorial, url), IOException); + EXPECT_EXCEPTION(Serialization().saveTutorial(&tutorial, url), IOException); } void SerializationTest::testAvailableExporterTypes() { - QString types = Serialization::availableExporterTypes(); + QString types = Serialization().availableExporterTypes(); QCOMPARE(types, i18nc("@item:combobox A KFileDialog filter", "*.js|Javascript file")); @@ -211,7 +211,7 @@ KUrl url = KGlobal::dirs()->saveLocation("tmp") + "/SerializationTest.js"; - Serialization::exportTutorial(&tutorial, "*.js", url); + Serialization().exportTutorial(&tutorial, "*.js", url); mFile = new QFile(url.toLocalFile()); QVERIFY(mFile->exists()); @@ -239,7 +239,7 @@ mFile->open(QIODevice::WriteOnly | QIODevice::Text); writeFile(mFile, "Hello world!"); - Serialization::exportTutorial(&tutorial, "*.js", url); + Serialization().exportTutorial(&tutorial, "*.js", url); QVERIFY(mFile->exists()); QVERIFY(mFile->open(QIODevice::ReadOnly | QIODevice::Text)); @@ -267,7 +267,7 @@ writeFile(mFile, "Hello world!"); QVERIFY(QFile::setPermissions(mFile->fileName(), 0)); - EXPECT_EXCEPTION(Serialization::exportTutorial(&tutorial, "*.js", url), + EXPECT_EXCEPTION(Serialization().exportTutorial(&tutorial, "*.js", url), IOException); } @@ -278,7 +278,7 @@ KUrl url = KGlobal::dirs()->saveLocation("tmp"); - EXPECT_EXCEPTION(Serialization::exportTutorial(&tutorial, "*.js", url), + EXPECT_EXCEPTION(Serialization().exportTutorial(&tutorial, "*.js", url), IOException); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |