summaryrefslogtreecommitdiffstats
path: root/khexedit/progress.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /khexedit/progress.h
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khexedit/progress.h')
-rw-r--r--khexedit/progress.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/khexedit/progress.h b/khexedit/progress.h
new file mode 100644
index 0000000..fa6e8a3
--- /dev/null
+++ b/khexedit/progress.h
@@ -0,0 +1,130 @@
+/*
+ * khexedit - Versatile hex editor
+ * Copyright (C) 1999 Espen Sand, espensa@online.no
+ * This file is based on the work by F. Zigterman, fzr@dds.nl
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef _PROGRESS_H_
+#define _PROGRESS_H_
+
+#include <qdatetime.h>
+#include "hexerror.h"
+
+
+struct SProgressData
+{
+ SProgressData( float f )
+ {
+ useFraction = 1;
+ fraction = f;
+ }
+
+ SProgressData( int cPage, int mPage )
+ {
+ useFraction = 0;
+ curPage = cPage;
+ maxPage = mPage;
+ }
+
+ int valid( void ) const
+ {
+ return( (useFraction == 1 && fraction >= 0) ||
+ (useFraction == 0 && curPage >= 0) ? 1 : 0 );
+ }
+
+ int useFraction;
+ float fraction;
+ int curPage;
+ int maxPage;
+};
+
+
+
+typedef int (*ProgressFunc)( void *clientData, SProgressData &pd );
+
+class CProgress
+{
+ public:
+ CProgress( void )
+ {
+ define( 0, 0 );
+ mInterruptTimer.start();
+ }
+
+ CProgress( ProgressFunc progressFunc, void *clientData )
+ {
+ define( progressFunc, clientData );
+ mInterruptTimer.start();
+ }
+
+ void define( ProgressFunc progressFunc, void *clientData )
+ {
+ mProgressFunc = progressFunc;
+ mClientData = clientData;
+ }
+
+ void finish( void ) const
+ {
+ if( mProgressFunc == 0 )
+ {
+ return;
+ }
+ SProgressData pd( -1.0 );
+ mProgressFunc( mClientData, pd );
+ }
+
+ bool expired( void )
+ {
+ return( mInterruptTimer.elapsed() > 200 );
+ }
+
+ int step( float fraction )
+ {
+ mInterruptTimer.start();
+
+ if( mProgressFunc == 0 )
+ {
+ return( Err_Success );
+ }
+ SProgressData pd( fraction );
+ int errCode = mProgressFunc( mClientData, pd );
+ return( errCode );
+ }
+
+ int step( int curPage, int maxPage )
+ {
+ mInterruptTimer.start();
+
+ if( mProgressFunc == 0 )
+ {
+ return( Err_Success );
+ }
+ SProgressData pd( curPage, maxPage );
+ int errCode = mProgressFunc( mClientData, pd );
+ return( errCode );
+ }
+
+ private:
+ ProgressFunc mProgressFunc;
+ void *mClientData;
+ QTime mInterruptTimer;
+};
+
+#endif
+
+