[Ktutorial-commits] SF.net SVN: ktutorial:[215] trunk/ktutorial/ktutorial-editor/src
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-29 23:59:07
|
Revision: 215
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=215&view=rev
Author: danxuliu
Date: 2010-03-29 23:58:59 +0000 (Mon, 29 Mar 2010)
Log Message:
-----------
Add a command line option to load a tutorial
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp
trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h
trunk/ktutorial/ktutorial-editor/src/main.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 23:40:17 UTC (rev 214)
+++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 23:58:59 UTC (rev 215)
@@ -73,6 +73,33 @@
setupGUI();
}
+void KTutorialEditor::loadTutorialFromUrl(const KUrl& url) {
+ Tutorial* tutorial;
+ try {
+ tutorial = Serialization::loadTutorial(url);
+ } catch (IOException e) {
+ QString text = i18nc("@label", "There was a problem when trying to "
+"open the file:<nl/>%1", e.message());
+ QString caption = i18nc("@title:window", "File could not be read");
+ KMessageBox::error(this, text, caption);
+ return;
+ } catch (DeserializationException e) {
+ QString text = i18nc("@label", "There was a problem when trying to "
+"load the tutorial:<nl/>%1", e.message());
+ QString caption = i18nc("@title:window", "Tutorial could not be "
+"loaded");
+ KMessageBox::error(this, text, caption);
+ return;
+ }
+
+ setTutorialToBeEdited(tutorial);
+ mTutorialUrl = url;
+ mUndoStack->setClean();
+ //Force clean state, as setting an empty stack as clean would not emit
+ //cleanChanged()
+ handleUndoStackCleanChanged(true);
+}
+
//protected:
bool KTutorialEditor::queryClose() {
@@ -416,30 +443,7 @@
return;
}
- Tutorial* tutorial;
- try {
- tutorial = Serialization::loadTutorial(dialog->selectedUrl());
- } catch (IOException e) {
- QString text = i18nc("@label", "There was a problem when trying to "
-"open the file:<nl/>%1", e.message());
- QString caption = i18nc("@title:window", "File could not be read");
- KMessageBox::error(this, text, caption);
- return;
- } catch (DeserializationException e) {
- QString text = i18nc("@label", "There was a problem when trying to "
-"load the tutorial:<nl/>%1", e.message());
- QString caption = i18nc("@title:window", "Tutorial could not be "
-"loaded");
- KMessageBox::error(this, text, caption);
- return;
- }
-
- setTutorialToBeEdited(tutorial);
- mTutorialUrl = dialog->selectedUrl();
- mUndoStack->setClean();
- //Force clean state, as setting an empty stack as clean would not emit
- //cleanChanged()
- handleUndoStackCleanChanged(true);
+ loadTutorialFromUrl(dialog->selectedUrl());
}
bool KTutorialEditor::saveTutorial() {
Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 23:40:17 UTC (rev 214)
+++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 23:58:59 UTC (rev 215)
@@ -43,6 +43,15 @@
*/
KTutorialEditor();
+ /**
+ * Loads the tutorial to be edited from the given URL.
+ * The tutorial URL is updated and a clean state is forced.
+ * An error message is shown if the tutorial couldn't be opened.
+ *
+ * @param url The URL to load the tutorial from.
+ */
+ void loadTutorialFromUrl(const KUrl& url);
+
protected:
/**
@@ -197,8 +206,7 @@
/**
* Shows a KFileDialog to select the file to open the tutorial from.
- * The tutorial URL is updated and a clean state is forced.
- * An error message is shown if the tutorial couldn't be opened.
+ * The tutorial is loaded from the URL selected by the user.
*/
void openTutorial();
Modified: trunk/ktutorial/ktutorial-editor/src/main.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-29 23:40:17 UTC (rev 214)
+++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-29 23:58:59 UTC (rev 215)
@@ -35,10 +35,20 @@
"dan...@gm...");
KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineOptions options;
+ options.add("+[URL]", ki18nc("@info:shell", "The tutorial to open"));
+
+ KCmdLineArgs::addCmdLineOptions(options);
+
KApplication app;
KTutorialEditor* window = new KTutorialEditor();
window->show();
+ KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
+ if (args->count() == 1) {
+ window->loadTutorialFromUrl(args->url(0));
+ }
+
return app.exec();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|