Changeset d06ae27 for src


Ignore:
Timestamp:
04/15/10 14:01:48 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
f5b68a4
Parents:
be9b645
Message:

store URL's for conferences

  • use it at update
  • let user update the url before request
Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/fosdem.sql

    rbe9b645 rd06ae27  
    1010    , day_change INTEGER
    1111    , timeslot_duration INTEGER
    12     , active INTEGER DEFAULT 0);
    13 INSERT INTO "CONFERENCE" VALUES(1,'FOSDEM 2010','Free and Opensource Software Developers European Meeting','ULB (Campus Solbosch)','Brussels',1265414400,1265500800,2,28800,900,1);
     12    , active INTEGER DEFAULT 0
     13    , url VARCHAR UNIQUE);
     14INSERT 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");
    1415CREATE TABLE TRACK ( id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL
    1516    , name VARCHAR UNIQUE NOT NULL );
  • src/gui/importschedulewidget.cpp

    rbe9b645 rd06ae27  
    3030#include <appsettings.h>
    3131
    32 const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
     32// TODO: this is temporary
     33#include <QInputDialog>
     34
     35#include "conference.h"
     36
     37// const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
    3338
    3439const QString PROXY_USERNAME;
     
    9196        }
    9297
    93         importData(file.readAll());
     98        importData(file.readAll(), QString());
    9499
    95100    }
     
    108113    else
    109114    {
    110         importData(aReply->readAll());
     115        importData(aReply->readAll(), aReply->url().toEncoded());
    111116    }
    112117}
     
    115120{
    116121    QNetworkRequest request;
    117     request.setUrl(QUrl(SCHEDULE_URL));
     122
     123    // TODO: make a nicer GUI
     124    // basically, you have to do the following things:
     125    // 1. store schedule URL for each conteferce
     126    // 2. allow refreshing of the current conference schedule with "1 button click"
     127    // 3. allow changing of the URL for a conference;
     128    //     run refresh together with it is ok and even justified by usability,
     129    //     but it must not loose this change if refresh not available.
     130    //     So it cannot be done as "do like #4 and rely on REPLACE".
     131    // 4. allow getting the new conference by URL
     132
     133    QString url_default;
     134    try {
     135        url_default = Conference::getById(Conference::activeConference()).getUrl();
     136    } catch (OrmException& e) {
     137        qWarning() << "failed to get default URL:" << e.text();
     138    }
     139
     140    bool ok = false;
     141    QString url = QInputDialog::getText(this, "URL request", "Put proper schedule URL or let it try with it", QLineEdit::Normal, url_default, &ok);
     142    if (!ok) { // cancel pressed
     143        return;
     144    }
     145    request.setUrl(QUrl(url));
    118146
    119147    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
     
    121149}
    122150
    123 void ImportScheduleWidget::importData(const QByteArray &aData)
     151void ImportScheduleWidget::importData(const QByteArray &aData, const QString& url)
    124152{
    125153    browse->hide();
     
    128156    // proxySettings->hide();
    129157
    130     int confId = mXmlParser->parseData(aData);
     158    int confId = mXmlParser->parseData(aData, url);
    131159
    132160    progressBar->hide();
  • src/gui/importschedulewidget.h

    rbe9b645 rd06ae27  
    4242        void scheduleImported(int confId);
    4343    private:
    44         void importData(const QByteArray &aData);
     44        void importData(const QByteArray &aData, const QString& url);
    4545    private:
    4646        ScheduleXmlParser *mXmlParser;
  • src/mvc/conference.cpp

    rbe9b645 rd06ae27  
    3030    << QSqlField("day_change", QVariant::Int)
    3131    << QSqlField("timeslot_duration", QVariant::Int)
    32     << QSqlField("active", QVariant::Bool));
     32    << QSqlField("active", QVariant::Bool)
     33    << QSqlField("url", QVariant::String));
    3334
    3435QString const Conference::sTableName = QString("conference");
     
    5859        activeConfs.append(query.record().value("id").toInt());
    5960
     61    qDebug() << __PRETTY_FUNCTION__
     62        << "activeConfs.count()" << activeConfs.count()
     63        ;
     64
    6065    if(activeConfs.count()==0) // no active DB
    6166        return 1;
  • src/mvc/conference.h

    rbe9b645 rd06ae27  
    4949    int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
    5050    bool isActive() const { return value("active").toBool(); }
     51    QString getUrl() const
     52    {
     53        QVariant val = value("url");
     54        qDebug() << __PRETTY_FUNCTION__ << val;
     55        if (val.isValid()) {
     56            return val.toString();
     57        } else {
     58            return QString();
     59        }
     60    }
    5161
    5262    void setId(int id) { setValue("id", id); }
     
    6171    void setTimeslotDuration(int timeslotDuration) { setValue("timeslot_duration", timeslotDuration); }
    6272    void setActive(bool active) { setValue("active", (int)((active))); }
     73    void setUrl(const QString& url) { setValue("url", url.isNull() ? QVariant() : url); }
    6374};
    6475
  • src/sql/schedulexmlparser.cpp

    rbe9b645 rd06ae27  
    3131}
    3232
    33 int ScheduleXmlParser::parseData(const QByteArray &aData)
     33int ScheduleXmlParser::parseData(const QByteArray &aData, const QString& url)
    3434{
    3535    QDomDocument document;
     
    5757            conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
    5858            conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
     59            conference["url"] = url;
    5960            SqlEngine::addConferenceToDB(conference);
    6061            confId = conference["id"].toInt();
  • src/sql/schedulexmlparser.h

    rbe9b645 rd06ae27  
    2929
    3030    public slots:
    31         int parseData(const QByteArray &aData); // returns 'confId' of parsed conference schedule
     31        int parseData(const QByteArray &aData, const QString& url); // returns 'confId' of parsed conference schedule
    3232
    3333    signals:
  • src/sql/sqlengine.cpp

    rbe9b645 rd06ae27  
    102102        if(!confId) // conference 'aConference' isn't in the table => insert
    103103        {
    104             QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9'") \
    105                              .arg(aConference["title"]) \
    106                              .arg(aConference["subtitle"]) \
    107                              .arg(aConference["venue"]) \
    108                              .arg(aConference["city"]) \
    109                              .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
    110                              .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
    111                              .arg(aConference["days"]) \
    112                              .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
    113                              .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
    114                              values.append(QString(", '%1'").arg(confsList.count()>0?"0":"1"));
    115 
    116             QString query = QString("INSERT INTO CONFERENCE (title,subtitle,venue,city,start,end,days,day_change,timeslot_duration,active) VALUES (%1)").arg(values);
    117             QSqlQuery result (query, db);
    118             aConference["id"] = result.lastInsertId().toString(); // 'id' is assigned automatically
     104            QSqlQuery query(db);
     105            query.prepare("INSERT INTO CONFERENCE (title,url,subtitle,venue,city,start,end,days,"
     106                                                    "day_change,timeslot_duration,active) "
     107                            " VALUES (:title,:url,:subtitle,:venue,:city,:start,:end,:days,"
     108                                                    ":day_change,:timeslot_duration,:active)");
     109            foreach (QString prop_name, (QList<QString>() << "title" << "url" << "subtitle" << "venue" << "city" << "days")) {
     110                query.bindValue(QString(":") + prop_name, aConference[prop_name]);
     111            }
     112            query.bindValue(":start", QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t());
     113            query.bindValue(":end", QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t());
     114            query.bindValue(":day_change", -QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0)));
     115            query.bindValue(":day_change", -QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
     116            query.bindValue(":active", confsList.count() > 0 ? 0 : 1);
     117            query.exec();
     118            aConference["id"] = query.lastInsertId().toString(); // 'id' is assigned automatically
    119119        }
    120120    }
Note: See TracChangeset for help on using the changeset viewer.