source: src/gui/importschedulewidget.cpp @ 05afe5f

qt5
Last change on this file since 05afe5f was b86d4aa, checked in by pavelpa <pavelpa@…>, 13 years ago

reimplemented 'import schedule'

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include "importschedulewidget.h"
2
3#include <schedulexmlparser.h>
4#include <sqlengine.h>
5
6#include <QDir>
7#include <QFile>
8#include <QFileDialog>
9#include <QDebug>
10
11ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
12    : QWidget(aParent)
13    , mSqlEngine(NULL)
14{
15    setupUi(this);
16
17    mXmlParser = new ScheduleXmlParser(this);
18    connect(mXmlParser, SIGNAL(progressStatus(int)), SLOT(showParsingProgress(int)));
19    connect(mXmlParser, SIGNAL(parsingSchedule(const QString &)), SLOT(parsingSchedule(const QString &)));
20
21    connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
22    progressBar->hide();
23}
24
25ImportScheduleWidget::~ImportScheduleWidget()
26{
27    if(mXmlParser)
28    {
29        delete mXmlParser;
30        mXmlParser = NULL;
31    }
32}
33
34void ImportScheduleWidget::setSqlEngine(SqlEngine *aSqlEngine)
35{
36    Q_ASSERT(aSqlEngine != NULL);
37
38    mSqlEngine = aSqlEngine;
39}
40
41void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
42{
43    importScheduleLabel->setText("Importing: " + aTitle);
44}
45
46void ImportScheduleWidget::showParsingProgress(int progress)
47{
48    progressBar->setValue(progress);
49}
50
51void ImportScheduleWidget::browseSchedule()
52{
53    Q_ASSERT(mSqlEngine != NULL);
54
55    QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
56    if(QFile::exists(scheduleFileName))
57    {
58        QFile file(scheduleFileName);
59        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
60        {
61            qDebug() << "can't open " << file.fileName();
62            return;
63        }
64
65        QByteArray data = file.readAll();
66        browse->hide();
67        progressBar->show();
68        int confId = mXmlParser->parseData(data,mSqlEngine);
69
70        progressBar->hide();
71        browse->show();
72        importScheduleLabel->setText("Import schedule: ");
73
74        emit(scheduleImported(confId));
75    }
76    else
77    {
78        progressBar->hide();
79    }
80}
81
Note: See TracBrowser for help on using the repository browser.