Ejemplo n.º 1
0
void rgb( uint8_t h, uint8_t s, uint8_t v,
		uint8_t *r, uint8_t *g, uint8_t *b )
{
	uint8_t f, hi;

	hi = hi8( h );
	f = f8( h );

	switch ( hi ) {
	case 0:
		*r = v;
		*g = t8( v, s, f );
		*b = p8( v, s );
		break;
	case 1:
		*r = q8( v, s, f );
		*g = v;
		*b = p8( v, s );
		break;
	case 2:
		*r = p8( v, s );
		*g = v;
		*b = t8( v, s, f );
		break;
	case 3:
		*r = p8( v, s );
		*g = q8( v, s, f );
		*b = v;
		break;
	case 4:
		*r = t8( v, s, f );
		*g = p8( v, s );
		*b = v;
		break;
	case 5:
		*r = v;
		*g = p8( v, s );
		*b = q8( v, s, f );
		break;
	default:
		/*	not reached	*/
		break;
	}
}
Ejemplo n.º 2
0
bool Database::createDatabase()
{
	QSqlQuery q0("create table Artist (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), mbid varchar(50))", db);
	QSqlQuery q1("create table Album (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), artist integer, mbid varchar(50))", db);
	QSqlQuery q2("create table Genre (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250))", db);
	QSqlQuery q4("create table Song (ID integer primary key autoincrement, File varchar(250), Track integer, Title varchar(200), Artist integer, Album integer, Genre integer, Year integer, Comment varchar(200), Length varchar(20), Rating integer, Type varchar(30), Date varchar(50))", db);
	QSqlQuery q5("create table Version (value integer)", db);
	QSqlQuery q6("insert into Version (value) values ("+QString::number(DB_VERSION)+")", db);
	QSqlQuery q8("create table Info(Mbid varchar(50) primary key, text varchar(10000))", db);
	QSqlQuery q9("create table SQLPlaylist (ID integer primary key autoincrement, value varchar(200), art varchar(250), data varchar(250))", db);
	CreateDefaultSqlPlaylists();
	return true;
}
Ejemplo n.º 3
0
void rgb( uint8_t h, uint8_t s, uint8_t v,
		uint8_t *r, uint8_t *g, uint8_t *b )
{
	uint8_t f, hi;
    int16_t p, q, t;

	hi = hi8( h );
    f = f8( h );
    p = p8( v, s );
    q = q8( v, s, f );
    t = t8( v, s, f );

	switch ( hi ) {
	case 0:
		*r = v;
        *g = t;
        *b = p;
        break;
	case 1:
        *r = q;
		*g = v;
        *b = p;
		break;
	case 2:
        *r = p;
		*g = v;
        *b = t;
		break;
	case 3:
        *r = p;
        *g = q;
		*b = v;
		break;
	case 4:
        *r = t;
        *g = p;
		*b = v;
		break;
	case 5:
		*r = v;
        *g = p;
        *b = q;
		break;
	default:
		exit( EXIT_FAILURE );
		break;
	}
}
Ejemplo n.º 4
0
bool Database::updateDatabase(int fromver)
{
    switch (fromver) {
    case 0: {
        QSqlQuery q0("create table Version (value integer)", db);
        //QSqlQuery q1("insert into Version (value) values ("+QString::number(DB_VERSION)+")");
        QSqlQuery q3("alter table Artist add column art varchar(250)", db);
        QSqlQuery q4("alter table Album add column art varchar(250)", db);
        QSqlQuery q5("alter table Genre add column art varchar(250)", db);
        QSqlQuery q6("alter table Song drop column Mark", db);
        QSqlQuery q2("drop table Mark", db);
        qDebug("Update database from version 0");
    }
    case 1: {
        QSqlQuery q0("create table Playlist (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), list varchar(250))", db);
        qDebug("Update database from version 1");
    }
    case 2: {
        QSqlQuery q0("alter table Album add column artist integer", db);
        qDebug("Update database from version 2");
        QSqlQuery q1("select distinct Artist, Album from Song", db);
        while(q1.next()) {
            int ar = q1.value(0).toString().toInt();
            QSqlQuery q2("select artist from Album where ID = "+q1.value(1).toString(), db);
            if(q2.next()) {
                int ar2 = q2.value(0).toString().toInt();
                if(!ar2) { // update
                    QSqlQuery q3("update Album set artist = "+q1.value(0).toString()+" where ID = "+q1.value(1).toString(), db);
                } else if(ar2 != ar) { // copy
                    QSqlQuery q4("select value, art, refs, rating from Album where ID = "+q1.value(1).toString()+" and artist = "+q2.value(0).toString(), db);
                    if(q4.next()) {
                        int old_ref = q4.value(2).toString().toInt();
                        int old_rat = q4.value(3).toString().toInt();
                        QSqlQuery q5("insert into Album (value,art,artist) values ('"+q4.value(0).toString()+"','"+q4.value(1).toString()+"',"+q1.value(0).toString(), db);
                        QSqlQuery q6("select ID from Album where value = '"+q4.value(0).toString()+"' and art = '"+q4.value(1).toString()+"' and artist = "+q1.value(0).toString(), db);
                        if(q6.next()) {
                            int id = q6.value(0).toString().toInt();
                            int ref=0, rat=0;
                            QSqlQuery q7("select ID, Rating from Song where Artist = "+q1.value(0).toString()+" and Album = "+q1.value(1).toString(), db);
                            while(q7.next()) {
                                ref ++;
                                rat += q7.value(1).toString().toInt();
                                QSqlQuery q8("update Song set Album = "+QString::number(id)+" where ID = "+q7.value(0).toString(), db);
                            }
                            QSqlQuery q8("update Album set refs = "+QString::number(ref)+", rating = "+QString::number(rat)+" where ID = "+QString::number(id), db);
                            QSqlQuery q9("update Album set refs = "+QString::number(old_ref-ref)+", rating = "+QString::number(old_rat-rat)+" where ID = "+q1.value(1).toString(), db);
                        }
                    }
                }
            }
        }
    }
	case 3: {
		QSqlQuery q0("alter table Artist add column mbid varchar(50)", db);
		QSqlQuery q1("alter table Album add column mbid varchar(50)", db);
		qDebug("Update database from version 3");
	}
	case 4: {
		QSqlQuery q0("create table Info(Mbid varchar(50) primary key, text varchar(10000))", db);
		qDebug("Update database from version 4");
	}
	case 5: {
		QSqlQuery q0("", db);
		q0.prepare("create table SQLPlaylist (ID integer primary key autoincrement, value varchar(200), art varchar(250), data varchar(250))");
		q0.exec();
		CreateDefaultSqlPlaylists();
		qDebug("Update database from version 5");
	}
	case 6: {
		QSqlQuery q0("alter table Song add column Type varchar(30)", db);
		qDebug("Update database from version 6");
	}
	case 7: {
		QSqlDatabase ldb;
		ldb = QSqlDatabase::addDatabase("QSQLITE", "tempLibraryDB");
		ldb.setDatabaseName(QDir::homePath()+"/.cuberok/library.db");
		if(!QFile::exists(ldb.databaseName())) {
			if(!QDir().mkpath(QDir::homePath()+"/.cuberok") || !ldb.open()) {
				qDebug("Can not create library database");
			} else {
				QSqlQuery q0("create table Version (value integer)", ldb);
				QSqlQuery q1("insert into Version (value) values (0)", ldb);
				QSqlQuery q2("create table Playlist (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), list varchar(250))", ldb);
				QSqlQuery q("select value, art from Playlist order by value ASC", db);
				q.exec();
				int records = 0;
				while(q.next()) {
					QSqlQuery q3("", ldb);
					q3.prepare("insert into Playlist (value, art) values (:val, :art)");
					q3.bindValue(":val", q.value(0).toString());
					q3.bindValue(":art", q.value(1).toString());
					q3.exec();
					records ++;
				}
				ldb.close();
				qDebug("%d records has been moved", records);
			}
		}
        QSqlQuery q2("drop table Playlist", db);
		QSqlDatabase::removeDatabase("tempLibraryDB");
		qDebug("Update database from version 7");
	}
	case 8: {
		QSqlQuery q0("alter table Song add column Date varchar(50)", db);
		CreateDefaultSqlPlaylists2();
		qDebug("Update database from version 8");
	}
    }
    proxy->message("Database update from version "+QString::number(fromver));
    QSqlQuery q1("delete from Version", db);
    QSqlQuery q2("insert into Version (value) values ("+QString::number(DB_VERSION)+")", db);
    return true;
}