KTutorial
0.5.1
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00003 * Copyright (C) 2009 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00004 * Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00005 * Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; If not, see <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 00021 #include "TutorialManager.h" 00022 #include "TutorialManager_p.h" 00023 00024 #include <KDebug> 00025 00026 #include "Tutorial.h" 00027 #include "TutorialInformation.h" 00028 00029 namespace ktutorial { 00030 extern int debugArea(); 00031 } 00032 00033 namespace ktutorial { 00034 00035 //public: 00036 00037 TutorialManager::TutorialManager(): QObject(), 00038 d(new TutorialManagerPrivate()) { 00039 } 00040 00041 TutorialManager::~TutorialManager() { 00042 delete d; 00043 } 00044 00045 bool TutorialManager::registerTutorial(Tutorial* tutorial) { 00046 if (d->mTutorialInformations.contains( 00047 tutorial->tutorialInformation()->id())) { 00048 kWarning(debugArea()) << "Tutorial with id" 00049 << tutorial->tutorialInformation()->id() 00050 << "already added"; 00051 return false; 00052 } 00053 00054 tutorial->setParent(this); 00055 00056 d->mTutorialInformations.insert(tutorial->tutorialInformation()->id(), 00057 tutorial->tutorialInformation()); 00058 d->mTutorials.insert(tutorial->tutorialInformation(), tutorial); 00059 00060 return true; 00061 } 00062 00063 QList<const TutorialInformation*> TutorialManager::tutorialInformations() 00064 const { 00065 return d->mTutorialInformations.values(); 00066 } 00067 00068 void TutorialManager::start(const QString& id) { 00069 if (!d->mTutorialInformations.contains(id)) { 00070 finish(); 00071 return; 00072 } 00073 00074 kDebug(debugArea()) << "Started:" << id; 00075 00076 Tutorial* tutorial = d->mTutorials.value( 00077 d->mTutorialInformations.value(id)); 00078 connect(tutorial, SIGNAL(finished(Tutorial*)), this, SLOT(finish())); 00079 00080 emit started(tutorial); 00081 00082 tutorial->start(); 00083 } 00084 00085 //private slots: 00086 00087 void TutorialManager::finish() { 00088 disconnect(this, SLOT(finish())); 00089 emit finished(); 00090 } 00091 00092 }