source: src/gui/importschedulewidget.cpp @ c15be10

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

import schedule dialog

  • changed to widget
  • moved to 'conference' tab
  • Property mode set to 100644
File size: 2.0 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(setWindowTitle(const QString &)));
20
21    connect(import, SIGNAL(clicked()), SLOT(importSchedule()));
22    connect(search, SIGNAL(clicked()), SLOT(searchSchedule()));
23    progressBar->hide();
24    import->setEnabled(false);
25}
26
27ImportScheduleWidget::~ImportScheduleWidget()
28{
29    if(mXmlParser)
30    {
31        delete mXmlParser;
32        mXmlParser = NULL;
33    }
34}
35
36void ImportScheduleWidget::setSqlEngine(SqlEngine *aSqlEngine)
37{
38    Q_ASSERT(aSqlEngine != NULL);
39
40    mSqlEngine = aSqlEngine;
41}
42
43void ImportScheduleWidget::showParsingProgress(int progress)
44{
45    progressBar->setValue(progress);
46}
47
48void ImportScheduleWidget::searchSchedule()
49{
50    Q_ASSERT(mSqlEngine != NULL);
51
52    mScheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
53    if(QFile::exists(mScheduleFileName))
54        import->setEnabled(true);
55    else
56    {
57        import->setEnabled(false);
58        progressBar->hide();
59    }
60}
61
62void ImportScheduleWidget::importSchedule()
63{
64    if(!mSqlEngine)
65    {
66        qDebug() << "ImportScheduleWidget::importSchedule(): sqlEngine not set";
67        return;
68    }
69
70    QFile file(mScheduleFileName);
71    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
72    {
73        qDebug() << "can't open " << file.fileName();
74        return;
75    }
76
77    QByteArray data = file.readAll();
78    progressBar->show();
79    int confId = mXmlParser->parseData(data,mSqlEngine);
80
81    // hide stuff
82    import->setEnabled(false);
83    progressBar->hide();
84
85    emit(scheduleImported(confId));
86}
87
Note: See TracBrowser for help on using the repository browser.