Browse Source

Implement progress bars for transfers to a real calculator.

git-svn-id: file:///var/svn/tigccpp/trunk@691 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 17 years ago
parent
commit
47b613cd06
5 changed files with 134 additions and 5 deletions
  1. 4 2
      ktigcc/KTIGCC.prj
  2. 92 0
      ktigcc/callbacks.cpp
  3. 27 0
      ktigcc/callbacks.h
  4. 4 2
      ktigcc/ktigcc.pro
  5. 7 1
      ktigcc/mainform.ui.h

+ 4 - 2
ktigcc/KTIGCC.prj

@@ -77,7 +77,8 @@ module.include.files=\
 	srcfilewin.ui.h\
 	srcfile.h\
 	tiemu.h\
-	tiemu_stub.h
+	tiemu_stub.h\
+	callbacks.h
 
 module.source.name=.
 module.source.type=
@@ -95,7 +96,8 @@ module.source.files=\
 	srcfilewin.ui\
 	errorlist.ui\
 	programoutput.ui\
-	tiemu_stub.cpp
+	tiemu_stub.cpp\
+	callbacks.cpp
 
 module.pixmap.name=.
 module.pixmap.type=

+ 92 - 0
ktigcc/callbacks.cpp

@@ -0,0 +1,92 @@
+/*
+   ktigcc - TIGCC IDE for KDE
+
+   Copyright (C) 2006 Kevin Kofler
+
+   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, 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.
+*/
+
+#include "callbacks.h"
+#include <cstdlib>
+#include <kprogress.h>
+#include <ticalcs.h>
+#include <qapplication.h>
+#include <qeventloop.h>
+
+static KProgressDialog *sendingProgress=0;
+
+static void callback_ticalcs_refresh(void)
+{
+  if (sendingProgress) {
+    QApplication::eventLoop()->processEvents(QEventLoop::AllEvents,100);
+    if (sendingProgress->wasCancelled()) ticalcsUpdate.cancel=TRUE;
+  }
+}
+
+static void callback_ticalcs_start(void)
+{
+  ticalcsUpdate.max1=ticalcsUpdate.cnt1=ticalcsUpdate.max2=ticalcsUpdate.max2=0;
+}
+
+static void callback_ticalcs_stop(void)
+{
+  ticalcsUpdate.max1=ticalcsUpdate.cnt1=ticalcsUpdate.max2=ticalcsUpdate.max2=0;
+}
+
+static void callback_ticalcs_pbar(void)
+{
+  sendingProgress->progressBar()->setTotalSteps(ticalcsUpdate.max1);
+  sendingProgress->progressBar()->setProgress(ticalcsUpdate.cnt1);
+  callback_ticalcs_refresh();
+}
+
+static void callback_ticalcs_label(void)
+{
+  sendingProgress->setLabel(ticalcsUpdate.text);
+  callback_ticalcs_refresh();
+}
+
+// Using this strange initialization technique here in an attempt to cope with
+// changes to the structure. In C, I'd use C99 designated initializers, but g++
+// doesn't like them.
+struct CalcUpdateInitialized : public CalcUpdate {
+  CalcUpdateInitialized() {
+    std::memset(static_cast<CalcUpdate *>(this),0,sizeof(CalcUpdate));
+    start=callback_ticalcs_start;
+    stop=callback_ticalcs_stop;
+    refresh=callback_ticalcs_refresh;
+    pbar=callback_ticalcs_pbar;
+    label=callback_ticalcs_label;
+  }
+};
+CalcUpdate ticalcsUpdate=CalcUpdateInitialized();
+
+void callbacksInit(QWidget *parent)
+{
+  sendingProgress=new KProgressDialog(parent,0,"Sending Variable",
+                                      QString::null,TRUE);
+  sendingProgress->show();
+  callback_ticalcs_refresh();
+}
+
+void callbacksCleanup(void)
+{
+  ticalcsUpdate.cancel=FALSE;
+  if (sendingProgress) {
+    delete sendingProgress;
+    sendingProgress=static_cast<KProgressDialog *>(NULL);
+  }
+  QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,100);
+}

+ 27 - 0
ktigcc/callbacks.h

@@ -0,0 +1,27 @@
+/*
+   ktigcc - TIGCC IDE for KDE
+
+   Copyright (C) 2006 Kevin Kofler
+
+   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, 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.
+*/
+
+#pragma once
+
+#include <ticalcs.h>
+class QWidget;
+extern CalcUpdate ticalcsUpdate;
+void callbacksInit(QWidget *parent);
+void callbacksCleanup(void);

+ 4 - 2
ktigcc/ktigcc.pro

@@ -10,12 +10,14 @@ HEADERS	+= tpr.h \
 	preferences.h \
 	srcfile.h \
 	tiemu.h \
-	tiemu_stub.h
+	tiemu_stub.h \
+	callbacks.h
 
 SOURCES	+= ktigcc.cpp \
 	preferences.cpp \
 	tpr.cpp \
-	tiemu_stub.cpp
+	tiemu_stub.cpp \
+	callbacks.cpp
 
 FORMS	= srcfilewin.ui \
 	projectoptions.ui \

+ 7 - 1
ktigcc/mainform.ui.h

@@ -93,6 +93,7 @@
 #include "errorlist.h"
 #include "programoutput.h"
 #include "tiemu.h"
+#include "callbacks.h"
 
 using std::puts;
 using std::exit;
@@ -4603,6 +4604,7 @@ void MainForm::debugRun()
       case LT_REALCALC:
         {
           ticables_options_set_timeout(cable,DFLT_TIMEOUT<<1);
+          ticalcs_update_set(calc,&ticalcsUpdate);
           for (QStringList::Iterator it=files.begin(); it!=files.end(); ++it) {
             const char *file=*it;
             int err;
@@ -4615,12 +4617,16 @@ void MainForm::debugRun()
               return;
             }
             // Send the file.
+            callbacksInit(this);
             if ((err=ticalcs_calc_send_var2(calc,MODE_NORMAL,file))) {
-              KMessageBox::error(this,tilibsErrorMessage(err));
+              bool cancelled=ticalcsUpdate.cancel;
+              callbacksCleanup();
+              if (!cancelled) KMessageBox::error(this,tilibsErrorMessage(err));
               ticalcs_handle_del(calc);
               ticables_handle_del(cable);
               return;
             }
+            callbacksCleanup();
           }
         }
         break;