summaryrefslogtreecommitdiffstats
path: root/kverbos/kverbos/kverbosdoc.cpp
blob: 9e4cc408d2ede20d302c38aea02e3180b582380f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/***************************************************************************
                          kverbosdoc.cpp  -  description
                             -------------------
    begin                : Fre Dez 14 19:28:09 CET 2001
    copyright            : (C) 2001 by Arnold Kraschinski
    email                : arnold.k67@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

// include eines Standardheaders
#include <iostream>
#include <ctime>
#include <cstdlib>

// include files for Qt
#include <qmessagebox.h>

// include files for KDE
#include <klocale.h>
#include <kmessagebox.h>
#include <kio/netaccess.h>

// application specific includes
#include "verbspanish.h"
#include "kverbosdoc.h"
#include "kverbosview.h"
#include "kverbosuser.h"




QPtrList<KVerbosView> *KVerbosDoc::pViewList = 0L;

KVerbosDoc::KVerbosDoc(QWidget *parent, const char *name) : QObject(parent, name)
{
	if(!pViewList)
	{
		pViewList = new QPtrList<KVerbosView>();
	};
	pViewList->setAutoDelete(true);
	// Zufallsgenerator mit einem seed-Wert versorgen
	srand((unsigned int)time((time_t *)NULL));
	// Den Zeiger auf einen Benutzer initialisieren
	benutzer = new KVerbosUser(getList(), DEFAULTUSER);
}

KVerbosDoc::~KVerbosDoc()
{
	if (benutzer != 0)
	{
		int result, number;
		pViewList->first()->userChanged(result, number);
		benutzer->saveUser(result, number);
		delete benutzer;
		benutzer = 0;
	};
	verbList2.clear();
}

void KVerbosDoc::addView(KVerbosView *view)
{
	pViewList->append(view);
	connect(this, SIGNAL(changeView()), view, SLOT(zeigeVerb()));
}

void KVerbosDoc::removeView(KVerbosView *view)
{
	pViewList->remove(view);
}

void KVerbosDoc::setURL(const KURL &url)
{
	doc_url=url;
}

const KURL& KVerbosDoc::URL() const
{
	return doc_url;
}

void KVerbosDoc::slotUpdateAllViews(KVerbosView *sender)
{
	KVerbosView *w;
	if(pViewList)
		for(w=pViewList->first(); w!=0; w=pViewList->next())
			if(w!=sender)
				w->repaint();
}

bool KVerbosDoc::saveModified()
{
  bool completed=true;

  if(modified)
  {
    KVerbosApp *win=(KVerbosApp *) parent();
    int want_save = KMessageBox::warningYesNoCancel(win,
                i18n("The current file has been modified.\nDo you want to save it?"),
                i18n("Warning"),KStdGuiItem::save(),KStdGuiItem::discard());
    switch(want_save)
    {
      // ich habe die Nummern gegenüber den originalen Nummern in der case-Anweisung
      // vertauscht, weil die originalen Nummern verkehrt zugeordnet sind!.
      // In der Dokumentation zu KMessageBox kann man die richtige Zuordnung der Buttons finden.
      case 2: // CANCEL
           completed=false;
           break;
      case 3: // YES
           if (doc_url.fileName() == i18n("Untitled"))
           {
             win->slotFileSaveAs();
           }
           else
           {
             saveDocument(URL());
       	   };

       	   deleteContents();
           completed=true;
           break;
      case 4: // NO
           setModified(false);
           deleteContents();
           completed=true;
           break;	
      default: // Verhalten wie CANCEL
           completed=false;
           break;
    }
  }

  return completed;
}

void KVerbosDoc::closeDocument()
{
	deleteContents();
}

bool KVerbosDoc::newDocument()
{
	// Die Verbenlist wird gelöscht, damit sie sicher leer ist.
	verbList2.clear();

	modified=false;
	doc_url.setFileName(i18n("Untitled"));
	emit anzahlVerbenGeaendert(getAnzahl());
	return true;
}

bool KVerbosDoc::openDocument(const KURL& url, const char *format /*=0*/)
{
	bool b = false;
	QString tmpfile;
	KIO::NetAccess::download( url, tmpfile );

	QFile file(url.path());
	if ( file.open(IO_ReadOnly) ) {    // file opened successfully
		deleteContents();
	if ((url.fileName().right(4) == "html")||(url.fileName().right(3) == "htm"))
	{
		// qWarning("öffnen eines HTML-files");
		b = openDocHTML(file);
	}
	else
	{
		// qWarning("öffnen eines .verbos-files");
		b = openDocVERBOS(file);
	};
	file.close();
	// Liste der Verben sortieren
    spanishVerbList vl;
    spanishVerbList::Iterator it1 = verbList2.begin();
    spanishVerbList::Iterator it2;
   	while (it1 != verbList2.end())
    {
			it2 = vl.begin();
   		bool inserted = false;
   		while (it2  != vl.end())
     	{
				if (*it1 < *it2)
    		{
        	vl.insert(it2, *it1);
         	inserted = true;
          it2 = vl.end();
      	}
	      else
  	      it2++;
      };
      if (!inserted)
      	vl.insert(it2, *it1);
      it1++;
    };
    verbList2.clear();
    verbList2 = vl;
    benutzer->fillList(getList());  	
    emit changeView();
  };

  KIO::NetAccess::removeTempFile( tmpfile );

  modified=false;
  emit anzahlVerbenGeaendert(getAnzahl());
  return b;
}

// Liesteine Datei als HTML-Dokument ein
bool KVerbosDoc::openDocHTML(QFile &f)
{
	bool result = true;
	QTextStream t( &f );          // use a text stream
	int count1;
	int count2;
	QString s;
	QString v[3];
	QString forms[60];
	verbSpanish NewVerb;
	while (!f.atEnd())
	{
		count1 = 0;
		// drei einlesen, das sind der Infinitiv, die deutsche Bedeutung, und der Typ
		while ((count1<3) && (!f.atEnd()))
		{
			s = t.readLine();
			if (s.left(9) == "<td width")
			{
				int a = s.find('>', 22, true);
				a++;
				int e = s.find('<', a, true);
				v[count1] = s.mid(a, e-a);
				count1++;
			};
		}; // while ((count1<3) && (!f.atEnd()))
		if (3 == count1)
		{
			NewVerb.setSpanish(v[0]);
			NewVerb.setForeign(v[1]);
			if (v[2] != "unregelm&auml;&szlig;ig")
			{
				// read a regular or a group verb
				int g = 0;
				if (v[2] == "regelm&auml;&szlig;ig")
					g = 0;
				else if (v[2] == "&lt;e &gt; ie&gt;")
					g = 2;
				else if (v[2] == "&lt;o &gt; ue&gt;")
					g = 3;
				else if (v[2] == "&lt;u &gt; ue&gt;")
					g = 4;
				else if (v[2] == "&lt;e &gt; i&gt;")
					g = 5;
				else if (v[2] == "&lt;c &gt; qu&gt;")
					g = 6;
				else if (v[2] == "&lt;g &gt; gu&gt;")
					g = 7;
				else if (v[2] == "&lt;z &gt; c&gt;")
					g = 8;
				else if (v[2] == "&lt;gu &gt; gü&gt;")
					g = 9;
				else if (v[2] == "&lt;c &gt; z&gt;")
					g = 10;
				else if (v[2] == "&lt;g &gt; j&gt;")
					g = 11;
				else if (v[2] == "&lt;gu &gt; g&gt;")
					g = 12;
				else if (v[2] == "&lt;qu &gt; c&gt;")
					g = 13;
				else if (v[2] == "&lt;accent like 'enviar'&gt;")
					g = 14;
				else if (v[2] == "&lt;accent like 'continuar&gt;")
					g = 15;
				else if (v[2] == "&lt;missing i&gt;")
					g = 16;
				else
					result = false;
				NewVerb.setGroup(g);
			}
			else
			{
				// ein unregelmäßiges Verb
				NewVerb.setGroup(IRREGULAR);
				// weitere 60 Zeilen einlesen, das sind die ganzen Formen
				count2 = 0;
				while ((count2<60) && (!f.atEnd()))
				{
					s = t.readLine();
					if ((s.left(4) == "<td>") && (s != "<td></td><td></td><td></td><td></td><td></td></tr><tr>"))
					{
						int a = s.find('>', 2, true);
						a++;
						int e = s.find('<', a, true);
						forms[count2] = s.mid(a, e-a);
						count2++;
						if (14 == count2)
						{
							forms[count2] = "participio";
							count2++;
						};
					};
				}; // while ((count2<60) && (!f.atEnd()))
				int i;
				// den ersten Tabellenteil übertragen
				for (i=0; (i<30) && (i<count2); i++)
				{
					int a = i % 5;
					int b = i / 5;
					// In der fünften ( a == 4 ) Spalte stehen die Gerundform und das Partizip
					if (a == 4)
					{
						if (b == 0)
						NewVerb.setGerund(forms[i]);
						if (b == 3)
						NewVerb.setPartizip(forms[i]);
					}
					else
					{
						// kommt ein Leerzeichen vor, muss man die Form aufteilen: In das
						// Reflexivpronomen und das eigentliche Verb
						if (forms[i].find(' ') >= 0)
						{
							NewVerb.setForm(a, b, forms[i].right(forms[i].length()-forms[i].find(' ')-1));
						}
						else
						{
							NewVerb.setForm(a, b, forms[i]);
						}
					};
				};
				// den zweiten Tabellenteil übertragen
				for (i=0; (i<30) && (i+30<count2); i++)
				{
					int a = i % 5 + 4;
					int b = i / 5;
					// In der Spalte 3 der zweiten Tabellenhälfte steht der subjuntivo futuro,
					// den ich vergessen habe und der deshalb zur Zeit ausgelassen wird.
					int offs = 30;
					// kommt ein Leerzeichen vor, muss man die Form aufteilen: In das
					// Reflexivpronomen und das eigentliche Verb      	
					if (forms[i+offs].find(' ') >= 0)
					{
						NewVerb.setForm(a, b, forms[i+offs].right(forms[i+offs].length()-forms[i+offs].find(' ')-1));
					}
					else
					{
						NewVerb.setForm(a, b, forms[i+offs]);
					};	
				};
			}; // if (v[2] == "unregelm&auml;&szlig;ig")
			appendVerb(NewVerb, false); // an die Liste anhängen
		};
	}; // while (!f.atEnd())
	emit anzahlVerbenGeaendert(getAnzahl());
	return result;
}

bool KVerbosDoc::openDocVERBOS(QFile &f)
{
	QTextStream t( &f );          // use a text stream
	int count;
	QString v[3];
	while (!f.atEnd())
	{
		count = 0;
		// drei einlesen, das sind der Infinitiv, die deutsche Bedeutung, und der Typ
		while ((count<3) && (!f.atEnd()))
		{
			v[count] = t.readLine();
			count++;
		}; // while ((count<3) && (!f.atEnd()))
		if (3 == count)
		{
			verbSpanish NewVerb;
			NewVerb.setSpanish(v[0]);
			NewVerb.setForeign(v[1]);
			int	g = v[2].toInt();
			if (IRREGULAR != g)
			{
				// ein regelmäßiges Verb
				NewVerb.setGroup(g);
			}
			else
			{
				// ein unregelmäßiges Verb
				NewVerb.setGroup(IRREGULAR);
				// erst den Gerund und das Partizip einlesen und dann die restlichen Formen.
				NewVerb.setGerund(t.readLine());
				NewVerb.setPartizip(t.readLine());
				count = 0;
				for (int i = presente; i <= imperativo; i++)
					for (int j = yo; j <= ellos; j++)
						if (!f.atEnd())
						{
							NewVerb.setForm(i, j, t.readLine());
							count++;
						};
				if (count < 54)
				{
					QMessageBox mb("kverbos warning", "An uncomplete verb has been found in the file",
									QMessageBox::Warning, 1, 0, 0, 0);
					mb.exec();
					//qWarning("Ein unvollständiges Verb kam vor!");
				};
			};
			appendVerb(NewVerb, false); // an die Liste anhängen
		};
	}; // while (!f.atEnd())
	emit anzahlVerbenGeaendert(getAnzahl());
	return true;
}

// sichert die Datei. Die Verben werden in einer Datei im HTML Format gespeichert.
bool KVerbosDoc::saveDocument(const KURL& url, const char *format /*=0*/)
{
	bool b = false;
	QFile file(url.path());
	if ( file.open(IO_WriteOnly) )
	{    // file opened successfully
		if ((url.fileName().right(4) == "html")||(url.fileName().right(3) == "htm"))
		{
			// qWarning("als HTML speichern");
			b = saveDocHTML(file);
		}
		else
		{
			// qWarning("als .verbos speichern");    	
			b = saveDocVERBOS(file);
		};
	};
	file.close();
	modified=false;
	return b;
}

// Die Verben als HTML-Datei abspeichern
bool KVerbosDoc::saveDocHTML(QFile &f)
{
	bool good = true;
  QTextStream t( &f );           // use a text stream
  // Den Anfang der HTML Datei schreiben
  t << "<html>" << endl;
  t << "<head>" << endl;
  t << "<title>verbos espa&ntilde;oles</title>" << endl;
  t << "<style type=\"text/css\">" << endl;
	t << "<!--" << endl;
 	t << "h1 { font-size:48pt; color:#FF0000; font-family:sans-serif; text-align:center; }" << endl;
 	t << ".n { font-size:12pt; color:#000000; font-family:sans-serif; margin:0pt; }" << endl;
 	t << ".v   { font-size:16pt; color:#0000ff; font-family:sans-serif; }" << endl;
	t << ".r   { font-size:16pt; color:#b0b0ff; font-family:sans-serif; }" << endl; 	
 	t << ".t { background-color:#f0f0f0; padding:4pt; font-size:12pt; color:#000000; font-family:sans-serif; margin:0pt; }" << endl;
	t << "td { background-color:#ffffff; padding:4pt; font-size:12pt; color:#000000; font-family:sans-serif; margin:0pt; }" << endl;
 	t << "//-->" << endl;
  t << "</style>" << endl;
  t << "</head>" << endl;
  t << "<body>" << endl;
  t << "<h1>verbos espa&ntilde;oles</h1>" << endl;
 	t << "<p class=\"n\">";
 	t << "Als regelm&auml;&szlig;ig gelten in diesem Programm alle Verben, die sich " << endl;
 	t << "ohne geringste Abweichung an das Konjugationsschema für die Verben mit den " << endl;
 	t << "Endungen -ar, -er und -ir halten. Die Gruppenverben, die auch eine gewisse " << endl;
 	t << "Regelm&auml;&szlig;keit f&uuml;r eine Gruppe von Verben erkennen lassen, " << endl;
 	t << "m&uuml;ssen als unregelm&auml;&szlig;ige eingegeben werden. </p>" << endl;
 	t << "<p class=\"n\">";
 	t << "Die Formen des 'subjuntivo futuro' werden einstweilen nicht mit in das " << endl;
 	t << "Programm aufgenommen. </p>" << endl;
 	t << "<p class=\"n\">";
 	t << "Diese Datei wurde automatisch durch das Programm KVerbos erstellt. Die " << endl;
 	t << "Verben wurden dabei in einem Format ausgegeben, die das Programm auch " << endl;
 	t << "wieder einlesen kann. Deshalb sollten an der Datei keine &Auml;nderungen " << endl;
 	t << "vorgenommen werden. Durch &Auml;nderungen kann die Datei f&uuml;r das Programm " << endl;
 	t << "unlesbar werden. <br></p>" << endl;
  // Die Verbenliste in die Datei schreiben.
  if (verbList2.isEmpty())
  {
    t << "<p class=\"n\">Es wurden keine Verben eingegeben.</p>" << endl;
  }
  else
  {
    spanishVerbList::Iterator it;
    for (it = verbList2.begin(); it != verbList2.end(); ++it)
    {
    	// erst die spanische und die deutsche Bedeutung abspeichern und den Typ
     	t << "<hr color=#000000 size=3 noshade>" << endl;
   		t << "<table width=100% border=\"0\"><tr>" << endl;
   		t << "<td width=37% class=\"v\">" << (*it).getSpanish() << "</td>" << endl;
     	t << "<td width=37% class=\"v\">" << (*it).getForeign() << "</td>" << endl;
     	if ((*it).isGroupVerb())
     	{
     	  t << "<td width=26% class=\"r\">";
				switch ((*it).getGroup())
				{
					case 0:
						t << "regelm&auml;&szlig;ig</td>" << endl; break;
					case 2:
						t << "&lt;e &gt; ie&gt;</td>" << endl; break;
					case 3:
						t << "&lt;o &gt; ue&gt;</td>" << endl; break;
					case 4:
						t << "&lt;u &gt; ue&gt;</td>" << endl; break;
					case 5:
						t << "&lt;e &gt; i&gt;</td>" << endl; break;
					case 6:
						t << "&lt;c &gt; qu&gt;</td>" << endl; break;
					case 7:
						t << "&lt;g &gt; gu&gt;</td>" << endl; break;
					case 8:
						t << "&lt;z &gt; c&gt;</td>" << endl; break;
					case 9:
						t << "&lt;gu &gt; gü&gt;</td>" << endl; break;
					case 10:
						t << "&lt;c &gt; z&gt;</td>" << endl; break;
					case 11:
						t << "&lt;g &gt; j&gt;</td>" << endl; break;
					case 12:
						t << "&lt;gu &gt; g&gt;</td>" << endl; break;
					case 13:
						t << "&lt;qu &gt; c&gt;</td>" << endl; break;
					case 14:
						t << "&lt;accent like 'enviar'&gt;</td>" << endl; break;
					case 15:
						t << "&lt;accent like 'continuar&gt;</td>" << endl; break;
					case 16:	
						t << "&lt;missing i&gt;</td>" << endl; break;
					default:
						good = false;
						//qWarning("Error! Wrong group!!");
				};
     	}
     	else
     	{
     	  t << "<td width=26% class=\"r\">unregelm&auml;&szlig;ig</td>" << endl;
     	};
     	t << "</tr></table>" << endl;
     	// Im Falle eines unregelmäßigen Verbes, die Formen sichern
     	if ((*it).isGroupVerb() == false)
     	{
   			t << "<table width=100%  border=\"0\">" << endl;
 				t << "<colgroup><col width=20%><col width=20%><col width=20%><col width=20%><col width=20%></colgroup>" << endl;
 				// erster Teil der Tabelle
 				t << "<tr>" << endl;
 				t << "<td class=\"t\">presente</td>" << endl;
 				t << "<td class=\"t\">imperfecto</td>" << endl;
 				t << "<td class=\"t\">indefinido</td>" << endl;
 				t << "<td class=\"t\">futuro</td>" << endl;
 				t << "<td class=\"t\">gerundio</td>" << endl;
 				t << "</tr>" << endl;
 				int i;
 				for (i = yo; i <= ellos; i++)
 				{
 				  t << "<tr>" << endl;
 				  for (int j = presente; j <= futuro; j++)
 				  {
   				  // Formen presente, imperfecto, indefinido, futuro
 	  			  t << "<td>";
		  		  if ((*it).isReflexiv())
              t << (*it).getRefPron(i) << ' ';
 				    t << (*it).getForm(j, i) << "</td>" << endl;
 				  };
 				  // Sonderformen gerundio und participo
 				  switch (i)
 				  {
 				    case 0:
 	            t << "<td>" << (*it).getGerund() << "</td>" << endl;					  					
 							break;
 						case 2:
 						  t << "<td class=\"t\">" << "participo</td>" << endl;					  					
 							break;
 						case 3:
 						  t << "<td>" << (*it).getPartizip() << "</td>" << endl;					  					
 							break;
 						default:
 						  t << "<td></td>" << endl;	
 				  }
 				  t << "</tr>" << endl;
 				}					
 				t << "<tr>" << endl;
 				t << "<td></td><td></td><td></td><td></td><td></td>";
 				t << "</tr>";
        // zweiter Teil der Tabelle
 				t << "<tr>" << endl;
 				t << "<td class=\"t\">condicional</td>" << endl;
 				t << "<td class=\"t\">subjuntivo presente</td>" << endl;
 				t << "<td class=\"t\">subjuntivo imperfecto</td>" << endl;
 				t << "<td class=\"t\">subjuntivo futuro</td>" << endl;
 				t << "<td class=\"t\">imperativo</td>" << endl;
 				t << "</tr>" << endl;
 				for (i = yo; i <= ellos; i++)
 				{
 				  t << "<tr>" << endl;
 				  for (int j = condicional; j <= imperativo; j++)
 				  {
   				  // Formen condicional, subjuntivo presente, subjuntivo imperfecto
   				  // subjuntivo futuro, imperativo
 	  			  t << "<td>";
		  		  if ((*it).isReflexiv())
              t << (*it).getRefPron(i) << ' ';
 				    t << (*it).getForm(j, i) << "</td>" << endl;
			    };
 				  t << "</tr>" << endl;
 				}					
 				t << "</table>" << endl;
     	}
 		  t << "<p></p>" << endl;
 		};
 	};
  // Das Ende der HTML Datei anfügen.
  t << "</body>" << endl;
  t << "</html>" << endl;
  return good;
}

bool KVerbosDoc::saveDocVERBOS(QFile &f)
{
  QTextStream t( &f );           // use a text stream
  // Die Verbenliste in die Datei schreiben.
  if (verbList2.isEmpty())
  {
    t << "Es wurden keine Verben eingegeben." << endl;
  }
  else
  {
    spanishVerbList::Iterator it;
    for (it = verbList2.begin(); it!=verbList2.end(); ++it)
    {
    	// erst die spanische und die deutsche Bedeutung abspeichern und den Typ
   		t << (*it).getSpanish() << endl;
     	t << (*it).getForeign() << endl;
     	t << (*it).getGroup() << endl;	
     	// Im Falle eines unregelmäßigen Verbes, die Formen sichern
     	if ((*it).isGroupVerb() == false)
     	{
			  t << (*it).getGerund() << endl;	
			  t << (*it).getPartizip() << endl;
			  for (int j = presente; j <= imperativo; j++)
 				{
   				for (int i = yo; i <= ellos; i++)
 				  {
 				    t << (*it).getForm(j, i) << endl;
 				  };
 				};
 			};
 		};
 	};
  return true;
}

void KVerbosDoc::deleteContents()
{
 	verbList2.clear();
	emit anzahlVerbenGeaendert(getAnzahl());
}

// Ein Verb wird der Liste hinzugefügt.
void KVerbosDoc::appendVerb(const verbSpanish v, bool emitStatus /*= true*/)
{
  verbList2.append(v);
  if (emitStatus)
    emit anzahlVerbenGeaendert(getAnzahl());
}

// es wird geprüft, ob die Liste leer ist.
bool KVerbosDoc::isEmpty() const
{
  return verbList2.isEmpty();
}
	
// Gibt die Liste des Dokumentes zurück.
spanishVerbList* KVerbosDoc::getList()
{
  return &verbList2;
}

// Diese Funktion ist auch die einzige über die diese Abfrage läuft, deshalb erhält sie auch
// die Aufgabe eine Auswahl anzuregen.
// Reihenfolge in dem Stringfeld: yo, tu, el, nosotros, vosotros, ellos, aleman, espanol
// Wird "- - - - - -" zurückgegeben, dann gibt es kein Verb in der Liste. Normalerweise
// wird die spanische Verbform zurückgegeben.
QString KVerbosDoc::getAuswahl(QString s[][3], int &t)
{
	bool verbOK = true;
	// feststellen, wie viele aktivierte Zeiten in den Optionen vorhanden sind
	int ti[MAX_TIEMPOS*MAX_SUBTYPES], ty[MAX_TIEMPOS*MAX_SUBTYPES];
	bool op[MAX_TIEMPOS][MAX_SUBTYPES];
	int zeitenZahl = 0;
	KVerbosApp *app = dynamic_cast<KVerbosApp*>(parent());
	if (app) {
		app->getTimeOptions(op);
	}
	for (int i=0; i<MAX_TIEMPOS; i++)
		for (int j=0; j<MAX_SUBTYPES; j++)
			if (op[i][j])
			{
				ti[zeitenZahl] = i;
				ty[zeitenZahl] = j;
				zeitenZahl++;
			};
	if ((0 == verbList2.count()) || (0 == zeitenZahl))
	{
		// Die Liste ist leer oder keine Zeit ist ausgewählt.
		for (int i=0; i<PERSONEN+1; i++)
		{
			s[i][0] = "- - - - - -";
			s[i][1] = "- - - - - -";
			s[i][2] = "- - - - - -";
			t = 0;
		};
	}
	else
	{
		spanishVerbList::Iterator it = findVerb(benutzer->suggestVerb());
		if (it == verbList2.end())
		{
			it = verbList2.at(rand() % verbList2.count());
		};
		zeitenZahl = rand() % zeitenZahl;
		// die deutsche und die spanische Form übernehmen
		s[6][0] = (*it).getSpanish();
		s[6][1] = (*it).getForeign();
		// die einzelnen Formen zusammenstellen
		for (int i=0; i<PERSONEN; i++)
		{
			verbOK = verbOK && (*it).getForm(ti[zeitenZahl], i, ty[zeitenZahl], s[i]);
		};
		t = ti[zeitenZahl] + ty[zeitenZahl]*MAX_TIEMPOS;
	};
	if (!verbOK)
	{
		QMessageBox mb("kverbos warning", "There is a problem with the verb " + s[6][0] +
						".\nPlease check the verb in the edit dialog.", QMessageBox::Warning, 1, 0, 0, 0);
		mb.exec();	
		for (int i=0; i<PERSONEN+1; i++)
		{
			s[i][0] = "- - - - - -";
			s[i][1] = "- - - - - -";
			s[i][2] = "- - - - - -";
			t = 0;
		};	
	};
	return s[6][1];
}

spanishVerbList::Iterator KVerbosDoc::findVerb(const QString& s)
{
	spanishVerbList::Iterator it = verbList2.begin();	
	while ((it != verbList2.end()) && (!((*it) == s)))
		it++;
	return it;
}

void KVerbosDoc::solved(const bool b)
{
	if (benutzer!=0)
		if (b)
		  benutzer->right();
		else
		  benutzer->wrong();
}

// sets a new user name, and deletes the old one. If the old one is differet from
// the default name'-------' then some information is stored about the user. The
// Program look if some information about the user is stored.
void KVerbosDoc::setNewUser(const QString n)
{
	if (0 != benutzer)
	{
		int result, number;
		pViewList->first()->userChanged(result, number);
		benutzer->saveUser(result, number);
		delete benutzer;
	};
	// prüfen ob über den Nutzer schon was gespeichert ist.
	benutzer = new KVerbosUser(getList(), n);
}

#include "kverbosdoc.moc"