File indexing completed on 2024-04-21 14:55:52

0001 /*  This file is part of the KDE Libraries
0002  *  Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)
0003  *  Additions 1999-2000 by Espen Sand (espen@kde.org)
0004  *                      and Holger Freyther <freyther@kde.org>
0005  *            2005-2006   Olivier Goffart <ogoffart @ kde.org>
0006  *            2006      Tobias Koenig <tokoe@kde.org>
0007  *
0008  *  This library is free software; you can redistribute it and/or
0009  *  modify it under the terms of the GNU Library General Public
0010  *  License as published by the Free Software Foundation; either
0011  *  version 2 of the License, or (at your option) any later version.
0012  *
0013  *  This library is distributed in the hope that it will be useful,
0014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016  *  Library General Public License for more details.
0017  *
0018  *  You should have received a copy of the GNU Library General Public License
0019  *  along with this library; see the file COPYING.LIB.  If not, write to
0020  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021  *  Boston, MA 02110-1301, USA.
0022  */
0023 
0024 #include "kdialogqueue_p.h"
0025 #include <QPointer>
0026 #include <QTimer>
0027 
0028 class KDialogQueue::Private
0029 {
0030 public:
0031     Private(KDialogQueue *q): q(q) {}
0032 
0033     void slotShowQueuedDialog();
0034 
0035     KDialogQueue *q;
0036     QList< QPointer<QDialog> > queue;
0037     bool busy;
0038 
0039 };
0040 
0041 class KDialogQueueSingleton
0042 {
0043 public:
0044     KDialogQueue self;
0045 };
0046 
0047 Q_GLOBAL_STATIC(KDialogQueueSingleton, globalKDialogQueue)
0048 
0049 KDialogQueue *KDialogQueue::self()
0050 {
0051     return &globalKDialogQueue()->self;
0052 }
0053 
0054 KDialogQueue::KDialogQueue()
0055     : d(new Private(this))
0056 {
0057     d->busy = false;
0058 }
0059 
0060 KDialogQueue::~KDialogQueue()
0061 {
0062     delete d;
0063 }
0064 
0065 // static
0066 void KDialogQueue::queueDialog(QDialog *dialog)
0067 {
0068     KDialogQueue *_this = self();
0069     _this->d->queue.append(dialog);
0070 
0071     QTimer::singleShot(0, _this, SLOT(slotShowQueuedDialog()));
0072 }
0073 
0074 void KDialogQueue::Private::slotShowQueuedDialog()
0075 {
0076     if (busy) {
0077         return;
0078     }
0079 
0080     QDialog *dialog;
0081     do {
0082         if (queue.isEmpty()) {
0083             return;
0084         }
0085         dialog = queue.first();
0086         queue.pop_front();
0087     } while (!dialog);
0088 
0089     busy = true;
0090     dialog->exec();
0091     busy = false;
0092     delete dialog;
0093 
0094     if (!queue.isEmpty()) {
0095         QTimer::singleShot(20, q, SLOT(slotShowQueuedDialog()));
0096     }
0097 }
0098 
0099 #include "moc_kdialogqueue_p.cpp"