KTutorial  0.5.1
WaitForWindow.cpp
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00003  *   Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; If not, see <http://www.gnu.org/licenses/>.  *
00017  ***************************************************************************/
00018 
00019 #include "WaitForWindow.h"
00020 #include "WaitForWindow_p.h"
00021 #include "KTutorial.h"
00022 #include "common/WindowVisibilitySpy.h"
00023 
00024 using ktutorial::common::WindowVisibilitySpy;
00025 
00026 namespace ktutorial {
00027 
00028 //public:
00029 
00030 WaitForWindow::WaitForWindow(): WaitFor(),
00031     d(new WaitForWindowPrivate()) {
00032     d->mConditionMet = false;
00033 
00034     WindowVisibilitySpy* spy = new WindowVisibilitySpy(this);
00035     spy->addWidgetToSpy(KTutorial::self()->mainApplicationWindow());
00036     connect(spy, SIGNAL(windowShown(QWidget*)),
00037             this, SLOT(checkWindowShown(QWidget*)));
00038 }
00039 
00040 WaitForWindow::WaitForWindow(const QString& objectName): WaitFor(),
00041     d(new WaitForWindowPrivate()) {
00042     d->mConditionMet = false;
00043 
00044     WindowVisibilitySpy* spy = new WindowVisibilitySpy(this);
00045     spy->addWidgetToSpy(KTutorial::self()->mainApplicationWindow());
00046     connect(spy, SIGNAL(windowShown(QWidget*)),
00047             this, SLOT(checkWindowShown(QWidget*)));
00048 
00049     setWindowObjectName(objectName);
00050 }
00051 
00052 WaitForWindow::~WaitForWindow() {
00053     delete d;
00054 }
00055 
00056 void WaitForWindow::setWindowObjectName(const QString& objectName) {
00057     d->mWindowObjectName = objectName;
00058 }
00059 
00060 bool WaitForWindow::conditionMet() const {
00061     return d->mConditionMet;
00062 }
00063 
00064 void WaitForWindow::setActive(bool active) {
00065     WaitFor::setActive(active);
00066 
00067     if (active) {
00068         d->mConditionMet = false;
00069     }
00070 }
00071 
00072 //private slots:
00073 
00074 void WaitForWindow::checkWindowShown(QWidget* window) {
00075     if (!isActive()) {
00076         return;
00077     }
00078 
00079     if (window->objectName() != d->mWindowObjectName) {
00080         return;
00081     }
00082 
00083     d->mConditionMet = true;
00084     emit waitEnded(this);
00085 }
00086 
00087 }