, 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');
#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;
return;
}
- importData(file.readAll());
+ importData(file.readAll(), QString());
}
else
}
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();
signals:
void scheduleImported(int confId);
private:
- void importData(const QByteArray &aData);
+ void importData(const QByteArray &aData, const QString& url);
private:
ScheduleXmlParser *mXmlParser;
QNetworkAccessManager *mNetworkAccessManager;
<< 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");
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
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); }
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 */
{
}
-int ScheduleXmlParser::parseData(const QByteArray &aData)
+int ScheduleXmlParser::parseData(const QByteArray &aData, const QString& url)
{
QDomDocument document;
document.setContent (aData, false);
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"]));
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
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
}
}
}