Changeset 222:618e7b31bae8 in SMSSender


Ignore:
Timestamp:
May 30, 2012 12:39:09 PM (8 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
default
Message:

Schoolnet:

  • Removed regular question list updates from DeepThought?. Instead an update is just done at the start (or after adding the first schoolnet account).
  • Sending answer correctness informations, which DeepThought? does not know, at the application start to him.
  • Highlighting wrong answers in the question list by striking them throught.
  • In the question list, disabling the answers of a question if one is loading.
Location:
gateways/Schoolnet
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • gateways/Schoolnet/schoolnet.pro

    r220 r222  
    77HEADERS += src/business/contactimporter/bccontactimporter.h \
    88    src/business/deepthought/datatypes.h \
     9    src/business/deepthought/datatypes_p.h \
    910    src/business/deepthought/deepthoughthelper.h \
    1011    src/business/deepthought/deepthought_daemons.h \
     
    2425    src/ui/vcquestionlist/vcquestionlist.h \
    2526    src/ui/vcaccount_guiintegration.h \
    26     src/library.h \
    27     src/business/deepthought/datatypes_p.h
     27    src/library.h
    2828SOURCES += src/business/contactimporter/bccontactimporter.cpp \
    2929    src/business/deepthought/datatypes.cpp \
  • gateways/Schoolnet/src/business/deepthought/deepthought_daemon_deepthought.cpp

    r220 r222  
    3131DeepThoughtDaemon::DeepThoughtDaemon(QObject* parent)
    3232    : QObject(parent)
     33    , questionsFetched_(false)
    3334{
    3435    connect(QuestionManager::instance(), SIGNAL(answerCorrectnessProvided(const Answer&)),
    3536            this, SLOT(onAnswerCorrectnessProvided(const Answer&)));
    3637
    37     connect(Library::instance()->managerFactory()->accountManager(), SIGNAL(accountAdded(IAccount*)),
    38             this, SLOT(accountAdded(IAccount*)));
     38    connect(Library::instance()->managerFactory()->accountManager(), SIGNAL(onAccountAdded(IAccount*)),
     39            this, SLOT(onAccountAdded(IAccount*)));
    3940    connect(Library::instance()->managerFactory()->accountManager(), SIGNAL(accountDataChanged(IAccount*, int)),
    40             SLOT(accountAdded(IAccount*)));
     41            SLOT(onAccountAdded(IAccount*)));
    4142
    42     timer_ = new QTimer(this);
    43     timer_->setInterval(60 * 60 * 1000); // Every hour
    44     connect(timer_, SIGNAL(timeout()), this, SLOT(fetchRemoteQuestions()));
    45 
    46     start();
     43    /* Ensure that this constructor does not get called multiple times due to a call
     44       of DeepThoughtHelper::instance() in the methods in start(). */
     45    QTimer::singleShot(0, this, SLOT(start()));
    4746}
    4847
    49 /*** This part is used to fetch question data from the deepthought server at a regular basis. ***/
    5048void DeepThoughtDaemon::start() {
    51     if (!timer_->isActive()) {
    52         fetchRemoteQuestions(); // Does an immediate call
    53         // timer_->start(); Don't start the timer here, since fetchRemoteQuestions can return immediately if no account has deepthought usage enabled.
    54     }
     49    sendKnowledgeToDeepThought();
     50    fetchRemoteQuestions();
    5551}
    56 void DeepThoughtDaemon::stop() {
    57     timer_->stop();
    58 }
    59 
    6052
    6153void DeepThoughtDaemon::fetchRemoteQuestions() {
     
    8274    task->start();
    8375
    84     // Start for the next update
    85     timer_->start();
     76    questionsFetched_ = true;
    8677}
    8778
    88 void DeepThoughtDaemon::accountAdded(IAccount* account) {
     79/**
     80 * Sends answer correctness informations, which DeepThought does not already know, to him.
     81 */
     82void DeepThoughtDaemon::sendKnowledgeToDeepThought() {
     83    foreach (Question question, QuestionManager::instance()->questions()) {
     84        foreach (Answer answer, question.answers()) {
     85            if (answer.isAnswered() && !answer.doesDeepThoughtKnowCorrectness()) {
     86                onAnswerCorrectnessProvided(answer);
     87            }
     88        }
     89    }
     90}
     91
     92
     93void DeepThoughtDaemon::onAccountAdded(IAccount* account) {
    8994    if (account->gateway() != BCGateway::instance()) {
    9095        return;
     
    96101    }
    97102
    98     start();
     103    if (!questionsFetched_) {
     104        fetchRemoteQuestions();
     105    }
    99106}
    100107
  • gateways/Schoolnet/src/business/deepthought/deepthought_daemons.h

    r220 r222  
    6767
    6868private:
    69     void start();
    70     void stop();
     69    void fetchRemoteQuestions();
     70    void sendKnowledgeToDeepThought();
    7171
    7272private slots:
    73     void accountAdded(IAccount* account);
    74     void fetchRemoteQuestions();
    75 
     73    void start();
     74    void onAccountAdded(IAccount* account);
    7675    void onAnswerCorrectnessProvided(const Answer& answer);
    7776
    7877private:
    79     QTimer* timer_;
     78    bool questionsFetched_;
    8079};
    8180
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_answertodeepthougth.cpp

    r220 r222  
    4747                                                                            .arg(question.nrNodeGuId())
    4848                                                                            .arg(question.eventTarget())
    49                                                                             .arg((int)answer().isCorrect())
     49                                                                            .arg(answer().isCorrect() ? 1 : 0)
    5050                                                                            .arg(answer().id())
    5151                                                                            .arg(question.hint()));
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_answertoschoolnet.cpp

    r220 r222  
    122122        // An answer is checked
    123123        QRegExp rx2("value=\"([^\"]+)\"", Qt::CaseInsensitive);
    124         QString selectedAnswerId;
    125124        if (rx2.indexIn(rx.cap(2)) != -1) {
    126125            QString selectedAnswerId = rx2.cap(1);
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_check_questionstatus_at_schoolnet.cpp

    r220 r222  
    3434{
    3535    setTitle(tr("Checking question status at schoolnet"));
     36
    3637    setSelfBlocking(false);
     38    addBlockingTask(UID_ACCOUNT_INIT, ACCOUNT_NAMESPACE_PREFIX + account->name());
     39    addBlockingTask(UID_SEND_SMS, ACCOUNT_NAMESPACE_PREFIX + account->name());
    3740}
    3841
  • gateways/Schoolnet/src/business/deepthought/questionmanager.cpp

    r220 r222  
    140140
    141141/**
    142  * Sets the "status at schoolnet checked" and the "question answered at schoolnet" flag.
    143  *
    144142 * @see DADeepThoughtStorage::setQuestionAnsweredAtSchoolnet()
    145143 */
    146144void QuestionManager::setQuestionAnsweredAtSchoolnet(BCAccount* account, const Question& question) const {
    147     setStatusAtSchoolnetChecked(account, question);
    148145    DADeepThoughtStorage::instance()->setQuestionAnsweredAtSchoolnet(account, question);
    149146}
  • gateways/Schoolnet/src/persistence/deepthought/dadeepthoughtstorage.cpp

    r220 r222  
    506506
    507507/**
    508  * Marks the given question as answered at schoolnet.
     508 * Marks the given question as answered at schoolnet and that the status has been checked as well.
    509509 *
    510510 * @param account The schoolnet account
     
    512512 */
    513513void DADeepThoughtStorage::setQuestionAnsweredAtSchoolnet(BCAccount *account, const Question &question) const {
    514     uint newStatus = questionStatusAtSchoolnet(account, question) | Question::AnsweredAtSchoolnet;
     514    uint newStatus = questionStatusAtSchoolnet(account, question)
     515            | Question::AnsweredAtSchoolnet
     516            | Question::StatusAtSchoolnetChecked;
    515517    setQuestionStatusAtSchoolnet(account, question, newStatus);
    516518}
  • gateways/Schoolnet/src/ui/models/questiontreemodel.cpp

    r220 r222  
    168168                }
    169169                break;
     170
     171            case Qt::FontRole:
     172                QFont font;
     173                if ((index.column() == ColAnswerText) && (answerStatus(answer) == asAnsweredWrong)) {
     174                    font.setStrikeOut(true);
     175                }
     176                return font;
    170177        }
    171178    }
     
    191198    if (node->isQuestion()) {
    192199        // It's a question
    193         //Question question = node->question();
    194         if (index.column() == ColQuestionText) {
     200        Question question = node->question();
     201        if ((index.column() == ColQuestionText) && (questionStatus(question) != qsLoading)) {
    195202            flags |= Qt::ItemIsEditable;
    196203        }
     
    203210                if (answerStatus(answer) == asCanBeAnswered) {
    204211                    flags |= Qt::ItemIsUserCheckable;
     212                }
     213                if (questionStatus(answer.question()) == qsLoading) {
     214                    flags &= !Qt::ItemIsEnabled; // Disable all if one answer is loading
    205215                }
    206216                break;
Note: See TracChangeset for help on using the changeset viewer.