Exemplo n.º 1
0
TreeItem* RhythmboxFeature::importMusicCollection() {
    qDebug() << "importMusicCollection Thread Id: " << QThread::currentThread();
     // Try and open the Rhythmbox DB. An API call which tells us where
     // the file is would be nice.
    QFile db(QDir::homePath() + "/.gnome2/rhythmbox/rhythmdb.xml");
    if (!db.exists()) {
        db.setFileName(QDir::homePath() + "/.local/share/rhythmbox/rhythmdb.xml");
        if (!db.exists()) {
            return NULL;
        }
    }

    if (!db.open(QIODevice::ReadOnly | QIODevice::Text))
        return NULL;

    //Delete all table entries of Traktor feature
    ScopedTransaction transaction(m_database);
    clearTable("rhythmbox_playlist_tracks");
    clearTable("rhythmbox_library");
    clearTable("rhythmbox_playlists");
    transaction.commit();

    transaction.transaction();
    QSqlQuery query(m_database);
    query.prepare("INSERT INTO rhythmbox_library (artist, title, album, year, "
                  "genre, comment, tracknumber, bpm, bitrate,"
                  "duration, location, rating ) "
                  "VALUES (:artist, :title, :album, :year, :genre, :comment, "
                  ":tracknumber, :bpm, :bitrate, :duration, :location, :rating )");


    QXmlStreamReader xml(&db);
    while (!xml.atEnd() && !m_cancelImport) {
        xml.readNext();
        if (xml.isStartElement() && xml.name() == "entry") {
            QXmlStreamAttributes attr = xml.attributes();
            //Check if we really parse a track and not album art information
            if (attr.value("type").toString() == "song") {
                importTrack(xml, query);
            }
        }
    }
    transaction.commit();

    if (xml.hasError()) {
        // do error handling
        qDebug() << "Cannot process Rhythmbox music collection";
        qDebug() << "XML ERROR: " << xml.errorString();
        return NULL;
    }

    db.close();
    if (m_cancelImport) {
        return NULL;
    }
    return importPlaylists();
}
Exemplo n.º 2
0
void MassImport::on_importSelectedTracksButton_clicked()
{
    QList<QTreeWidgetItem *> list;
    TreeItem *item;
    list=ui.treeWidget->selectedItems();
    for (int i = 0; i < list.size(); ++i) {
        item=(TreeItem*)list.at(i);
        if (item!=NULL && item->import==true) {
            if (importTrack(item)) {
                int	index=ui.treeWidget->indexOfTopLevelItem(item);
                if (index>=0) ui.treeWidget->takeTopLevelItem(index);
                delete item;
            } else {
                return;
            }
            qApp->processEvents();
        }
    }
}
Exemplo n.º 3
0
void MassImport::on_startImportButton_clicked()
{
    QList<QTreeWidgetItem *> list;
    for (int i=0; i<ui.treeWidget->topLevelItemCount(); i++) {
        list.push_back(ui.treeWidget->topLevelItem(i));
    }
    TreeItem *item;
    for (int i = 0; i < list.size(); ++i) {
        item=(TreeItem*)list.at(i);
        if (item!=NULL && item->import==true) {
            if (importTrack(item)) {
                int	index=ui.treeWidget->indexOfTopLevelItem(item);
                if (index>=0) ui.treeWidget->takeTopLevelItem(index);
                delete item;
            } else {
                return;
            }
            qApp->processEvents();
        }
    }
}