예제 #1
0
void AddEntryDlg::OnButtonInsertPressed() // depricated ?
{
	QString filepath = le_path.text();
	QByteArray md5sum;
	QDateTime last_changed;
	if(!filepath.isEmpty() && !QFile::exists(filepath))
	{
		if( QMessageBox::No == QMessageBox::question(this, "Incorrect Filepath", "The File does not exist. Do you really want to continue?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
		 return;

		calculate_md5sum(filepath.toAscii().data(), &md5sum);
		last_changed = QFileInfo(filepath).lastModified();
	}
	QString insert_cmd("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') VALUES (NULL , '");

	insert_cmd.append(corr(le_title.text()));
	insert_cmd.append("', '");
	insert_cmd.append(corr(le_artist.text()));
	insert_cmd.append("', '");
	insert_cmd.append(corr(le_album.text()));
	insert_cmd.append("', '");
	insert_cmd.append(corr(le_tag.text()));
	insert_cmd.append("', '");
	insert_cmd.append(corr(le_genre.text()));
	insert_cmd.append("', '");
	insert_cmd.append(le_year.text());
	insert_cmd.append("', '");
	
	if(cb_interest_others.isChecked())
	 insert_cmd.append("1");
	else
	 insert_cmd.append("0");
	
	insert_cmd.append("', '");
	
	if(cb_interest_yours.isChecked())
	 insert_cmd.append("1");
	else
	 insert_cmd.append("0");
	
	insert_cmd.append("', '");
	insert_cmd.append(le_filetype.text());
	insert_cmd.append("', '");
	insert_cmd.append(le_quality.text());
	insert_cmd.append("', '");
	insert_cmd.append(QString::number(sb_vote_yours.value()));
	insert_cmd.append("', '");
	insert_cmd.append(QString::number(sb_vote_others.value()));
	insert_cmd.append("', '");
	insert_cmd.append(filepath);
	insert_cmd.append("', '");
	insert_cmd.append(last_changed.toTime_t());
	insert_cmd.append("', '");
	insert_cmd.append(md5sum.toHex().data());
	insert_cmd.append("', '");
	insert_cmd.append(corr(le_source.text()));
	insert_cmd.append("');");
	
	printf("Query command: %s\n", insert_cmd.toAscii().data());
	
	sqlhelper.exec(insert_cmd);
	// sqlhelper.INSERT(insert_cmd);

	accept();
}
예제 #2
0
bool SqlHelper::INSERT(const char* filepath, const char* url) const // TODO: NULL allowed?
{
#if 0
	if(mPlayerConnection == NULL)
		return;

	mPlayerConnection->pass_remote_command((QString("loadfile \"%1\"\n").arg(filepath).toAscii().data()));

	QString filename = filepath; // filename as SQL wants it
	filename.replace('\'', "''");

	QString metaTitle = corr( mPlayerConnection->fetchValue("get_meta_title\n", "ANS_META_TITLE=") );
	printf("metaTitle: %s\n",metaTitle.toAscii().data());
	if(metaTitle == "''")
	{
		metaTitle = strrchr(filepath, QDir::separator().toAscii()) + 1;
		metaTitle.resize(metaTitle.lastIndexOf('.')); // get rid of ending

		/*
			handle spaces
		*/
		metaTitle.replace('_', ' ');
		bool lastWasSpace = true;
		for(int i = 0; i<metaTitle.size(); i++)
		{
			if( lastWasSpace )
			 metaTitle[i] = metaTitle[i].toUpper();
			lastWasSpace = (metaTitle[i] == ' ');
		}
		metaTitle.prepend('\'');
		metaTitle.append('\'');

		metaTitle = corr(metaTitle);
		printf("metaTitle now: %s\n",metaTitle.toAscii().data());
	}

	QByteArray md5sum;
	calculate_md5sum(filepath, &md5sum);
	QDateTime last_changed = QFileInfo(filepath).lastModified();
	printf("str: %s\n",QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
				   "VALUES ( NULL, %1, %2, %3, '', %4, %5, '0', '0', %6, %7, '0', '0', '%8', '%9', '%10', '%11');")
				 .arg(
					 metaTitle,
					 corr( mPlayerConnection->fetchValue("get_meta_artist\n", "ANS_META_ARTIST=") ),
					 corr( mPlayerConnection->fetchValue("get_meta_album\n", "ANS_META_ALBUM=") ),

					 corr( mPlayerConnection->fetchValue("get_meta_genre\n", "ANS_META_GENRE=") ),
					 mPlayerConnection->fetchValue("get_meta_year\n", "ANS_META_YEAR="),
					 // TODO: interest

					 mPlayerConnection->fetchValue("get_audio_codec\n", "ANS_AUDIO_CODEC="),
					 mPlayerConnection->fetchValue("get_audio_bitrate\n", "ANS_AUDIO_BITRATE="),

					 filename,
					 md5sum.toHex().data()
				).arg(
					last_changed.toTime_t()
				).arg(
					url
				).toAscii().data());

	const QSqlQuery query = db.exec(
	/*QString str =*/	QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, %1, %2, %3, '', %4, %5, '0', '0', %6, %7, '0', '0', '%8', '%9', '%10', '%11');")
					.arg(
						metaTitle,
						corr( mPlayerConnection->fetchValue("get_meta_artist\n", "ANS_META_ARTIST=") ),
						corr( mPlayerConnection->fetchValue("get_meta_album\n", "ANS_META_ALBUM=") ),

						corr( mPlayerConnection->fetchValue("get_meta_genre\n", "ANS_META_GENRE=") ),
						mPlayerConnection->fetchValue("get_meta_year\n", "ANS_META_YEAR="),
						// TODO: interest

						mPlayerConnection->fetchValue("get_audio_codec\n", "ANS_AUDIO_CODEC="),
						mPlayerConnection->fetchValue("get_audio_bitrate\n", "ANS_AUDIO_BITRATE="),

						filename )
					.arg(
						last_changed.toTime_t()
						)
					.arg (
						md5sum.toHex().data()
					)
					.arg (
						corr(url)
					)
			);
	if(!query.isValid()) {
		fputs(query.lastError().text().toAscii().data(),stderr);
	}
#else
	TagLib::FileRef fp(filepath);
	if(fp.isNull()) {
		printf("Warning: File not found.");
		return false;
	}
	TagLib::Tag* tag = fp.tag();
	TagLib::AudioProperties* audio_props = fp.audioProperties();

	QString filename = filepath; // filename as SQL wants it
	filename.replace('\'', "''");

	QString metaTitle = corr( TStringToQString(tag->title()) );
	printf("metaTitle: %s\n",metaTitle.toAscii().data());
	if(metaTitle.isEmpty())
	{
		metaTitle = strrchr(filepath, QDir::separator().toAscii()) + 1;
		metaTitle.resize(metaTitle.lastIndexOf('.')); // get rid of ending

		/*
			handle spaces
		*/
		metaTitle.replace('_', ' ');
		bool lastWasSpace = true;
		for(int i = 0; i<metaTitle.size(); i++)
		{
			if( lastWasSpace )
			 metaTitle[i] = metaTitle[i].toUpper();
			lastWasSpace = (metaTitle[i] == ' ');
		}
//		metaTitle.prepend('\'');
//		metaTitle.append('\'');

		metaTitle = corr(metaTitle);
		printf("metaTitle now: %s\n",metaTitle.toAscii().data());
	}

	QByteArray md5sum;
	calculate_md5sum(filepath, &md5sum);
	QDateTime last_changed = QFileInfo(filepath).lastModified();

	QString audio_codec = filename;
	audio_codec.remove(0, audio_codec.lastIndexOf('.')+1);

	printf("str: %s\n",QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, '%1', '%2', '%3', '', '%4', '%5', '0', '0', '%6', '%7', '0', '0', '%8', '%9', '%10', '%11');")
				 .arg(
					metaTitle,
					corr( TStringToQString(tag->artist()) ),
					corr( TStringToQString(tag->album()) ),

					corr( TStringToQString(tag->genre()) ),
					get_year(tag),
					// TODO: interest

					audio_codec,
					QString::number(audio_props->bitrate()),

					filename,
					md5sum.toHex().data()
				).arg(
					last_changed.toTime_t()
				).arg(
					url
				).toAscii().data());

	const QSqlQuery query = db.exec(
	/*QString str =*/	QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, '%1', '%2', '%3', '', '%4', '%5', '0', '0', '%6', '%7', '0', '0', '%8', '%9', '%10', '%11');")
					.arg(
						metaTitle,
						corr( TStringToQString(tag->artist()) ),
						corr( TStringToQString(tag->album()) ),

						corr( TStringToQString(tag->genre()) ),
						get_year(tag),
						// TODO: interest

						audio_codec,
						QString::number(audio_props->bitrate()),

						filename)
					.arg(
						last_changed.toTime_t()
						)
					.arg (
						md5sum.toHex().data()
					)
					.arg (
						corr(url)
					)
			);
	if(!query.isValid()) {
		fputs(query.lastError().text().toAscii().data(),stderr);
	}

	return true;
#endif

}