callbacks.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2006-2008 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "callbacks.h"
  17. #include <cstring>
  18. #include <kprogressdialog.h>
  19. #include <ticalcs.h>
  20. #include <QApplication>
  21. #include <QEventLoop>
  22. static KProgressDialog *sendingProgress=0;
  23. static void callback_ticalcs_refresh(void)
  24. {
  25. if (sendingProgress) {
  26. QCoreApplication::processEvents(QEventLoop::AllEvents,100);
  27. if (sendingProgress->wasCancelled()) ticalcsUpdate.cancel=TRUE;
  28. }
  29. }
  30. static void callback_ticalcs_start(void)
  31. {
  32. ticalcsUpdate.max1=ticalcsUpdate.cnt1=
  33. ticalcsUpdate.max2=ticalcsUpdate.cnt2=
  34. ticalcsUpdate.max3=ticalcsUpdate.cnt3=0;
  35. }
  36. static void callback_ticalcs_stop(void)
  37. {
  38. ticalcsUpdate.max1=ticalcsUpdate.cnt1=
  39. ticalcsUpdate.max2=ticalcsUpdate.cnt2=
  40. ticalcsUpdate.max3=ticalcsUpdate.cnt3=0;
  41. }
  42. static void callback_ticalcs_pbar(void)
  43. {
  44. sendingProgress->progressBar()->setRange(0,ticalcsUpdate.max1);
  45. sendingProgress->progressBar()->setValue(ticalcsUpdate.cnt1);
  46. callback_ticalcs_refresh();
  47. }
  48. static void callback_ticalcs_label(void)
  49. {
  50. sendingProgress->setLabelText(QString("Sending \'%1\'").arg(ticalcsUpdate.text));
  51. callback_ticalcs_refresh();
  52. }
  53. // Using this strange initialization technique here in an attempt to cope with
  54. // changes to the structure. In C, I'd use C99 designated initializers, but g++
  55. // doesn't like them.
  56. struct CalcUpdateInitialized : public CalcUpdate {
  57. CalcUpdateInitialized() {
  58. std::memset(static_cast<CalcUpdate *>(this),0,sizeof(CalcUpdate));
  59. start=callback_ticalcs_start;
  60. stop=callback_ticalcs_stop;
  61. refresh=callback_ticalcs_refresh;
  62. pbar=callback_ticalcs_pbar;
  63. label=callback_ticalcs_label;
  64. }
  65. };
  66. CalcUpdate ticalcsUpdate=CalcUpdateInitialized();
  67. void callbacksInit(QWidget *parent)
  68. {
  69. sendingProgress=new KProgressDialog(parent,"Sending Variable",
  70. QString::null);
  71. sendingProgress->setModal(true);
  72. sendingProgress->show();
  73. callback_ticalcs_refresh();
  74. }
  75. void callbacksCleanup(void)
  76. {
  77. ticalcsUpdate.cancel=FALSE;
  78. if (sendingProgress) {
  79. delete sendingProgress;
  80. sendingProgress=static_cast<KProgressDialog *>(NULL);
  81. }
  82. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,100);
  83. }