void MirandaSkinnedDialog::storeToDB(const SkinOptions *opts)
{
	for (unsigned int i = 0; i < opts->getNumOptions(); i++)
		storeToDB(opts->getOption(i));

	fireOnSkinChanged();
}
Example #2
0
int readLinesFromFile(char * filename){
	FILE *file = fopen(filename, "r");
	int success =0;

	if (file != NULL){
		char line [ MAXSIZE ]; /* or other suitable maximum line size */
		while (fgets(line, sizeof line, file) != NULL){
			if (strlen(line) > 1){
				//validate the line before any further processing
				if(validateLine(line)==1)
				{
					//remove the '{' and '}'
					line[0] = ' ';
					line[strlen(line) - 2] = '\0';
					//remove the extra spaces
					char *ch = line;
					char *p1 = ch;
					char *p2 = ch;
					p1 = ch;
					while (*p1 != 0){
						if (isspace(*p1) || (*p1) == '\"'){
							++p1;
						}
						else
							*p2++ = *p1++;
					}
					*p2 = 0;

					//now the string without extra spaces is stored in 'ch'
					//printf("Splitting string \"%s\" into tokens:\n", ch);
					char * keyV[13];

					char *str = line;
					char * pch;
					pch = strtok(str, ",");
					int i = 0;
					while (pch != NULL){
						keyV[i] = pch;
						pch = strtok(NULL, ",");
						i++;
					}

					//now tokenize them further
					//now each of those tokens is a key-value pair
					char *values[26];
					int k, x;
					x = 0;
					for (k = 0; k < i; k++){
						char *str2 = keyV[k];
						char * pch2;
						pch2 = strtok(str2, ":");
						while (pch2 != NULL){
							values[x++] = pch2;
							pch2 = strtok(NULL, ":");
						}
					}
					//call function to insert to db with the cprrect params
					success = storeToDB(values[1], values[3], values[5], values[7], values[9], values[11], values[13], values[15], values[17], values[19], values[21], values[23],values[25]);
					memset(line, 0, sizeof (line));
					if(success==0){//if it fails any where, break here
						break;
					}
				}
				else {
					printf("Not a valid json string\n");
				}
			}
		}
		fclose(file);
	}
	else{
		perror(filename); /* why didn't the file open? */
	}
	return success;
}
void MirandaSkinnedDialog::onOptionChange(const SkinOption *opt)
{
	storeToDB(opt);
}