void Widget::on_pushButtonDelete_clicked()
{

    ui->treeView->setSelectionMode(QTreeView::ExtendedSelection);
    ui->treeView->setSelectionBehavior(QTreeView::SelectRows);
    QModelIndexList list = ui->treeView->selectionModel()->selectedIndexes();
    QDirModel* model = (QDirModel*)ui->treeView->model();
    QModelIndex index = list[0];
    QFileInfo fileInfo = model->fileInfo(index);
    QString selectedfilepath = fileInfo.absoluteFilePath();
    qDebug() << selectedfilepath << '\n';

    QSqlQuery query;
    //query.exec("INSERT INTO test VALUES('','sss','sss')");
    //query.exec("SELECT * FROM test");
    QString selectedfromdb = "SELECT absdirectory FROM test WHERE symlinkdirectory = '" + selectedfilepath + "'";
    query.exec(selectedfromdb);
    query.next();
    QString selectedasbd = query.value(0).toString();
    qDebug() << selectedasbd << "\n";

    QByteArray ba1 = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
    const char *dirnow1 = ba1.data();
    remove(dirnow1);
    QByteArray ba2 = selectedfilepath.toAscii();//将所得文件名转换为字符//yfx0527
    const char *dirnow2 = ba2.data();
    remove(dirnow2);
}
void ItemLibraryTreeView::activateItem( const QModelIndex & /*index*/)
{
    QMimeData *mimeData = model()->mimeData(selectedIndexes());
    if (!mimeData)
        return;

    QString name;
    QDirModel *dirModel = qobject_cast<QDirModel*>(model());
    Q_ASSERT(dirModel);
    QFileInfo fileInfo = dirModel->fileInfo(selectedIndexes().front());
    QPixmap pixmap(fileInfo.absoluteFilePath());
    if (!pixmap.isNull()) {
        name = "image^" + fileInfo.absoluteFilePath();
        emit itemActivated(name);
    }
}
void Widget::on_pushButtonGetIDV3_clicked()
{
    ui->treeView->setSelectionMode(QTreeView::ExtendedSelection);
    ui->treeView->setSelectionBehavior(QTreeView::SelectRows);
    QModelIndexList list = ui->treeView->selectionModel()->selectedIndexes();
    QDirModel* model = (QDirModel*)ui->treeView->model();
    QModelIndex index = list[0];
    QFileInfo fileInfo = model->fileInfo(index);
    QString selectedfilepath = fileInfo.absoluteFilePath();
    qDebug() << selectedfilepath << '\n';

    QSqlQuery query;
    //query.exec("INSERT INTO test VALUES('','sss','sss')");
    //query.exec("SELECT * FROM test");
    QString selectedfromdb = "SELECT absdirectory FROM test WHERE symlinkdirectory = '" + selectedfilepath + "'";
    query.exec(selectedfromdb);
    query.next();
    QString selectedasbd = query.value(0).toString();
    qDebug() << selectedasbd << "\n";

    FILE *pFile; //文件指针
    Mp3Info song;
    QByteArray ba = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
    const char *dirnow = ba.data();
    //printf("%s\n",dirnow);
    pFile = fopen(dirnow, "r");
    fseek(pFile, -128, SEEK_END);
    fread(&song, 1, sizeof (Mp3Info), pFile); //读取MP3文件ID3V标签
    //printf("%s\n",song.album);
    QString title = QString::fromLocal8Bit(song.title,30);
    QString artist = QString::fromLocal8Bit(song.artist,30);
    QString album = QString::fromLocal8Bit(song.album,30);
    QString year = QString::fromLocal8Bit(song.year,4);
    QString comment = QString::fromLocal8Bit(song.comment,28);
    ui->lineEditTitle->setText(title);
    ui->lineEditArtist->setText(artist);
    ui->lineEditAlbum->setText(album);
    ui->lineEditYear->setText(year);
    ui->lineEditComment->setText(comment);
    fclose(pFile);
}
/**
 * Przechwytuje zdarzenie wywołania menu kontekstowego.
 *
 * Wyświetla menu kontekstowe z akcjami widoku. Jeśli bieżący element jest
 * katalogiem, pierwsza z akcji menu służy do zwinięcia/rozwinięcia gałęzi
 * drzewa. Jeśli bieżący element jest plikiem, pierwsza akcja wczytuje
 * plik z przestrzeni roboczej.
 *
 * @param event obiekt informacji o zdarzeniu
 */
void WorkspaceTreeView::contextMenuEvent(QContextMenuEvent* event)
{
    QMenu menu(this);

    QDirModel* dirModel = static_cast<QDirModel*>(model());
    if (dirModel->fileInfo(currentIndex()).isDir())
    {
        bool exp = isExpanded(currentIndex());
        actionExpandOrCollapse->setText(exp ? tr("Collapse") : tr("Expand"));
        menu.addAction(actionExpandOrCollapse);
    }
    else
    {
        menu.addAction(actionLoad);
    }

    menu.addAction(actionRemove);
    menu.addSeparator();
    menu.addAction(actionRefresh);
    menu.exec(event->globalPos());
}
void Widget::on_pushButtonChIDV3_clicked()
{
    ui->treeView->setSelectionMode(QTreeView::ExtendedSelection);
    ui->treeView->setSelectionBehavior(QTreeView::SelectRows);
    QModelIndexList list = ui->treeView->selectionModel()->selectedIndexes();
    QDirModel* model = (QDirModel*)ui->treeView->model();
    QModelIndex index = list[0];
    QFileInfo fileInfo = model->fileInfo(index);
    QString selectedfilepath = fileInfo.absoluteFilePath();
    qDebug() << selectedfilepath << '\n';

    QSqlQuery query;
    //query.exec("INSERT INTO test VALUES('','sss','sss')");
    //query.exec("SELECT * FROM test");
    QString selectedfromdb = "SELECT absdirectory FROM test WHERE symlinkdirectory = '" + selectedfilepath + "'";
    query.exec(selectedfromdb);
    query.next();
    QString selectedasbd = query.value(0).toString();
    qDebug() << selectedasbd << "\n";

    FILE *pFile; //文件指针
    Mp3Info song;
    QByteArray ba = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
    const char *dirnow = ba.data();
    //printf("%s\n",dirnow);
    pFile = fopen(dirnow, "wb");
    fseek(pFile, -125, SEEK_END);

    int i = 0;
    char title[30];
    for(i = 0;i < 30;i ++)
    {
        title[i] = ' ';
    }
    char artist[30];
    for(i = 0;i < 30;i ++)
    {
        artist[i] = ' ';
    }
    char album[30];
    for(i = 0;i < 30;i ++)
    {
        album[i] = ' ';
    }
    char year[4];
    for(i = 0;i < 4;i ++)
    {
        year[i] = ' ';
    }
    char comment[28];
    for(i = 0;i < 28;i ++)
    {
        comment[i] = ' ';
    }

    QByteArray ba1;
    ba1 = ui->lineEditArtist->text().toAscii();//将所得文件名转换为字符//yfx0527
    strcpy(artist,ba1.data());
    ba1 = ui->lineEditTitle->text().toAscii();//将所得文件名转换为字符//yfx0527
    strcpy(title,ba1.data());
    ba1 = ui->lineEditAlbum->text().toAscii();//将所得文件名转换为字符//yfx0527
    strcpy(album,ba1.data());
    ba1 = ui->lineEditYear->text().toAscii();//将所得文件名转换为字符//yfx0527
    strcpy(year,ba1.data());
    ba1 = ui->lineEditComment->text().toAscii();//将所得文件名转换为字符//yfx0527
    strcpy(comment,ba1.data());

    char whatmm[3] = "XX";
    fwrite(whatmm,sizeof(char),3,pFile);
    fwrite(title,sizeof(char),30,pFile);
    fwrite(artist,sizeof(char),30,pFile);
    fwrite(album,sizeof(char),30,pFile);
    fwrite(year,sizeof(char),4,pFile);
    fwrite(comment,sizeof(char),28,pFile);

    fclose(pFile);
}