forgotten Import Schedule Dialog files
authorpavelpa <pavelpa@localhost>
Thu, 21 Jan 2010 15:29:21 +0000 (15:29 +0000)
committerpavelpa <pavelpa@localhost>
Thu, 21 Jan 2010 15:29:21 +0000 (15:29 +0000)
src/gui/importscheduledialog.cpp [new file with mode: 0644]
src/gui/importscheduledialog.h [new file with mode: 0644]
src/gui/importscheduledialog.ui [new file with mode: 0644]

diff --git a/src/gui/importscheduledialog.cpp b/src/gui/importscheduledialog.cpp
new file mode 100644 (file)
index 0000000..c42d18d
--- /dev/null
@@ -0,0 +1,68 @@
+#include "importscheduledialog.h"
+
+#include <schedulexmlparser.h>
+#include <sqlengine.h>
+
+#include <QDir>
+#include <QFile>
+#include <QFileDialog>
+#include <QDebug>
+
+ImportScheduleDialog::ImportScheduleDialog(SqlEngine *aSqlEngine, QWidget *aParent)
+    : QDialog(aParent)
+    , mSqlEngine(aSqlEngine)
+{
+    setupUi(this);
+
+    mXmlParser = new ScheduleXmlParser(this);
+    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
+    connect(import, SIGNAL(clicked()), SLOT(importSchedule()));
+    connect(search, SIGNAL(clicked()), SLOT(searchSchedule()));
+    progressBar->hide();
+    import->setEnabled(false);
+}
+
+ImportScheduleDialog::~ImportScheduleDialog()
+{
+    if(mXmlParser)
+    {
+        delete mXmlParser;
+        mXmlParser = NULL;
+    }
+}
+
+void ImportScheduleDialog::showParsingProgress(int progress)
+{
+    progressBar->setValue(progress);
+}
+
+void ImportScheduleDialog::searchSchedule()
+{
+    mScheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
+    fileName->setText(mScheduleFileName);
+    if(QFile::exists(mScheduleFileName))
+        import->setEnabled(true);
+    else
+    {
+        import->setEnabled(false);
+        progressBar->hide();
+    }
+}
+
+void ImportScheduleDialog::importSchedule()
+{
+    QFile file(mScheduleFileName);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        qDebug() << "can't open " << file.fileName();
+        return;
+    }
+
+    QByteArray data = file.readAll();
+    if(mSqlEngine)
+    {
+        progressBar->show();
+        mXmlParser->parseData(data,mSqlEngine);
+    }
+}
+
diff --git a/src/gui/importscheduledialog.h b/src/gui/importscheduledialog.h
new file mode 100644 (file)
index 0000000..7fef281
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef IMPORTSCHEDULEDIALOG_H
+#define IMPORTSCHEDULEDIALOG_H
+
+#include <QDialog>
+#include "ui_importscheduledialog.h"
+
+class ScheduleXmlParser;
+class SqlEngine;
+
+class ImportScheduleDialog : public QDialog, Ui::ImportScheduleDialog
+{
+    Q_OBJECT
+    public:
+        ImportScheduleDialog(SqlEngine *aSqlEngine, QWidget *aParent = NULL);
+        ~ImportScheduleDialog();
+    private slots:
+        void searchSchedule();
+        void importSchedule();
+        void showParsingProgress(int progress);
+    private:
+        ScheduleXmlParser *mXmlParser;
+        SqlEngine *mSqlEngine; // uses it
+        QString mScheduleFileName;
+};
+
+#endif /* IMPORTSCHEDULEDIALOG_H */
+
diff --git a/src/gui/importscheduledialog.ui b/src/gui/importscheduledialog.ui
new file mode 100644 (file)
index 0000000..d7771a5
--- /dev/null
@@ -0,0 +1,113 @@
+<ui version="4.0" >
+ <class>ImportScheduleDialog</class>
+ <widget class="QDialog" name="ImportScheduleDialog" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>408</width>
+    <height>118</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Import schedule</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <layout class="QVBoxLayout" name="verticalLayout" >
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout" >
+       <item>
+        <widget class="QLabel" name="fileName" >
+         <property name="text" >
+          <string>Select conference schedule file</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer" >
+         <property name="orientation" >
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0" >
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QPushButton" name="search" >
+         <property name="text" >
+          <string>Search</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QProgressBar" name="progressBar" >
+       <property name="value" >
+        <number>0</number>
+       </property>
+       <property name="textVisible" >
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2" >
+       <item>
+        <spacer name="horizontalSpacer_2" >
+         <property name="orientation" >
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0" >
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QPushButton" name="import" >
+         <property name="text" >
+          <string>Import</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="cancel" >
+         <property name="text" >
+          <string>Cancel</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>cancel</sender>
+   <signal>clicked()</signal>
+   <receiver>ImportScheduleDialog</receiver>
+   <slot>close()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>515</x>
+     <y>124</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>283</x>
+     <y>80</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>