~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/kst/kstdoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
// include files for KDE
35
35
#include <dcopclient.h>
36
 
#include <kdebug.h>
 
36
#include "ksdebug.h"
37
37
#include <kdeversion.h>
38
38
#include <kfiledialog.h>
39
39
#include <kmessagebox.h>
42
42
#include <ksavefile.h>
43
43
 
44
44
// application specific includes
 
45
#include "kst2dplot.h"
 
46
#include "kstcsd.h"
45
47
#include "kstdoc.h"
46
48
#include "kstgraphfiledialog_i.h"
47
49
#include "kstequation.h"
 
50
#include "ksteventmonitorentry.h"
48
51
#include "ksthistogram.h"
 
52
#include "kstimage.h"
 
53
#include "kstmatrixdefaults.h"
49
54
#include "kstplugin.h"
50
55
#include "kstpsd.h"
51
56
#include "kstrvector.h"
53
58
#include "kstvectordefaults.h"
54
59
#include "kstsvector.h"
55
60
#include "kstavector.h"
 
61
#include "kstrmatrix.h"
 
62
#include "kstamatrix.h"
 
63
#include "kstsmatrix.h"
56
64
#include "kstviewwindow.h"
57
65
#include "logevents.h"
58
66
#include "threadevents.h"
65
73
  _updating = false;
66
74
  _stopping = false;
67
75
  _nextEventPaint = false;
 
76
  _title = "Untitled";
68
77
}
69
78
 
70
79
KstDoc::~KstDoc() {
83
92
  return _absFilePath;
84
93
}
85
94
 
 
95
void KstDoc::setLastFilePath(const QString& filename) {
 
96
  _lastFilePath = filename;
 
97
}
 
98
 
 
99
const QString& KstDoc::lastFilePath() const {
 
100
  return _lastFilePath;
 
101
}
 
102
 
86
103
void KstDoc::setTitle(const QString& t) {
87
104
  _title = t;
88
105
}
100
117
      int want_save = KMessageBox::warningYesNoCancel( win, i18n("The current plot definition has been modified. Do you want to save it?"), i18n("Question"));
101
118
      switch (want_save) {
102
119
        case KMessageBox::Yes:
103
 
          if (_title == i18n("Untitled")) {
 
120
          if (_title == "Untitled") {
104
121
            if (!win->slotFileSaveAs()) {
105
122
              return false;
106
123
            }
146
163
    deleteContents();
147
164
    _modified = false;
148
165
    _absFilePath = QDir::homeDirPath();
149
 
    _title = i18n("Untitled");
 
166
    _title = "Untitled";
 
167
    KstApp::inst()->newWindow(i18n("default name of first window", "W1"));
150
168
    createScalars();
151
169
    emit updateDialogs();
152
170
  //}
162
180
    return false;
163
181
  }
164
182
 
 
183
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
165
184
  opening = true;
166
185
 
167
186
  deleteContents();
170
189
 
171
190
  QFile f(url.path());
172
191
  if (!f.exists()) {
173
 
    KMessageBox::sorry(0L, i18n("%1: There is no file with that name to open.").arg(url.path()));
 
192
    KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.path()));
174
193
    opening = false;
175
194
    _updating = false;
176
195
    KstApp::inst()->setPaused(false);
 
196
    QApplication::restoreOverrideCursor();
177
197
    return false;
178
198
  }
179
199
 
180
200
  _title = url.fileName(false);
181
201
  _absFilePath = url.path();
 
202
  _lastFilePath = url.path();
182
203
  if (_title.isEmpty()) {
183
204
    _title = _absFilePath;
184
205
  }
185
206
  QDomDocument doc(_title);
186
207
 
187
208
  if (!f.open(IO_ReadOnly)) {
188
 
    KMessageBox::sorry(0L, i18n("%1: File exists, but kst could not open it.").arg(url.path()));
 
209
    KMessageBox::sorry(KstApp::inst(), i18n("%1: File exists, but kst could not open it.").arg(url.path()));
189
210
    opening = false;
190
211
    _updating = false;
191
212
    KstApp::inst()->setPaused(false);
 
213
    QApplication::restoreOverrideCursor();
192
214
    return false;
193
215
  }
194
216
 
195
217
  if (!doc.setContent(&f)) {
196
 
    KMessageBox::sorry(0L, i18n("%1: Not a valid kst plot specification file.").arg(url.path()));
 
218
    KMessageBox::sorry(KstApp::inst(), i18n("%1: Not a valid kst plot specification file.").arg(url.path()));
197
219
    f.close();
198
220
    opening = false;
199
221
    _updating = false;
200
222
    KstApp::inst()->setPaused(false);
 
223
    QApplication::restoreOverrideCursor();
201
224
    return false;
202
225
  }
203
226
 
214
237
  QString readingDocument = i18n("Reading Kst file");
215
238
 
216
239
  if (docElem.tagName() != "kstdoc") {
217
 
    f.close();
 
240
    QString err = i18n("Error opening file %1.  Does not appear to be a Kst file.").arg(url.path());
 
241
    KstDebug::self()->log(err, KstDebug::Error);
 
242
    KMessageBox::sorry(KstApp::inst(), err);
218
243
    opening = false;
219
244
    _updating = false;
220
245
    KstApp::inst()->setPaused(false);
 
246
    QApplication::restoreOverrideCursor();
221
247
    return false;
222
248
  }
223
249
 
224
 
  if (!docElem.attribute("version").isEmpty()) {
225
 
    f.close();
 
250
  if (docElem.attribute("version") != "1.2" && !docElem.attribute("version").isEmpty()) {
 
251
    QString err = i18n("Error opening file %2.  Version %1 is too new.  Update Kst or fix the Kst file.").arg(docElem.attribute("version")).arg(url.path());
 
252
    KstDebug::self()->log(err, KstDebug::Error);
 
253
    KMessageBox::sorry(KstApp::inst(), err);
226
254
    opening = false;
227
255
    _updating = false;
228
256
    KstApp::inst()->setPaused(false);
 
257
    QApplication::restoreOverrideCursor();
229
258
    return false;
230
259
  }
231
260
 
340
369
        KstDataObjectPtr p = new KstPSD(e);
341
370
        KstWriteLocker dowl(&KST::dataObjectList.lock());
342
371
        KST::dataObjectList.append(p);
 
372
      } else if (e.tagName() == "csdobject") {
 
373
        KstDataObjectPtr p = new KstCSD(e);
 
374
        KstWriteLocker dowl(&KST::dataObjectList.lock());
 
375
        KST::dataObjectList.append(p);
343
376
      } else if (e.tagName() == "histogram") {
344
377
        KstDataObjectPtr p = new KstHistogram(e);
345
378
        KstWriteLocker dowl(&KST::dataObjectList.lock());
351
384
      } else if (e.tagName() == "plot") {
352
385
        KstBaseCurveList l = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList);
353
386
        Kst2DPlotPtr plot = new Kst2DPlot(e);
354
 
        app->plotHolderWhileOpeningDocument().insert(plot->tagName(), plot);
355
 
      } else if (e.tagName() == "matrix") {
356
 
        KstDataObjectPtr p = new KstMatrix(e);
357
 
        KstWriteLocker dowl(&KST::dataObjectList.lock());
358
 
        KST::dataObjectList.append(p);
 
387
        app->plotHolderWhileOpeningDocument()->insert(plot->tagName(), plot);
 
388
      } else if (e.tagName() == "amatrix") {
 
389
        KstAMatrixPtr p = new KstAMatrix(e);
 
390
        KST::addMatrixToList(KstMatrixPtr(p));
 
391
      } else if (e.tagName() == "smatrix") {
 
392
        KstSMatrixPtr p = new KstSMatrix(e);
 
393
        KST::addMatrixToList(KstMatrixPtr(p));
 
394
      } else if (e.tagName() == "rmatrix") {
 
395
        KstRMatrixPtr p = new KstRMatrix(e);
 
396
        KST::addMatrixToList(KstMatrixPtr(p));
359
397
      } else if (e.tagName() == "image") {
360
398
        KstDataObjectPtr p = new KstImage(e);
361
399
        KstWriteLocker dowl(&KST::dataObjectList.lock());
381
419
          app->closeWindow(toDelete);
382
420
        }
383
421
      } else {
384
 
        KstDebug::self()->log(i18n("Unsupported element '%1' in file %2.").arg(e.tagName()).arg(o_file), KstDebug::Warning);
 
422
        KstDebug::self()->log(i18n("Unsupported element '%1' in file %2.").arg(e.tagName()).arg(url.path()), KstDebug::Warning);
385
423
      }
386
424
    }
387
425
    handled++;
391
429
  }
392
430
 
393
431
  if (warnOldKstFile) {
394
 
    KMessageBox::sorry(0L, i18n("You tried to load an old Kst file.  Curves created by equations or PSDs will not be loaded."));
 
432
    QApplication::restoreOverrideCursor();
 
433
    KMessageBox::sorry(KstApp::inst(), i18n("You tried to load an old Kst file.  Curves created by equations or PSDs will not be loaded."));
 
434
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
395
435
  }
396
436
 
397
437
  app->slotUpdateProgress(0, 0, i18n("Creating plots"));
398
438
  // if we have anything left in plotHolderWhileOpeningDocument then
399
439
  //  we are most likely reading an old style document, so we create
400
440
  //  a default view and fill it with whatever is left...
401
 
  if (!app->plotHolderWhileOpeningDocument().isEmpty() && !app->activeWindow()) {
 
441
  if (!app->plotHolderWhileOpeningDocument()->isEmpty() && !app->activeWindow()) {
402
442
 
403
443
    QString winName = app->newWindow(QString::null);
404
444
    KstViewWindow *win = dynamic_cast<KstViewWindow*>(app->findWindow(winName));
409
449
        win->view()->setColumns(columns);
410
450
      }
411
451
 
412
 
      for (Kst2DPlotMap::Iterator it = app->plotHolderWhileOpeningDocument().begin();
413
 
          it != app->plotHolderWhileOpeningDocument().end(); ++it ) {
 
452
      for (Kst2DPlotMap::Iterator it = app->plotHolderWhileOpeningDocument()->begin();
 
453
          it != app->plotHolderWhileOpeningDocument()->end(); ++it ) {
414
454
        Kst2DPlotPtr plot = *it;
415
455
 
 
456
        // Legacy 1.0 loading code
416
457
        if (plot->_width > 0.0 && plot->_height > 0.0 ) {
417
458
          win->view()->appendChild(plot.data(), true);
418
459
          if (plot->_width > 1.0 && plot->_height > 1.0) {
429
470
    }
430
471
  }
431
472
 
432
 
  app->plotHolderWhileOpeningDocument().clear();
 
473
  app->plotHolderWhileOpeningDocument()->clear();
433
474
 
434
475
  app->slotUpdateProgress(0, 0, i18n("Loading data"));
435
476
 
441
482
    KST::dataObjectList.lock().readUnlock();
442
483
    for (KstDataObjectList::Iterator i = dol.begin(); i != dol.end(); ++i) {
443
484
      assert(*i);
444
 
      //kdDebug() << "Load inputs for " << (*i)->tagName() << " " << (void*)*i << endl;
 
485
      //kstdDebug() << "Load inputs for " << (*i)->tagName() << " " << (void*)*i << endl;
445
486
      (*i)->KstRWLock::writeLock();
446
487
      bool rc = (*i)->loadInputs();
447
488
      (*i)->KstRWLock::writeUnlock();
465
506
      names += (*i)->tagName();
466
507
    }
467
508
 
 
509
    QApplication::restoreOverrideCursor();
468
510
#if KDE_VERSION < KDE_MAKE_VERSION(3,3,90)
469
 
    KMessageBox::informationList(0L, i18n("The Kst file could not be loaded in its entirety due to missing objects or data."), names);
 
511
    KMessageBox::informationList(KstApp::inst(), i18n("The Kst file could not be loaded in its entirety due to missing objects or data."), names);
470
512
#else
471
 
    KMessageBox::errorList(0L, i18n("The Kst file could not be loaded in its entirety due to missing objects or data."), names);
 
513
    KMessageBox::errorList(KstApp::inst(), i18n("The Kst file could not be loaded in its entirety due to missing objects or data."), names);
472
514
#endif
 
515
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
473
516
  }
474
517
 
475
518
  createScalars();
497
540
  opening = false;
498
541
 
499
542
  KstApp::inst()->setPaused(false);
 
543
  QApplication::restoreOverrideCursor();
 
544
  
500
545
  return true;
501
546
}
502
547
 
 
548
 
503
549
void KstDoc::saveDocument(QTextStream& ts, bool saveAbsoluteVectorPositions) {
504
550
  KstApp *app = KstApp::inst();
505
551
  ts << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
506
 
  ts << "<kstdoc>" << endl;
 
552
  ts << "<kstdoc version=\"1.2\">" << endl;
507
553
  // save window geometry for this kst file
508
554
  ts << "  <windowsize>" << endl;
509
555
  ts << "    <width>" << app->width() << "</width>" << endl;
537
583
  ts << "\" />" << endl;
538
584
 
539
585
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
 
586
  KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
540
587
 
541
588
  // save files
542
589
  KST::dataSourceList.lock().readLock();
543
590
  for (uint i = 0; i < KST::dataSourceList.count(); i++) {
544
591
    KstDataSourcePtr dsp = KST::dataSourceList[i];
545
 
    for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
546
 
      if ((*it)->dataSource() == dsp) {
547
 
        ts << "  <kstfile>" << endl;
548
 
        dsp->save(ts, "    ");
549
 
        ts << "  </kstfile>" << endl;
550
 
        break;
 
592
    bool saved = false;
 
593
    for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end() && !saved; ++it) {
 
594
      if ((*it)->dataSource() == dsp) {
 
595
        ts << "  <kstfile>" << endl;
 
596
        dsp->save(ts, "    ");
 
597
        ts << "  </kstfile>" << endl;
 
598
        saved = true;
 
599
      } 
 
600
    }
 
601
    for (KstRMatrixList::Iterator it = rml.begin(); it != rml.end() && !saved; ++it) {
 
602
      if ((*it)->dataSource() == dsp) {
 
603
        ts << "  <kstfile>" << endl;
 
604
        dsp->save(ts, "    ");
 
605
        ts << "  </kstfile>" << endl;
 
606
        saved = true;
551
607
      }
552
608
    }
553
609
  }
572
628
  }
573
629
 
574
630
  // save vectors
575
 
//   for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
576
 
//     ts << "  <vector>" << endl;
577
 
//     (*it)->save(ts, "    ", saveAbsoluteVectorPositions);
578
 
//     ts << "  </vector>" << endl;
579
 
//   }
580
631
  for (KstVectorList::Iterator it = KST::vectorList.begin(); it != KST::vectorList.end(); ++it) {
581
632
    if ((*it)->saveable()) {
582
 
      //      ts << "  <vector>" << endl;
583
633
      (*it)->save(ts, "  ", saveAbsoluteVectorPositions);
584
 
      //ts << "  </vector>" << endl;
585
634
    }
586
635
  }
 
636
  
 
637
  // save matrices
 
638
  for (KstMatrixList::Iterator it = KST::matrixList.begin(); it != KST::matrixList.end(); ++it) {
 
639
    if ((*it)->saveable()) {
 
640
      (*it)->save(ts, "  ");  
 
641
    }  
 
642
  }
587
643
 
588
644
  // save data objects
589
645
  KST::dataObjectList.lock().readLock();
591
647
    (*it)->save(ts, "  ");
592
648
  }
593
649
  KST::dataObjectList.lock().readUnlock();
 
650
  
594
651
  // save plots
595
652
  KMdiIterator<KMdiChildView*> *it = app->createIterator();
596
653
  while (it->currentItem()) {
601
658
        Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(*i);
602
659
        if (plot) {
603
660
          ts << "  <plot>" << endl;
604
 
          plot->save(ts, "    ");
 
661
          plot->saveAttributes(ts, "    ");
605
662
          ts << "  </plot>" << endl;
606
663
        }
607
664
      }
628
685
  ts << "</kstdoc>" << endl;
629
686
}
630
687
 
631
 
bool KstDoc::saveDocument(const QString &filename, bool saveAbsoluteVectorPositions) {
 
688
 
 
689
bool KstDoc::saveDocument(const QString& filename, bool saveAbsoluteVectorPositions, bool prompt) {
632
690
  backupFile(filename);
633
691
  QFile f(filename);
634
692
 
635
 
  if (f.exists() && filename != absFilePath()) {
636
 
    if (KMessageBox::warningYesNo(0L, i18n("%1: A file of this name already exists.").arg(filename),
 
693
  if (prompt && f.exists() && filename != absFilePath()) {
 
694
    if (KMessageBox::warningYesNo(KstApp::inst(), i18n("%1: A file of this name already exists.").arg(filename),
637
695
                                  i18n("Warning"),i18n("&Overwrite"),
638
696
                                  i18n("&Cancel")) == KMessageBox::No) {
639
697
      return false;
641
699
  }
642
700
 
643
701
  if (!f.open(IO_WriteOnly|IO_Truncate)) {
644
 
    KMessageBox::sorry(0L, i18n("%1: Could not open file for saving. The plot description has not been saved. Try a different filename or directory.").arg(filename));
 
702
    if (prompt) {
 
703
      KMessageBox::sorry(KstApp::inst(), i18n("%1: Could not open file for saving. The plot description has not been saved. Try a different filename or directory.").arg(filename));
 
704
    }
645
705
    return false;
646
706
  }
647
707
 
 
708
  // FIXME: KIO enable
648
709
  QTextStream ts(&f);
649
710
  ts.setEncoding(QTextStream::UnicodeUTF8);
 
711
  ts.precision(14);
 
712
 
 
713
  _lastFilePath = KURL(filename).path();
650
714
 
651
715
  saveDocument(ts, saveAbsoluteVectorPositions);
652
716
 
659
723
 
660
724
void KstDoc::deleteContents() {
661
725
  KST::vectorDefaults.sync();
 
726
  KST::matrixDefaults.sync();
662
727
 
663
728
  KstApp *app = KstApp::inst();
664
729
  if (app) { // Can be null on application exit
676
741
  KST::vectorList.lock().writeLock();
677
742
  KST::vectorList.clear();
678
743
  KST::vectorList.lock().writeUnlock();
 
744
  
 
745
  KST::matrixList.lock().writeLock();
 
746
  KST::matrixList.clear();
 
747
  KST::matrixList.lock().writeUnlock();
679
748
 
680
749
  KST::scalarList.lock().writeLock();
681
750
  KST::scalarList.clear();
696
765
  emit updateDialogs();
697
766
}
698
767
 
 
768
 
699
769
void KstDoc::samplesUp() {
700
 
  KstRVectorPtr V;
701
 
  int f0, n, skip;
702
 
  bool doSkip, doAve;
703
 
  int fileN;
704
 
 
 
770
  bool changed = false;
705
771
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
706
772
  for (int i = 0; i < (int)rvl.count(); i++) {
707
 
    V = rvl[i];
 
773
    KstRVectorPtr V = rvl[i];
708
774
    V->writeLock();
709
 
    f0 = V->reqStartFrame();
710
 
    n = V->reqNumFrames();
711
 
    skip = V->skip();
712
 
    doSkip = V->doSkip();
713
 
    doAve =  V->doAve();
714
 
    fileN = V->fileLength();
 
775
    int f0 = V->reqStartFrame();
 
776
    int n = V->reqNumFrames();
 
777
    int skip = V->skip();
 
778
    bool doSkip = V->doSkip();
 
779
    bool doAve = V->doAve();
 
780
    int fileN = V->fileLength();
715
781
 
 
782
    bool didChange = false;
716
783
    if (f0 + 2 * n > fileN) {
 
784
      didChange = f0 != fileN - n;
 
785
      changed = changed || didChange;
717
786
      f0 = fileN - n;
718
787
    } else {
 
788
      didChange = true;
719
789
      f0 += n;
720
790
    }
721
 
    V->changeFrames(f0, n, skip, doSkip, doAve);
 
791
 
 
792
    if (didChange) {
 
793
      V->changeFrames(f0, n, skip, doSkip, doAve);
 
794
    }
722
795
    V->writeUnlock();
723
796
  }
724
797
 
725
 
  setModified();
726
 
  forceUpdate();
727
 
 
728
 
  emit dataChanged();
 
798
  if (changed) {
 
799
    setModified();
 
800
    forceUpdate();
 
801
    emit dataChanged();
 
802
  }
729
803
}
730
804
 
731
805
 
732
806
void KstDoc::samplesDown() {
733
 
  KstRVectorPtr V;
734
 
  int f0, n, skip;
735
 
  bool doSkip, doAve;
736
 
  int fileN;
737
 
 
 
807
  bool changed = false;
738
808
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
739
809
  for (int i = 0; i < (int)rvl.count(); i++) {
740
 
    V = rvl[i];
 
810
    KstRVectorPtr V = rvl[i];
741
811
    V->writeLock();
742
 
    f0 = V->reqStartFrame();
743
 
    if (f0 == -1)
 
812
    int f0 = V->reqStartFrame();
 
813
    if (f0 == -1) {
744
814
      f0 = V->startFrame();
745
 
    n = V->reqNumFrames();
746
 
    skip = V->skip();
747
 
    doSkip = V->doSkip();
748
 
    doAve =  V->doAve();
749
 
    fileN = V->fileLength();
 
815
    }
 
816
    int n = V->reqNumFrames();
 
817
    int skip = V->skip();
 
818
    bool doSkip = V->doSkip();
 
819
    bool doAve =  V->doAve();
750
820
 
 
821
    bool didChange = false;
751
822
    if (f0 - n < 0) {
 
823
      didChange = f0 != 0;
 
824
      changed = changed || didChange;
752
825
      f0 = 0;
753
826
    } else {
 
827
      didChange = true;
754
828
      f0 -= n;
755
829
    }
756
830
 
757
 
    V->changeFrames(f0, n, skip, doSkip, doAve);
 
831
    if (didChange) {
 
832
      V->changeFrames(f0, n, skip, doSkip, doAve);
 
833
    }
758
834
    V->writeUnlock();
759
835
  }
760
836
 
761
 
  setModified();
762
 
  forceUpdate();
763
 
 
764
 
  emit dataChanged();
 
837
  if (changed) {
 
838
    setModified();
 
839
    forceUpdate();
 
840
    emit dataChanged();
 
841
  }
765
842
}
766
843
 
767
844
 
803
880
void KstDoc::purge() {
804
881
  QString purging = i18n("Purging unused objects");
805
882
  bool modified = false;
806
 
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
 
883
  bool again = true;
807
884
  KstApp *app = KstApp::inst();
808
885
 
809
 
  KST::dataObjectList.lock().writeLock();
810
 
  int cnt = rvl.count() + KST::dataObjectList.count();
811
 
  int prg = 0;
812
 
 
813
 
  app->slotUpdateProgress(cnt, prg, purging);
814
 
 
815
 
  // ASSUMPTION: this only gets called from the data manager!
816
 
  for (KstDataObjectList::Iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++it) {
817
 
    //kdDebug() << "OBJECT: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
818
 
    if ((*it)->getUsage() == 0) {
819
 
      //kdDebug() << "    -> REMOVED" << endl;
820
 
      KstDataObjectList::Iterator byebye = it;
821
 
      --it;
822
 
      KST::dataObjectList.remove(byebye);
823
 
      modified = true;
824
 
    }
825
 
    prg++;
826
 
    app->slotUpdateProgress(cnt, prg, purging);
827
 
  }
828
 
  KST::dataObjectList.lock().writeUnlock();
829
 
 
830
 
  for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
831
 
    //kdDebug() << "VECTOR: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
832
 
    if ((*it)->getUsage() == 1) {
833
 
      //kdDebug() << "    -> REMOVED" << endl;
834
 
      KST::vectorList.lock().writeLock();
835
 
      KST::vectorList.remove((*it).data());
836
 
      KST::vectorList.lock().writeUnlock();
837
 
      modified = true;
838
 
    }
839
 
    prg++;
840
 
    app->slotUpdateProgress(cnt, prg, purging);
841
 
  }
842
 
 
843
 
  app->slotUpdateProgress(0, 0, QString::null);
844
 
 
845
 
  rvl.clear();
 
886
  while (again) {
 
887
    KST::dataObjectList.lock().readLock();
 
888
    KST::matrixList.lock().readLock();
 
889
    KST::vectorList.lock().readLock();
 
890
    int cnt = KST::matrixList.count() + KST::vectorList.count() + KST::dataObjectList.count();
 
891
    KST::vectorList.lock().readUnlock();
 
892
    KST::matrixList.lock().readUnlock();
 
893
    KST::dataObjectList.lock().readUnlock();
 
894
    
 
895
    int prg = 0;
 
896
    app->slotUpdateProgress(cnt, prg, purging);
 
897
    again = false;
 
898
  
 
899
    // ASSUMPTION: this only gets called from the data manager!
 
900
    KST::dataObjectList.lock().writeLock();
 
901
    for (KstDataObjectList::Iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++it) {
 
902
      //kstdDebug() << "OBJECT: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
 
903
      if ((*it)->getUsage() == 0) {
 
904
        //kstdDebug() << "    -> REMOVED" << endl;
 
905
        KstDataObjectList::Iterator byebye = it;
 
906
        --it;
 
907
        KST::dataObjectList.remove(byebye);
 
908
        again = true;
 
909
        modified = true;
 
910
      }
 
911
      ++prg;
 
912
      app->slotUpdateProgress(cnt, prg, purging);
 
913
    }
 
914
    KST::dataObjectList.lock().writeUnlock();
 
915
  
 
916
    KST::vectorList.lock().readLock();
 
917
    KstVectorList vectorList = QDeepCopy<KstVectorList>(KST::vectorList);
 
918
    KST::vectorList.lock().readUnlock();
 
919
    
 
920
    // clear unused vectors that are editable 
 
921
    for (KstVectorList::ConstIterator it = vectorList.begin(); it != vectorList.end(); ++it) {
 
922
      //kstdDebug() << "VECTOR: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
 
923
      if ((*it)->getUsage() == 1) {
 
924
        //kstdDebug() << "    -> REMOVED" << endl;
 
925
        KST::vectorList.lock().writeLock();
 
926
        KST::vectorList.remove(const_cast<KstVector*>((*it).data()));
 
927
        KST::vectorList.lock().writeUnlock();
 
928
        again = true;
 
929
        modified = true;
 
930
      }
 
931
      ++prg;
 
932
      app->slotUpdateProgress(cnt, prg, purging);
 
933
    }
 
934
    
 
935
    KST::matrixList.lock().readLock();
 
936
    KstMatrixList matrixList = QDeepCopy<KstMatrixList>(KST::matrixList);
 
937
    KST::matrixList.lock().readUnlock();
 
938
 
 
939
    // clear unused matrices that are editable
 
940
    for (KstMatrixList::ConstIterator it = matrixList.begin(); it != matrixList.end(); ++it) {
 
941
      if ((*it)->getUsage() == 1) {
 
942
        //kstdDebug() << "    -> REMOVED" << endl;
 
943
        KST::matrixList.lock().writeLock();
 
944
        KST::matrixList.remove(const_cast<KstMatrix*>((*it).data()));
 
945
        KST::matrixList.lock().writeUnlock();
 
946
        again = true;
 
947
        modified = true;
 
948
      }
 
949
      ++prg;
 
950
      app->slotUpdateProgress(cnt, prg, purging);
 
951
    }
 
952
  }
 
953
 
 
954
  KstDataSourceList dataList;
 
955
  KST::dataSourceList.lock().readLock();
 
956
  for (KstDataSourceList::ConstIterator it = KST::dataSourceList.begin(); it != KST::dataSourceList.end(); ++it) {
 
957
      if ((*it)->getUsage() == 1) {
 
958
        //kstdDebug() << "    -> REMOVED" << endl;
 
959
        dataList.append(const_cast<KstDataSource*>((*it).data()));
 
960
        modified = true;
 
961
      }
 
962
  }
 
963
  KST::dataSourceList.lock().readUnlock();
 
964
  KST::dataSourceList.lock().writeLock();
 
965
  for (KstDataSourceList::ConstIterator it = dataList.begin(); it != dataList.end(); ++it) {
 
966
    KST::dataSourceList.remove(const_cast<KstDataSource*>((*it).data()));
 
967
  }
 
968
  KST::dataSourceList.lock().writeUnlock();
 
969
 
846
970
  setModified(modified);
847
971
  emit updateDialogs();
 
972
  
 
973
  app->slotUpdateProgress(0, 0, QString::null);
848
974
}
849
975
 
850
976
 
867
993
    switch (te->_eventType) {
868
994
      case ThreadEvent::UpdateDataDialogs:
869
995
        {
870
 
          //kdDebug() << "Update data dialogs" << endl;
871
996
          emit dataChanged();
 
997
          KstApp::inst()->updateDataNotifier();
872
998
          // HACK: remove me later
873
999
          KMdiIterator<KMdiChildView*> *it = KstApp::inst()->createIterator();
874
1000
          if (it) {
901
1027
            }
902
1028
            KstApp::inst()->deleteIterator(it);
903
1029
          }
904
 
          KstApp::inst()->paintAll();
 
1030
          KstApp::inst()->paintAll(KstPainter::P_UPDATE);
905
1031
        }
906
1032
        break;
907
1033
      case ThreadEvent::UpdateAllDialogs:
908
 
        //kdDebug() << "Update ALL dialogs" << endl;
 
1034
        //kstdDebug() << "Update ALL dialogs" << endl;
909
1035
        {
910
1036
          KMdiIterator<KMdiChildView*>* it = KstApp::inst()->createIterator();
911
1037
          if (it) {
946
1072
      switch (le->_eventType) {
947
1073
        case LogEvent::LogAdded:
948
1074
          emit logAdded(le->_msg);
 
1075
          if (le->_msg.level == KstDebug::Error) {
 
1076
            QTimer::singleShot(0, KstApp::inst(), SLOT(createDebugNotifier()));
 
1077
          }
949
1078
          break;
950
1079
        case LogEvent::LogCleared:
951
1080
          emit logCleared();