KTutorial  0.5.1
TutorialManagerDialog.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 "TutorialManagerDialog.h"
00022 #include "TutorialListModel.h"
00023 #include "ui_TutorialManagerDialog.h"
00024 #include "../TutorialInformation.h"
00025 #include "../TutorialManager.h"
00026 
00027 namespace ktutorial {
00028 namespace view {
00029 
00030 //public:
00031 
00032 TutorialManagerDialog::TutorialManagerDialog(TutorialManager* tutorialManager,
00033                                              QWidget* parent):
00034         KDialog(parent),
00035     mTutorialManager(tutorialManager),
00036     mCurrentTutorialInformation(0) {
00037 
00038     QWidget *widget = new QWidget(this);
00039     ui = new Ui::TutorialManagerDialog();
00040     ui->setupUi(widget);
00041 
00042     setMainWidget(widget);
00043 
00044     setCaption(i18nc("@title:window", "Tutorial manager"));
00045     setButtons(KDialog::User1 | KDialog::Close);
00046 
00047     ui->tutorialsList->setModel(new TutorialListModel(tutorialManager, this));
00048 
00049     setButtonIcon(User1, KIcon("dialog-ok"));
00050     setButtonText(User1, i18nc("@action:button Used to start a tutorial", "Start"));
00051     setButtonToolTip(User1, i18nc("@info:tooltip", "Start the selected tutorial"));
00052     setButtonWhatsThis(User1, i18nc("@info:whatsthis", "Start the selected tutorial"));
00053     setDefaultButton(User1);
00054     enableButton(User1, false);
00055 
00056     connect(ui->tutorialsList->selectionModel(),
00057             SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
00058             this, SLOT(select(QItemSelection)));
00059     connect(this, SIGNAL(user1Clicked()), this, SLOT(start()));
00060 
00061     connect(mTutorialManager, SIGNAL(finished()), this, SLOT(finish()));
00062 }
00063 
00064 TutorialManagerDialog::~TutorialManagerDialog() {
00065     delete ui;
00066 }
00067 
00068 //public slots:
00069 
00070 void TutorialManagerDialog::finish() {
00071     show();
00072 }
00073 
00074 //private:
00075 
00076 void TutorialManagerDialog::select(const TutorialInformation* tutorialInformation) {
00077     if (tutorialInformation == 0) {
00078         return;
00079     }
00080 
00081     enableButton(User1, true);
00082 
00083     ui->descriptionLabel->setText(tutorialInformation->description());
00084 
00085     mCurrentTutorialInformation = tutorialInformation;
00086 }
00087 
00088 //private slots:
00089 
00090 void TutorialManagerDialog::select(const QItemSelection& selected) {
00091     const TutorialListModel* model = qobject_cast<const TutorialListModel*>(selected.indexes()[0].model());
00092 
00093     select(model->getTutorialInformationForIndex(selected.indexes()[0]));
00094 }
00095 
00096 void TutorialManagerDialog::start() {
00097     hide();
00098 
00099     mTutorialManager->start(mCurrentTutorialInformation->id());
00100 }
00101 
00102 }
00103 }