Error QTar::extract() { //ifstream ofstream to seekg() QArchive::extract(); if(!exists()) return Archive::OpenError; char buff[Header::RecordSize]; //QFile outFile; //FILE* f; size_t bytes_read; unsigned int filesize; #if ARCREADER_QT4 if(!open(QIODevice::ReadOnly)) { error(); #else if(open(IO_ReadOnly)) { qDebug("open error"); #endif //ARCREADER_QT4 return Archive::OpenError; } Q_D(QArchive); for (;;) { #if ARCREADER_QT4 bytes_read = read(buff,Header::RecordSize); #else bytes_read = readBlock(buff,Header::RecordSize); #endif //ARCREADER_QT4 //put them here emit byteProcessed(d->processedSize+=Header::RecordSize); d->current_fileName=QFileInfo(buff).fileName(); if (bytes_read < Header::RecordSize) { fprintf(stderr,"Short read. expected 512, got %d\n", bytes_read); return Archive::ReadError; } if (isEndBuff(buff)) { #if USE_SLOT emit byteProcessed(d->processedSize+=Header::RecordSize); //header; #else estimate(); progressHandler->Progress(d->current_fileName, d->size, d->processedSize+=Header::RecordSize, d->totalSize, d->speed, d->elapsed, d->left); #endif finishMessage(); return End; } if (!verifyChecksum(buff)) { fprintf(stderr, "Checksum failure\n"); return ChecksumError; } switch (buff[156]) { case Header::LinkFlag::kLink : printf(" Ignoring hardlink %s\n", buff); break; case Header::LinkFlag::kSymbolicLink : printf(" Ignoring symlink %s\n", buff); break; ///////////////////////// case Header::LinkFlag::kCharacter: printf(" Ignoring character device %s\n", buff); break; case Header::LinkFlag::kBlock: printf(" Ignoring block device %s\n", buff); break; case Header::LinkFlag::kDirectory: createDir(QString::fromLocal8Bit(buff), parseOct(buff + 100, 8)); filesize = 0; break; case Header::LinkFlag::kFIFO: printf(" Ignoring FIFO %s\n", buff); break; default: createFile(QString::fromLocal8Bit(buff), parseOct(buff + 100, 8)); break; } ++d->numFiles; filesize = parseOct(buff + 124, 12); d->size = filesize; #if USE_SLOT updateMessage(); #endif while (filesize > 0) { checkTryPause(); #if ARCREADER_QT4 bytes_read = read(buff,Header::RecordSize); #else bytes_read = readBlock(buff,Header::RecordSize); #endif //ARCREADER_QT4 if (bytes_read < Header::RecordSize) { fprintf(stderr,"Short read. Expected 512, got %d\n",bytes_read); return Archive::ReadError; } if (filesize < Header::RecordSize) bytes_read = filesize; if (d->outFile.isOpen()) { #if CONFIG_QT4 if(d->outFile.write(buff,bytes_read)!=bytes_read) { fprintf(stderr, "[%s] %s @%d: Failed to write %s\n",__FILE__,__PRETTY_FUNCTION__,__LINE__,qPrintable(d->outFile.fileName())); #else if(d->outFile.writeBlock(buff,bytes_read)!=bytes_read) { fprintf(stderr, "[%s] %s @%d: Failed to write %s\n",__FILE__,__PRETTY_FUNCTION__,__LINE__,qPrintable(d->outFile.name())); #endif d->outFile.close(); } /*if (fwrite(buff, 1, bytes_read, f)!= bytes_read) { fprintf(stderr, "Failed write\n"); fclose(f); f = NULL; }*/ } #if USE_SLOT forceShowMessage(1000); emit byteProcessed(d->processedSize+=Header::RecordSize);//bytes_read); #else estimate(); progressHandler->Progress(d->current_fileName, d->size, d->processedSize+=Header::RecordSize, d->totalSize, d->speed, d->elapsed, d->left); #endif filesize -= bytes_read; } //emit byteProcessed(processedSize+=size); if(d->outFile.isOpen()) d->outFile.close(); } close(); } Archive::Error QTar::extract(const QString& archive,const QString& dir) { setArchive(archive); setOutDir(dir); return extract(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), mScanner(nullptr) { Messages::setHandler(this); setupUi(this); qApp->setWindowIcon(loadMainIcon()); toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolBar->setIconSize(QSize(24,24)); qApp->setAttribute(Qt::AA_DontShowIconsInMenus, true); qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, true); #ifdef Q_OS_MAC this->setUnifiedTitleAndToolBarOnMac(true); setWindowIcon(QIcon()); trackView->setFrameShape(QFrame::NoFrame); splitter->setStyleSheet("::handle{ border-right: 1px solid #b6b6b6;}"); #endif setAcceptDrops(true); setAcceptDrops(true); this->setContextMenuPolicy(Qt::NoContextMenu); outPatternButton->setToolTip(outPatternEdit->toolTip()); outDirEdit->setToolTip(actionSelectResultDir->toolTip()); // TrackView ............................................... trackView->setRootIsDecorated(false); trackView->setItemsExpandable(false); trackView->hideColumn((int)TrackView::ColumnComment); trackView->setAlternatingRowColors(false); // Tag edits ............................................... tagGenreEdit->setTagId(TagId::Genre); connect(tagGenreEdit, SIGNAL(textEdited(QString)), this, SLOT(setTrackTag())); tagYearEdit->setTagId(TagId::Date); connect(tagYearEdit, SIGNAL(textEdited(QString)), this, SLOT(setTrackTag())); tagArtistEdit->setTagId(TagId::Artist); connect(tagArtistEdit, SIGNAL(textEdited(QString)), this, SLOT(setTrackTag())); connect(tagArtistEdit, SIGNAL(textEdited(QString)), this, SLOT(refreshEdits())); tagDiskPerformerEdit->setTagId(TagId::AlbumArtist); connect(tagDiskPerformerEdit, SIGNAL(textEdited(QString)), this, SLOT(setDiskTag())); connect(tagDiskPerformerEdit, SIGNAL(textEdited(QString)), this, SLOT(refreshEdits())); tagAlbumEdit->setTagId(TagId::Album); connect(tagAlbumEdit, SIGNAL(textEdited(QString)), this, SLOT(setTrackTag())); tagDiscIdEdit->setTagId(TagId::DiscId); connect(tagStartNumEdit, SIGNAL(editingFinished()), this, SLOT(setStartTrackNum())); connect(tagStartNumEdit, SIGNAL(valueChanged(int)), this, SLOT(setStartTrackNum())); connect(trackView->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), this, SLOT(refreshEdits())); connect(trackView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(trackViewMenu(QPoint))); connect(editTagsButton, &QPushButton::clicked, this, &MainWindow::openEditTagsDialog); initActions(); // Buttons ................................................. outDirButton->setAutoRaise(true); outDirButton->setStyleSheet("border: none;"); initOutDirButton(); configureEncoderBtn->setDefaultAction(actionConfigureEncoder); configureEncoderBtn->setAutoRaise(true); configureEncoderBtn->setStyleSheet("border: none;"); outPatternButton->addPattern("%n", tr("Insert \"Track number\"")); outPatternButton->addPattern("%N", tr("Insert \"Total number of tracks\"")); outPatternButton->addPattern("%a", tr("Insert \"Artist\"")); outPatternButton->addPattern("%A", tr("Insert \"Album title\"")); outPatternButton->addPattern("%t", tr("Insert \"Track title\"")); outPatternButton->addPattern("%y", tr("Insert \"Year\"")); outPatternButton->addPattern("%g", tr("Insert \"Genre\"")); outPatternButton->addPattern("%d", tr("Insert \"Disk number\"")); outPatternButton->addPattern("%D", tr("Insert \"Total number of disks\"")); const QString patterns[] = { "%a/{%y - }%A/%n - %t", "%a -{ %y }%A/%n - %t", "{%y }%A - %a/%n - %t", "%a/%A/%n - %t", "%a - %A/%n - %t", "%A - %a/%n - %t" }; for (QString pattern: patterns) { outPatternButton->addFullPattern(pattern, tr("Use \"%1\"", "Predefined out file pattern, string like 'Use \"%a/%A/%n - %t\"'") .arg(pattern) + " ( " + PatternExpander::example(pattern) + ".flac )"); } outPatternButton->menu()->addSeparator(); outPatternEdit->deleteItemAction()->setText(tr("Delete current pattern from history")); outPatternButton->menu()->addAction(outPatternEdit->deleteItemAction()); connect(outPatternButton, SIGNAL(paternSelected(QString)), this, SLOT(insertOutPattern(QString))); connect(outPatternButton, SIGNAL(fullPaternSelected(QString)), this, SLOT(replaceOutPattern(QString))); outPatternButton->setIcon(Icon("pattern-button")); // Format combo ............................................ initOutFormatCombo(); loadSettings(); outDirEdit->setHistory(settings->value(Settings::OutFiles_DirectoryHistory).toStringList()); outDirEdit->setCurrentText(settings->value(Settings::OutFiles_Directory).toString()); outPatternEdit->setHistory(settings->value(Settings::OutFiles_PatternHistory).toStringList()); // Signals ................................................. connect(settings, SIGNAL(changed()), trackView->model(), SIGNAL(layoutChanged())); connect(outPatternEdit->lineEdit(), SIGNAL(editingFinished()), this, SLOT(setPattern())); connect(outPatternEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(setPattern())); connect(outDirEdit->lineEdit(), SIGNAL(editingFinished()), this, SLOT(setOutDir())); connect(outDirEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(setOutDir())); connect(outFormatCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setOutFormat())); connect(codepageCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCodePage())); connect(trackView, SIGNAL(selectCueFile(Disk*)), this, SLOT(setCueForDisc(Disk*))); connect(trackView, SIGNAL(selectAudioFile(Disk*)), this, SLOT(setAudioForDisk(Disk*))); connect(trackView, SIGNAL(selectCoverImage(Disk*)), this, SLOT(setCoverImage(Disk*))); connect(trackView, SIGNAL(downloadInfo(Disk*)), this, SLOT(downloadDiskInfo(Disk*))); connect(trackView->model(), SIGNAL(layoutChanged()), this, SLOT(refreshEdits())); connect(trackView->model(), SIGNAL(layoutChanged()), this, SLOT(setControlsEnable())); connect(trackView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(refreshEdits())); connect(trackView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(setControlsEnable())); connect(project, SIGNAL(layoutChanged()), trackView, SLOT(layoutChanged())); connect(project, SIGNAL(layoutChanged()), this, SLOT(refreshEdits())); connect(project, SIGNAL(layoutChanged()), this, SLOT(setControlsEnable())); connect(project, SIGNAL(diskChanged(Disk*)), this, SLOT(refreshEdits())); connect(project, SIGNAL(diskChanged(Disk*)), this, SLOT(setControlsEnable())); connect(Application::instance(), &Application::visualModeChanged, [](){ Icon::setDarkMode(Application::instance()->isDarkVisualMode()); }); Icon::setDarkMode(Application::instance()->isDarkVisualMode()); refreshEdits(); setControlsEnable(); }
/** Update the output directory label if the Mantid system output * directory has changed * @param pDirInfo :: a pointer to an object with the output directory name in * it */ void SANSAddFiles::changeOutputDir( Mantid::Kernel::ConfigValChangeNotification_ptr pDirInfo) { if (pDirInfo->key() == "defaultsave.directory") { setOutDir(pDirInfo->curValue()); } }