Esempio n. 1
0
ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);

    {
        // load JSON data from file to QVariant
        bb::data::JsonDataAccess jda;
        QVariantList lst = jda.load("app/native/assets/mydata.json").toList();
        if (jda.hasError()) {
            bb::data::DataAccessError error = jda.error();
            qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
        }
        else {
            qDebug() << "JSON data loaded OK!";
            GroupDataModel *m = new GroupDataModel();
            // insert the JSON data to model
            m->insertList(lst);
            // make the model flat
            m->setGrouping(ItemGrouping::None);
            // find cascades component of type ListView with an objectName property set to the value 'listView'
            // usable if one do not want to expose GroupDataModel to QML (qmlRegisterType<GroupDataModel>("com.example", 1, 0, "MyListModel");)
            ListView *list_view = root->findChild<ListView*>("listView");
            // assign data model object (m) to its GUI representation object (list_view)
            if(list_view) list_view->setDataModel(m);
        }
    }
}
Esempio n. 2
0
GroupDataModel * Database::getQueryModel(QString query)
{
    GroupDataModel *model = new GroupDataModel(QStringList());
    QVariant data = sqlda->execute(query);
    model->insertList(data.value<QVariantList>());
    return model;
}
Esempio n. 3
0
void MainScreen::sendMessage(Peer* peer, const QString& message)
{
    QByteArray bytes = message.toUtf8();
    if (peer->type() == TGL_BROADCAST_CHAT)
    {
        BroadcastChat* chat = (BroadcastChat*)peer;

        GroupDataModel* members = (GroupDataModel*)chat->members();

        tgl_peer_id_t* peers = new tgl_peer_id_t[members->size()];

        int idx = 0;
        for (QVariantList indexPath = members->first(); !indexPath.isEmpty(); indexPath = members->after(indexPath))
        {
            User* user = (User*)members->data(indexPath).value<QObject*>();
            peers[idx].type = user->type();
            peers[idx].id = user->id();
            idx++;
        }

        tgl_do_send_broadcast(gTLS, members->size(), peers, bytes.data(), bytes.length(), Storage::_broadcastSended, chat);

        delete[] peers;
    }
    else
        tgl_do_send_message(gTLS, {peer->type(), peer->id()}, (const char*)bytes.data(), bytes.length(), 0, 0);
}
Esempio n. 4
0
void Auction::requestFinished(QNetworkReply* reply)
{
	qDebug() << "\n Got Auctions";
	// Check the network reply for errors
	if (reply->error() == QNetworkReply::NoError) {
		mListView = root->findChild<ListView*>("auctionView");
		QString xmldata = QString(reply->readAll());
		qDebug() << "\n "+xmldata;
		GroupDataModel *model = new GroupDataModel(QStringList() << "albumid");
		// Specify the type of grouping to use for the headers in the list
		model->setGrouping(ItemGrouping::None);

		XmlDataAccess xda;
		QVariant list = xda.loadFromBuffer(xmldata, "/cardcategories/album");
		QVariantMap tempMap = list.value<QVariantMap>();
		QVariantList tempList;
		if (tempMap.isEmpty()) {
			tempList = list.value<QVariantList>();
		}
		else {
			tempList.append(tempMap);
		}

		model->insertList(tempList);

		mListView->setDataModel(model);
	}
	else
	{
		qDebug() << "\n Problem with the network";
		qDebug() << "\n" << reply->errorString();
	}

	mActivityIndicator->stop();
}
void SmileyPickerController::pushToView(Emoticon *e) {
    if(e == NULL)
        return;

    // ----------------------------------------------------------------------------------------------
        // get the dataModel of the listview if not already available
        using namespace bb::cascades;

        if(m_ListView == NULL) {
            qWarning() << "did not received the listview. quit.";
            return;
        }

        GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
        if (!dataModel) {

            qDebug() << "create new model";
            dataModel = new GroupDataModel(
                    QStringList() << "tag"
                                  << "localUrl"
                     );
            m_ListView->setDataModel(dataModel);
        }

        // ----------------------------------------------------------------------------------------------
        // push data to the view

        dataModel->insert(e);

}
Esempio n. 6
0
void BalanceController::getWeightsList() {

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;


    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    if (dataModel) {
        dataModel->clear();
    } else {
        qWarning() << "no group data model!";
        return;
    }


    QList<QObject*> datas;

    QList< BodyWeight* > bodyweights = Database::get()->getBodyWeights();
    for(int i = 0 ; i < bodyweights.size() ; ++i) {
        datas.push_back(bodyweights[i]);
    }

    dataModel->insertList(datas);

    emit completed();

}
static void addChatMessageToListModel(void *item, void *user_data)
{
    GroupDataModel *model = (GroupDataModel *)user_data;
    LinphoneChatMessage *message = (LinphoneChatMessage *)item;

    QVariantMap entry;
    entry = fillEntryWithMessageValues(entry, message);
    model->insert(entry);
}
Esempio n. 8
0
void RocknRoll::parseJSON() {
	GroupDataModel *model = new GroupDataModel(QStringList() << "artist" << "song" << "genre" << "year");

	JsonDataAccess jda;
	QVariant list = jda.load("dummy.json");

	model->insertList(list.value<QVariantList>());

	ListView *listView = new ListView();
	listView->setDataModel(model);
}
Esempio n. 9
0
void DriveController::onImageReady(const QString &url, const QString &diskPath) {

    if(diskPath == "loading")
        return;

    if(url[0] == '/')
        return;

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    if (!dataModel) {
        qDebug() << "create new model";
        dataModel = new GroupDataModel(
                QStringList() << "id"
                              << "iconLink"
                              << "title"
                              << "type"
                              << "timestamp"
                );
        m_ListView->setDataModel(dataModel);
    }

    QSettings settings("Amonchakai", "Hg10");
    QStringList keys = dataModel->sortingKeys();
    if(!keys.isEmpty() && keys.last() != settings.value("DriveSortKey", "type").toString()) {
        keys.clear();
        keys.push_back(settings.value("DriveSortKey", "type").toString());
        dataModel->setSortingKeys(keys);
    }

    m_Mutex.lockForWrite();
    for(int i = 0 ; i < m_DriveItems.length() ; ++i) {
        if(m_DriveItems.at(i)->getIconLink() == url) {
            m_DriveItems.at(i)->setIconLink(diskPath);
            dataModel->insert(m_DriveItems.at(i));
            break;
        }
    }
    m_Mutex.unlock();

    emit complete();

}
Esempio n. 10
0
void DriveController::openForSharing(const QString &id, const QString &type) {

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());

    if(type == "application/vnd.google-apps.folder") {
        if(dataModel != NULL)
            dataModel->clear();

        m_Google->getFileList(id);
    } else {
        using namespace bb::cascades;
        using namespace bb::system;

        SystemDialog *dialog = new SystemDialog("Yes", "No");

        dialog->setTitle("Share");
        dialog->setBody("Do you want to share this document?");

        bool success = connect(dialog,
             SIGNAL(finished(bb::system::SystemUiResult::Type)),
             this,
             SLOT(onPromptFinishedShareFile(bb::system::SystemUiResult::Type)));

        if (success) {
            // Signal was successfully connected.
            // Now show the dialog box in your UI.
            m_SelectedItemForSharing = id;
            dialog->show();
        } else {
            // Failed to connect to signal.
            // This is not normal in most cases and can be a critical
            // situation for your app! Make sure you know exactly why
            // this has happened. Add some code to recover from the
            // lost connection below this line.
            dialog->deleteLater();
        }

    }

}
Esempio n. 11
0
void HeatScores::requestFinished(QNetworkReply* reply)
{
    // Check the network reply for errors
    if (reply->error() == QNetworkReply::NoError) {
    	QString colours [] = {"asset:///images/scoring/red.png", "asset:///images/scoring/black.png",
    	    	"asset:///images/scoring/blue.png", "asset:///images/scoring/green.png", "asset:///images/scoring/white.png"};

    	QString result(reply->readAll());

    	qDebug() << "\n Scoring result: " << result;

    	GroupDataModel *model = new GroupDataModel();
		model->setGrouping(ItemGrouping::None);

    	XmlDataAccess xda;
		QVariant scoreData = xda.loadFromBuffer(result);

		QVariantMap scoreMap = scoreData.value<QVariantMap>();

		QVariantMap scoresMap = scoreMap["scores"].value<QVariantMap>();
		QVariantList scoreList = scoresMap["score"].value<QVariantList>();
		QMap<QString, QVariant> scoreEntry;
		for (int i = 0; i < scoreList.size(); i++) {
			QVariantMap score = scoreList[i].value<QVariantMap>();
			QVariantMap wavesMap = score["waves"].value<QVariantMap>();
			QVariantList waveList = wavesMap["wave"].value<QVariantList>();

			scoreEntry["surfer_name"] = score["surfer_name"].value<QString>();
			scoreEntry["surfer_points"] = score["surfer_points"].value<QString>();
			scoreEntry["surfer_points_needed"] = score["surfer_points_needed"].value<QString>();
			scoreEntry["surfer_colour"] = colours[i%5];
			scoreEntry["waves"] = waveList;

			model->insert(scoreEntry);
		}

		(root->findChild<ListView*>("heatListView"))->setDataModel(model);
		(root->findChild<ListView*>("heatListView"))->setListItemProvider(mScoreFactory);
    }
    else {
        qDebug() << "\n Scoring Problem with the network";
        qDebug() << "\n Scoring " << reply->errorString();
    }

    (root->findChild<Label*>("scoresRefreshingLabel"))->setText("");
    mActivityIndicator->stop();
    mLoading = false;
}
Esempio n. 12
0
void DriveController::search(const QString &key) {
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());

    if(dataModel != NULL) {
        m_DriveItems.clear();
        dataModel->clear();
    }

    m_Google->search(key);
}
Esempio n. 13
0
void BalanceController::onPromptFinishedDeleteRecord(bb::system::SystemUiResult::Type type) {
    if(type == bb::system::SystemUiResult::ConfirmButtonSelection) {

        Database::get()->deleteBodyWeight(m_tmp_id);

        if(m_ListView == NULL) {
            qWarning() << "did not received the listview. quit.";
            return;
        }

        using namespace bb::cascades;
        GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
        QVariantList indexPath = dataModel->find(QVariantList() << m_tmp_id);
        dataModel->removeAt(indexPath);

    }
}
Esempio n. 14
0
void ProfileController::parseFeedback(const QString& page) {
    QRegExp feedback("<a href=\"[^\"]+\" target=\"_blank\">(.*)</a></td><td class=\"col2\">(.*)</td><td class=\"col3 .*\">(.*)</td><td>([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9])</td><td class=\"col4\">(.*)</a></td>");
    feedback.setMinimal(true);


    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;


    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    if (dataModel) {
        dataModel->clear();
    }

    // ----------------------------------------------------------------------------------------------
    // push data to the view

    int pos = 0;
    while((pos = feedback.indexIn(page, pos)) != -1) {

        ReviewListItem *item = new ReviewListItem;
        item->setFrom(feedback.cap(1));
        item->setRole(feedback.cap(2));
        item->setDate(feedback.cap(4));
        item->setAdvice(feedback.cap(3));
        item->setReview(feedback.cap(5));
        item->setTimestamp(QDateTime::fromString(feedback.cap(3), "dd/MM/yyyy").toMSecsSinceEpoch());

        QRegExp cleanup("<a href=\"[^\"]+\" target=\"_blank\">(.*)");
        if(cleanup.indexIn(feedback.cap(5)) != -1) {
            item->setReview(cleanup.cap(1));
        }

        dataModel->insert(item);

        pos += feedback.matchedLength();
    }
}
void ListFavoriteController::updateView() {
	// ----------------------------------------------------------------------------------------------
	// get the dataModel of the listview if not already available
	using namespace bb::cascades;


	if(m_ListView == NULL) {
		qWarning() << "did not received the listview. quit.";
		return;
	}

	GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
	if (dataModel) {
		dataModel->clear();
	} else {
		qDebug() << "create new model";
		dataModel = new GroupDataModel(
				QStringList() << "title"
							  << "timestamp"
							  << "lastAuthor"
							  << "urlFirstPage"
							  << "urlLastPage"
							  << "urlLastPostRead"
							  << "pages"
							  << "flagType"
							  << "read"
							  << "color"
							  << "groupKey"
				);
		m_ListView->setDataModel(dataModel);
	}
	dataModel->setGrouping(ItemGrouping::ByFullValue);

	// ----------------------------------------------------------------------------------------------
	// push data to the view

	QList<QObject*> datas;
	for(int i = m_Datas->length()-1 ; i >= 0 ; --i) {
		datas.push_back(m_Datas->at(i));
	}

	dataModel->clear();
	dataModel->insertList(datas);
}
void ExploreCategoryController::updateView() {

	// ----------------------------------------------------------------------------------------------
	// get the dataModel of the listview if not already available

	if(m_ListView == NULL) {
		qWarning() << "the list view is either not provided or not a listview...";
		return;
	}

	using namespace bb::cascades;

	GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
	if (dataModel) {
		dataModel->clear();
	} else {
		dataModel = new GroupDataModel(
						QStringList() << "title"
									  << "timestamp"
									  << "lastAuthor"
									  << "urlFirstPage"
									  << "urlLastPage"
									  << "urlLastPostRead"
									  << "pages"
									  << "flagType"
									  << "read"
					);
		m_ListView->setDataModel(dataModel);
	}
	dataModel->setGrouping(ItemGrouping::ByFullValue);

	// ----------------------------------------------------------------------------------------------
	// push data to the view

	QList<QObject*> datas;
	for(int i = m_Datas->length()-1 ; i >= 0 ; --i) {
		datas.push_back(m_Datas->at(i));
	}

	dataModel->clear();
	dataModel->insertList(datas);

}
Esempio n. 17
0
GroupDataModel* Database::getLive(int uid,int offset,QString type)
{

    GroupDataModel *model = new GroupDataModel(QStringList());
    QString query = "select * from messagesTab where (fromId = \"";
    query.append(QString::number(uid));
    query.append("\" or toId = \"");
    query.append(QString::number(uid));
    query.append("\" ) and type = \"");
    query.append(type);
    query.append("\" and id > \"");
    query.append(QString::number(offset));
    query.append("\" order by date desc");
    QVariant list = sqlda->execute(query);
    model->clear();
    model->insertList(list.value<QVariantList>());
    qDebug()<< "userid in database " << uid << offset << type;
    qDebug() << query << model->size();
    return model;
}
Esempio n. 18
0
void DriveController::onDialogSortingKeyFinished(bb::system::SystemUiResult::Type result) {

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());


    if(result == bb::system::SystemUiResult::ConfirmButtonSelection) {

        const QList<int> &indices = m_listdialog->selectedIndices();
        QStringList keys;

        switch(indices[0]) {
            case 0:
                keys.push_back("title");
                break;
            case 1:
                keys.push_back("type");
                break;
            case 2:
                keys.push_back("timestamp");
                break;
        }

        if(!keys.isEmpty()) {
            QSettings settings("Amonchakai", "Hg10");
            settings.setValue("DriveSortKey", keys.last());
        }


        dataModel->setSortingKeys(keys);

    }
}
Esempio n. 19
0
void DriveController::open(const QString &id, const QString &type) {
    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());

    if(type == "application/vnd.google-apps.folder") {
        if(dataModel != NULL)
            dataModel->clear();

        m_Google->getFileList(id);
    } else {

        QString link;
        m_Mutex.lockForRead();
        for(int i = 0 ; i < m_DriveItems.length() ; ++i) {
            if(m_DriveItems.at(i)->getID() == id) {
                link = m_DriveItems.at(i)->getOpenLink();
                break;
            }
        }
        m_Mutex.unlock();

        if(!link.isEmpty())
            emit pushOpenLink(link);
        else {
            bb::system::SystemToast *toast = new bb::system::SystemToast(this);

            toast->setBody(tr("Cannot open this file..."));
            toast->setPosition(bb::system::SystemUiPosition::MiddleCenter);
            toast->show();
        }
    }

}
Esempio n. 20
0
void SmileyPickerController::updateView() {
    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    if (dataModel) {
        dataModel->clear();
    } else {
        qDebug() << "create new model";
        dataModel = new GroupDataModel(
                QStringList() << "tag"
                              << "localUrl"
                 );
        m_ListView->setDataModel(dataModel);
    }

    // ----------------------------------------------------------------------------------------------
    // push data to the view

    QList<QObject*> datas;
    for(int i = 0 ; i < m_Emoticons.size() ; ++i) {

        Emoticon *e = new Emoticon;
        e->setLocalUrl(m_Emoticons.at(i)->getLocalUrl());
        e->setTag(m_Emoticons.at(i)->getTag());
        datas.push_back(e);

    }

    dataModel->clear();
    dataModel->insertList(datas);


}
Esempio n. 21
0
void SmileyPickerController::getSmiley(const QString &keyword) {

    if(keyword.isEmpty())
        return;

	// list green + yellow flags
	const QUrl url(DefineConsts::FORUM_URL + "/message-smi-mp-aj.php?config=hfr.inc&findsmilies=" + keyword);

	QNetworkRequest request(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

	QSslConfiguration sslConfig = request.sslConfiguration();
    sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
    sslConfig.setPeerVerifyDepth(1);
    sslConfig.setProtocol(QSsl::TlsV1);
    sslConfig.setSslOption(QSsl::SslOptionDisableSessionTickets, true);

    request.setSslConfiguration(sslConfig);


	QNetworkReply* reply = HFRNetworkAccessManager::get()->get(request);
	bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkReply()));
	Q_ASSERT(ok);
	Q_UNUSED(ok);

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    dataModel->clear();

}
Esempio n. 22
0
void BugReportController::updateView() {
    // ----------------------------------------------------------------------------------------------
        // get the dataModel of the listview if not already available
        using namespace bb::cascades;


        if(m_ListView == NULL) {
            qWarning() << "did not received the listview. quit.";
            return;
        }

        GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
        if (dataModel) {
            dataModel->clear();
        } else {
            qDebug() << "create new model";
            dataModel = new GroupDataModel(
                    QStringList() << "title"
                                  << "author"
                                  << "number"
                                  << "locked"
                                  << "avatar"
                                  << "comments"
                    );
            m_ListView->setDataModel(dataModel);
        }

        // ----------------------------------------------------------------------------------------------
        // push data to the view

        QList<QObject*> datas;
        for(int i = m_Issues.length()-1 ; i >= 0 ; --i) {
            datas.push_back(m_Issues.at(i));
        }

        dataModel->clear();
        dataModel->insertList(datas);
}
Esempio n. 23
0
Pelatihan::Pelatihan(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime


	qmlRegisterType<WebImageView>("WebImageView", 1, 0, "WebImageView");
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);


	// create root object for the UI
	AbstractPane *root = qml->createRootObject<AbstractPane>();
	ListView *lv= root->findChild<ListView*>("listdata");

	bb::data::JsonDataAccess jda;

	QVariant data = jda.load(
			QDir::currentPath() + "/app/native/assets/db.json");

	QVariantList dataList = data.toList();

	qDebug()<< dataList.size();
	GroupDataModel *dm = new GroupDataModel(QStringList() << "id");
	dm->setGrouping(ItemGrouping::None);

	for (QList<QVariant>::iterator it = dataList.begin(); it != dataList.end();
			it++) {
		QVariantMap post = it->toMap();
		dm->insert(post);
	}


	lv->setDataModel(dm);


	// set created root object as a scene
	app->setScene(root);
}
Esempio n. 24
0
void SmileyPickerController::getPrevPage() {
	if(m_IndexSubpagesInFile.length() == 0)
		return;

	if(m_Page.isEmpty())
	    return;

    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    dataModel->clear();

	m_lastId = std::max(m_lastId-1, 0);

	parse(m_Page, m_IndexSubpagesInFile[m_lastId]);
}
Esempio n. 25
0
void HistoryBrowserController::updateThreadsView(const QByteArray& buffer) {
    using namespace bb::data;
    JsonDataAccess jda;

    QVariant qtData = jda.loadFromBuffer(buffer);

    if(jda.hasError()) {
        qDebug() << jda.error().errorMessage();
    }


    if(m_HistoryList == NULL) {
        qWarning() << "did not received the list. quit.";
        return;
    }

    using namespace bb::cascades;
    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_HistoryList->dataModel());
    dataModel->clear();

    dataModel->insertList(qtData.toMap()["threads"].toList());

    emit completed();
}
Esempio n. 26
0
void Weather::requestFinished(QNetworkReply* reply)
{
    // Check the network reply for errors
    if (reply->error() == QNetworkReply::NoError) {

    	QString timeString("");
    	QTextStream timeStream(&timeString);
    	QTime time;
    	time.start();
    	qDebug() << "\n weather time: " << time.toString("hh:mm:ss.zzz");
    	qDebug() << "\n weather time hh: " << time.toString("hh");
    	qDebug() << "\n weather time.hour(): " << time.hour();
    	qDebug() << "\n weather time.minute(): " << time.minute();
    	qDebug() << "\n weather time.second(): " << time.second();

    	timeStream << time.hour() << "00";

    	qDebug() << "\n weather timeString: " << timeString;

    	QString result(reply->readAll());

    	qDebug() << "\n result: " << result;

		XmlDataAccess xda;
		QVariant weatherData = xda.loadFromBuffer(result, "/data/weather");

		QVariantMap weatherMap = weatherData.value<QVariantMap>();

		qDebug() << "\n weather date: " << weatherMap["date"].value<QString>();
		qDebug() << "\n weather maxtempC: " << weatherMap["maxtempC"].value<QString>();
		qDebug() << "\n weather mintempC: " << weatherMap["mintempC"].value<QString>();

		QVariantList qList = weatherMap["hourly"].value<QVariantList>();

		GroupDataModel *model = new GroupDataModel(QStringList() << "id");
		// Specify the type of grouping to use for the headers in the list
		model->setGrouping(ItemGrouping::None);

		QMap<QString, QVariant> weatherEntry;
		QString hString;
		for (int i = 0; i < qList.size(); i++) {
			QVariantMap temp = qList[i].value<QVariantMap>();
			hString = temp["time"].value<QString>();
			if (hString.length() <= 3) {
				hString.prepend(QString("0"));
			}
			hString.remove(2, 2);
			hString.append(QString("h"));


			weatherEntry["id"] = i;
			weatherEntry["time"] = hString;
			weatherEntry["weatherIconUrl"] = temp["weatherIconUrl"].value<QString>();
			weatherEntry["windspeedKmph"] = temp["windspeedKmph"].value<QString>();
			weatherEntry["winddirDegree"] = temp["winddirDegree"].value<QString>();
			weatherEntry["tempC"] = temp["tempC"].value<QString>();
			weatherEntry["cloudcover"] = temp["cloudcover"].value<QString>();
			weatherEntry["pressure"] = temp["pressure"].value<QString>();
			weatherEntry["humidity"] = temp["humidity"].value<QString>();
			weatherEntry["swellHeight_m"] = temp["swellHeight_m"].value<QString>();
			weatherEntry["swellDir"] = temp["swellDir"].value<QString>();

			model->insert(weatherEntry);

			if ((temp["time"].value<QString>()).toInt() <= timeString.toInt()) {
				(root->findChild<Label*>("dateLabel"))->setText(weatherMap["date"].value<QString>());
				(root->findChild<Label*>("maxTempLabel"))->setText(weatherMap["maxtempC"].value<QString>());
				(root->findChild<Label*>("minTempLabel"))->setText(weatherMap["mintempC"].value<QString>());
			}
		}

		(root->findChild<Label*>("maxTempLabelHeader"))->setVisible(true);
		(root->findChild<Label*>("minTempLabelHeader"))->setVisible(true);
		(root->findChild<Container*>("weatherTitleList"))->setVisible(true);

		(root->findChild<ListView*>("weatherListView"))->setDataModel(model);
		(root->findChild<ListView*>("weatherListView"))->setListItemProvider(mWeatherFactory);
    }
    else {
        qDebug() << "\n Problem with the network";
        qDebug() << "\n" << reply->errorString();
    }

    mActivityIndicator->stop();
}
Esempio n. 27
0
void OnAuctionList::requestFinished(QNetworkReply* reply)
{
	qDebug() << "\n Got OnAuction List";
	// Check the network reply for errors
	if (reply->error() == QNetworkReply::NoError) {
		mListView = root->findChild<ListView*>("onAuctionListList");
		QString xmldata = QString(reply->readAll());

		qDebug() << "\nOnAuctionList xml: " << xmldata;

		GroupDataModel *model = new GroupDataModel(QStringList() << "description");
		// Specify the type of grouping to use for the headers in the list
		model->setGrouping(ItemGrouping::None);

		XmlDataAccess xda;
		QVariant list = xda.loadFromBuffer(xmldata, (mUserAuctions)?"/auctionsincategory/auction":"/auctionsincategory");

		QVariantList tempList;
		QVariantMap tempMap;
		if (!mUserAuctions) {
			QVariantMap allMap = list.value<QVariantMap>();
			QString credits = allMap["credits"].value<QString>();
			QString premium = allMap["premium"].value<QString>();

			(root->findChild<Label*>("auctionCreditsLabel"))->setText(credits);
			(root->findChild<Label*>("auctionPremiumLabel"))->setText(premium);

			tempMap = allMap["auction"].value<QVariantMap>();
			if (tempMap.isEmpty()) {
				tempList = allMap["auction"].value<QVariantList>();
			}
			else {
				tempList.append(tempMap);
			}
		}
		else {
			(root->findChild<Label*>("auctionCreditsLabel"))->setText("");
			(root->findChild<Label*>("auctionPremiumLabel"))->setText("");

			tempMap = list.value<QVariantMap>();

			if (tempMap.isEmpty()) {
				tempList = list.value<QVariantList>();
			}
			else {
				tempList.append(tempMap);
			}
		}

		model->insertList(tempList);

		mListView->setDataModel(model);
		AuctionItemFactory *itemfactory = new AuctionItemFactory();
		mListView->setListItemProvider(itemfactory);
	}
	else
	{
		qDebug() << "\n Problem with the network";
		qDebug() << "\n" << reply->errorString();
	}

	mActivityIndicator->stop();
}