Exemplo n.º 1
0
//load data from json into controllers
//{ "device" : int,
//	"buttons": [ int, int, int, ..., 16]
//}
int Frontend::loadConfigFromJson(QString file) {
	JsonDataAccess jda;
	int i;

	QVariantMap data = jda.load(file).toMap();

	if(data.isEmpty()){
		return -1;
	}

	m_controllers[0].device = data["device"].toInt();

	if(data["buttons"].isValid()){
		for(i=0;i<16;++i) {
			m_controllers[0].buttons[i] = data["buttons"].toList()[i].toInt();
		}
	}

	if(data["gamepad"].isValid()){
		for(i=0;i<16;++i) {
			m_controllers[0].gamepad[i] = data["gamepad"].toList()[i].toInt();
		}
	}

	return 0;
}
Exemplo n.º 2
0
void AccountList::removeAccountAt(int i)
{
	JsonDataAccess jda;
	QVariantList list = jda.load(this->file).value<QVariantList>();
	list.removeAt(i);
	jda.save(QVariant(list), this->file);
	loadAccounts();
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
void RetroArch::findCores()
{
   DIR *dirp;
   struct dirent* direntp;
   int count=0, i=0;

   dirp = opendir(g_settings.libretro);
   if( dirp != NULL )
   {
      for(;;)
      {
         direntp = readdir( dirp );
         if( direntp == NULL ) break;
         count++;
      }
      fflush(stdout);
      rewinddir(dirp);

      if(count==2)
      {
         printf("No Cores Found");fflush(stdout);
      }

      coreList = (char**)malloc(count*sizeof(char*));
      count = 0;

      for(;;)
      {
         direntp = readdir( dirp );
         if( direntp == NULL ) break;
         coreList[count++] = strdup((char*)direntp->d_name);
      }

      //Load info for Cores
      JsonDataAccess jda;

      coreInfo = jda.load("app/native/assets/coreInfo.json").toMap();

      Option *tmp;

      //Populate DropDown
      for (i = 2; i < count; ++i)
      {
         qDebug() << GET_CORE_INFO(i, "display_name");

         tmp = Option::create().text(GET_CORE_INFO(i, "display_name"))
                               .value(i);

         coreSelection->add(tmp);
      }
   }

   closedir(dirp);
}
Exemplo n.º 5
0
void ApplicationUI::startLevel(const QVariantList &indexPath)
{
	if (!m_gamePage) {
		QmlDocument *qml = QmlDocument::create("asset:///Game.qml").parent(this);
		qml->setContextProperty("_app", this);
		m_gamePage = qml->createRootObject<Page>();
		m_progressAnimation = m_gamePage->findChild<SequentialAnimation*>("progressAnimation");
	}

	if (indexPath.count() > 0)
		m_levelIndex = indexPath[0].toInt();
	else
		m_levelIndex = 0; // Uhoh?

	m_phase = COMPILE;
	m_selectedFunction = 0;
	setShouldShowFunctions(false);
	setIsInFunction(-1);
	Container *compileContainer = m_gamePage->findChild<Container*>("compilePhaseContainer");
	compileContainer->setVisible(true);

	m_gamePage->findChild<Container*>("tutorial1Container")->setProperty("state", 0);
	m_gamePage->findChild<Container*>("tutorial2Container")->setProperty("state", 0);
	m_gamePage->findChild<Container*>("tutorial3Container")->setProperty("state", 0);
	m_gamePage->findChild<Container*>("progressBar")->setTranslationX(0);
	m_gamePage->findChild<Container*>("creditsContainer")->setVisible(false);

	m_gamePage->findChild<Button*>("menuButton")->setText("Continue");
	m_gamePage->findChild<Container*>("menuContainer")->setVisible(false);

	QVariantMap levelInfo = m_levelList->dataModel()->data(indexPath).toMap();
	QString levelPath = levelInfo["level"].toString();
	JsonDataAccess jda;
	qDebug() << "Attempting to load " << levelPath;
	QVariantMap levelData = jda.load(levelPath).toMap();
	if (jda.hasError()) {
		bb::data::DataAccessError error = jda.error();
		qFatal("JSON loading error: %d: %s", error.errorType(), qPrintable(error.errorMessage()));
		return;
	} else {
		qDebug() << "JSON data loaded OK!";
	}

	setupLevel(levelData);
	setupQueue();

	m_navigationPane->push(m_gamePage);

	m_timer.setInterval(2000);

	m_gamePage->findChild<Container*>("compileFunctionContainer")->setVisible(m_functionCount > 0);
	drawSelectedFunction();
}
Exemplo n.º 6
0
void AccountList::loadAccounts()
{
	this->accounts = QList<Account>();
	JsonDataAccess jda;
	QVariantList list = jda.load(this->file).value<QVariantList>();
	bool* ok = new bool;
	for(int i = 0; i < list.size(); i++)
	{
		accounts.append(Account(list.at(i).toMap().value("name").toString(), list.at(i).toMap().value("start").toInt(ok), list.at(i).toMap().value("stop").toInt(ok)));
	}
	delete(ok);

}
Exemplo n.º 7
0
void AccountList::editAccount(int i, QString name, int start, int stop)
{
	JsonDataAccess jda;
	QVariantList list = jda.load(this->file).value<QVariantList>();
	QVariantMap acc;
	acc["name"] = QVariant(name);
	acc["start"] = QVariant(start);
	acc["stop"] = QVariant(stop);
	list.removeAt(i);
	list.insert(i, QVariant(acc));
	jda.save(QVariant(list), this->file);
	loadAccounts();
}
Exemplo n.º 8
0
void AccountList::addAccount(QString name, int start, int stop)
{
	JsonDataAccess jda;
	QVariantList list = jda.load(this->file).value<QVariantList>();
	QVariantMap acc;
	acc["name"] = QVariant(name);
	acc["start"] = QVariant(start);
	acc["stop"] = QVariant(stop);
	list.append(QVariant(acc));

	jda.save(QVariant(list), this->file);
	loadAccounts();
}
Exemplo n.º 9
0
void ApplicationUI::loadSavedState()
{
	QString filePath(QDir::currentPath() + "/data/levelState.json");
	if (QFile::exists(filePath)) {
		JsonDataAccess jda;
		QVariantMap state = jda.load(filePath).toMap();
		if (jda.hasError())
			return;
		if (state.contains("levelAvailable")) {
			int levelAvailable = state["levelAvailable"].toInt();
			if (levelAvailable > 0) {
				setLevelAvailable(levelAvailable);
			}
		}
	}
	qDebug() << "Level available" << m_levelAvailable;
}
Exemplo n.º 10
0
QVariant SongsDataModel::setupAlbumListModel()
{
    // Create a new GroupDataModel; the GroupDataModel is a helper class that ListView uses for data handling.
    // It uses in-memory storage so we can populate data.
    // We load the GroupDataModel with help from the JsonDataAcces function, load().
    JsonDataAccess jda;
    QDir home = QDir::home();
    QVariantMap existingAlbums = jda.load(home.absoluteFilePath("albumslist.json")).value<QVariantMap>();
    if (jda.hasError()) {
        bb::data::DataAccessError error = jda.error();
        qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
        return QVariant();
    }

    // Sort on region in the model so we will get different categories.
    //m_albumsModel->insertList(existingAlbums);
    return existingAlbums;
}
Exemplo n.º 11
0
void MyListModel::load(const QString& file_name)
{
    // clear model
    clear();
    // clear not filtered data cache
    m_data.clear();
    {
        JsonDataAccess jda;
        m_data = jda.load(file_name).toList();
        if (jda.hasError()) {
            DataAccessError error = jda.error();
            qDebug() << file_name << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
        }
        else {
            qDebug() << file_name << "JSON data loaded OK!";
            // when loaded, show all data (no filtering)
            append(m_data);
        }
    }
}
Exemplo n.º 12
0
void WeatherDataSource::onHttpFinished()
{
    JsonDataAccess jda;
    QVariantList weatherDataFromServer;
    int httpStatus = -1; // controls the final behavior of this function

    if (mReply->error() == QNetworkReply::NoError) {
        // Load the data using the reply QIODevice.
        weatherDataFromServer = jda.load(mReply).value<QVariantList>();

        if (jda.hasError()) {
            bb::data::DataAccessError error = jda.error();
            qDebug() << "JSON loading error:" << error.errorType() << " : " << error.errorMessage();
            httpStatus = -2;
        } else {
            httpStatus = 200;
        }
    } else {
        // An error occurred, try to get the http status code and reason
        QVariant statusCode = mReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
        QString reason = mReply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();

        if (statusCode.isValid()) {
            httpStatus = statusCode.toInt();
        }

        qDebug() << "Network request to " << mReply->request().url().toString()
                << " failed with http status " << httpStatus << " " << reason;
    }

    // Now behave
    switch (httpStatus) {
        case 200:
            loadNetworkReplyDataIntoDataBase(weatherDataFromServer);
            break;
        case 404:
            if (mCursor.index == 0) {
                // If we requested index 0 and didn't get an empty array it means the city does not exist and we should show an error
                setErrorCode(WeatherError::InvalidCity);
            } else {
                // If we get a 404 in the middle of a data set it simply means there is no more data
                emit noMoreWeather();
            }
            break;
        case 503:
            // TODO: perhaps try again a few times and eventually just stop? if we end up stopping and the list is empty, show an alert message. if the list isn't empty just stop fetching
            setErrorCode(WeatherError::ServerBusy);
            break;
        case -2:
            setErrorCode(WeatherError::JsonError);
            break;
        case 500:
        default:
            // The server crapped out, if we don't have any entries let the user know an error occurred, otherwise just stop fetching
            setErrorCode(WeatherError::ServerError);
            break;
    }

    // The reply is not needed now so we call deleteLater() function since we are in a slot.
    mReply->deleteLater();
    mReply = 0;
}