store URL's for conferences
authorkirilma <kirilma@localhost>
Thu, 15 Apr 2010 12:01:48 +0000 (12:01 +0000)
committerkirilma <kirilma@localhost>
Thu, 15 Apr 2010 12:01:48 +0000 (12:01 +0000)
* use it at update
* let user update the url before request

src/fosdem.sql
src/gui/importschedulewidget.cpp
src/gui/importschedulewidget.h
src/mvc/conference.cpp
src/mvc/conference.h
src/sql/schedulexmlparser.cpp
src/sql/schedulexmlparser.h
src/sql/sqlengine.cpp

index 7054fc0..c2358dc 100644 (file)
@@ -9,8 +9,9 @@ CREATE TABLE CONFERENCE ( id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL
     , days INTEGER
     , day_change INTEGER
     , timeslot_duration INTEGER
-    , active INTEGER DEFAULT 0);
-INSERT INTO "CONFERENCE" VALUES(1,'FOSDEM 2010','Free and Opensource Software Developers European Meeting','ULB (Campus Solbosch)','Brussels',1265414400,1265500800,2,28800,900,1);
+    , active INTEGER DEFAULT 0
+    , url VARCHAR UNIQUE);
+INSERT INTO "CONFERENCE" VALUES(1,'FOSDEM 2010','Free and Opensource Software Developers European Meeting','ULB (Campus Solbosch)','Brussels',1265414400,1265500800,2,28800,900,1,"http://fosdem.org/2010/schedule/xml");
 CREATE TABLE TRACK ( id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL
     , name VARCHAR UNIQUE NOT NULL );
 INSERT INTO "TRACK" VALUES(1,'Keynotes');
index a63d93f..e6f3e02 100644 (file)
 #include <QDebug>
 #include <appsettings.h>
 
-const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
+// TODO: this is temporary
+#include <QInputDialog>
+
+#include "conference.h"
+
+// const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
 
 const QString PROXY_USERNAME;
 const QString PROXY_PASSWD;
@@ -90,7 +95,7 @@ void ImportScheduleWidget::browseSchedule()
             return;
         }
 
-        importData(file.readAll());
+        importData(file.readAll(), QString());
 
     }
     else
@@ -107,27 +112,50 @@ void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
     }
     else
     {
-        importData(aReply->readAll());
+        importData(aReply->readAll(), aReply->url().toEncoded());
     }
 }
 
 void ImportScheduleWidget::downloadSchedule()
 {
     QNetworkRequest request;
-    request.setUrl(QUrl(SCHEDULE_URL));
+
+    // TODO: make a nicer GUI
+    // basically, you have to do the following things:
+    // 1. store schedule URL for each conteferce
+    // 2. allow refreshing of the current conference schedule with "1 button click"
+    // 3. allow changing of the URL for a conference;
+    //     run refresh together with it is ok and even justified by usability,
+    //     but it must not loose this change if refresh not available.
+    //     So it cannot be done as "do like #4 and rely on REPLACE".
+    // 4. allow getting the new conference by URL
+
+    QString url_default;
+    try {
+        url_default = Conference::getById(Conference::activeConference()).getUrl();
+    } catch (OrmException& e) {
+        qWarning() << "failed to get default URL:" << e.text();
+    }
+
+    bool ok = false;
+    QString url = QInputDialog::getText(this, "URL request", "Put proper schedule URL or let it try with it", QLineEdit::Normal, url_default, &ok);
+    if (!ok) { // cancel pressed
+        return;
+    }
+    request.setUrl(QUrl(url));
 
     mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
     mNetworkAccessManager->get(request);
 }
 
-void ImportScheduleWidget::importData(const QByteArray &aData)
+void ImportScheduleWidget::importData(const QByteArray &aData, const QString& url)
 {
     browse->hide();
     online->hide();
     progressBar->show();
     // proxySettings->hide();
 
-    int confId = mXmlParser->parseData(aData);
+    int confId = mXmlParser->parseData(aData, url);
 
     progressBar->hide();
     browse->show();
index 6f25d22..f067921 100644 (file)
@@ -41,7 +41,7 @@ class ImportScheduleWidget : public QWidget, Ui::ImportScheduleWidget
     signals:
         void scheduleImported(int confId);
     private:
-        void importData(const QByteArray &aData);
+        void importData(const QByteArray &aData, const QString& url);
     private:
         ScheduleXmlParser *mXmlParser;
         QNetworkAccessManager *mNetworkAccessManager;
index b08a248..23c4cc2 100644 (file)
@@ -29,7 +29,8 @@ QSqlRecord const Conference::sColumns = Conference::toRecord(QList<QSqlField>()
     << QSqlField("days", QVariant::Int)
     << QSqlField("day_change", QVariant::Int)
     << QSqlField("timeslot_duration", QVariant::Int)
-    << QSqlField("active", QVariant::Bool));
+    << QSqlField("active", QVariant::Bool)
+    << QSqlField("url", QVariant::String));
 
 QString const Conference::sTableName = QString("conference");
 
@@ -57,6 +58,10 @@ int Conference::activeConference()
     while(query.next())
         activeConfs.append(query.record().value("id").toInt());
 
+    qDebug() << __PRETTY_FUNCTION__
+        << "activeConfs.count()" << activeConfs.count()
+        ;
+
     if(activeConfs.count()==0) // no active DB
         return 1;
     else // even if there are more active confs, the first from the list is confidered active
index d8b9318..26ea87b 100644 (file)
@@ -48,6 +48,16 @@ public:
     int dayChange() const { return value("day_change").toInt(); } // in seconds from 00:00
     int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
     bool isActive() const { return value("active").toBool(); }
+    QString getUrl() const
+    {
+        QVariant val = value("url");
+        qDebug() << __PRETTY_FUNCTION__ << val;
+        if (val.isValid()) {
+            return val.toString();
+        } else {
+            return QString();
+        }
+    }
 
     void setId(int id) { setValue("id", id); }
     void setTitle(const QString& title) { setValue("title", title); }
@@ -60,6 +70,7 @@ public:
     void setDayChange(int dayChange) { setValue("day_change", dayChange); }
     void setTimeslotDuration(int timeslotDuration) { setValue("timeslot_duration", timeslotDuration); }
     void setActive(bool active) { setValue("active", (int)((active))); }
+    void setUrl(const QString& url) { setValue("url", url.isNull() ? QVariant() : url); }
 };
 
 #endif /* CONFERENCE_H */
index 8ce0a68..fb869ae 100644 (file)
@@ -30,7 +30,7 @@ ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
 {
 }
 
-int ScheduleXmlParser::parseData(const QByteArray &aData)
+int ScheduleXmlParser::parseData(const QByteArray &aData, const QString& url)
 {
     QDomDocument document;
     document.setContent (aData, false);
@@ -56,6 +56,7 @@ int ScheduleXmlParser::parseData(const QByteArray &aData)
             conference["days"] = conferenceElement.firstChildElement("days").text(); // int
             conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
             conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
+            conference["url"] = url;
             SqlEngine::addConferenceToDB(conference);
             confId = conference["id"].toInt();
             emit(parsingSchedule(conference["title"]));
index bd324e1..147728f 100644 (file)
@@ -28,7 +28,7 @@ class ScheduleXmlParser : public QObject
         ScheduleXmlParser (QObject *aParent = NULL);\r
 \r
     public slots:\r
-        int parseData(const QByteArray &aData); // returns 'confId' of parsed conference schedule\r
+        int parseData(const QByteArray &aData, const QString& url); // returns 'confId' of parsed conference schedule\r
 \r
     signals:\r
         void progressStatus(int aStatus);\r
index 99049df..cc7122f 100644 (file)
@@ -101,21 +101,21 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference)
 
         if(!confId) // conference 'aConference' isn't in the table => insert
         {
-            QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9'") \
-                             .arg(aConference["title"]) \
-                             .arg(aConference["subtitle"]) \
-                             .arg(aConference["venue"]) \
-                             .arg(aConference["city"]) \
-                             .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
-                             .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
-                             .arg(aConference["days"]) \
-                             .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
-                             .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
-                             values.append(QString(", '%1'").arg(confsList.count()>0?"0":"1"));
-
-            QString query = QString("INSERT INTO CONFERENCE (title,subtitle,venue,city,start,end,days,day_change,timeslot_duration,active) VALUES (%1)").arg(values);
-            QSqlQuery result (query, db);
-            aConference["id"] = result.lastInsertId().toString(); // 'id' is assigned automatically
+            QSqlQuery query(db);
+            query.prepare("INSERT INTO CONFERENCE (title,url,subtitle,venue,city,start,end,days,"
+                                                    "day_change,timeslot_duration,active) "
+                            " VALUES (:title,:url,:subtitle,:venue,:city,:start,:end,:days,"
+                                                    ":day_change,:timeslot_duration,:active)");
+            foreach (QString prop_name, (QList<QString>() << "title" << "url" << "subtitle" << "venue" << "city" << "days")) {
+                query.bindValue(QString(":") + prop_name, aConference[prop_name]);
+            }
+            query.bindValue(":start", QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t());
+            query.bindValue(":end", QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t());
+            query.bindValue(":day_change", -QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0)));
+            query.bindValue(":day_change", -QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
+            query.bindValue(":active", confsList.count() > 0 ? 0 : 1);
+            query.exec();
+            aConference["id"] = query.lastInsertId().toString(); // 'id' is assigned automatically
         }
     }
 }