summaryrefslogtreecommitdiffstats
path: root/src/common/common/synchronous.cpp
blob: dbf782f5fad7e96dcb98c09aa274daab5d0a8dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/***************************************************************************
 *   Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "synchronous.h"

#include "common/global/global.h"
#  include <tqwidget.h>

Synchronous::Synchronous(uint timeout)
{
  connect(&_timer, TQT_SIGNAL(timeout()), TQT_SLOT(done()));
  if (timeout) _timer.start(timeout, true);
}

// uplifted from tdelibs...
void tqt_enter_modal(TQWidget *widget);
void tqt_leave_modal(TQWidget *widget);

bool Synchronous::enterLoop()
{
  TQWidget *dummy = 0;
  if ( tqApp->type()!=TQApplication::Tty ) {
    dummy = new TQWidget(0, 0, WType_Dialog | WShowModal);
    dummy->setFocusPolicy(TQWidget::NoFocus);
    tqt_enter_modal(dummy);
  }
  TQApplication::eventLoop()->enterLoop();
  if ( tqApp->type()!=TQApplication::Tty ) {
    tqt_leave_modal(dummy);
    delete dummy;
  }
  return _timer.isActive();
}

void Synchronous::done()
{
  TQApplication::eventLoop()->exitLoop();
}