KTutorial  0.5.1
KTutorial.cpp
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 "KTutorial.h"
00022 #include "KTutorial_p.h"
00023 
00024 #include <KDebug>
00025 
00026 #include "TutorialManager.h"
00027 #include "customization/DefaultKdeCustomization.h"
00028 #include "scripting/ScriptingModule.h"
00029 #include "scripting/ScriptManager.h"
00030 
00031 #ifdef QT_QTDBUS_FOUND
00032 #include "editorsupport/EditorSupport.h"
00033 #endif
00034 
00035 using ktutorial::customization::DefaultKdeCustomization;
00036 using ktutorial::scripting::ScriptingModule;
00037 using ktutorial::scripting::ScriptManager;
00038 
00039 namespace ktutorial {
00040 
00041 //The function is used in subdirectories, and each subdirectory has its own
00042 //static library. The unit tests for the subdirectories are linked against the
00043 //static library of its subdirectory and the main shared library (where this
00044 //function is defined). Thus, the function must be exported for the linker to be
00045 //able to find it when the unit tests for the subdirectories are built.
00046 KTUTORIAL_EXPORT int debugArea() {
00047     static int s_area = KDebug::registerArea("ktutorial");
00048     return s_area;
00049 }
00050 
00051 //public:
00052 
00053 KTutorial* KTutorial::self() {
00054     return sSelf;
00055 }
00056 
00057 KTutorial::~KTutorial() {
00058     delete d;
00059 }
00060 
00061 bool KTutorial::registerWaitForMetaObject(const QMetaObject& waitForMetaObject,
00062                                     const QString& typeName /*= QString()*/) {
00063     return ScriptingModule::self()->registerWaitForMetaObject(waitForMetaObject,
00064                                                               typeName);
00065 }
00066 
00067 void KTutorial::setup(KXmlGuiWindow* window) {
00068     DefaultKdeCustomization* defaultKdeCustomization =
00069                                             new DefaultKdeCustomization(window);
00070     setup(defaultKdeCustomization);
00071 }
00072 
00073 void KTutorial::setup(KTutorialCustomization* ktutorialCustomization) {
00074     d->mCustomization = ktutorialCustomization;
00075     d->mCustomization->setParent(this);
00076 
00077     d->mCustomization->setup(d->mTutorialmanager);
00078 
00079     ScriptManager().loadTutorials(d->mTutorialmanager);
00080 
00081 #ifdef QT_QTDBUS_FOUND
00082     editorsupport::EditorSupport* editorSupport =
00083                                         new editorsupport::EditorSupport(this);
00084     editorSupport->setObjectFinder(d->mObjectFinder);
00085     editorSupport->setup(mainApplicationWindow());
00086     connect(editorSupport, SIGNAL(started(Tutorial*)),
00087             ktutorialCustomization, SLOT(showTutorialUI(Tutorial*)));
00088 #endif
00089 }
00090 
00091 bool KTutorial::registerTutorial(Tutorial* tutorial) {
00092     return d->mTutorialmanager->registerTutorial(tutorial);
00093 }
00094 
00095 QWidget* KTutorial::mainApplicationWindow() const {
00096     return d->mCustomization->mainApplicationWindow();
00097 }
00098 
00099 //private:
00100 
00101 KTutorial* KTutorial::sSelf = new KTutorial();
00102 
00103 KTutorial::KTutorial():
00104     d(new KTutorialPrivate()) {
00105     d->mTutorialmanager = new TutorialManager();
00106     d->mTutorialmanager->setParent(this);
00107     d->mObjectFinder = new ObjectFinder(this);
00108     d->mCustomization = 0;
00109 }
00110 
00111 ObjectFinder* KTutorial::objectFinder() const {
00112     return d->mObjectFinder;
00113 }
00114 
00115 }