From 2cbcca0db1343e1c40e52af729a5eb34ca8a7e37 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 27 Jun 2024 21:53:17 +0900 Subject: Rename date and time nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/kernel/ntqasyncio.h | 2 +- src/kernel/ntqnamespace.h | 4 +- src/kernel/ntqt.h | 6 +- src/kernel/ntqtimer.h | 91 ----------- src/kernel/ntqurlinfo.h | 2 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qclipboard_x11.cpp | 2 +- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qeventloop.cpp | 2 +- src/kernel/qfontdatabase_x11.cpp | 2 +- src/kernel/qmngio.cpp | 2 +- src/kernel/qmovie.cpp | 2 +- src/kernel/qnetworkprotocol.cpp | 2 +- src/kernel/qprocess_unix.cpp | 2 +- src/kernel/qpsprinter.cpp | 4 +- src/kernel/qt_kernel.pri | 4 +- src/kernel/qt_pch.h | 4 +- src/kernel/qtimer.cpp | 338 --------------------------------------- src/kernel/qvariant.cpp | 2 +- src/kernel/tqtimer.cpp | 338 +++++++++++++++++++++++++++++++++++++++ src/kernel/tqtimer.h | 91 +++++++++++ src/kernel/tqwidget_x11.cpp | 2 +- 22 files changed, 453 insertions(+), 453 deletions(-) delete mode 100644 src/kernel/ntqtimer.h delete mode 100644 src/kernel/qtimer.cpp create mode 100644 src/kernel/tqtimer.cpp create mode 100644 src/kernel/tqtimer.h (limited to 'src/kernel') diff --git a/src/kernel/ntqasyncio.h b/src/kernel/ntqasyncio.h index 19fe284b0..b2c88ce4d 100644 --- a/src/kernel/ntqasyncio.h +++ b/src/kernel/ntqasyncio.h @@ -44,7 +44,7 @@ #ifndef QT_H #include "tqobject.h" #include "ntqsignal.h" -#include "ntqtimer.h" +#include "tqtimer.h" #endif // QT_H #ifndef TQT_NO_ASYNC_IO diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index c0c34533a..587b8720a 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -948,14 +948,14 @@ public: // compatibility typedef Dock ToolBarDock; - // documented in qdatetime.cpp + // documented in tqdatetime.cpp enum DateFormat { TextDate, // default TQt ISODate, // ISO 8601 LocalDate // locale dependent }; - // documented in qdatetime.cpp + // documented in tqdatetime.cpp enum TimeSpec { LocalTime, UTC diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 5afa96e1d..4dee12662 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -48,7 +48,7 @@ #include "tqstrlist.h" #include "tqvaluelist.h" #include "tqmap.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqmime.h" #include "ntqasciidict.h" #include "ntqpaintdevice.h" @@ -95,7 +95,7 @@ #include #include "ntqrangecontrol.h" #include "ntqbuttongroup.h" -#include +#include #include "ntqgvector.h" #include "ntqhbox.h" #include @@ -185,7 +185,7 @@ #include #include #include -#include "ntqtimer.h" +#include "tqtimer.h" #include #include #include diff --git a/src/kernel/ntqtimer.h b/src/kernel/ntqtimer.h deleted file mode 100644 index 40aae8724..000000000 --- a/src/kernel/ntqtimer.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Definition of TQTimer class -** -** Created : 931111 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQTIMER_H -#define TQTIMER_H - -#ifndef QT_H -#include "tqobject.h" -#endif // QT_H - - -class TQ_EXPORT TQTimer : public TQObject -{ - TQ_OBJECT -public: - TQTimer( TQObject *parent=0, const char *name=0 ); - ~TQTimer(); - - bool isActive() const; - - int start( int msec, bool sshot = FALSE ); - void changeInterval( int msec ); - void stop(); - - static void singleShot( int msec, TQObject *receiver, const char *member ); - - int timerId() const { return id; } - -signals: - void timeout(); - -protected: - bool event( TQEvent * ); - -private: - int id; - uint single : 1; - uint nulltimer : 1; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQTimer( const TQTimer & ); - TQTimer &operator=( const TQTimer & ); -#endif -}; - - -inline bool TQTimer::isActive() const -{ - return id >= 0; -} - - -#endif // TQTIMER_H diff --git a/src/kernel/ntqurlinfo.h b/src/kernel/ntqurlinfo.h index b9fa36eae..8c0269f84 100644 --- a/src/kernel/ntqurlinfo.h +++ b/src/kernel/ntqurlinfo.h @@ -42,7 +42,7 @@ #define TQURLINFO_H #ifndef QT_H -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqstring.h" #endif // QT_H diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index 0a1d62cf8..33fa0ceca 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -73,7 +73,7 @@ #include "ntqbitarray.h" #include "ntqpainter.h" #include "ntqpixmapcache.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqtextcodec.h" #include "ntqdatastream.h" #include "ntqbuffer.h" diff --git a/src/kernel/qclipboard_x11.cpp b/src/kernel/qclipboard_x11.cpp index 7776cf606..dbe3a7f78 100644 --- a/src/kernel/qclipboard_x11.cpp +++ b/src/kernel/qclipboard_x11.cpp @@ -67,7 +67,7 @@ #include "ntqapplication.h" #include "ntqeventloop.h" #include "ntqbitmap.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdragobject.h" #include "ntqbuffer.h" #include "tqtextcodec.h" diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 859a3c1a6..7e2a1fd04 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -46,7 +46,7 @@ #include "tqwidget.h" #include "ntqintdict.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdict.h" #include "ntqguardedptr.h" #include "ntqdragobject.h" diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp index 402894f2a..e08a1ee1c 100644 --- a/src/kernel/qeventloop.cpp +++ b/src/kernel/qeventloop.cpp @@ -39,7 +39,7 @@ #include "qeventloop_p.h" // includes qplatformdefs.h #include "ntqeventloop.h" #include "ntqapplication.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #ifdef TQT_THREAD_SUPPORT # include "ntqthread.h" diff --git a/src/kernel/qfontdatabase_x11.cpp b/src/kernel/qfontdatabase_x11.cpp index c449b8961..d1045740d 100644 --- a/src/kernel/qfontdatabase_x11.cpp +++ b/src/kernel/qfontdatabase_x11.cpp @@ -40,7 +40,7 @@ #include -#include +#include #include #include "qt_x11_p.h" diff --git a/src/kernel/qmngio.cpp b/src/kernel/qmngio.cpp index deb0225c3..5c46cbd74 100644 --- a/src/kernel/qmngio.cpp +++ b/src/kernel/qmngio.cpp @@ -38,7 +38,7 @@ ** **********************************************************************/ -#include "ntqdatetime.h" +#include "tqdatetime.h" #ifndef TQT_NO_IMAGEIO_MNG diff --git a/src/kernel/qmovie.cpp b/src/kernel/qmovie.cpp index d52f662a7..7be719725 100644 --- a/src/kernel/qmovie.cpp +++ b/src/kernel/qmovie.cpp @@ -40,7 +40,7 @@ // #define QT_SAVE_MOVIE_HACK -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqpainter.h" #include "tqptrlist.h" #include "ntqbitmap.h" diff --git a/src/kernel/qnetworkprotocol.cpp b/src/kernel/qnetworkprotocol.cpp index 8d7ff8f1a..718a7ac11 100644 --- a/src/kernel/qnetworkprotocol.cpp +++ b/src/kernel/qnetworkprotocol.cpp @@ -44,7 +44,7 @@ #include "ntqlocalfs.h" #include "ntqurloperator.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqmap.h" #include "tqptrqueue.h" diff --git a/src/kernel/qprocess_unix.cpp b/src/kernel/qprocess_unix.cpp index 87f76848d..0e5a2299a 100644 --- a/src/kernel/qprocess_unix.cpp +++ b/src/kernel/qprocess_unix.cpp @@ -53,7 +53,7 @@ #include "tqptrqueue.h" #include "tqptrlist.h" #include "ntqsocketnotifier.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqcleanuphandler.h" #include "ntqregexp.h" #include "private/qinternal_p.h" diff --git a/src/kernel/qpsprinter.cpp b/src/kernel/qpsprinter.cpp index 943cefff4..c9ce2ea7d 100644 --- a/src/kernel/qpsprinter.cpp +++ b/src/kernel/qpsprinter.cpp @@ -60,7 +60,7 @@ #include "ntqapplication.h" #include "ntqpaintdevicemetrics.h" #include "tqimage.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqstring.h" #include "ntqdict.h" #include "ntqmemarray.h" @@ -5351,7 +5351,7 @@ static void emitBits( char *out, int & byte, int & bit, //#define DEBUG_COMPRESS #ifdef DEBUG_COMPRESS -#include +#include #endif static TQByteArray compress( const TQImage & image, bool gray ) { diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index c812e5843..446019b6e 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -78,7 +78,7 @@ kernel { $$KERNEL_H/tqstyle.h \ $$KERNEL_H/tqstylesheet.h \ $$KERNEL_H/ntqthread.h \ - $$KERNEL_H/ntqtimer.h \ + $$KERNEL_H/tqtimer.h \ $$KERNEL_H/ntqurl.h \ $$KERNEL_H/ntqlocalfs.h \ $$KERNEL_H/ntqurloperator.h \ @@ -249,7 +249,7 @@ kernel { $$KERNEL_CPP/qsound.cpp \ $$KERNEL_CPP/tqstylesheet.cpp \ $$KERNEL_CPP/qthread.cpp \ - $$KERNEL_CPP/qtimer.cpp \ + $$KERNEL_CPP/tqtimer.cpp \ $$KERNEL_CPP/qurl.cpp \ $$KERNEL_CPP/qlocalfs.cpp \ $$KERNEL_CPP/qurloperator.cpp \ diff --git a/src/kernel/qt_pch.h b/src/kernel/qt_pch.h index a4655ff25..aff826dc0 100644 --- a/src/kernel/qt_pch.h +++ b/src/kernel/qt_pch.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include // All moc genereated code has this include @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/kernel/qtimer.cpp b/src/kernel/qtimer.cpp deleted file mode 100644 index ca2dddb9e..000000000 --- a/src/kernel/qtimer.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQTimer class -** -** Created : 931111 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqtimer.h" -#include "ntqsignal.h" -#include "tqobjectlist.h" - -/*! - \class TQTimer ntqtimer.h - \brief The TQTimer class provides timer signals and single-shot timers. - - \ingroup time - \ingroup events - \mainclass - - It uses \link TQTimerEvent timer events\endlink internally to - provide a more versatile timer. TQTimer is very easy to use: - create a TQTimer, call start() to start it and connect its - timeout() to the appropriate slots. When the time is up it will - emit the timeout() signal. - - Note that a TQTimer object is destroyed automatically when its - parent object is destroyed. - - Example: - \code - TQTimer *timer = new TQTimer( myObject ); - connect( timer, TQ_SIGNAL(timeout()), myObject, TQ_SLOT(timerDone()) ); - timer->start( 2000, TRUE ); // 2 seconds single-shot timer - \endcode - - You can also use the static singleShot() function to create a - single shot timer. - - As a special case, a TQTimer with timeout 0 times out as soon as - all the events in the window system's event queue have been - processed. - - This can be used to do heavy work while providing a snappy - user interface: - \code - TQTimer *t = new TQTimer( myObject ); - connect( t, TQ_SIGNAL(timeout()), TQ_SLOT(processOneThing()) ); - t->start( 0, FALSE ); - \endcode - - myObject->processOneThing() will be called repeatedly and should - return quickly (typically after processing one data item) so that - TQt can deliver events to widgets and stop the timer as soon as it - has done all its work. This is the traditional way of - implementing heavy work in GUI applications; multi-threading is - now becoming available on more and more platforms, and we expect - that null events will eventually be replaced by threading. - - Note that TQTimer's accuracy depends on the underlying operating - system and hardware. Most platforms support an accuracy of 20ms; - some provide more. If TQt is unable to deliver the requested - number of timer clicks, it will silently discard some. - - An alternative to using TQTimer is to call TQObject::startTimer() - for your object and reimplement the TQObject::timerEvent() event - handler in your class (which must, of course, inherit TQObject). - The disadvantage is that timerEvent() does not support such - high-level features as single-shot timers or signals. - - Some operating systems limit the number of timers that may be - used; TQt tries to work around these limitations. -*/ - - -static const int INV_TIMER = -1; // invalid timer id - - -/*! - Constructs a timer called \a name, with the parent \a parent. - - Note that the parent object's destructor will destroy this timer - object. -*/ - -TQTimer::TQTimer( TQObject *parent, const char *name ) - : TQObject( parent, name ), id(INV_TIMER), single(0), nulltimer(0) -{ -} - -/*! - Destroys the timer. -*/ - -TQTimer::~TQTimer() -{ - if ( id != INV_TIMER ) // stop running timer - stop(); -} - - -/*! - \fn void TQTimer::timeout() - - This signal is emitted when the timer is activated. -*/ - -/*! - \fn bool TQTimer::isActive() const - - Returns TRUE if the timer is running (pending); otherwise returns - FALSE. -*/ - -/*! - \fn int TQTimer::timerId() const - - Returns the ID of the timer if the timer is running; otherwise returns - -1. -*/ - - -/*! - Starts the timer with a \a msec milliseconds timeout, and returns - the ID of the timer, or zero when starting the timer failed. - - If \a sshot is TRUE, the timer will be activated only once; - otherwise it will continue until it is stopped. - - Any pending timer will be stopped. - - \sa singleShot() stop(), changeInterval(), isActive() -*/ - -int TQTimer::start( int msec, bool sshot ) -{ - if ( id >=0 && nulltimer && !msec && sshot ) - return id; - if ( id != INV_TIMER ) // stop running timer - stop(); - single = sshot; - nulltimer = ( !msec && sshot ); - return id = startTimer( msec ); -} - - -/*! - Changes the timeout interval to \a msec milliseconds. - - If the timer signal is pending, it will be stopped and restarted; - otherwise it will be started. - - \sa start(), isActive() -*/ - -void TQTimer::changeInterval( int msec ) -{ - if ( id == INV_TIMER ) { // create new timer - start( msec ); - } else { - killTimer( id ); // restart timer - id = startTimer( msec ); - } -} - -/*! - Stops the timer. - - \sa start() -*/ - -void TQTimer::stop() -{ - if ( id != INV_TIMER ) { - killTimer( id ); - id = INV_TIMER; - } -} - - -/*! - \reimp -*/ -bool TQTimer::event( TQEvent *e ) -{ - if ( e->type() != TQEvent::Timer ) // ignore all other events - return FALSE; - if ( single ) // stop single shot timer - stop(); - emit timeout(); // emit timeout signal - return TRUE; -} - - -/* - The TQSingleShotTimer class is an internal class for implementing - TQTimer::singleShot(). It starts a timer and emits the signal - and kills itself when it gets the timeout. -*/ - -static TQObjectList *sst_list = 0; // list of single shot timers - -static void sst_cleanup() -{ - if ( sst_list ) { - sst_list->setAutoDelete( TRUE ); - delete sst_list; - sst_list = 0; - } -} - -static void sst_init() -{ - if ( !sst_list ) { - sst_list = new TQObjectList; - TQ_CHECK_PTR( sst_list ); - tqAddPostRoutine( sst_cleanup ); - } -} - - -class TQSingleShotTimer : public TQObject -{ -public: - ~TQSingleShotTimer(); - bool start( int msec, TQObject *r, const char * m ); - bool isActive() const { return timerId > 0; } -protected: - bool event( TQEvent * ); -private: - TQSignal signal; - int timerId; -}; - -extern int qStartTimer( int interval, TQObject *obj ); // implemented in qapp_xxx.cpp -extern bool qKillTimer( int id ); - -TQSingleShotTimer::~TQSingleShotTimer() -{ - if (timerId != 0) { - qKillTimer(timerId); - timerId = 0; - } -} - -bool TQSingleShotTimer::start( int msec, TQObject *r, const char *m ) -{ - timerId = 0; - if ( signal.connect(r, m) ) - timerId = qStartTimer( msec, (TQObject *)this ); - return timerId != 0; -} - -bool TQSingleShotTimer::event( TQEvent * ) -{ - qKillTimer( timerId ); // no more timeouts - signal.activate(); // emit the signal - signal.disconnect( 0, 0 ); - timerId = 0; // mark as inactive - return TRUE; -} - - -/*! - This static function calls a slot after a given time interval. - - It is very convenient to use this function because you do not need - to bother with a \link TQObject::timerEvent() timerEvent\endlink or - to create a local TQTimer object. - - Example: - \code - #include - #include - - int main( int argc, char **argv ) - { - TQApplication a( argc, argv ); - TQTimer::singleShot( 10*60*1000, &a, TQ_SLOT(quit()) ); - ... // create and show your widgets - return a.exec(); - } - \endcode - - This sample program automatically terminates after 10 minutes (i.e. - 600000 milliseconds). - - The \a receiver is the receiving object and the \a member is the - slot. The time interval is \a msec. -*/ - -void TQTimer::singleShot( int msec, TQObject *receiver, const char *member ) -{ - if ( !sst_list ) - sst_init(); - // search the list for a free ss timer we could reuse - TQSingleShotTimer *sst = (TQSingleShotTimer*)sst_list->first(); - while ( sst && sst->isActive() ) - sst = (TQSingleShotTimer*)sst_list->next(); - // create a new one if not successful - if ( !sst ) { - sst = new TQSingleShotTimer; - sst_list->append( sst ); - } - sst->start(msec, receiver, member); -} diff --git a/src/kernel/qvariant.cpp b/src/kernel/qvariant.cpp index d3782f483..7e9b659ac 100644 --- a/src/kernel/qvariant.cpp +++ b/src/kernel/qvariant.cpp @@ -59,7 +59,7 @@ #include "ntqpointarray.h" #include "ntqbitmap.h" #include "ntqcursor.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqsizepolicy.h" #include "ntqshared.h" #include "ntqbitarray.h" diff --git a/src/kernel/tqtimer.cpp b/src/kernel/tqtimer.cpp new file mode 100644 index 000000000..11fecf81f --- /dev/null +++ b/src/kernel/tqtimer.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Implementation of TQTimer class +** +** Created : 931111 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqtimer.h" +#include "ntqsignal.h" +#include "tqobjectlist.h" + +/*! + \class TQTimer tqtimer.h + \brief The TQTimer class provides timer signals and single-shot timers. + + \ingroup time + \ingroup events + \mainclass + + It uses \link TQTimerEvent timer events\endlink internally to + provide a more versatile timer. TQTimer is very easy to use: + create a TQTimer, call start() to start it and connect its + timeout() to the appropriate slots. When the time is up it will + emit the timeout() signal. + + Note that a TQTimer object is destroyed automatically when its + parent object is destroyed. + + Example: + \code + TQTimer *timer = new TQTimer( myObject ); + connect( timer, TQ_SIGNAL(timeout()), myObject, TQ_SLOT(timerDone()) ); + timer->start( 2000, TRUE ); // 2 seconds single-shot timer + \endcode + + You can also use the static singleShot() function to create a + single shot timer. + + As a special case, a TQTimer with timeout 0 times out as soon as + all the events in the window system's event queue have been + processed. + + This can be used to do heavy work while providing a snappy + user interface: + \code + TQTimer *t = new TQTimer( myObject ); + connect( t, TQ_SIGNAL(timeout()), TQ_SLOT(processOneThing()) ); + t->start( 0, FALSE ); + \endcode + + myObject->processOneThing() will be called repeatedly and should + return quickly (typically after processing one data item) so that + TQt can deliver events to widgets and stop the timer as soon as it + has done all its work. This is the traditional way of + implementing heavy work in GUI applications; multi-threading is + now becoming available on more and more platforms, and we expect + that null events will eventually be replaced by threading. + + Note that TQTimer's accuracy depends on the underlying operating + system and hardware. Most platforms support an accuracy of 20ms; + some provide more. If TQt is unable to deliver the requested + number of timer clicks, it will silently discard some. + + An alternative to using TQTimer is to call TQObject::startTimer() + for your object and reimplement the TQObject::timerEvent() event + handler in your class (which must, of course, inherit TQObject). + The disadvantage is that timerEvent() does not support such + high-level features as single-shot timers or signals. + + Some operating systems limit the number of timers that may be + used; TQt tries to work around these limitations. +*/ + + +static const int INV_TIMER = -1; // invalid timer id + + +/*! + Constructs a timer called \a name, with the parent \a parent. + + Note that the parent object's destructor will destroy this timer + object. +*/ + +TQTimer::TQTimer( TQObject *parent, const char *name ) + : TQObject( parent, name ), id(INV_TIMER), single(0), nulltimer(0) +{ +} + +/*! + Destroys the timer. +*/ + +TQTimer::~TQTimer() +{ + if ( id != INV_TIMER ) // stop running timer + stop(); +} + + +/*! + \fn void TQTimer::timeout() + + This signal is emitted when the timer is activated. +*/ + +/*! + \fn bool TQTimer::isActive() const + + Returns TRUE if the timer is running (pending); otherwise returns + FALSE. +*/ + +/*! + \fn int TQTimer::timerId() const + + Returns the ID of the timer if the timer is running; otherwise returns + -1. +*/ + + +/*! + Starts the timer with a \a msec milliseconds timeout, and returns + the ID of the timer, or zero when starting the timer failed. + + If \a sshot is TRUE, the timer will be activated only once; + otherwise it will continue until it is stopped. + + Any pending timer will be stopped. + + \sa singleShot() stop(), changeInterval(), isActive() +*/ + +int TQTimer::start( int msec, bool sshot ) +{ + if ( id >=0 && nulltimer && !msec && sshot ) + return id; + if ( id != INV_TIMER ) // stop running timer + stop(); + single = sshot; + nulltimer = ( !msec && sshot ); + return id = startTimer( msec ); +} + + +/*! + Changes the timeout interval to \a msec milliseconds. + + If the timer signal is pending, it will be stopped and restarted; + otherwise it will be started. + + \sa start(), isActive() +*/ + +void TQTimer::changeInterval( int msec ) +{ + if ( id == INV_TIMER ) { // create new timer + start( msec ); + } else { + killTimer( id ); // restart timer + id = startTimer( msec ); + } +} + +/*! + Stops the timer. + + \sa start() +*/ + +void TQTimer::stop() +{ + if ( id != INV_TIMER ) { + killTimer( id ); + id = INV_TIMER; + } +} + + +/*! + \reimp +*/ +bool TQTimer::event( TQEvent *e ) +{ + if ( e->type() != TQEvent::Timer ) // ignore all other events + return FALSE; + if ( single ) // stop single shot timer + stop(); + emit timeout(); // emit timeout signal + return TRUE; +} + + +/* + The TQSingleShotTimer class is an internal class for implementing + TQTimer::singleShot(). It starts a timer and emits the signal + and kills itself when it gets the timeout. +*/ + +static TQObjectList *sst_list = 0; // list of single shot timers + +static void sst_cleanup() +{ + if ( sst_list ) { + sst_list->setAutoDelete( TRUE ); + delete sst_list; + sst_list = 0; + } +} + +static void sst_init() +{ + if ( !sst_list ) { + sst_list = new TQObjectList; + TQ_CHECK_PTR( sst_list ); + tqAddPostRoutine( sst_cleanup ); + } +} + + +class TQSingleShotTimer : public TQObject +{ +public: + ~TQSingleShotTimer(); + bool start( int msec, TQObject *r, const char * m ); + bool isActive() const { return timerId > 0; } +protected: + bool event( TQEvent * ); +private: + TQSignal signal; + int timerId; +}; + +extern int qStartTimer( int interval, TQObject *obj ); // implemented in qapp_xxx.cpp +extern bool qKillTimer( int id ); + +TQSingleShotTimer::~TQSingleShotTimer() +{ + if (timerId != 0) { + qKillTimer(timerId); + timerId = 0; + } +} + +bool TQSingleShotTimer::start( int msec, TQObject *r, const char *m ) +{ + timerId = 0; + if ( signal.connect(r, m) ) + timerId = qStartTimer( msec, (TQObject *)this ); + return timerId != 0; +} + +bool TQSingleShotTimer::event( TQEvent * ) +{ + qKillTimer( timerId ); // no more timeouts + signal.activate(); // emit the signal + signal.disconnect( 0, 0 ); + timerId = 0; // mark as inactive + return TRUE; +} + + +/*! + This static function calls a slot after a given time interval. + + It is very convenient to use this function because you do not need + to bother with a \link TQObject::timerEvent() timerEvent\endlink or + to create a local TQTimer object. + + Example: + \code + #include + #include + + int main( int argc, char **argv ) + { + TQApplication a( argc, argv ); + TQTimer::singleShot( 10*60*1000, &a, TQ_SLOT(quit()) ); + ... // create and show your widgets + return a.exec(); + } + \endcode + + This sample program automatically terminates after 10 minutes (i.e. + 600000 milliseconds). + + The \a receiver is the receiving object and the \a member is the + slot. The time interval is \a msec. +*/ + +void TQTimer::singleShot( int msec, TQObject *receiver, const char *member ) +{ + if ( !sst_list ) + sst_init(); + // search the list for a free ss timer we could reuse + TQSingleShotTimer *sst = (TQSingleShotTimer*)sst_list->first(); + while ( sst && sst->isActive() ) + sst = (TQSingleShotTimer*)sst_list->next(); + // create a new one if not successful + if ( !sst ) { + sst = new TQSingleShotTimer; + sst_list->append( sst ); + } + sst->start(msec, receiver, member); +} diff --git a/src/kernel/tqtimer.h b/src/kernel/tqtimer.h new file mode 100644 index 000000000..40aae8724 --- /dev/null +++ b/src/kernel/tqtimer.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Definition of TQTimer class +** +** Created : 931111 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQTIMER_H +#define TQTIMER_H + +#ifndef QT_H +#include "tqobject.h" +#endif // QT_H + + +class TQ_EXPORT TQTimer : public TQObject +{ + TQ_OBJECT +public: + TQTimer( TQObject *parent=0, const char *name=0 ); + ~TQTimer(); + + bool isActive() const; + + int start( int msec, bool sshot = FALSE ); + void changeInterval( int msec ); + void stop(); + + static void singleShot( int msec, TQObject *receiver, const char *member ); + + int timerId() const { return id; } + +signals: + void timeout(); + +protected: + bool event( TQEvent * ); + +private: + int id; + uint single : 1; + uint nulltimer : 1; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQTimer( const TQTimer & ); + TQTimer &operator=( const TQTimer & ); +#endif +}; + + +inline bool TQTimer::isActive() const +{ + return id >= 0; +} + + +#endif // TQTIMER_H diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index 78d1e850e..bc31e7e75 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -48,7 +48,7 @@ #include "tqobjectlist.h" #include "ntqlayout.h" #include "tqtextcodec.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqcursor.h" #include "qt_x11_p.h" #include -- cgit v1.2.3