Back to index

fet  5.18.0
import.cpp
Go to the documentation of this file.
00001 /*
00002 File import.cpp
00003 */
00004 
00005 /***************************************************************************
00006                                 FET
00007                           -------------------
00008    copyright            : (C) by Lalescu Liviu
00009     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00010  ***************************************************************************
00011                           import.cpp  -  description
00012                              -------------------
00013     begin                : Mar 2008
00014     copyright            : (C) by Volker Dirr
00015                          : http://www.timetabling.de/
00016  ***************************************************************************
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 // Code contributed by Volker Dirr ( http://www.timetabling.de/ )
00026 
00027 //TODO: import days per week
00028 //TODO: import hours per day
00029 
00030 #include "import.h"
00031 #include <QtGui>
00032 #include <QProgressDialog>
00033 
00034 #include "centerwidgetonscreen.h"
00035 
00036 extern Timetable gt;
00037 
00038 // maybe I can add some of them again as parameter into function name?
00039 // it is not possible with fieldNumber and fieldName, because that conflicts with the using of command connect with chooseFieldsDialogUpdate (there are no parameters possible)
00040 static QString fileName;                         // file name of the csv file
00041 
00042 static QString fieldSeparator=",";
00043 static QString textquote="\"";
00044 static QString setSeparator="+";
00045 
00046 static QString importThing;
00047 
00048 static int numberOfFields;                       // number of fields per line of the csv file
00049 static QStringList fields;                       // list of the fields of the first line of the csv file
00050 static bool head;                                // true = first line of csv file contain heading, so skip this line
00051 static QString fieldName[NUMBER_OF_FIELDS];             // field name (normally similar to the head)
00052 static int fieldNumber[NUMBER_OF_FIELDS];        // field number in the csv file
00053                                                  // fieldNumber >= 0 is the number of the field
00054                                                  // fieldNumber can also be IMPORT_DEFAULT_ITEM (==IMPORT_DEFAULT_ITEM). That mean that items of fieldList get the name of fieldDefaultItem (not of field[fieldNumber] from csv
00055                                                  // fieldNumber can also be DO_NOT_IMPORT (==-2). That mean that items are not imported into fieldList.
00056 static QStringList fieldList[NUMBER_OF_FIELDS];  // items of the fields (items from "field number")
00057 static QString fieldDefaultItem[NUMBER_OF_FIELDS];      // used, if fieldNumber == IMPORT_DEFAULT_ITEM
00058 static QString warnText;                         // warnings about the csv file
00059 static QStringList dataWarning;                  // warnings about the current conflicts between the csv file and the data that is already in memory
00060 static QString lastWarning;
00061 
00062 
00063 int Import::chooseWidth(int w)
00064 {
00065        int ww=w;
00066        if(ww>1000)
00067               ww=1000;
00068        
00069        return ww;
00070 }
00071 
00072 int Import::chooseHeight(int h)
00073 {
00074        int hh=h;
00075        if(hh>650)
00076               hh=650;
00077        
00078        return hh;
00079 }
00080 
00081 Import::Import()
00082 {
00083 }
00084 
00085 Import::~Import()
00086 {
00087 }
00088 
00089 void Import::prearrangement(){
00090        assert(gt.rules.initialized);
00091 
00092        fieldName[FIELD_LINE_NUMBER]=Import::tr("Line");
00093        fieldName[FIELD_YEAR_NAME]=Import::tr("Year");
00094        fieldName[FIELD_YEAR_NUMBER_OF_STUDENTS]=Import::tr("Number of Students per Year");
00095        fieldName[FIELD_GROUP_NAME]=Import::tr("Group");
00096        fieldName[FIELD_GROUP_NUMBER_OF_STUDENTS]=Import::tr("Number of Students per Group");
00097        fieldName[FIELD_SUBGROUP_NAME]=Import::tr("Subgroup");
00098        fieldName[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]=Import::tr("Number of Students per Subgroup");
00099        fieldName[FIELD_SUBJECT_NAME]=Import::tr("Subject");
00100        fieldName[FIELD_ACTIVITY_TAG_NAME]=Import::tr("Activity Tag");
00101        fieldName[FIELD_TEACHER_NAME]=Import::tr("Teacher");
00102        fieldName[FIELD_BUILDING_NAME]=Import::tr("Building");
00103        fieldName[FIELD_ROOM_NAME]=Import::tr("Room Name");
00104        fieldName[FIELD_ROOM_CAPACITY]=Import::tr("Room Capacity");
00105        fieldName[FIELD_STUDENTS_SET]=Import::tr("Students Sets");
00106        fieldName[FIELD_TEACHERS_SET]=Import::tr("Teachers");
00107        fieldName[FIELD_TOTAL_DURATION]=Import::tr("Total Duration");
00108        fieldName[FIELD_SPLIT_DURATION]=Import::tr("Split Duration");
00109        fieldName[FIELD_MIN_DAYS]=Import::tr("Min Days");
00110        fieldName[FIELD_MIN_DAYS_WEIGHT]=Import::tr("Min Days Weight");
00111        fieldName[FIELD_MIN_DAYS_CONSECUTIVE]=Import::tr("Min Days Consecutive");
00112        fieldName[FIELD_ACTIVITY_TAGS_SET]=Import::tr("Activity Tags");
00113        for(int i=0; i<NUMBER_OF_FIELDS; i++){
00114               fieldNumber[i]=DO_NOT_IMPORT;
00115               fieldDefaultItem[i]="";
00116               fieldList[i].clear();
00117        }
00118        fieldNumber[FIELD_LINE_NUMBER]=IMPORT_DEFAULT_ITEM;
00119        fieldDefaultItem[FIELD_LINE_NUMBER]=Import::tr("line");
00120        dataWarning.clear();
00121        warnText.clear();
00122        lastWarning.clear();
00123 }
00124 
00125 
00126 //TODO: add this into the first function!? form to full?!
00127 ChooseFieldsDialog::ChooseFieldsDialog(QWidget *parent): QDialog(parent)
00128 {
00129        assert(fields.size()>0);
00130 
00131        this->setWindowTitle(tr("FET - Import from CSV file"));
00132        QGridLayout* chooseFieldsMainLayout=new QGridLayout(this);
00133 
00134        QVBoxLayout* fieldBox[NUMBER_OF_FIELDS];
00135        QHBoxLayout* fieldLine1[NUMBER_OF_FIELDS];
00136        QHBoxLayout* fieldLine2[NUMBER_OF_FIELDS];
00137        QHBoxLayout* fieldLine3[NUMBER_OF_FIELDS];
00138        QHBoxLayout* fieldLine3b[NUMBER_OF_FIELDS];
00139 
00140        int gridRow=0;
00141        int gridColumn=0;
00142        for(int i=1; i<NUMBER_OF_FIELDS; i++){
00143               assert(fieldNumber[i]==DO_NOT_IMPORT || fieldNumber[i]==IMPORT_DEFAULT_ITEM);
00144               fieldGroupBox[i] = new QGroupBox(Import::tr("Please specify the %1 field:").arg(fieldName[i]));
00145               fieldBox[i] = new QVBoxLayout();
00146               fieldRadio1[i] = new QRadioButton(Import::tr("Don't import \"%1\".").arg(fieldName[i]));
00147               fieldRadio2[i] = new QRadioButton(Import::tr("Import this field from CSV:"));
00148               
00149               //trick to keep the translation active, maybe we need it in the future
00150               QString s=Import::tr("Set always the same name:");
00151               Q_UNUSED(s);
00152               
00153               //fieldRadio3[i] = new QRadioButton(Import::tr("Set always the same name:"));
00154               fieldRadio3[i] = new QRadioButton(Import::tr("Set always the same value:")); //modified by Liviu on 18 March 2009
00155               fieldRadio3b[i] = new QRadioButton(Import::tr("Set always the same value:"));
00156 
00157               fieldLine1[i] = new QHBoxLayout();
00158               fieldLine1[i]->addWidget(fieldRadio1[i]);
00159               fieldBox[i]->addLayout(fieldLine1[i]);
00160               
00161               fieldLine2CB[i] = new QComboBox();
00162               fieldLine2CB[i]->setMaximumWidth(220);                  //max
00163               fieldLine2CB[i]->insertItems(0,fields);
00164               fieldLine2[i] = new QHBoxLayout();
00165               fieldLine2[i]->addWidget(fieldRadio2[i]);
00166               fieldLine2[i]->addWidget(fieldLine2CB[i]);
00167               fieldBox[i]->addLayout(fieldLine2[i]);
00168               fieldRadio2[i]->setChecked(true);
00169 
00170               fieldLine3Text[i] = new QLineEdit(Import::tr("Please modify this text."));
00171 //            fieldLine3Text[i]->setMaximumWidth(220);         //max
00172               fieldLine3[i] = new QHBoxLayout();
00173               fieldLine3[i]->addWidget(fieldRadio3[i]);
00174               
00175               //Added by Liviu - 18 March 2009, so that the dialog looks nice when dialog is maximized
00176               
00177               //TODO: add this line or not???
00178               fieldLine3[i]->addStretch();
00179               //fieldLine3Text[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
00180               
00181               fieldLine3[i]->addWidget(fieldLine3Text[i]);
00182               fieldBox[i]->addLayout(fieldLine3[i]);
00183 
00184               fieldLine3bSpinBox[i] = new QSpinBox();
00185               fieldLine3bSpinBox[i]->setMaximumWidth(220);            //max
00186               fieldLine3b[i] = new QHBoxLayout();
00187               fieldLine3b[i]->addWidget(fieldRadio3b[i]);
00188               fieldLine3b[i]->addWidget(fieldLine3bSpinBox[i]);
00189               fieldBox[i]->addLayout(fieldLine3b[i]);
00190 
00191               fieldGroupBox[i]->setLayout(fieldBox[i]);
00192               chooseFieldsMainLayout->addWidget(fieldGroupBox[i], gridRow, gridColumn);
00193               if(fieldNumber[i]==DO_NOT_IMPORT)
00194                      fieldGroupBox[i]->hide();
00195               else {
00196                      if(gridColumn==1){
00197                             gridColumn=0;
00198                             gridRow++;
00199                      } else
00200                             gridColumn++;
00201               }
00202 
00203               if(i==FIELD_YEAR_NAME || i==FIELD_TEACHER_NAME)
00204                      fieldRadio1[i]->hide();
00205               if(i==FIELD_ROOM_CAPACITY){
00206                      fieldRadio1[i]->hide();
00207                      fieldLine3bSpinBox[i]->setMaximum(MAX_ROOM_CAPACITY);
00208                      fieldLine3bSpinBox[i]->setMinimum(0);
00209                      fieldLine3bSpinBox[i]->setValue(MAX_ROOM_CAPACITY);
00210                      fieldRadio3b[i]->setChecked(true);
00211                      fieldRadio3[i]->hide();
00212                      fieldLine3Text[i]->hide();
00213               } else if(i==FIELD_YEAR_NUMBER_OF_STUDENTS || i==FIELD_GROUP_NUMBER_OF_STUDENTS || i==FIELD_SUBGROUP_NUMBER_OF_STUDENTS){
00214                      fieldRadio1[i]->hide();
00215                      fieldLine3bSpinBox[i]->setMaximum(MAX_TOTAL_SUBGROUPS);
00216                      fieldLine3bSpinBox[i]->setMinimum(0);
00217                      fieldLine3bSpinBox[i]->setValue(0);
00218                      fieldRadio3b[i]->setChecked(true);
00219                      fieldRadio3[i]->hide();
00220                      fieldLine3Text[i]->hide();
00221               } else {
00222                      fieldRadio3b[i]->hide();
00223                      fieldLine3bSpinBox[i]->hide();
00224               }
00225               if(i==FIELD_SUBJECT_NAME){
00226                      fieldRadio1[i]->hide();
00227                      fieldRadio3[i]->hide();
00228                      fieldLine3Text[i]->hide();
00229               }
00230               if(i==FIELD_ACTIVITY_TAG_NAME){
00231                      fieldRadio1[i]->hide();
00232                      fieldRadio3[i]->hide();
00233                      fieldLine3Text[i]->hide();
00234               }
00235               if(i==FIELD_ROOM_NAME){
00236                      fieldRadio3[i]->hide();
00237                      fieldLine3Text[i]->hide();
00238               }
00239               
00240               if(i==FIELD_TOTAL_DURATION){
00241                      fieldRadio1[i]->hide();
00242                      fieldLine3Text[i]->setText("1");
00243               }
00244               if(i==FIELD_SPLIT_DURATION){
00245                      fieldRadio1[i]->hide();
00246                      fieldLine3Text[i]->setText("1");
00247               }
00248               if(i==FIELD_MIN_DAYS){
00249                      fieldRadio1[i]->hide();
00250                      fieldLine3Text[i]->setText("1");
00251               }
00252               if(i==FIELD_MIN_DAYS_WEIGHT){
00253                      fieldRadio1[i]->hide();
00254                      fieldLine3Text[i]->setText("95");
00255               }
00256               if(i==FIELD_MIN_DAYS_CONSECUTIVE){
00257                      fieldRadio1[i]->hide();
00258                      fieldLine3Text[i]->setText("1");
00259               }
00260        }
00261 
00262        gridRow++;
00263        /*
00264        pb=new QPushButton(tr("OK"));
00265        chooseFieldsMainLayout->addWidget(pb,gridRow,1);
00266        cancelpb=new QPushButton(tr("Cancel"));
00267        chooseFieldsMainLayout->addWidget(cancelpb,gridRow,2);*/
00268        pb=new QPushButton(tr("OK"));
00269        cancelpb=new QPushButton(tr("Cancel"));
00270        buttonsLayout=new QHBoxLayout();
00271        buttonsLayout->addStretch();
00272        buttonsLayout->addWidget(pb);
00273        buttonsLayout->addWidget(cancelpb);
00274        chooseFieldsMainLayout->addLayout(buttonsLayout,gridRow,1);
00275 
00276        chooseFieldsDialogUpdateRadio1();
00277        chooseFieldsDialogUpdateRadio2();
00278        chooseFieldsDialogUpdateRadio3();
00279        chooseFieldsDialogUpdateRadio3b();
00280 
00281        //connect(pb, SIGNAL(clicked()), this, SLOT(accept()));
00282        connect(pb, SIGNAL(clicked()), this, SLOT(chooseFieldsDialogClose()));
00283        connect(cancelpb, SIGNAL(clicked()), this, SLOT(reject()));
00284        for(int i=1; i<NUMBER_OF_FIELDS; i++){
00285               connect(fieldRadio1[i], SIGNAL(toggled(bool)), this, SLOT(chooseFieldsDialogUpdateRadio1()));
00286               connect(fieldRadio2[i], SIGNAL(toggled(bool)), this, SLOT(chooseFieldsDialogUpdateRadio2()));
00287               connect(fieldRadio3[i], SIGNAL(toggled(bool)), this, SLOT(chooseFieldsDialogUpdateRadio3()));
00288               connect(fieldRadio3b[i], SIGNAL(toggled(bool)), this, SLOT(chooseFieldsDialogUpdateRadio3b()));
00289               connect(fieldLine3Text[i], SIGNAL(textChanged(QString)), this, SLOT(chooseFieldsDialogUpdateLine3Text()));
00290        }
00291        
00292        pb->setDefault(true);
00293        pb->setFocus();
00294        
00295        //_settingsName=settingsName;
00296        //restoreFETDialogGeometry(this, _settingsName);
00297 }
00298 
00299 ChooseFieldsDialog::~ChooseFieldsDialog()
00300 {
00301        //saveFETDialogGeometry(this, _settingsName);
00302 }
00303 
00304 void ChooseFieldsDialog::chooseFieldsDialogUpdateRadio1(){
00305        if(fieldRadio1[FIELD_GROUP_NAME]->isChecked()){
00306               fieldRadio1[FIELD_GROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00307               fieldRadio1[FIELD_SUBGROUP_NAME]->setChecked(true);
00308               fieldRadio1[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00309               fieldGroupBox[FIELD_GROUP_NUMBER_OF_STUDENTS]->setDisabled(true);
00310               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(true);
00311               fieldGroupBox[FIELD_SUBGROUP_NAME]->setDisabled(true);
00312        }
00313        if(fieldRadio1[FIELD_SUBGROUP_NAME]->isChecked()){
00314               fieldRadio1[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00315               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(true);
00316        }
00317        if(fieldRadio1[FIELD_ROOM_NAME]->isChecked()){
00318               fieldRadio1[FIELD_ROOM_CAPACITY]->setChecked(true);
00319               fieldGroupBox[FIELD_ROOM_CAPACITY]->setDisabled(true);
00320        }
00321        if(fieldRadio1[FIELD_BUILDING_NAME]->isChecked()&&fieldRadio1[FIELD_ROOM_NAME]->isChecked()){
00322               pb->setDisabled(true);
00323        }
00324        if((fieldRadio1[FIELD_BUILDING_NAME]->isChecked()&&!fieldRadio1[FIELD_ROOM_NAME]->isChecked()&&fieldLine3Text[FIELD_BUILDING_NAME]->displayText()!="")
00325               ||(!fieldRadio1[FIELD_BUILDING_NAME]->isChecked()&&fieldRadio1[FIELD_ROOM_NAME]->isChecked()&&fieldLine3Text[FIELD_BUILDING_NAME]->displayText()!="")){
00326               pb->setDisabled(false);
00327        }
00328 }
00329 
00330 
00331 void ChooseFieldsDialog::chooseFieldsDialogUpdateRadio2(){
00332        if(fieldRadio2[FIELD_GROUP_NAME]->isChecked()){
00333               fieldGroupBox[FIELD_SUBGROUP_NAME]->setDisabled(false);
00334               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00335               fieldGroupBox[FIELD_GROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00336               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00337               if(fieldRadio1[FIELD_GROUP_NUMBER_OF_STUDENTS]->isChecked())
00338                      fieldRadio3b[FIELD_GROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00339               if(fieldRadio1[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->isChecked())
00340                      fieldRadio3b[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00341        }
00342        if(fieldRadio2[FIELD_ROOM_NAME]->isChecked()){
00343               if(fieldRadio1[FIELD_ROOM_CAPACITY]->isChecked())
00344                      fieldRadio3b[FIELD_ROOM_CAPACITY]->setChecked(true);
00345               fieldGroupBox[FIELD_ROOM_CAPACITY]->setDisabled(false);
00346        }
00347 }
00348 
00349 
00350 void ChooseFieldsDialog::chooseFieldsDialogUpdateRadio3(){
00351        if(fieldRadio3[FIELD_GROUP_NAME]->isChecked()){
00352               fieldGroupBox[FIELD_SUBGROUP_NAME]->setDisabled(false);
00353               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00354               fieldGroupBox[FIELD_GROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00355               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00356               if(fieldRadio1[FIELD_GROUP_NUMBER_OF_STUDENTS]->isChecked())
00357                      fieldRadio3b[FIELD_GROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00358               if(fieldRadio1[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->isChecked())
00359                      fieldRadio3b[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00360        }
00361        if(fieldRadio3[FIELD_ROOM_NAME]->isChecked()){
00362               if(fieldRadio1[FIELD_ROOM_CAPACITY]->isChecked())
00363                      fieldRadio3b[FIELD_ROOM_CAPACITY]->setChecked(true);
00364               fieldGroupBox[FIELD_ROOM_CAPACITY]->setDisabled(false);
00365        }
00366 }
00367 
00368 void ChooseFieldsDialog::chooseFieldsDialogUpdateRadio3b(){
00369        if(fieldRadio3b[FIELD_GROUP_NAME]->isChecked()){
00370               fieldGroupBox[FIELD_SUBGROUP_NAME]->setDisabled(false);
00371               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00372               fieldGroupBox[FIELD_GROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00373               fieldGroupBox[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setDisabled(false);
00374               if(fieldRadio1[FIELD_GROUP_NUMBER_OF_STUDENTS]->isChecked())
00375                      fieldRadio3b[FIELD_GROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00376               if(fieldRadio1[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->isChecked())
00377                      fieldRadio3b[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]->setChecked(true);
00378        }
00379        if(fieldRadio3b[FIELD_ROOM_NAME]->isChecked()){
00380               if(fieldRadio1[FIELD_ROOM_CAPACITY]->isChecked())
00381                      fieldRadio3b[FIELD_ROOM_CAPACITY]->setChecked(true);
00382               fieldGroupBox[FIELD_ROOM_CAPACITY]->setDisabled(false);
00383        }
00384 }
00385 
00386 
00387 void ChooseFieldsDialog::chooseFieldsDialogUpdateLine3Text(){
00388        bool textOK=true;
00389        for(int i=1; i<NUMBER_OF_FIELDS; i++){
00390               if(fieldLine3Text[i]->displayText()=="")
00391                      textOK=false;
00392        }
00393        //by Liviu - always enabled
00394        if(1 || textOK)
00395               pb->setDisabled(false);
00396        else
00397               pb->setDisabled(true);
00398 }
00399 
00400 
00401 void ChooseFieldsDialog::chooseFieldsDialogClose(){
00402        for(int i=1; i<NUMBER_OF_FIELDS; i++){
00403               if(fieldNumber[i]!=DO_NOT_IMPORT){
00404                      if(fieldRadio1[i]->isChecked()){
00405                             fieldNumber[i]=DO_NOT_IMPORT;
00406                      }
00407                      if(fieldRadio2[i]->isChecked()){
00408                             fieldNumber[i]=fieldLine2CB[i]->currentIndex();
00409                             assert(fieldNumber[i]<fields.size());
00410                             assert(fieldNumber[i]>=0);
00411                      }
00412                      if(fieldRadio3[i]->isChecked()){
00413                             fieldNumber[i]=IMPORT_DEFAULT_ITEM;
00414                             //fieldName[i]=fieldLine3CB[i]->currentText();
00415                             fieldDefaultItem[i]=fieldLine3Text[i]->displayText();
00416                      }
00417                      if(fieldRadio3b[i]->isChecked()){
00418                             fieldNumber[i]=IMPORT_DEFAULT_ITEM;
00419                             fieldDefaultItem[i]=fieldLine3bSpinBox[i]->cleanText();
00420                      }
00421               }
00422        }
00423        
00424        this->accept();
00425 }
00426 
00427 
00428 LastWarningsDialog::LastWarningsDialog(QWidget *parent): QDialog(parent)
00429 {
00430        this->setWindowTitle(tr("FET - import %1 comment", "The comment of the importing of the category named %1").arg(importThing));
00431        QVBoxLayout* lastWarningsMainLayout=new QVBoxLayout(this);
00432 
00433        QPlainTextEdit* lastWarningsText=new QPlainTextEdit();
00434        lastWarningsText->setMinimumWidth(500);                        //width
00435        lastWarningsText->setMinimumHeight(250);
00436        lastWarningsText->setReadOnly(true);
00437        lastWarningsText->setWordWrapMode(QTextOption::NoWrap);
00438        lastWarningsText->setPlainText(lastWarning);
00439 
00440        //Start Buttons
00441        QPushButton* pb1=new QPushButton(tr("&OK"));
00442        //pb1->setAutoDefault(true);
00443 
00444        QHBoxLayout* hl=new QHBoxLayout();
00445        hl->addStretch();
00446        hl->addWidget(pb1);
00447 
00448        //Start adding all into main layout
00449        lastWarningsMainLayout->addWidget(lastWarningsText);
00450        lastWarningsMainLayout->addLayout(hl);
00451 
00452        QObject::connect(pb1, SIGNAL(clicked()), this, SLOT(accept()));
00453        
00454        //pb1->setDefault(true);
00455 
00456        pb1->setDefault(true);
00457        pb1->setFocus();
00458 }
00459 
00460 LastWarningsDialog::~LastWarningsDialog()
00461 {
00462 }
00463 
00464 // private funtions ---------------------------------------------------------------------------------------------------
00465 int Import::getFileSeparatorFieldsAndHead(QWidget* parent, QDialog* &newParent){
00466        assert(gt.rules.initialized);
00467        
00468        newParent=((QDialog*)parent);
00469        
00470        QString settingsName;
00471 
00472        if(fieldNumber[FIELD_ACTIVITY_TAG_NAME]==IMPORT_DEFAULT_ITEM){
00473               importThing=Import::tr("activity tags");
00474               settingsName=QString("ImportActivityTagsSelectSeparatorsDialog");
00475        }
00476        if(fieldNumber[FIELD_ROOM_NAME]==IMPORT_DEFAULT_ITEM){
00477               importThing=Import::tr("buildings and rooms");
00478               settingsName=QString("ImportBuildingsRoomsSelectSeparatorsDialog");
00479        }
00480        if(fieldNumber[FIELD_TEACHER_NAME]==IMPORT_DEFAULT_ITEM){
00481               importThing=Import::tr("teachers");
00482               settingsName=QString("ImportTeachersSelectSeparatorsDialog");
00483        }
00484        if(fieldNumber[FIELD_SUBJECT_NAME]==IMPORT_DEFAULT_ITEM){
00485               importThing=Import::tr("subjects");
00486               settingsName=QString("ImportSubjectsSelectSeparatorsDialog");
00487        }
00488        if(fieldNumber[FIELD_YEAR_NAME]==IMPORT_DEFAULT_ITEM){
00489               importThing=Import::tr("years, groups and subgroups");
00490               settingsName=QString("ImportYearsGroupsSubgroupsSelectSeparatorsDialog");
00491        }
00492        if(fieldNumber[FIELD_STUDENTS_SET]==IMPORT_DEFAULT_ITEM){
00493               importThing=Import::tr("activities");
00494               settingsName=QString("ImportActivitiesSelectSeparatorsDialog");
00495        }
00496 
00497        fileName=QFileDialog::getOpenFileName(parent, Import::tr("FET - Import %1 from CSV file").arg(importThing), IMPORT_DIRECTORY, 
00498               Import::tr("Text Files")+" (*.csv *.dat *.txt)" + ";;" + Import::tr("All Files") + " (*)");
00499 
00500        const QString NO_SEPARATOR_TRANSLATED=Import::tr("no separator");
00501        fieldSeparator=NO_SEPARATOR_TRANSLATED;   //needed, because a csv file contain maybe just one field!
00502        const QString NO_TEXTQUOTE_TRANSLATED=Import::tr("no textquote");
00503        textquote=NO_TEXTQUOTE_TRANSLATED;
00504        fields.clear();
00505        QFile file(fileName);
00506        if(fileName.isEmpty()){
00507               return false;
00508        }
00509        if(!file.open(QIODevice::ReadOnly|QIODevice::Text)){
00510               return false;
00511        }
00512        QTextStream in(&file);
00513        in.setCodec("UTF-8");
00514        QString line = in.readLine();
00515        file.close();
00516        
00517        if(line.size()<=0){
00518               QMessageBox::warning(parent, tr("FET warning"), tr("The first line of the file is empty. Please fix this."));
00519               return false;
00520        }
00521        
00522        if(fieldNumber[FIELD_ACTIVITY_TAG_NAME]==IMPORT_DEFAULT_ITEM
00523               && line.contains("\"Activity Tag\"")
00524               && line.size()<=QString("\"Activity Tag\"").length()+1
00525               && line.size()>=QString("\"Activity Tag\"").length()){
00526               fieldNumber[FIELD_ACTIVITY_TAG_NAME]=0;
00527               head=true;
00528               fieldSeparator=",";
00529               textquote="\"";
00530               fields<<line;
00531               return true;
00532        }
00533 
00534        if(fieldNumber[FIELD_ROOM_NAME]==IMPORT_DEFAULT_ITEM
00535               && line.contains("\"Room\",\"Room Capacity\",\"Building\"")
00536               && line.size()<=QString("\"Room\",\"Room Capacity\",\"Building\"").length()+1
00537               && line.size()>=QString("\"Room\",\"Room Capacity\",\"Building\"").length()){
00538               fieldNumber[FIELD_BUILDING_NAME]=2;
00539               fieldNumber[FIELD_ROOM_NAME]=0;
00540               fieldNumber[FIELD_ROOM_CAPACITY]=1;
00541               head=true;
00542               fieldSeparator=",";
00543               textquote="\"";
00544               fields=line.split(fieldSeparator);
00545               return true;
00546        }
00547 
00548        if(fieldNumber[FIELD_TEACHER_NAME]==IMPORT_DEFAULT_ITEM
00549               && line.contains("\"Teacher\"")
00550               && line.size()<=QString("\"Teacher\"").length()+1
00551               && line.size()>=QString("\"Teacher\"").length()){
00552               fieldNumber[FIELD_TEACHER_NAME]=0;
00553               head=true;
00554               fieldSeparator=",";
00555               textquote="\"";
00556               fields<<line;
00557               return true;
00558        }
00559 
00560        if(fieldNumber[FIELD_SUBJECT_NAME]==IMPORT_DEFAULT_ITEM
00561               && line.contains("\"Subject\"")
00562               && line.size()<=QString("\"Subject\"").length()+1
00563               && line.size()>=QString("\"Subject\"").length()){
00564               fieldNumber[FIELD_SUBJECT_NAME]=0;
00565               head=true;
00566               fieldSeparator=",";
00567               textquote="\"";
00568               fields<<line;
00569               return true;
00570        }
00571 
00572        if(fieldNumber[FIELD_YEAR_NAME]==IMPORT_DEFAULT_ITEM
00573               && line.contains("\"Year\",\"Number of Students per Year\",\"Group\",\"Number of Students per Group\",\"Subgroup\",\"Number of Students per Subgroup\"")
00574               && line.size()<=QString("\"Year\",\"Number of Students per Year\",\"Group\",\"Number of Students per Group\",\"Subgroup\",\"Number of Students per Subgroup\"").length()+1
00575               && line.size()>=QString("\"Year\",\"Number of Students per Year\",\"Group\",\"Number of Students per Group\",\"Subgroup\",\"Number of Students per Subgroup\"").length()){
00576               fieldNumber[FIELD_YEAR_NAME]=0;
00577               fieldNumber[FIELD_YEAR_NUMBER_OF_STUDENTS]=1;
00578               fieldNumber[FIELD_GROUP_NAME]=2;
00579               fieldNumber[FIELD_GROUP_NUMBER_OF_STUDENTS]=3;
00580               fieldNumber[FIELD_SUBGROUP_NAME]=4;
00581               fieldNumber[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]=5;
00582               head=true;
00583               fieldSeparator=",";
00584               textquote="\"";
00585               fields=line.split(fieldSeparator);
00586               return true;
00587        }
00588 
00589        if(fieldNumber[FIELD_STUDENTS_SET]==IMPORT_DEFAULT_ITEM
00590               && line.contains("\"Students Sets\",\"Subject\",\"Teachers\",\"Activity Tags\",\"Total Duration\",\"Split Duration\",\"Min Days\",\"Weight\",\"Consecutive\"")
00591               && line.size()<=QString("\"Students Sets\",\"Subject\",\"Teachers\",\"Activity Tags\",\"Total Duration\",\"Split Duration\",\"Min Days\",\"Weight\",\"Consecutive\"").length()+1
00592               && line.size()>=QString("\"Students Sets\",\"Subject\",\"Teachers\",\"Activity Tags\",\"Total Duration\",\"Split Duration\",\"Min Days\",\"Weight\",\"Consecutive\"").length()){
00593               fieldNumber[FIELD_ACTIVITY_TAGS_SET]=3;
00594               fieldNumber[FIELD_SUBJECT_NAME]=1;
00595               fieldNumber[FIELD_STUDENTS_SET]=0;
00596               fieldNumber[FIELD_TEACHERS_SET]=2;
00597               fieldNumber[FIELD_TOTAL_DURATION]=4;
00598               fieldNumber[FIELD_SPLIT_DURATION]=5;
00599               fieldNumber[FIELD_MIN_DAYS]=6;
00600               fieldNumber[FIELD_MIN_DAYS_WEIGHT]=7;
00601               fieldNumber[FIELD_MIN_DAYS_CONSECUTIVE]=8;
00602               head=true;
00603               fieldSeparator=",";
00604               textquote="\"";
00605               fields=line.split(fieldSeparator);
00606               return true;
00607        }
00608 
00609        QStringList separators;
00610        QStringList textquotes;
00611        separators<<fieldSeparator;
00612        const int NO_SEPARATOR_POS=0; //it is the first element. It may have length > 1 QChar
00613        textquotes<<textquote;
00614        const int NO_TEXTQUOTE_POS=0; //it is the first element. It may have length > 1 QChar
00615        for(int i=0; i<line.size();i++){
00616               //if(!(line.at(i)>='A'&&line.at(i)<='Z')&&!(line.at(i)>='a'&&line.at(i)<='z')&&!(line.at(i)>='0'&&line.at(i)<='9')&&!separators.contains(line.at(i))){
00617               if(!(line.at(i).isLetterOrNumber())&&!separators.contains(line.at(i))){
00618                      separators<<line.at(i);
00619                      //careful: if you intend to add strings longer than one QChar, take care of assert in line 647 (below in the same function) (fieldSeparator.size()==1)
00620               }
00621               if(!(line.at(i).isLetterOrNumber())&&!textquotes.contains(line.at(i))){
00622                      textquotes<<line.at(i);
00623                      //careful: if you intend to add strings longer than one QChar, take care of assert in line 659 (below in the same function) (textquote.size()==1)
00624               }
00625        }
00626 
00627        newParent=new QDialog(parent);
00628        QDialog& separatorsDialog=(*newParent);
00629        separatorsDialog.setWindowTitle(Import::tr("FET - Import %1 from CSV file").arg(importThing));
00630        QVBoxLayout* separatorsMainLayout=new QVBoxLayout(&separatorsDialog);
00631 
00632        QHBoxLayout* top=new QHBoxLayout();
00633        QLabel* topText=new QLabel();
00634 
00635        int tmpi=fileName.lastIndexOf(FILE_SEP);
00636        tmpi=fileName.size()-tmpi-1;
00637        QString shortFileName=fileName.right(tmpi);
00638        topText->setText(Import::tr("The first line of file\n%1\nis:").arg(shortFileName));
00639        top->addWidget(topText);
00640        top->addStretch();
00641        QPlainTextEdit* textOfFirstLine=new QPlainTextEdit();
00642        textOfFirstLine->setReadOnly(true);
00643        textOfFirstLine->setPlainText(line);
00644 
00645        QGroupBox* separatorsGroupBox = new QGroupBox(Import::tr("Please specify the used separator between fields:"));
00646        QComboBox* separatorsCB=NULL;
00647        if(separators.size()>1){
00648               QHBoxLayout* separatorBoxChoose=new QHBoxLayout();
00649               separatorsCB=new QComboBox();
00650               
00651               QLabel* separatorTextChoose=new QLabel();
00652               separatorTextChoose->setText(Import::tr("Used field separator:"));
00653               separatorsCB->insertItems(0,separators);
00654               separatorBoxChoose->addWidget(separatorTextChoose);
00655               separatorBoxChoose->addWidget(separatorsCB);
00656               separatorsGroupBox->setLayout(separatorBoxChoose);
00657        }
00658 
00659        QGroupBox* textquoteGroupBox = new QGroupBox(Import::tr("Please specify the used text quote of text fields:"));
00660        QComboBox* textquoteCB=NULL;
00661        if(separators.size()>1){
00662               QHBoxLayout* textquoteBoxChoose=new QHBoxLayout();
00663               textquoteCB=new QComboBox();
00664               
00665               QLabel* textquoteTextChoose=new QLabel();
00666               textquoteTextChoose->setText(Import::tr("Used textquote:"));
00667               textquoteCB->insertItems(0,textquotes);
00668               textquoteBoxChoose->addWidget(textquoteTextChoose);
00669               textquoteBoxChoose->addWidget(textquoteCB);
00670               textquoteGroupBox->setLayout(textquoteBoxChoose);
00671        }
00672 
00673        QGroupBox* firstLineGroupBox = new QGroupBox(Import::tr("Please specify the contents of the first line:"));
00674        QVBoxLayout* firstLineChooseBox=new QVBoxLayout();
00675        QRadioButton* firstLineRadio1 = new QRadioButton(Import::tr("The first line is the heading. Don't import that line."));
00676        QRadioButton* firstLineRadio2 = new QRadioButton(Import::tr("The first line contains data. Import that line."));
00677        firstLineRadio1->setChecked(true);
00678        firstLineChooseBox->addWidget(firstLineRadio1);
00679        firstLineChooseBox->addWidget(firstLineRadio2);
00680        firstLineGroupBox->setLayout(firstLineChooseBox);
00681 
00682        QPushButton* pb=new QPushButton(tr("OK"));
00683        QPushButton* cancelpb=new QPushButton(tr("Cancel"));
00684        QHBoxLayout* hl=new QHBoxLayout();
00685        hl->addStretch();
00686        hl->addWidget(pb);
00687        hl->addWidget(cancelpb);
00688        
00689        separatorsMainLayout->addLayout(top);
00690        separatorsMainLayout->addWidget(textOfFirstLine);
00691        if(separators.size()>1){
00692               separatorsMainLayout->addWidget(separatorsGroupBox);
00693               separatorsMainLayout->addWidget(textquoteGroupBox);
00694        }
00695        else{
00696               delete separatorsGroupBox;
00697               delete textquoteGroupBox;
00698        }
00699        separatorsMainLayout->addWidget(firstLineGroupBox);
00700        separatorsMainLayout->addLayout(hl);
00701        QObject::connect(pb, SIGNAL(clicked()), &separatorsDialog, SLOT(accept()));
00702        QObject::connect(cancelpb, SIGNAL(clicked()), &separatorsDialog, SLOT(reject()));
00703        
00704        pb->setDefault(true);
00705        pb->setFocus();
00706        
00707        int w=chooseWidth(separatorsDialog.sizeHint().width());
00708        int h=chooseHeight(separatorsDialog.sizeHint().height());
00709        separatorsDialog.resize(w,h);
00710        centerWidgetOnScreen(&separatorsDialog);
00711        restoreFETDialogGeometry(&separatorsDialog, settingsName);
00712        
00713        int ok=separatorsDialog.exec();
00714        saveFETDialogGeometry(&separatorsDialog, settingsName);
00715        if(!ok) return false;
00716        
00717        if(separators.size()>1){
00718               assert(separatorsCB!=NULL);
00719               assert(textquoteCB!=NULL);
00720               fieldSeparator=separatorsCB->currentText();
00721               
00722               if(separatorsCB->currentIndex()==NO_SEPARATOR_POS){
00723                      assert(fieldSeparator==NO_SEPARATOR_TRANSLATED);
00724                      fieldSeparator=QString("no sep"); //must have length >= 2
00725               }
00726               else{
00727                      assert(fieldSeparator.size()==1);
00728                      //assert(!fieldSeparator.at(0).isLetterOrNumber());
00729               }
00730               
00731               textquote=textquoteCB->currentText();
00732               
00733               if(textquoteCB->currentIndex()==NO_TEXTQUOTE_POS){
00734                      assert(textquote==NO_TEXTQUOTE_TRANSLATED);
00735                      textquote=QString("no tquote"); //must have length >= 2
00736               }
00737               else{
00738                      assert(textquote.size()==1);
00739                      //assert(!textquote.at(0).isLetterOrNumber());
00740               }
00741        }
00742        else{
00743               assert(separatorsCB==NULL);
00744               assert(textquoteCB==NULL);
00745               fieldSeparator="";
00746               textquote="";
00747        }
00748 //NEW start
00749                      QString tmp;
00750                      QString tmpLine=line;
00751                      while(!tmpLine.isEmpty()){
00752                             tmp.clear();
00753                             bool foundField=false;
00754                             if(tmpLine.left(1)==textquote){
00755                                    tmpLine.remove(0,1);
00756                                    while(!foundField && tmpLine.size()>1){
00757                                           if(tmpLine.left(1)!=textquote){
00758                                                  tmp+=tmpLine.left(1);
00759                                           } else {
00760                                                  if(tmpLine.mid(1,1)==fieldSeparator){
00761                                                         foundField=true;
00762                                                         tmpLine.remove(0,1);
00763                                                  } else if(tmpLine.mid(1,1)==textquote){
00764                                                         tmp+=textquote;
00765                                                         tmpLine.remove(0,1);
00766                                                  } else {
00767                                                         QMessageBox::critical(newParent, tr("FET warning"), Import::tr("Missing field separator or text quote in first line. Import might be incorrect.")+"\n");
00768                                                  }
00769                                           }
00770                                           tmpLine.remove(0,1);
00771                                    }
00772                                    if(!foundField && tmpLine.size()==1){
00773                                           if(tmpLine.left(1)==textquote){
00774                                                  tmpLine.remove(0,1);
00775                                           } else {
00776                                                  QMessageBox::critical(newParent, tr("FET warning"), Import::tr("Missing closing text quote in first line. Import might be incorrect.")+"\n");
00777                                                  tmp+=tmpLine.left(1);
00778                                                  tmpLine.remove(0,1);
00779                                           }
00780                                           
00781                                    }
00782                             } else {
00783                                    while(!foundField && !tmpLine.isEmpty()){
00784                                           if(tmpLine.left(1)!=fieldSeparator)
00785                                                  tmp+=tmpLine.left(1);
00786                                           else
00787                                                  foundField=true;
00788                                           tmpLine.remove(0,1);
00789                                    }
00790                             }
00791                             fields << tmp;
00792                             if(foundField && tmpLine.isEmpty())
00793                                    fields << "";
00794                      }
00795 //NEW end
00796 
00797 /* OLD
00798        if(separators.size()>1){
00799               fieldSeparator=separatorsCB->currentText();
00800               fields=line.split(fieldSeparator);
00801        } else {
00802               fieldSeparator=separators.takeFirst();
00803               fields<<line;
00804        }
00805 OLD */
00806 
00807        if(firstLineRadio1->isChecked())
00808               head=true;
00809        else head=false;
00810        return true;
00811 }
00812 
00813 int Import::readFields(QWidget* parent){
00814        QSet<QString> checkSet;
00815        QString check;
00816        numberOfFields=fields.size();
00817        assert(numberOfFields>0);
00818        for(int i=0; i<NUMBER_OF_FIELDS; i++){
00819               assert(fieldNumber[i]<=numberOfFields);
00820               assert(fieldNumber[i]>=DO_NOT_IMPORT);
00821        }
00822 
00823        QFile file(fileName);
00824        if(fileName.isEmpty()){
00825               QMessageBox::warning(parent, tr("FET warning"), tr("Empty filename."));
00826               return false;
00827        }
00828        if(!file.open(QIODevice::ReadOnly)){
00829               QMessageBox::warning(parent, tr("Error! Can't open file."),fileName);
00830               return false;
00831        }
00832        QTextStream in(&file);
00833        in.setCodec("UTF-8");
00834 
00835        qint64 size=file.size();
00836        QProgressDialog* _progress=new QProgressDialog(parent);
00837        QProgressDialog& progress=(*_progress);
00838        progress.setWindowTitle(tr("Importing", "Title of a progress dialog"));
00839        progress.setLabelText(tr("Loading file"));
00840        progress.setModal(true);
00841        progress.setRange(0, size);
00842        //cout<<"progress in readFields starts"<<endl;
00843        qint64 crt=0;
00844 
00845        QStringList fields;
00846        QString itemOfField[NUMBER_OF_FIELDS];
00847        int lineNumber=0;
00848        while(!in.atEnd()){
00849               progress.setValue(crt);
00850               QString line = in.readLine();
00851               lineNumber++;
00852         crt+=line.length();
00853               if(progress.wasCanceled()){
00854                      QMessageBox::warning(parent, "FET", Import::tr("Loading canceled by user."));
00855                      file.close();
00856                      return false;
00857               }
00858               bool ok=true;
00859               if(!(lineNumber==1&&head)){
00860                      fields.clear();
00861                      QString tmp;
00862                      QString tmpLine=line;
00863                      while(!tmpLine.isEmpty()){
00864                             tmp.clear();
00865                             bool foundField=false;
00866                             if(tmpLine.left(1)==textquote){
00867                                    tmpLine.remove(0,1);
00868                                    while(!foundField && tmpLine.size()>1){
00869                                           if(tmpLine.left(1)!=textquote){
00870                                                  tmp+=tmpLine.left(1);
00871                                           } else {
00872                                                  if(tmpLine.mid(1,1)==fieldSeparator){
00873                                                         foundField=true;
00874                                                         tmpLine.remove(0,1);
00875                                                  } else if(tmpLine.mid(1,1)==textquote){
00876                                                         tmp+=textquote;
00877                                                         tmpLine.remove(0,1);
00878                                                  } else
00879                                                         warnText+=Import::tr("Warning: FET expected field separator or text separator in line %1. Import might be incorrect.").arg(lineNumber)+"\n";
00880                                           }
00881                                           tmpLine.remove(0,1);
00882                                    }
00883                                    if(!foundField && tmpLine.size()==1){
00884                                           if(tmpLine.left(1)==textquote){
00885                                                  tmpLine.remove(0,1);
00886                                           } else {
00887                                                  warnText+=Import::tr("Warning: FET expected closing text separator in line %1. Import might be incorrect.").arg(lineNumber)+"\n";
00888                                                  tmp+=tmpLine.left(1);
00889                                                  tmpLine.remove(0,1);
00890                                           }
00891                                           
00892                                    }
00893                             } else {
00894                                    while(!foundField && !tmpLine.isEmpty()){
00895                                           if(tmpLine.left(1)!=fieldSeparator)
00896                                                  tmp+=tmpLine.left(1);
00897                                           else
00898                                                  foundField=true;
00899                                           tmpLine.remove(0,1);
00900                                    }
00901                             }
00902                             fields << tmp;
00903                             if(foundField && tmpLine.isEmpty())
00904                                    fields << "";
00905                      }
00906 /*
00907                      if(separator.size()==1){
00908                             fields = line.split(separator);
00909                      } else
00910                             fields << line;
00911 */
00912                      if(numberOfFields!=fields.size()){
00913                             warnText+=Import::tr("Skipped line %1: FET expected %2 fields but found %3 fields.").arg(lineNumber).arg(numberOfFields).arg(fields.size())+"\n";
00914                             ok=false;
00915                      } else {
00916                             for(int i=0; i<NUMBER_OF_FIELDS; i++){
00917                                    if(fieldNumber[i]>=0){
00918                                           itemOfField[i].clear();
00919                                           itemOfField[i] = fields[fieldNumber[i]];
00920                                           if(itemOfField[i].isEmpty()){
00921                                                  if(i==FIELD_YEAR_NAME || i==FIELD_TEACHER_NAME || i==FIELD_SUBJECT_NAME){
00922                                                         warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(lineNumber).arg(fieldName[i])+"\n";
00923                                                         ok=false;
00924                                                  }
00925                                                  if(i==FIELD_YEAR_NUMBER_OF_STUDENTS || i==FIELD_GROUP_NUMBER_OF_STUDENTS || i==FIELD_SUBGROUP_NUMBER_OF_STUDENTS){
00926                                                         itemOfField[i]="0";
00927                                                  }
00928                                                  //if(i==FIELD_SUBGROUP_NAME) is OK
00929                                                  //if(i==FIELD_ACTIVITY_TAG_NAME) is OK
00930                                                  //if(i==FIELD_ROOM_NAME) is OK
00931                                                  if(i==FIELD_ROOM_CAPACITY){
00932                                                         itemOfField[i]==fieldDefaultItem[i];
00933                                                  }
00934                                                  if(i==FIELD_MIN_DAYS){
00935                                                         itemOfField[i]="0";
00936                                                  }
00937                                                  if(i==FIELD_MIN_DAYS_WEIGHT){
00938                                                         if(itemOfField[FIELD_MIN_DAYS].isEmpty()){
00939                                                                ok=false;
00940                                                                warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(lineNumber).arg(fieldName[FIELD_MIN_DAYS])+"\n";
00941                                                         } else 
00942                                                                itemOfField[i]="95";
00943                                                  }
00944                                                  if(i==FIELD_MIN_DAYS_CONSECUTIVE){
00945                                                         if(itemOfField[FIELD_MIN_DAYS].isEmpty()){
00946                                                                ok=false;
00947                                                                warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(lineNumber).arg(fieldName[FIELD_MIN_DAYS])+"\n";
00948                                                         } else 
00949                                                                itemOfField[i]="N";
00950                                                  }
00951                                           }
00952                                           if(ok && i==FIELD_SUBGROUP_NAME && !itemOfField[FIELD_SUBGROUP_NAME].isEmpty() && itemOfField[FIELD_GROUP_NAME].isEmpty()){
00953                                                  warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(lineNumber).arg(fieldName[FIELD_GROUP_NAME])+"\n";
00954                                                  ok=false;
00955                                           }
00956                                           if(ok && i==FIELD_SPLIT_DURATION){
00957                                                  if(itemOfField[FIELD_SPLIT_DURATION].isEmpty()){
00958                                                         if(!itemOfField[FIELD_TOTAL_DURATION].isEmpty()){
00959                                                                int totalInt=itemOfField[FIELD_TOTAL_DURATION].toInt(&ok, 10);
00960                                                                if(ok && totalInt>=1){
00961                                                                       if(totalInt<=MAX_SPLIT_OF_AN_ACTIVITY){
00962                                                                              QString tmpString;
00963                                                                              for(int n=0; n<totalInt; n++){
00964                                                                                     if(n!=0)
00965                                                                                            tmpString+="+";
00966                                                                                     tmpString+="1";
00967                                                                              }
00968                                                                              itemOfField[FIELD_SPLIT_DURATION]=tmpString;
00969                                                                       } else {
00970                                                                              warnText+=Import::tr("Skipped line %1: Field '%2' produces too many subactivities.").arg(lineNumber).arg(fieldName[FIELD_TOTAL_DURATION])+"\n";
00971                                                                              ok=false;
00972                                                                       }
00973                                                                } else {
00974                                                                       warnText+=Import::tr("Skipped line %1: Field '%2' contain incorrect data.").arg(lineNumber).arg(fieldName[FIELD_TOTAL_DURATION])+"\n";
00975                                                                       ok=false;
00976                                                                }
00977                                                         } else {
00978                                                                warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(lineNumber).arg(fieldName[i])+"\n";
00979                                                                ok=false;
00980                                                         }
00981                                                  } else {
00982                                                         QStringList splittedList;
00983                                                         if(itemOfField[FIELD_SPLIT_DURATION].count("+")<MAX_SPLIT_OF_AN_ACTIVITY){
00984                                                                splittedList = itemOfField[FIELD_SPLIT_DURATION].split("+");
00985                                                                int tmpInt=0;
00986                                                                QString splitted;
00987                                                                while(ok && !splittedList.isEmpty()){
00988                                                                       splitted=splittedList.takeFirst();
00989                                                                       tmpInt+=splitted.toInt(&ok, 10);
00990                                                                       if(!ok)
00991                                                                              warnText+=Import::tr("Skipped line %1: Field '%2' doesn't contain an integer value.").arg(lineNumber).arg(fieldName[FIELD_SPLIT_DURATION])+"\n";
00992                                                                }
00993                                                                if(itemOfField[FIELD_TOTAL_DURATION].isEmpty()){
00994                                                                       itemOfField[FIELD_TOTAL_DURATION]=CustomFETString::number(tmpInt);    
00995                                                                } else {
00996                                                                       int totalInt=itemOfField[FIELD_TOTAL_DURATION].toInt(&ok, 10);
00997                                                                       if(totalInt!=tmpInt){
00998                                                                              warnText+=Import::tr("Skipped line %1: Fields '%2' and '%3' haven't the same value.").arg(lineNumber).arg(fieldName[i]).arg(fieldName[FIELD_TOTAL_DURATION])+"\n";
00999                                                                              ok=false;
01000                                                                       }
01001                                                                }
01002                                                         } else {
01003                                                                warnText+=Import::tr("Skipped line %1: Field '%2' contains too many subactivities.").arg(lineNumber).arg(fieldName[i])+"\n";
01004                                                                ok=false;
01005                                                         }
01006                                                  }
01007                                           }
01008                                           if(ok && !itemOfField[FIELD_BUILDING_NAME].isEmpty() && itemOfField[FIELD_ROOM_NAME].isEmpty() && i==FIELD_ROOM_NAME){
01009                                                  warnText+=Import::tr("Warning in line %1: Field with building name doesn't affect to a room").arg(lineNumber)+"\n";
01010                                           }
01011                                           if(ok && (i==FIELD_YEAR_NUMBER_OF_STUDENTS || i==FIELD_GROUP_NUMBER_OF_STUDENTS || i==FIELD_SUBGROUP_NUMBER_OF_STUDENTS || i==FIELD_ROOM_CAPACITY || i==FIELD_TOTAL_DURATION || i==FIELD_MIN_DAYS)){
01012                                                  if(!itemOfField[i].isEmpty()){
01013                                                         int value=itemOfField[i].toInt(&ok, 10);
01014                                                         if(!ok)
01015                                                                warnText+=Import::tr("Skipped line %1: Field '%2' doesn't contain an integer value.").arg(lineNumber).arg(fieldName[i])+"\n";
01016                                                         else {
01017                                                                if(value<0){
01018                                                                       warnText+=Import::tr("Skipped line %1: Field '%2' contains an invalid integer value.").arg(lineNumber).arg(fieldName[i])+"\n";
01019                                                                       ok=false;
01020                                                                }
01021                                                         }
01022                                                  } else if(i==FIELD_TOTAL_DURATION){
01023                                                          assert(true);
01024                                                  }else{
01025                                                         ok=false;
01026                                                         warnText+=Import::tr("Skipped line %1: Field '%2' doesn't contain an integer value.").arg(lineNumber).arg(fieldName[i])+"\n";
01027                                                         //because of bug reported by murad on 25 May 2010, crash when importing rooms, if capacity is empty
01028                                                         //assert(false);
01029                                                  }
01030                                           }
01031                                           if(ok && i==FIELD_MIN_DAYS_WEIGHT){
01032 //                                               double weight=itemOfField[i].toDouble(&ok);
01033                                                  double weight=customFETStrToDouble(itemOfField[i], &ok);
01034                                                  if(!ok)
01035                                                         warnText+=Import::tr("Skipped line %1: Field '%2' doesn't contain a number (double) value.").arg(lineNumber).arg(fieldName[i])+"\n";
01036                                                  else {
01037                                                         if(weight<0.0 || weight>100.0){
01038                                                                warnText+=Import::tr("Skipped line %1: Field '%2' contains an number (double) value.").arg(lineNumber).arg(fieldName[i])+"\n";
01039                                                                ok=false;
01040                                                         }
01041                                                  }
01042                                           }
01043                                           if(ok && i==FIELD_MIN_DAYS_CONSECUTIVE){
01044                                                  QString tmpString;
01045                                                  tmpString=itemOfField[i];
01046                                                  tmpString=tmpString.toUpper();
01047                                                  if(tmpString=="Y" || tmpString=="YES" ||  tmpString=="T" || tmpString=="TRUE" || tmpString=="1")
01048                                                         itemOfField[i]="yes";
01049                                                  else if(tmpString=="N" || tmpString=="NO" || tmpString=="F" || tmpString=="FALSE" || tmpString=="0")
01050                                                         itemOfField[i]="no";
01051                                                  else
01052                                                         ok=false;
01053                                                  if(!ok)
01054                                                         warnText+=Import::tr("Skipped line %1: Field '%2' contain an unknown value.").arg(lineNumber).arg(fieldName[i])+"\n";
01055                                           }
01056                                    } else if(fieldNumber[i]==IMPORT_DEFAULT_ITEM){
01057                                           itemOfField[i].clear();
01058                                           itemOfField[i] = fieldDefaultItem[i];
01059                                           //Removed by Liviu - we may have empty default fields
01060                                           //assert(!fieldDefaultItem[i].isEmpty());
01061                                    }
01062                             }
01063                      }
01064                      if(ok){
01065                             check.clear();
01066                             for(int i=0; i<NUMBER_OF_FIELDS; i++){
01067                                    check+=itemOfField[i]+" ";
01068                             }
01069                             if(checkSet.contains(check)){
01070                                    if(fieldNumber[FIELD_SPLIT_DURATION]!=DO_NOT_IMPORT||fieldNumber[FIELD_TOTAL_DURATION]!=DO_NOT_IMPORT){
01071                                           warnText+=Import::tr("Note about line %1: Data was already in a previous line. So this data will be imported once again.").arg(lineNumber)+"\n";
01072                                    } else {
01073                                           warnText+=Import::tr("Skipped line %1: Data was already in a previous line.").arg(lineNumber)+"\n";
01074                                           ok=false;
01075                                    }
01076                             } else
01077                                    checkSet<<check;
01078                      }
01079                      if(ok){
01080                             //QString tmp;
01081                             //tmp=tr("%1").arg(lineNumber);
01082                             //itemOfField[FIELD_LINE_NUMBER]=tmp;
01083                             itemOfField[FIELD_LINE_NUMBER]=CustomFETString::number(lineNumber);
01084                             for(int i=0; i<NUMBER_OF_FIELDS; i++){
01085                                    if(fieldNumber[i]!=DO_NOT_IMPORT)
01086                                           fieldList[i]<<itemOfField[i];
01087                             }
01088                      } else 
01089                             warnText+="   "+Import::tr("Line %1 is: %2").arg(lineNumber).arg(line)+"\n";
01090               }
01091        }
01092        progress.setValue(size);
01093        //cout<<"progress in readFields ends"<<endl;
01094        int max=0;
01095        for(int i=0; i<NUMBER_OF_FIELDS; i++){
01096               if(max==0)
01097                      max=fieldList[i].size();
01098               if(fieldNumber[i]>DO_NOT_IMPORT){
01099                      assert(fieldList[i].size()==max);
01100               }
01101               else
01102                      assert(fieldList[i].isEmpty());
01103        }
01104        file.close();
01105        return true;
01106 }
01107 
01108 
01109 int Import::showFieldsAndWarnings(QWidget* parent, QDialog* &newParent){
01110        newParent=((QDialog*)parent);
01111 
01112        int ok=true;
01113 
01114        int max=0;
01115        for(int i=0; i<NUMBER_OF_FIELDS; i++){
01116               if(fieldNumber[i]>DO_NOT_IMPORT){
01117                      if(max==0)
01118                             max=fieldList[i].size();
01119                      assert(fieldList[i].size()==max);
01120               }
01121               else{
01122                      if(i!=FIELD_TEACHER_NAME){         //needed for activities!
01123                             //assert(fieldList[i].isEmpty());
01124                             //because of bug reported 17.03.2008. Please add again?! compare add activities function
01125                      }
01126               }
01127        }
01128        // Start Dialog
01129        newParent=new QDialog(parent);
01130        QDialog& addItemsDialog=(*newParent);
01131        addItemsDialog.setWindowTitle(Import::tr("FET import %1 question").arg(importThing));
01132        QVBoxLayout* addItemsMainLayout=new QVBoxLayout(&addItemsDialog);
01133 
01134        //Start Warnings
01135        QHBoxLayout* headWarnings=new QHBoxLayout();
01136        QLabel* headWarningsText=new QLabel();
01137 
01138        int tmp=fileName.lastIndexOf(FILE_SEP);
01139        tmp=fileName.size()-tmp-1;
01140        QString shortFileName=fileName.right(tmp);
01141        if(!warnText.isEmpty())
01142               headWarningsText->setText(Import::tr("There are several problems in file\n%1").arg(shortFileName));
01143        else
01144               headWarningsText->setText(Import::tr("There are no problems in file\n%1").arg(shortFileName));
01145 
01146 //TODO
01147 /*
01148 tr("There are no problems in file")
01149 +
01150 "\n"
01151 +
01152 FILE_STRIPPED_NAME
01153 */
01154 
01155        headWarnings->addWidget(headWarningsText);
01156        headWarnings->addStretch();
01157 
01158        QPlainTextEdit* textOfWarnings=new QPlainTextEdit();
01159        textOfWarnings->setMinimumWidth(500);                   //width
01160        textOfWarnings->setReadOnly(true);
01161        textOfWarnings->setWordWrapMode(QTextOption::NoWrap);
01162        textOfWarnings->setPlainText(warnText);
01163 
01164        //Start data table
01165        QLabel* headTableText=new QLabel();
01166        if(max!=0)
01167               headTableText->setText(Import::tr("Following data found in the file:"));
01168        else
01169               headTableText->setText(Import::tr("There is no usable data in the file."));
01170 
01171        QTableWidget* fieldsTable= new QTableWidget;
01172        fieldsTable->setRowCount(max);
01173        QStringList fieldsTabelLabel;
01174 
01175        int colums=0;
01176        for(int i=0; i<NUMBER_OF_FIELDS; i++){
01177               if(fieldNumber[i]>DO_NOT_IMPORT){
01178                      fieldsTabelLabel<<tr("%1").arg(fieldName[i]);
01179                      colums++;
01180               }
01181        }
01182        fieldsTable->setColumnCount(colums);
01183        fieldsTable->setHorizontalHeaderLabels(fieldsTabelLabel);
01184        for(int i=0; i<max; i++){
01185               int colum=0;
01186               for(int f=0; f<NUMBER_OF_FIELDS; f++){
01187                      if(fieldNumber[f]>DO_NOT_IMPORT){
01188                             QTableWidgetItem* newItem=new QTableWidgetItem(fieldList[f][i]);
01189                             newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01190                             fieldsTable->setItem(i, colum, newItem);
01191                             colum++;
01192                      }
01193               }
01194        }
01195        fieldsTable->resizeColumnsToContents();
01196        fieldsTable->resizeRowsToContents();
01197 
01198        //Start current data warning
01199        QVBoxLayout* dataWarningBox=new QVBoxLayout();
01200        QLabel* dataWarningText=new QLabel();
01201        if(dataWarning.size()==1)
01202               dataWarningText->setText(Import::tr("FET noticed %1 warning with the current data.").arg(dataWarning.size()));
01203        else
01204               dataWarningText->setText(Import::tr("FET noticed %1 warnings with the current data.").arg(dataWarning.size()));
01205        dataWarningBox->addWidget(dataWarningText);
01206 
01207        QListWidget* dataWarningItems=new QListWidget();
01208        dataWarningItems->addItems(dataWarning);
01209        if(dataWarning.size()>0)
01210               dataWarningBox->addWidget(dataWarningItems);
01211        else
01212               delete dataWarningItems;
01213 
01214        //Start Buttons
01215        QPushButton* pb1=new QPushButton(tr("&Import"));
01216        QPushButton* pb2=new QPushButton(tr("&Cancel"));
01217 
01218        //TODO: why doesn't work this?
01219        //if((dataWarning.size()>0&&dataWarning.size()==max)||!warnText.isEmpty())
01220        //     pb2->setDefault(true);
01221        //else
01222        //      pb1->setDefault(true);
01223        //      pb1->setFocus();
01224               // pb1->setAutoDefault(true);
01225 
01226        QHBoxLayout* hl=new QHBoxLayout();
01227        hl->addStretch();
01228        hl->addWidget(pb1);
01229        hl->addWidget(pb2);
01230 
01231        //Start adding all into main layout
01232        addItemsMainLayout->addLayout(headWarnings);
01233        if(!warnText.isEmpty())
01234               addItemsMainLayout->addWidget(textOfWarnings);
01235        else
01236               delete textOfWarnings;
01237        addItemsMainLayout->addWidget(headTableText);
01238        if(max!=0)
01239               addItemsMainLayout->addWidget(fieldsTable);
01240        else
01241               delete fieldsTable;
01242        addItemsMainLayout->addLayout(dataWarningBox);
01243        addItemsMainLayout->addLayout(hl);
01244 
01245        QObject::connect(pb1, SIGNAL(clicked()), &addItemsDialog, SLOT(accept()));
01246        QObject::connect(pb2, SIGNAL(clicked()), &addItemsDialog, SLOT(reject()));
01247 
01248        //pb1->setDefault(true);
01249        
01250        int w=chooseWidth(addItemsDialog.sizeHint().width());
01251        int h=chooseHeight(addItemsDialog.sizeHint().height());
01252        addItemsDialog.resize(w,h);
01253        
01254        QString settingsName;
01255        if(importThing==Import::tr("activity tags"))
01256               settingsName=QString("ImportActivityTagsShowFieldsAndWarningsDialog");
01257        else if(importThing==Import::tr("buildings and rooms"))
01258               settingsName=QString("ImportBuildingsRoomsShowFieldsAndWarningsDialog");
01259        else if(importThing==Import::tr("teachers"))
01260               settingsName=QString("ImportTeachersShowFieldsAndWarningsDialog");
01261        else if(importThing==Import::tr("subjects"))
01262               settingsName=QString("ImportSubjectsShowFieldsAndWarningsDialog");
01263        else if(importThing==Import::tr("years, groups and subgroups"))
01264               settingsName=QString("ImportYearsGroupsSubgroupsShowFieldsAndWarningsDialog");
01265        else if(importThing==Import::tr("activities"))
01266               settingsName=QString("ImportActivitiesShowFieldsAndWarningsDialog");
01267        
01268        pb1->setDefault(true);
01269        pb1->setFocus();
01270 
01271        centerWidgetOnScreen(&addItemsDialog);
01272        restoreFETDialogGeometry(&addItemsDialog, settingsName);
01273 
01274        ok=addItemsDialog.exec();
01275        saveFETDialogGeometry(&addItemsDialog, settingsName);
01276        
01277        return ok;
01278 }
01279 
01280 void Import::importCSVActivityTags(QWidget* parent){
01281        prearrangement();
01282        fieldNumber[FIELD_ACTIVITY_TAG_NAME]=IMPORT_DEFAULT_ITEM;
01283        int ok;
01284 
01285        QDialog* newParent;
01286        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01287        //DON'T ADD THIS! newParent->deleteLater();
01288        if(!ok)       return;
01289 
01290        if(fieldNumber[FIELD_ACTIVITY_TAG_NAME]==IMPORT_DEFAULT_ITEM){
01291               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01292               const QString settingsName=QString("ImportActivityTagsChooseFieldsDialog");
01293               //DON'T ADD THIS! newParent2->deleteLater();
01294               newParent=newParent2;
01295               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01296               int w= chooseWidth(cfd.sizeHint().width());
01297               int h= chooseHeight(cfd.sizeHint().height());
01298               cfd.resize(w,h);
01299               centerWidgetOnScreen(&cfd);
01300               restoreFETDialogGeometry(&cfd, settingsName);
01301               
01302               ok=cfd.exec();
01303               saveFETDialogGeometry(&cfd, settingsName);
01304               if(!ok)       return;
01305        }
01306 
01307        ok = readFields(newParent);
01308        if(!ok) return;
01309 
01310        //check empty fields (start)
01311        for(int i=0; i<fieldList[FIELD_ACTIVITY_TAG_NAME].size(); i++){
01312               if(fieldList[FIELD_ACTIVITY_TAG_NAME][i].isEmpty())
01313                      warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_ACTIVITY_TAG_NAME])+"\n";
01314        }
01315        //check empty fields (end)
01316 
01317        //check if already in memory (start)
01318        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
01319               ActivityTag* a=gt.rules.activityTagsList[i];
01320               if(fieldList[FIELD_ACTIVITY_TAG_NAME].contains(a->name))
01321                      dataWarning<<Import::tr("%1 is already in FET data.").arg(a->name);
01322        }
01323        //check if already in memory (end)
01324        QDialog* newParent2;
01325        ok = showFieldsAndWarnings(newParent, newParent2);
01326        //DON'T ADD THIS! newParent2->deleteLater();
01327        newParent=newParent2;
01328        if(!ok) return;
01329 
01330        //add subjects (start) - similar to teachersform.cpp by Liviu modified by Volker
01331        int count=0;
01332        for(int i=0; i<fieldList[FIELD_ACTIVITY_TAG_NAME].size(); i++){
01333               if(!fieldList[FIELD_ACTIVITY_TAG_NAME][i].isEmpty()){
01334                      ActivityTag* a=new ActivityTag();
01335                      a->name=fieldList[FIELD_ACTIVITY_TAG_NAME][i];
01336                      if(!gt.rules.addActivityTag(a)){
01337                             delete a;
01338                      } else count++;
01339               }
01340        }
01341        QMessageBox::information(newParent, tr("FET information"), Import::tr("%1 activity tags added. Please check activity tag form.").arg(count));
01342        //add subjects (end) - similar to teachersform.cpp by Liviu modified by Volker
01343        int tmp=fileName.lastIndexOf(FILE_SEP);
01344        IMPORT_DIRECTORY=fileName.left(tmp);
01345        gt.rules.internalStructureComputed=false;
01346 }
01347 
01348 
01349 void Import::importCSVRoomsAndBuildings(QWidget* parent){
01350        prearrangement();
01351        fieldNumber[FIELD_ROOM_NAME]=IMPORT_DEFAULT_ITEM;
01352        fieldNumber[FIELD_ROOM_CAPACITY]=IMPORT_DEFAULT_ITEM;
01353        fieldNumber[FIELD_BUILDING_NAME]=IMPORT_DEFAULT_ITEM;
01354        int ok;
01355 
01356        QDialog* newParent;
01357        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01358        //DON'T ADD THIS! newParent->deleteLater();
01359        if(!ok)       return;
01360 
01361        if(fieldNumber[FIELD_ROOM_NAME]==IMPORT_DEFAULT_ITEM){
01362               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01363               const QString settingsName=QString("ImportRoomsBuildingsChooseFieldsDialog");
01364               //DON'T ADD THIS! newParent2->deleteLater();
01365               newParent=newParent2;
01366               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01367               int w= chooseWidth(cfd.sizeHint().width());
01368               int h= chooseHeight(cfd.sizeHint().height());
01369               cfd.resize(w,h);
01370               centerWidgetOnScreen(&cfd);
01371               restoreFETDialogGeometry(&cfd, settingsName);
01372 
01373               ok=cfd.exec();
01374               saveFETDialogGeometry(&cfd, settingsName);
01375        }
01376 
01377        if(!ok)       return;
01378 
01379        ok = readFields(newParent);
01380        if(!ok) return;
01381 
01382        QStringList duplicatesCheck;
01383        //check duplicates of rooms in cvs
01384        if(fieldNumber[FIELD_ROOM_NAME]!=DO_NOT_IMPORT)
01385               for(int i=0; i<fieldList[FIELD_ROOM_NAME].size(); i++)
01386                      if(duplicatesCheck.contains(fieldList[FIELD_ROOM_NAME][i]))
01387                             warnText+=Import::tr("Skipped line %1: Field '%2' is already in a previous line.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_ROOM_NAME])+"\n";
01388                      else
01389                             duplicatesCheck<<fieldList[FIELD_ROOM_NAME][i];
01390        duplicatesCheck.clear();
01391        //check duplicates of buildings in cvs. only if no room is imported.
01392        if(fieldNumber[FIELD_ROOM_NAME]==DO_NOT_IMPORT&&fieldNumber[FIELD_BUILDING_NAME]!=DO_NOT_IMPORT)
01393               for(int i=0; i<fieldList[FIELD_BUILDING_NAME].size(); i++)
01394                      if(duplicatesCheck.contains(fieldList[FIELD_BUILDING_NAME][i]))
01395                             warnText+=Import::tr("Skipped line %1: Field '%2' is already in a previous line.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_BUILDING_NAME])+"\n";
01396                      else
01397                             duplicatesCheck<<fieldList[FIELD_BUILDING_NAME][i];
01398        duplicatesCheck.clear();
01399        //check empty rooms (start)
01400        if(fieldNumber[FIELD_ROOM_NAME!=DO_NOT_IMPORT])
01401               for(int i=0; i<fieldList[FIELD_ROOM_NAME].size(); i++)
01402                      if(fieldList[FIELD_ROOM_NAME][i].isEmpty())
01403                             warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_ROOM_NAME])+"\n";
01404        //check empty rooms (end)
01405        //check empty buildings (start)
01406        if((fieldNumber[FIELD_ROOM_NAME]==DO_NOT_IMPORT||fieldNumber[FIELD_ROOM_NAME]==IMPORT_DEFAULT_ITEM)&&fieldNumber[FIELD_BUILDING_NAME!=DO_NOT_IMPORT])
01407               for(int i=0; i<fieldList[FIELD_BUILDING_NAME].size(); i++)
01408                      if(fieldList[FIELD_BUILDING_NAME][i].isEmpty())
01409                             warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_BUILDING_NAME])+"\n";
01410        //check empty buildings (end)
01411 
01412        //check if rooms are already in memory (start)
01413        QStringList dataWarning;
01414        for(int i=0; i<gt.rules.roomsList.size(); i++){
01415               Room* r=gt.rules.roomsList[i];
01416               if(fieldList[FIELD_ROOM_NAME].contains(r->name))
01417                      dataWarning<<Import::tr("%1 is already in FET data.").arg(r->name);
01418        }
01419        //check if rooms are already in memory (end)
01420 
01421        //check if buildings are already in memory (start)
01422        if(fieldNumber[FIELD_ROOM_NAME]<0){
01423               for(int i=0; i<gt.rules.buildingsList.size(); i++){
01424                      Building* b=gt.rules.buildingsList[i];
01425                      if(fieldList[FIELD_BUILDING_NAME].contains(b->name))
01426                             dataWarning<<Import::tr("%1 is already in FET data.").arg(b->name);
01427               }
01428        }
01429        //check if buildings are already in memory (end)
01430 
01431        QDialog* newParent2;
01432        ok = showFieldsAndWarnings(newParent, newParent2);
01433        //DON'T ADD THIS! newParent2->deleteLater();
01434        newParent=newParent2;
01435        if(!ok) return;
01436 
01437        //add buildings (start) - similar to teachersform.cpp by Liviu modified by Volker
01438        int count=0;
01439        for(int i=0; i<fieldList[FIELD_BUILDING_NAME].size(); i++){
01440               if(!fieldList[FIELD_BUILDING_NAME][i].isEmpty()){
01441                      Building* b=new Building();
01442                      b->name=fieldList[FIELD_BUILDING_NAME][i];
01443                      if(!gt.rules.addBuilding(b)){
01444                             delete b;
01445                      } else count++;
01446               }
01447        }
01448        //add buildings (end) - similar to teachersform.cpp by Liviu modified by Volker
01449 
01450        //add rooms (start) - similar to teachersform.cpp by Liviu modified by Volker
01451        int countroom=0;
01452        for(int i=0; i<fieldList[FIELD_BUILDING_NAME].size(); i++){
01453               if(!fieldList[FIELD_ROOM_NAME][i].isEmpty()){
01454                      Room* r=new Room();
01455                      r->name=fieldList[FIELD_ROOM_NAME][i];
01456                      if(fieldNumber[FIELD_BUILDING_NAME]!=DO_NOT_IMPORT)
01457                             r->building=fieldList[FIELD_BUILDING_NAME][i];
01458                      else
01459                             r->building="";
01460                      if(fieldNumber[FIELD_ROOM_CAPACITY]!=DO_NOT_IMPORT){
01461                             QString tmpInt=fieldList[FIELD_ROOM_CAPACITY][i];
01462                             r->capacity=tmpInt.toInt();
01463                      }
01464                      else
01465                             assert(0==1);
01466                      if(!gt.rules.addRoom(r)){
01467                             delete r;
01468                      } else countroom++;
01469               }
01470        }
01471        //add rooms (end) - similar to teachersform.cpp by Liviu modified by Volker
01472        QMessageBox::information(newParent, tr("FET information"), 
01473         Import::tr("%1 buildings added. Please check rooms form.").arg(count)+"\n"+tr("%2 rooms added. Please check rooms form.").arg(countroom));
01474 
01475        int tmp=fileName.lastIndexOf(FILE_SEP);
01476        IMPORT_DIRECTORY=fileName.left(tmp);
01477        gt.rules.internalStructureComputed=false;
01478 }
01479 
01480 void Import::importCSVSubjects(QWidget* parent){
01481        prearrangement();
01482        fieldNumber[FIELD_SUBJECT_NAME]=IMPORT_DEFAULT_ITEM;
01483        int ok;
01484 
01485        QDialog* newParent;
01486        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01487        //DON'T ADD THIS! newParent->deleteLater();
01488        if(!ok)       return;
01489 
01490        if(fieldNumber[FIELD_SUBJECT_NAME]==IMPORT_DEFAULT_ITEM){
01491               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01492               const QString settingsName=QString("ImportSubjectsChooseFieldsDialog");
01493               //DON'T ADD THIS! newParent2->deleteLater();
01494               newParent=newParent2;
01495               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01496               int w= chooseWidth(cfd.sizeHint().width());
01497               int h= chooseHeight(cfd.sizeHint().height());
01498               cfd.resize(w,h);
01499               centerWidgetOnScreen(&cfd);
01500               restoreFETDialogGeometry(&cfd, settingsName);
01501 
01502               ok=cfd.exec();
01503               saveFETDialogGeometry(&cfd, settingsName);
01504        }
01505 
01506        if(!ok)       return;
01507 
01508        ok = readFields(newParent);
01509        if(!ok) return;
01510 
01511        //check empty fields (start)
01512        for(int i=0; i<fieldList[FIELD_SUBJECT_NAME].size(); i++){
01513               if(fieldList[FIELD_SUBJECT_NAME][i].isEmpty())
01514                      warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_SUBJECT_NAME])+"\n";
01515        }
01516        //check empty fields (end)
01517 
01518        //check if already in memory (start)
01519        for(int i=0; i<gt.rules.subjectsList.size(); i++){
01520               Subject* s=gt.rules.subjectsList[i];
01521               if(fieldList[FIELD_SUBJECT_NAME].contains(s->name))
01522                      dataWarning<<Import::tr("%1 is already in FET data.").arg(s->name);
01523        }
01524        //check if already in memory (end)
01525 
01526        QDialog* newParent2;
01527        ok = showFieldsAndWarnings(newParent, newParent2);
01528        //DON'T ADD THIS! newParent2->deleteLater();
01529        newParent=newParent2;
01530        if(!ok) return;
01531 
01532        //add subjects (start) - similar to teachersform.cpp by Liviu modified by Volker
01533        int count=0;
01534        for(int i=0; i<fieldList[FIELD_SUBJECT_NAME].size(); i++){
01535               if(!fieldList[FIELD_SUBJECT_NAME][i].isEmpty()){
01536                      Subject* s=new Subject();
01537                      s->name=fieldList[FIELD_SUBJECT_NAME][i];
01538                      if(!gt.rules.addSubject(s)){
01539                             delete s;
01540                      } else count++;
01541               }
01542        }
01543        //add subjects (end) - similar to teachersform.cpp by Liviu modified by Volker
01544        QMessageBox::information(newParent, tr("FET information"), Import::tr("%1 subjects added. Please check subjects form.").arg(count));
01545        int tmp=fileName.lastIndexOf(FILE_SEP);
01546        IMPORT_DIRECTORY=fileName.left(tmp);
01547        gt.rules.internalStructureComputed=false;
01548 }
01549 
01550 
01551 void Import::importCSVTeachers(QWidget* parent){
01552        prearrangement();
01553        fieldNumber[FIELD_TEACHER_NAME]=IMPORT_DEFAULT_ITEM;
01554        int ok;
01555 
01556        QDialog* newParent;
01557        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01558        //DON'T ADD THIS! newParent->deleteLater();
01559        if(!ok)       return;
01560 
01561        if(fieldNumber[FIELD_TEACHER_NAME]==IMPORT_DEFAULT_ITEM){
01562               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01563               const QString settingsName=QString("ImportTeachersChooseFieldsDialog");
01564               //DON'T ADD THIS! newParent2->deleteLater();
01565               newParent=newParent2;
01566               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01567               int w= chooseWidth(cfd.sizeHint().width());
01568               int h= chooseHeight(cfd.sizeHint().height());
01569               cfd.resize(w,h);
01570               centerWidgetOnScreen(&cfd);
01571               restoreFETDialogGeometry(&cfd, settingsName);
01572 
01573               ok=cfd.exec();
01574               saveFETDialogGeometry(&cfd, settingsName);
01575        }
01576 
01577        if(!ok)       return;
01578 
01579        ok = readFields(newParent);
01580        if(!ok) return;
01581 
01582        //check empty fields (start)
01583        for(int i=0; i<fieldList[FIELD_TEACHER_NAME].size(); i++){
01584               if(fieldList[FIELD_TEACHER_NAME][i].isEmpty())
01585                      warnText+=Import::tr("Skipped line %1: Field '%2' is empty.").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(fieldName[FIELD_TEACHER_NAME])+"\n";
01586        }
01587        //check empty fields (end)
01588 
01589        //check if already in memory (start)
01590        for(int i=0; i<gt.rules.teachersList.size(); i++){
01591               Teacher* t=gt.rules.teachersList[i];
01592               if(fieldList[FIELD_TEACHER_NAME].contains(t->name))
01593                      dataWarning<<Import::tr("%1 is already in FET data.").arg(t->name);
01594        }
01595        //check if already in memory (end)
01596 
01597        QDialog* newParent2;
01598        ok = showFieldsAndWarnings(newParent, newParent2);
01599        //DON'T ADD THIS! newParent2->deleteLater();
01600        newParent=newParent2;
01601        if(!ok) return;
01602 
01603        //add teachers (start) - similar to teachersform.cpp by Liviu modified by Volker
01604        int count=0;
01605        for(int i=0; i<fieldList[FIELD_TEACHER_NAME].size(); i++){
01606               if(!fieldList[FIELD_TEACHER_NAME][i].isEmpty()){
01607                      Teacher* tch=new Teacher();
01608                      tch->name=fieldList[FIELD_TEACHER_NAME][i];
01609                      if(!gt.rules.addTeacher(tch)){
01610                             delete tch;
01611                      } else count++;
01612               }
01613        }
01614        QMessageBox::information(newParent, tr("FET information"), Import::tr("%1 teachers added. Please check teachers form.").arg(count));
01615        //add teachers (end) - similar to teachersform.cpp by Liviu modified by Volker
01616        int tmp=fileName.lastIndexOf(FILE_SEP);
01617        IMPORT_DIRECTORY=fileName.left(tmp);
01618        gt.rules.internalStructureComputed=false;
01619 }
01620 
01621 void Import::importCSVStudents(QWidget* parent){
01622        prearrangement();
01623        fieldNumber[FIELD_YEAR_NAME]=IMPORT_DEFAULT_ITEM;
01624        fieldNumber[FIELD_YEAR_NUMBER_OF_STUDENTS]=IMPORT_DEFAULT_ITEM;
01625        fieldNumber[FIELD_GROUP_NAME]=IMPORT_DEFAULT_ITEM;
01626        fieldNumber[FIELD_GROUP_NUMBER_OF_STUDENTS]=IMPORT_DEFAULT_ITEM;
01627        fieldNumber[FIELD_SUBGROUP_NAME]=IMPORT_DEFAULT_ITEM;
01628        fieldNumber[FIELD_SUBGROUP_NUMBER_OF_STUDENTS]=IMPORT_DEFAULT_ITEM;
01629        int ok;
01630 
01631        QDialog* newParent;
01632        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01633        //DON'T ADD THIS! newParent->deleteLater();
01634        if(!ok)       return;
01635        
01636        if(fieldNumber[FIELD_YEAR_NAME]==IMPORT_DEFAULT_ITEM){
01637               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01638               const QString settingsName=QString("ImportYearsGroupsSubgroupsChooseFieldsDialog");
01639               //DON'T ADD THIS! newParent2->deleteLater();
01640               newParent=newParent2;
01641               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01642               int w=chooseWidth(cfd.sizeHint().width());
01643               int h=chooseHeight(cfd.sizeHint().height());
01644               cfd.resize(w,h);
01645 
01646               centerWidgetOnScreen(&cfd);
01647               restoreFETDialogGeometry(&cfd, settingsName);
01648 
01649               ok=cfd.exec();
01650               saveFETDialogGeometry(&cfd, settingsName);
01651               if(!ok)       return;
01652        }
01653 
01654        ok = readFields(newParent);
01655        if(!ok) return;
01656 
01657        //check if already in memory (start) - similar to adding items by Liviu modified by Volker
01658        QString yearName;
01659        QString groupName;
01660        QString subgroupName;
01661        QSet<QString> usedCSVYearNames;                  // this is much fater then QStringList
01662        QSet<QString> usedCSVGroupNames;
01663        QSet<QString> usedCSVSubgroupNames;
01664 
01665        //check csv
01666        QProgressDialog* _progress=new QProgressDialog(newParent);
01667        QProgressDialog& progress=(*_progress);
01668        progress.setWindowTitle(tr("Importing", "Title of a progress dialog"));
01669        //cout<<"progress in importCSVStudents starts, range="<<fieldList[FIELD_YEAR_NAME].size()<<endl;
01670        progress.setLabelText(tr("Checking CSV"));
01671        progress.setModal(true);
01672        progress.setRange(0, fieldList[FIELD_YEAR_NAME].size());
01673        for(int i=0; i<fieldList[FIELD_YEAR_NAME].size(); i++){
01674               progress.setValue(i);
01675               if(progress.wasCanceled()){
01676                      QMessageBox::warning(newParent, "FET", Import::tr("Checking CSV canceled by user."));
01677                      return;
01678               }
01679               if(fieldNumber[FIELD_YEAR_NAME]>=0)
01680                      yearName=fieldList[FIELD_YEAR_NAME][i];
01681               else
01682                      yearName=fieldDefaultItem[FIELD_YEAR_NAME];
01683               if((fieldNumber[FIELD_GROUP_NAME])>=0)
01684                      groupName=fieldList[FIELD_GROUP_NAME][i];
01685               else
01686                      groupName=fieldDefaultItem[FIELD_GROUP_NAME];
01687               if((fieldNumber[FIELD_SUBGROUP_NAME])>=0)
01688                      subgroupName=fieldList[FIELD_SUBGROUP_NAME][i];
01689               else
01690                      subgroupName=fieldDefaultItem[FIELD_SUBGROUP_NAME];
01691               if((fieldNumber[FIELD_YEAR_NAME])>=IMPORT_DEFAULT_ITEM){
01692                      if(!yearName.isEmpty())
01693                             if(!usedCSVYearNames.contains(yearName))
01694                                    usedCSVYearNames<<yearName;
01695               }
01696               if((fieldNumber[FIELD_GROUP_NAME])>=IMPORT_DEFAULT_ITEM){
01697                      if(!groupName.isEmpty())
01698                             if(!usedCSVGroupNames.contains(groupName))
01699                                    usedCSVGroupNames<<groupName;
01700                      if(usedCSVYearNames.contains(groupName))
01701                             warnText+=Import::tr("Problem in line %1: Group name %2 is taken for a year - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(groupName)+"\n";
01702                      if(usedCSVGroupNames.contains(yearName))
01703                             warnText+=Import::tr("Problem in line %1: Year name %2 is taken for a group - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(yearName)+"\n";
01704 
01705               }
01706               if((fieldNumber[FIELD_SUBGROUP_NAME])>=IMPORT_DEFAULT_ITEM){
01707                      if(!subgroupName.isEmpty())
01708                             if(!usedCSVSubgroupNames.contains(subgroupName))
01709                                    usedCSVSubgroupNames<<subgroupName;
01710                      if(usedCSVYearNames.contains(subgroupName))
01711                             warnText+=Import::tr("Problem in line %1: Subgroup name %2 is taken for a year - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(subgroupName)+"\n";
01712                      if(usedCSVGroupNames.contains(subgroupName))
01713                             warnText+=Import::tr("Problem in line %1: Subgroup name %2 is taken for a group - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(subgroupName)+"\n";
01714                      if(usedCSVSubgroupNames.contains(groupName))
01715                             warnText+=Import::tr("Problem in line %1: Group name %2 is taken for a subgroup - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(groupName)+"\n";
01716                      if(usedCSVSubgroupNames.contains(yearName))
01717                             warnText+=Import::tr("Problem in line %1: Year name %2 is taken for a subgroup - please consider another name").arg(fieldList[FIELD_LINE_NUMBER][i]).arg(yearName)+"\n";
01718               }
01719        }
01720        progress.setValue(fieldList[FIELD_YEAR_NAME].size());
01721        //cout<<"progress in importCSVStudents ends"<<endl;
01722 
01723        //check current data
01724        QProgressDialog* _progress2=new QProgressDialog(newParent);
01725        QProgressDialog& progress2=(*_progress2);
01726        progress2.setWindowTitle(tr("Importing", "Title of a progress dialog"));
01727        progress2.setLabelText(tr("Checking data"));
01728        progress2.setModal(true);
01729        progress2.setRange(0, fieldList[FIELD_YEAR_NAME].size());
01730        //cout<<"progress2 in importCSVStudents starts, range="<<fieldList[FIELD_YEAR_NAME].size()<<endl;
01731        int kk=0;
01732        for(int i=0; i<gt.rules.yearsList.size(); i++){
01733               progress2.setValue(kk);
01734               kk++;
01735               if(progress2.wasCanceled()){
01736                      QMessageBox::warning(newParent, "FET", Import::tr("Checking data canceled by user."));
01737                      return;
01738               }
01739               StudentsYear* sty=gt.rules.yearsList[i];
01740               if(usedCSVYearNames.contains(sty->name))
01741                      dataWarning<<Import::tr("Year %1 is already in FET data.").arg(sty->name);
01742               if(usedCSVGroupNames.contains(sty->name))
01743                      dataWarning<<Import::tr("Can't import group %1. Name is already taken for a year.").arg(sty->name);
01744               if(usedCSVSubgroupNames.contains(sty->name))
01745                      dataWarning<<Import::tr("Can't import subgroup %1. Name is already taken for a year.").arg(sty->name);
01746               for(int j=0; j<sty->groupsList.size(); j++){
01747                      progress2.setValue(kk);
01748                      kk++;
01749                      if(progress2.wasCanceled()){
01750                             QMessageBox::warning(newParent, "FET", Import::tr("Checking data canceled by user."));
01751                             return;
01752                      }
01753 
01754                      StudentsGroup* stg=sty->groupsList[j];
01755                      if(usedCSVYearNames.contains(stg->name))
01756                             dataWarning<<Import::tr("Can't import year %1. Name is already taken for a group.").arg(stg->name);
01757                      if(usedCSVGroupNames.contains(stg->name))
01758                             dataWarning<<Import::tr("Group name %1 is already in FET data (In the same or in an other year).").arg(stg->name);
01759                      if(usedCSVSubgroupNames.contains(stg->name))
01760                             dataWarning<<Import::tr("Can't import subgroup %1. Name is already taken for a group.").arg(stg->name);
01761                      for(int k=0; k<stg->subgroupsList.size(); k++){
01762                             progress2.setValue(kk);
01763                             kk++;
01764 
01765                             if(progress2.wasCanceled()){
01766                                    QMessageBox::warning(newParent, "FET", Import::tr("Checking data canceled by user."));
01767                                    return;
01768                             }
01769 
01770                             StudentsSubgroup* sts=stg->subgroupsList[k];
01771                             if(usedCSVYearNames.contains(sts->name))
01772                                    dataWarning<<Import::tr("Can't import year %1. Name is already taken for a subgroup.").arg(sts->name);
01773                             if(usedCSVGroupNames.contains(sts->name))
01774                                    dataWarning<<Import::tr("Can't import group %1. Name is taken for a subgroup.").arg(sts->name);
01775                             if(usedCSVSubgroupNames.contains(sts->name))
01776                                    dataWarning<<Import::tr("Subgroup name %1 is already in FET data (In the same or in an other group).").arg(sts->name);
01777                      }
01778               }
01779        }
01780        progress2.setValue(fieldList[FIELD_YEAR_NAME].size());
01781        //cout<<"progress2 in importCSVStudents ends"<<endl;
01782 
01783        QDialog* newParent2;
01784        ok = showFieldsAndWarnings(newParent, newParent2);
01785        //DON'T ADD THIS! newParent2->deleteLater();
01786        newParent=newParent2;
01787        if(!ok) return;
01788 
01789        //add students (start) - similar to adding items by Liviu modified by Volker
01790        lastWarning.clear();
01791        int addedYears=0;
01792        int addedGroups=0;
01793        int addedSubgroups=0;
01794        QProgressDialog* _progress3=new QProgressDialog(newParent);
01795        QProgressDialog& progress3=(*_progress3);
01796        progress3.setWindowTitle(tr("Importing", "Title of a progress dialog"));
01797        progress3.setLabelText(tr("Importing data"));
01798        progress3.setModal(true);
01799        progress3.setRange(0, fieldList[FIELD_YEAR_NAME].size());
01800        //cout<<"progress3 in importCSVStudents starts, range="<<fieldList[FIELD_YEAR_NAME].size()<<endl;
01801        
01802        for(int i=0; i<fieldList[FIELD_YEAR_NAME].size(); i++){
01803               progress3.setValue(i);
01804               if(progress3.wasCanceled()){
01805                      QMessageBox::warning(newParent, "FET", Import::tr("Importing data canceled by user."));
01806                      //return false;
01807                      ok=false;
01808                      goto ifUserCanceledProgress3;
01809               }
01810               ok=true;
01811               bool tryNext=false;
01812               if(fieldNumber[FIELD_YEAR_NAME]!=IMPORT_DEFAULT_ITEM)
01813                      yearName=fieldList[FIELD_YEAR_NAME][i];
01814               else
01815                      yearName=fieldDefaultItem[FIELD_YEAR_NAME];
01816               assert(!yearName.isEmpty());
01817               StudentsSet* ss=gt.rules.searchStudentsSet(yearName);
01818               if(ss!=NULL){
01819                      if(ss->type==STUDENTS_SUBGROUP)
01820                             ok=false;
01821                      else if(ss->type==STUDENTS_GROUP)
01822                             ok=false;
01823                      else if(ss->type==STUDENTS_YEAR){
01824                             ok=false;
01825                             tryNext=true;
01826                      }
01827               }
01828               if(ok){
01829                      StudentsYear* sy=new StudentsYear();
01830                      sy->name=yearName;
01831                      QString tmpString=fieldList[FIELD_YEAR_NUMBER_OF_STUDENTS][i];
01832                      sy->numberOfStudents=tmpString.toInt();
01833                      assert(!fieldList[FIELD_YEAR_NUMBER_OF_STUDENTS].isEmpty());
01834                      if(gt.rules.searchYear(yearName) >=0 )
01835                             delete sy;
01836                      else {
01837                             bool tmp=gt.rules.addYear(sy);
01838                             assert(tmp);
01839                             addedYears++;
01840                      }
01841               }
01842               if((tryNext || ok) && fieldNumber[FIELD_GROUP_NAME]!=DO_NOT_IMPORT){
01843                      ok=true;
01844                      tryNext=false;
01845                      StudentsGroup* sg;
01846                      sg=NULL;
01847                      if(fieldNumber[FIELD_GROUP_NAME]!=IMPORT_DEFAULT_ITEM)
01848                             groupName=fieldList[FIELD_GROUP_NAME][i];
01849                      else
01850                             groupName=fieldDefaultItem[FIELD_GROUP_NAME];
01851                      if(groupName.isEmpty())
01852                             ok=false;
01853                      else {
01854                             if(ok && gt.rules.searchGroup(yearName, groupName)>=0){
01855                                    ok=false;
01856                                    tryNext=true;
01857                             }
01858                             StudentsSet* ss=gt.rules.searchStudentsSet(groupName);
01859                             if(ss!=NULL && ss->type==STUDENTS_YEAR)
01860                                    ok=false;
01861                             if(ss!=NULL && ss->type==STUDENTS_SUBGROUP)
01862                                    ok=false;
01863                             if(ss!=NULL && ss->type==STUDENTS_GROUP){
01864                                    if(fieldNumber[FIELD_SUBGROUP_NAME]==DO_NOT_IMPORT)
01865                                           lastWarning+=Import::tr("Group name %1 exists in another year. It means that some years share the same group.").arg(groupName)+"\n";
01866                                    if(fieldNumber[FIELD_SUBGROUP_NAME]!=DO_NOT_IMPORT)
01867                                           if(fieldList[FIELD_SUBGROUP_NAME].isEmpty())
01868                                                  lastWarning+=Import::tr("Group name %1 exists in another year. It means that some years share the same group.").arg(groupName)+"\n";
01869                             }
01870                             if(ss!=NULL&&ok){
01871                                    sg=(StudentsGroup*)ss;
01872                             }
01873                             if(ss==NULL&&ok){
01874                                    sg=new StudentsGroup();
01875                                    sg->name=groupName;
01876                                    QString tmpString=fieldList[FIELD_GROUP_NUMBER_OF_STUDENTS][i];
01877                                    sg->numberOfStudents=tmpString.toInt();
01878                                    assert(ok);
01879                                    assert(!fieldList[FIELD_GROUP_NUMBER_OF_STUDENTS].isEmpty());
01880                             }
01881                             if(ok){
01882                                    gt.rules.addGroup(yearName, sg);
01883                                    addedGroups++;
01884                             }
01885                      }
01886               }
01887               if((tryNext || ok) && fieldNumber[FIELD_SUBGROUP_NAME]!=DO_NOT_IMPORT){
01888                      ok=true;
01889                      if(fieldNumber[FIELD_SUBGROUP_NAME]!=IMPORT_DEFAULT_ITEM)
01890                             subgroupName=fieldList[FIELD_SUBGROUP_NAME][i];
01891                      else
01892                             subgroupName=fieldDefaultItem[FIELD_SUBGROUP_NAME];
01893                      if(subgroupName.isEmpty())
01894                             ok=false;
01895                      else {
01896                             if(ok && gt.rules.searchSubgroup(yearName, groupName, subgroupName)>=0){
01897                                    ok=false;
01898                             }
01899                             StudentsSet* ss=gt.rules.searchStudentsSet(subgroupName);
01900                             StudentsSubgroup* sts;
01901                             sts=NULL;
01902                             if(ss!=NULL && ss->type==STUDENTS_YEAR){
01903                                    ok=false;
01904                             }
01905                             if(ss!=NULL && ss->type==STUDENTS_GROUP){
01906                                    ok=false;
01907                             }
01908                             if(ss!=NULL && ss->type==STUDENTS_SUBGROUP){
01909                                    lastWarning+=Import::tr("Subgroup name %1 exists in another group. It means that some groups share the same subgroup.").arg(subgroupName)+"\n";
01910                             }
01911                             if(ss!=NULL&&ok){
01912                                    sts=(StudentsSubgroup*)ss;
01913                             }
01914                             if(ss==NULL&&ok) {
01915                                    sts=new StudentsSubgroup();
01916                                    sts->name=subgroupName;
01917                                    QString tmpString=fieldList[FIELD_SUBGROUP_NUMBER_OF_STUDENTS][i];
01918                                    sts->numberOfStudents=tmpString.toInt();
01919                                    assert(ok);
01920                                    assert(!fieldList[FIELD_SUBGROUP_NUMBER_OF_STUDENTS].isEmpty());
01921                             }
01922                             if(ok){
01923                                    gt.rules.addSubgroup(yearName, groupName, sts);
01924                                    addedSubgroups++;
01925                             }
01926                      }
01927               }
01928        }
01929        progress3.setValue(fieldList[FIELD_YEAR_NAME].size());
01930        //cout<<"progress3 in importCSVStudents ends"<<endl;
01931        //add students (end) - similar to adding items by Liviu modified by Volker
01932        
01933 ifUserCanceledProgress3:
01934 
01935        if(!lastWarning.isEmpty())
01936               lastWarning.insert(0,"\n"+Import::tr("Notes:")+"\n");
01937        lastWarning.insert(0,Import::tr("%1 subgroups added. Please check subgroups form.").arg(addedSubgroups)+"\n");
01938        lastWarning.insert(0,Import::tr("%1 groups added. Please check groups form.").arg(addedGroups)+"\n");
01939        lastWarning.insert(0,Import::tr("%1 years added. Please check years form.").arg(addedYears)+"\n");
01940 
01941        LastWarningsDialog lwd(newParent);
01942        int w=chooseWidth(lwd.sizeHint().width());
01943        int h=chooseHeight(lwd.sizeHint().height());
01944        lwd.resize(w,h);
01945        centerWidgetOnScreen(&lwd);
01946 
01947        ok=lwd.exec();
01948 
01949        int tmp=fileName.lastIndexOf(FILE_SEP);
01950        IMPORT_DIRECTORY=fileName.left(tmp);
01951        gt.rules.internalStructureComputed=false;
01952 }
01953 
01954 void Import::importCSVActivities(QWidget* parent){
01955        prearrangement();
01956        fieldNumber[FIELD_STUDENTS_SET]=IMPORT_DEFAULT_ITEM;
01957        fieldNumber[FIELD_SUBJECT_NAME]=IMPORT_DEFAULT_ITEM;
01958        fieldNumber[FIELD_TEACHERS_SET]=IMPORT_DEFAULT_ITEM;
01959        fieldNumber[FIELD_ACTIVITY_TAGS_SET]=IMPORT_DEFAULT_ITEM;
01960        fieldNumber[FIELD_TOTAL_DURATION]=IMPORT_DEFAULT_ITEM;
01961        fieldNumber[FIELD_SPLIT_DURATION]=IMPORT_DEFAULT_ITEM;
01962        fieldNumber[FIELD_MIN_DAYS]=IMPORT_DEFAULT_ITEM;
01963        fieldNumber[FIELD_MIN_DAYS_WEIGHT]=IMPORT_DEFAULT_ITEM;
01964        fieldNumber[FIELD_MIN_DAYS_CONSECUTIVE]=IMPORT_DEFAULT_ITEM;
01965 
01966        int ok;
01967 
01968        QDialog* newParent;
01969        ok = getFileSeparatorFieldsAndHead(parent, newParent);
01970        //DON'T ADD THIS! newParent->deleteLater();
01971        if(!ok)       return;
01972 
01973        if(fieldNumber[FIELD_SUBJECT_NAME]==IMPORT_DEFAULT_ITEM){
01974               QDialog* newParent2=new ChooseFieldsDialog(newParent);
01975               const QString settingsName=QString("ImportActivitiesChooseFieldsDialog");
01976               //DON'T ADD THIS! newParent2->deleteLater();
01977               newParent=newParent2;
01978               ChooseFieldsDialog& cfd=(*((ChooseFieldsDialog*)newParent));
01979               int w=chooseWidth(cfd.sizeHint().width());
01980               int h=chooseHeight(cfd.sizeHint().height());
01981               cfd.resize(w,h);
01982               centerWidgetOnScreen(&cfd);
01983               restoreFETDialogGeometry(&cfd, settingsName);
01984 
01985               ok=cfd.exec();
01986               saveFETDialogGeometry(&cfd, settingsName);
01987        }
01988        if(!ok)       return;
01989 
01990        if(fieldNumber[FIELD_SPLIT_DURATION]==DO_NOT_IMPORT&&fieldNumber[FIELD_TOTAL_DURATION]==DO_NOT_IMPORT){
01991               QMessageBox::warning(newParent, tr("FET warning"), Import::tr("FET need to know %1 or %2 if you import %3.").arg(fieldName[FIELD_SPLIT_DURATION]).arg(fieldName[FIELD_TOTAL_DURATION]).arg(importThing));
01992               return;
01993        }
01994 
01995        ok = readFields(newParent);
01996        if(!ok) return;
01997 
01998        //check number of fields (start) //because of bug reported 17.03.2008
01999        int checkNumber=0;
02000        if(fieldList[FIELD_STUDENTS_SET].size()>0){
02001               checkNumber=fieldList[FIELD_STUDENTS_SET].size();
02002        }
02003        if(fieldList[FIELD_SUBJECT_NAME].size()>0){
02004               if(checkNumber>0){
02005                      assert(checkNumber==fieldList[FIELD_SUBJECT_NAME].size());
02006               }
02007               checkNumber=fieldList[FIELD_SUBJECT_NAME].size();
02008        }
02009        if(fieldList[FIELD_TEACHERS_SET].size()>0){
02010               if(checkNumber>0){
02011                      assert(checkNumber==fieldList[FIELD_TEACHERS_SET].size());
02012               }
02013               checkNumber=fieldList[FIELD_TEACHERS_SET].size();
02014        }
02015        if(fieldList[FIELD_ACTIVITY_TAGS_SET].size()>0){
02016               if(checkNumber>0){
02017                      assert(checkNumber==fieldList[FIELD_ACTIVITY_TAGS_SET].size());
02018               }
02019               checkNumber=fieldList[FIELD_ACTIVITY_TAGS_SET].size();
02020        }
02021        if(fieldList[FIELD_TOTAL_DURATION].size()>0){
02022               if(checkNumber>0){
02023                      assert(checkNumber==fieldList[FIELD_TOTAL_DURATION].size());
02024               }
02025               checkNumber=fieldList[FIELD_TOTAL_DURATION].size();
02026        }
02027        if(fieldList[FIELD_SPLIT_DURATION].size()>0){
02028               if(checkNumber>0){
02029                      assert(checkNumber==fieldList[FIELD_SPLIT_DURATION].size());
02030               }
02031               checkNumber=fieldList[FIELD_SPLIT_DURATION].size();
02032        }
02033        if(fieldList[FIELD_MIN_DAYS].size()>0){
02034               if(checkNumber>0){
02035                      assert(checkNumber==fieldList[FIELD_MIN_DAYS].size());
02036               }
02037               checkNumber=fieldList[FIELD_MIN_DAYS].size();
02038        }
02039        if(fieldList[FIELD_MIN_DAYS_WEIGHT].size()>0){
02040               if(checkNumber>0){
02041                      assert(checkNumber==fieldList[FIELD_MIN_DAYS_WEIGHT].size());
02042               }
02043               checkNumber=fieldList[FIELD_MIN_DAYS_WEIGHT].size();
02044        }
02045        if(fieldList[FIELD_MIN_DAYS_CONSECUTIVE].size()>0){
02046               if(checkNumber>0){
02047                      assert(checkNumber==fieldList[FIELD_MIN_DAYS_CONSECUTIVE].size());
02048               }
02049               checkNumber=fieldList[FIELD_MIN_DAYS_CONSECUTIVE].size();
02050        }
02051 
02052        if(fieldList[FIELD_STUDENTS_SET].size()==0){
02053               for(int i=0; i<checkNumber; i++)
02054                      fieldList[FIELD_STUDENTS_SET]<<"";
02055        }
02056        if(fieldList[FIELD_SUBJECT_NAME].size()==0){
02057               for(int i=0; i<checkNumber; i++)
02058                      fieldList[FIELD_SUBJECT_NAME]<<"";
02059        }
02060        if(fieldList[FIELD_TEACHERS_SET].size()==0){
02061               for(int i=0; i<checkNumber; i++)
02062                      fieldList[FIELD_TEACHERS_SET]<<"";
02063        }
02064        if(fieldList[FIELD_ACTIVITY_TAGS_SET].size()==0){
02065               for(int i=0; i<checkNumber; i++)
02066                      fieldList[FIELD_ACTIVITY_TAGS_SET]<<"";
02067        }
02068        if(fieldList[FIELD_TOTAL_DURATION].size()==0){
02069               for(int i=0; i<checkNumber; i++)
02070                      fieldList[FIELD_TOTAL_DURATION]<<"1";
02071        }
02072        if(fieldList[FIELD_SPLIT_DURATION].size()==0){
02073               for(int i=0; i<checkNumber; i++)
02074                      fieldList[FIELD_SPLIT_DURATION]<<"1";
02075        }
02076        if(fieldList[FIELD_MIN_DAYS].size()==0){
02077               for(int i=0; i<checkNumber; i++)
02078                      fieldList[FIELD_MIN_DAYS]<<"1";
02079        }
02080        if(fieldList[FIELD_MIN_DAYS_WEIGHT].size()==0){
02081               for(int i=0; i<checkNumber; i++)
02082                      fieldList[FIELD_MIN_DAYS_WEIGHT]<<"95";
02083        }
02084        if(fieldList[FIELD_MIN_DAYS_CONSECUTIVE].size()==0){
02085               for(int i=0; i<checkNumber; i++)
02086                      fieldList[FIELD_MIN_DAYS_CONSECUTIVE]<<"no";
02087        }
02088 
02089        //check number of fields (end) //because of bug reported 17.03.2008
02090 
02091        //check if already in memory (start)
02092        //check if students set is in memory
02093        lastWarning.clear();
02094        QString line;
02095        QStringList students;
02096        bool firstWarning=true;
02097        for(int i=0; i<fieldList[FIELD_STUDENTS_SET].size(); i++){
02098               line.clear();
02099               line=fieldList[FIELD_STUDENTS_SET][i];
02100               students.clear();
02101               students=line.split("+");
02102               if(!fieldList[FIELD_STUDENTS_SET][i].isEmpty()){
02103                      for(int s=0; s<students.size(); s++){
02104                             StudentsSet* ss=gt.rules.searchStudentsSet(students[s]);
02105                             if(ss==NULL){
02106                                    if(firstWarning){
02107                                           lastWarning+=Import::tr("FET can't import activities, because FET needs to know the stucture of the "
02108                                           "students sets. You must add (or import) years, groups and subgroups first.")+"\n"+
02109                                           tr("I recommend to import also teachers, rooms, buildings, subjects and activity tags before "
02110                                           "importing activities. It is not needed, because FET will automatically do it, but you can "
02111                                           "check the activity csv file by that.")+"\n";
02112                                           firstWarning=false;
02113                                    }
02114                                    lastWarning+=Import::tr("Student set %1 doesn't exist. You must add (or import) years, groups and subgroups first.").arg(students[s])+"\n";
02115                             }
02116                      }
02117               }
02118        }
02119        if(lastWarning.size()>0){
02120               QDialog* newParent2=new LastWarningsDialog(newParent);
02121               //DON'T ADD THIS! newParent2->deleteLater();
02122               newParent=newParent2;
02123               LastWarningsDialog& lwd=(*((LastWarningsDialog*)newParent));
02124               int w=chooseWidth(lwd.sizeHint().width());
02125               int h=chooseHeight(lwd.sizeHint().height());
02126               lwd.resize(w,h);
02127               centerWidgetOnScreen(&lwd);
02128 
02129               ok=lwd.exec();
02130               return;
02131        }
02132        //check if teacher is in memory
02133        assert(fieldList[FIELD_TEACHER_NAME].isEmpty());
02134        QStringList teachers;
02135        QStringList tmpList;
02136        tmpList.clear();
02137        for(int i=0; i<gt.rules.teachersList.size(); i++){
02138               Teacher* t=gt.rules.teachersList[i];
02139               tmpList<<t->name;
02140        }
02141        for(int i=0; i<fieldList[FIELD_TEACHERS_SET].size(); i++){
02142               line.clear();
02143               line=fieldList[FIELD_TEACHERS_SET][i];
02144               teachers.clear();
02145               teachers=line.split("+");
02146               for(int t=0; t<teachers.size(); t++){
02147                      bool add=true;
02148                      if(tmpList.contains(teachers[t]) || teachers[t]=="")
02149                             add=false;
02150                      if(add){
02151                             dataWarning<<Import::tr("%1 %2 will be added.", "For instance 'Subject Math will be added', so use singular").arg(fieldName[FIELD_TEACHER_NAME]).arg(teachers[t]);
02152                             tmpList<<teachers[t];
02153                             fieldList[FIELD_TEACHER_NAME]<<teachers[t];
02154                      }
02155               }
02156        }
02157        //check is subject is in memory
02158        tmpList.clear();
02159        for(int i=0; i<gt.rules.subjectsList.size(); i++){
02160               Subject* s=gt.rules.subjectsList[i];
02161               tmpList<<s->name;
02162        }
02163        for(int sn=0; sn<fieldList[FIELD_SUBJECT_NAME].size(); sn++){
02164               bool add=true;
02165               if(tmpList.contains(fieldList[FIELD_SUBJECT_NAME][sn]) || fieldList[FIELD_SUBJECT_NAME][sn]=="")
02166                      add=false;
02167               if(add){
02168                      dataWarning<<Import::tr("%1 %2 will be added.", "For instance 'Subject Math will be added', so use singular").arg(fieldName[FIELD_SUBJECT_NAME]).arg(fieldList[FIELD_SUBJECT_NAME][sn]);
02169                      tmpList<<fieldList[FIELD_SUBJECT_NAME][sn];
02170               }                    
02171        }
02172        //check is activity tag is in memory
02173        assert(fieldList[FIELD_ACTIVITY_TAG_NAME].isEmpty());
02174        QStringList activityTags;
02175        tmpList.clear();
02176        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
02177               ActivityTag* at=gt.rules.activityTagsList[i];
02178               tmpList<<at->name;
02179        }
02180        for(int i=0; i<fieldList[FIELD_ACTIVITY_TAGS_SET].size(); i++){
02181               line.clear();
02182               line=fieldList[FIELD_ACTIVITY_TAGS_SET][i];
02183               activityTags.clear();
02184               activityTags=line.split("+");
02185               for(int at=0; at<activityTags.size(); at++){
02186                      bool add=true;
02187                      if(tmpList.contains(activityTags[at]) || activityTags[at]=="")
02188                             add=false;
02189                      if(add){
02190                             dataWarning<<Import::tr("%1 %2 will be added.", "For instance 'Subject Math will be added', so use singular").arg(fieldName[FIELD_ACTIVITY_TAG_NAME]).arg(activityTags[at]);
02191                             tmpList<<activityTags[at];
02192                             fieldList[FIELD_ACTIVITY_TAG_NAME]<<activityTags[at];
02193                      }
02194               }
02195        }
02196        tmpList.clear();
02197        //check if already in memory (end)
02198 
02199        QDialog* newParent2;
02200        ok = showFieldsAndWarnings(newParent, newParent2);
02201        //DON'T ADD THIS! newParent2->deleteLater();
02202        newParent=newParent2;
02203        if(!ok) return;
02204 
02205        //add teachers
02206        //maybe TODO write a function, so also import teacher csv can share this code
02207        int count=0;
02208        for(int i=0; i<fieldList[FIELD_TEACHER_NAME].size(); i++){
02209               if(!fieldList[FIELD_TEACHER_NAME][i].isEmpty()){
02210                      Teacher* tch=new Teacher();
02211                      tch->name=fieldList[FIELD_TEACHER_NAME][i];
02212                      if(!gt.rules.addTeacher(tch)){
02213                             delete tch;
02214                      } else
02215                             count++;
02216               }
02217        }
02218        fieldList[FIELD_TEACHER_NAME].clear();
02219        if(count>0)
02220               lastWarning+=Import::tr("%1 teachers added. Please check teachers form.").arg(count)+"\n";
02221        //add subjects
02222        //maybe TODO write a function, so also import subjects csv can share this code
02223        count=0;
02224        for(int i=0; i<fieldList[FIELD_SUBJECT_NAME].size(); i++){
02225               if(!fieldList[FIELD_SUBJECT_NAME][i].isEmpty()){
02226                      Subject* s=new Subject();
02227                      s->name=fieldList[FIELD_SUBJECT_NAME][i];
02228                      if(!gt.rules.addSubject(s)){
02229                             delete s;
02230                      } else
02231                             count++;
02232               }
02233        }
02234        if(count>0)
02235               lastWarning+=Import::tr("%1 subjects added. Please check subjects form.").arg(count)+"\n";
02236        //add activity tags
02237        //maybe TODO write a function, so also import activity tags csv can share this code
02238        count=0;
02239        for(int i=0; i<fieldList[FIELD_ACTIVITY_TAG_NAME].size(); i++){
02240               if(!fieldList[FIELD_ACTIVITY_TAG_NAME][i].isEmpty()){
02241                      ActivityTag* a=new ActivityTag();
02242                      a->name=fieldList[FIELD_ACTIVITY_TAG_NAME][i];
02243                      if(!gt.rules.addActivityTag(a)){
02244                             delete a;
02245                      } else
02246                             count++;
02247               }
02248        }
02249        if(count>0)
02250               lastWarning+=Import::tr("%1 activity tags added. Please check activity tags form.").arg(count)+"\n";
02251 
02252        //add activities (start) - similar to Livius code modified by Volker
02253        count=0;
02254        int count2=0;
02255        int activityid=0; //We set the id of this newly added activity = (the largest existing id + 1)
02256        for(int i=0; i<gt.rules.activitiesList.size(); i++){    //TODO: do it the same in addactivityfor.cpp (calculate activityid just one time)
02257               Activity* act=gt.rules.activitiesList[i];
02258               if(act->id > activityid)
02259                      activityid = act->id;
02260        }
02261        activityid++;
02262        QProgressDialog* _progress4=new QProgressDialog(newParent);
02263        QProgressDialog& progress4=(*_progress4);
02264        progress4.setWindowTitle(tr("Importing", "Title of a progress dialog"));
02265        progress4.setLabelText(tr("Importing activities"));
02266        progress4.setModal(true);
02267        progress4.setRange(0, fieldList[FIELD_SUBJECT_NAME].size());
02268 
02269        bool incorrect_bool_consecutive=false;
02270 
02271        for(int i=0; i<fieldList[FIELD_SUBJECT_NAME].size(); i++){
02272               progress4.setValue(i);
02273               if(progress4.wasCanceled()){
02274                      QMessageBox::warning(newParent, "FET", Import::tr("Importing data canceled by user."));
02275                      //return false;
02276                      ok=false;
02277                      goto ifUserCanceledProgress4;
02278               }
02279               bool ok2;
02280               QString tmpStr=fieldList[FIELD_MIN_DAYS_WEIGHT][i];
02281 //            double weight=tmpStr.toDouble(&ok2);
02282               double weight=customFETStrToDouble(tmpStr, &ok2);
02283               assert(ok2);
02284 
02285               QStringList teachers_names;
02286               if(!fieldList[FIELD_TEACHERS_SET][i].isEmpty())
02287                      teachers_names = fieldList[FIELD_TEACHERS_SET][i].split("+");
02288               
02289               QString subject_name = fieldList[FIELD_SUBJECT_NAME][i];
02290               
02291               QStringList activity_tags_names;
02292               if(!fieldList[FIELD_ACTIVITY_TAGS_SET][i].isEmpty())
02293                      activity_tags_names = fieldList[FIELD_ACTIVITY_TAGS_SET][i].split("+");
02294               
02295               QStringList students_names;
02296               if(!fieldList[FIELD_STUDENTS_SET][i].isEmpty())
02297                      students_names = fieldList[FIELD_STUDENTS_SET][i].split("+");
02298               QStringList splitDurationList;
02299               splitDurationList.clear();
02300               assert(!fieldList[FIELD_SPLIT_DURATION][i].isEmpty());
02301               splitDurationList = fieldList[FIELD_SPLIT_DURATION][i].split("+");
02302               int nsplit=splitDurationList.size();
02303               if(nsplit==1){
02304                      int duration=fieldList[FIELD_TOTAL_DURATION][i].toInt(&ok2, 10);
02305                      assert(ok2);
02306                      bool active=true;
02307                      //workaround only. Please rethink. (start)
02308                      /*QStringList activity_tag_names;
02309                      activity_tag_names<<activity_tag_name;*/
02310                      //workaround only. Please rethink. (end)
02311                      Activity a(gt.rules, activityid, 0, teachers_names, subject_name, activity_tags_names, students_names, duration, duration, active, true, -1);
02312        
02313                      bool already_existing=false;
02314                      for(int i=0; i<gt.rules.activitiesList.size(); i++){
02315                             Activity* act=gt.rules.activitiesList[i];
02316                             if((*act)==a)
02317                                    already_existing=true;
02318                      }
02319                      if(already_existing){
02320                             lastWarning+=Import::tr("Activity %1 already exists. A duplicate activity is imported. Please check the dataset!").arg(activityid)+"\n";
02321                      }
02322                      bool tmp=gt.rules.addSimpleActivity(newParent, activityid, 0, teachers_names, subject_name, activity_tags_names,
02323                             students_names,      duration, duration, active, true, -1);
02324                      activityid++;
02325                      if(tmp){
02326                             count++;
02327                             count2++;
02328                      }
02329                      else
02330                             QMessageBox::critical(newParent, tr("FET information"), tr("Activity NOT added - please report error"));
02331               }
02332               else{ //split activity
02333                      int totalduration;
02334                      int durations[MAX_SPLIT_OF_AN_ACTIVITY];
02335                      bool active[MAX_SPLIT_OF_AN_ACTIVITY];
02336        
02337                      totalduration=0;
02338                      for(int s=0; s<nsplit; s++){
02339                             durations[s]=splitDurationList[s].toInt(&ok2);
02340                             assert(ok2);
02341                             active[s]=true;
02342                             totalduration+=durations[s];
02343                      }
02344                      assert(totalduration==fieldList[FIELD_TOTAL_DURATION][i].toInt(&ok2));
02345                      assert(ok2);
02346        
02347                      int minD=fieldList[FIELD_MIN_DAYS][i].toInt(&ok2);
02348                      assert(ok2);
02349                      bool force;
02350                      
02351                      if(fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="YES" ||
02352                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="Y" ||
02353                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="TRUE" ||
02354                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="T" ||
02355                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="1"
02356                       )
02357                             force=true;
02358                      else if(
02359                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="NO" ||
02360                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="N" ||
02361                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="FALSE" ||
02362                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="F" ||
02363                       fieldList[FIELD_MIN_DAYS_CONSECUTIVE][i].toUpper()=="0"
02364                       )
02365                             force=false;
02366                      else{
02367                             incorrect_bool_consecutive=true;
02368                             force=true;
02369                      }
02370                      //workaround only. Please rethink. (start)
02371                      /*QStringList activity_tag_names;
02372                      activity_tag_names<<activity_tag_name;*/
02373                      //workaround only. Please rethink. (end)
02374                      bool tmp=gt.rules.addSplitActivity(newParent, activityid, activityid,
02375                             teachers_names, subject_name, activity_tags_names, students_names,
02376                             nsplit, totalduration, durations,
02377                             active, minD, weight, force, true, -1);
02378                      activityid+=nsplit;
02379                      if(tmp){
02380                             count++;
02381                             count2+=nsplit;
02382                      }
02383                      else
02384                             QMessageBox::critical(newParent, tr("FET information"), tr("Split activity NOT added - error???"));
02385               }
02386        }
02387        progress4.setValue(fieldList[FIELD_SUBJECT_NAME].size());
02388        //add activities (end) - similar to Livius code modified by Volker
02389 ifUserCanceledProgress4:
02390 
02391        if(incorrect_bool_consecutive){
02392               lastWarning.insert(0, tr("Warning: found tags for the 'consecutive' field of min days which are not a valid boolean value (%1) - making them %2").arg("1, 0, yes, no, y, n, true, false, t, f").arg("true")+"\n");
02393        }
02394 
02395        if(!lastWarning.isEmpty())
02396               lastWarning.insert(0,Import::tr("Notes:")+"\n");
02397        if(count>0)
02398               lastWarning.insert(0,Import::tr("%1 container activities (%2 total activities) added. Please check activity form.").arg(count).arg(count2)+"\n");
02399 
02400        QDialog* newParent3=new LastWarningsDialog(newParent);
02401        //DON'T ADD THIS! newParent3->deleteLater();
02402        newParent=newParent3;
02403        LastWarningsDialog& lwd=(*((LastWarningsDialog*)newParent));
02404        int w=chooseWidth(lwd.sizeHint().width());
02405        int h=chooseHeight(lwd.sizeHint().height());
02406        lwd.resize(w,h);
02407        centerWidgetOnScreen(&lwd);
02408 
02409        ok=lwd.exec();
02410 
02411        int tmp=fileName.lastIndexOf(FILE_SEP);
02412        IMPORT_DIRECTORY=fileName.left(tmp);
02413        gt.rules.internalStructureComputed=false;
02414 }