some performance optimizations
[toast/confclerk.git] / src / gui / importschedulewidget.cpp
1 #include "importschedulewidget.h"
2
3 #include <schedulexmlparser.h>
4
5 #include <QDir>
6 #include <QFile>
7 #include <QFileDialog>
8 #include <QDebug>
9
10 ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
11     : QWidget(aParent)
12 {
13     setupUi(this);
14
15     mXmlParser = new ScheduleXmlParser(this);
16     connect(mXmlParser, SIGNAL(progressStatus(int)), SLOT(showParsingProgress(int)));
17     connect(mXmlParser, SIGNAL(parsingSchedule(const QString &)), SLOT(parsingSchedule(const QString &)));
18
19     connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
20     progressBar->hide();
21 }
22
23 ImportScheduleWidget::~ImportScheduleWidget()
24 {
25     if(mXmlParser)
26     {
27         delete mXmlParser;
28         mXmlParser = NULL;
29     }
30 }
31
32 void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
33 {
34     importScheduleLabel->setText("Importing: " + aTitle);
35 }
36
37 void ImportScheduleWidget::showParsingProgress(int progress)
38 {
39     progressBar->setValue(progress);
40 }
41
42 void ImportScheduleWidget::browseSchedule()
43 {
44     QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
45     if(QFile::exists(scheduleFileName))
46     {
47         QFile file(scheduleFileName);
48         if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
49         {
50             qDebug() << "can't open " << file.fileName();
51             return;
52         }
53
54         QByteArray data = file.readAll();
55         browse->hide();
56         progressBar->show();
57         int confId = mXmlParser->parseData(data);
58
59         progressBar->hide();
60         browse->show();
61         importScheduleLabel->setText("Import schedule: ");
62
63         emit(scheduleImported(confId));
64     }
65     else
66     {
67         progressBar->hide();
68     }
69 }
70