kde-extraapps/ark/kerfuffle/extractiondialog.cpp
Ivailo Monev c0c0f194bc ark: rework extraction dialog
less space used by the options, automatic sub-folder detection even for
single folder archive and handling of dot (".") as the returned sub-folder
name by the archive list job (libarchive quirck).

tested batch and non-batch extraction, with and without automatic
sub-folder detection but with tar.xz and .deb files only

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2024-05-18 03:08:36 +03:00

150 lines
4 KiB
C++

/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2009 Harald Hvaal <haraldhv@stud.ntnu.no>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "extractiondialog.h"
#include "settings.h"
#include <KLocale>
#include <KIconLoader>
#include <KMessageBox>
#include <KStandardDirs>
#include <KDebug>
#include <KIO/NetAccess>
#include <kfilewidget.h>
#include <QDir>
#include "ui_extractiondialog.h"
namespace Kerfuffle
{
class ExtractionDialogUI: public QFrame, public Ui::ExtractionDialog
{
public:
ExtractionDialogUI(QWidget *parent = 0)
: QFrame(parent)
{
setupUi(this);
}
};
ExtractionDialog::ExtractionDialog(QWidget *parent)
: KFileDialog(KUrl(), QString(), parent)
{
setOperationMode(KFileDialog::Opening);
setMode(KFile::Directory | KFile::ExistingOnly);
m_ui = new ExtractionDialogUI(this);
fileWidget()->setCustomWidget(m_ui);
setCaption(i18nc("@title:window", "Extract"));
loadSettings();
connect(this, SIGNAL(finished(int)), SLOT(writeSettings()));
}
void ExtractionDialog::loadSettings()
{
setOpenDestinationFolderAfterExtraction(ArkSettings::openDestinationFolderAfterExtraction());
setCloseAfterExtraction(ArkSettings::closeAfterExtraction());
setPreservePaths(ArkSettings::preservePaths());
}
ExtractionDialog::~ExtractionDialog()
{
delete m_ui;
m_ui = 0;
}
void ExtractionDialog::setAutoSubfolder(bool value)
{
m_ui->autoSubfolders->setChecked(value);
}
bool ExtractionDialog::autoSubfolders() const
{
return m_ui->autoSubfolders->isChecked();
}
void ExtractionDialog::setOpenDestinationFolderAfterExtraction(bool value)
{
m_ui->openFolderCheckBox->setChecked(value);
}
void ExtractionDialog::setCloseAfterExtraction(bool value)
{
m_ui->closeAfterExtraction->setChecked(value);
}
void ExtractionDialog::setPreservePaths(bool value)
{
m_ui->preservePaths->setChecked(value);
}
bool ExtractionDialog::preservePaths() const
{
return m_ui->preservePaths->isChecked();
}
bool ExtractionDialog::openDestinationAfterExtraction() const
{
return m_ui->openFolderCheckBox->isChecked();
}
bool ExtractionDialog::closeAfterExtraction() const
{
return m_ui->closeAfterExtraction->isChecked();
}
QString ExtractionDialog::destinationDirectory() const
{
return selectedUrl().pathOrUrl(KUrl::AddTrailingSlash);
}
void ExtractionDialog::selectionModeOption()
{
setCaption(i18n("Extract selected"));
}
void ExtractionDialog::batchModeOption()
{
setCaption(i18n("Extract multiple archives"));
}
void ExtractionDialog::writeSettings()
{
ArkSettings::setOpenDestinationFolderAfterExtraction(openDestinationAfterExtraction());
ArkSettings::setCloseAfterExtraction(closeAfterExtraction());
ArkSettings::setPreservePaths(preservePaths());
ArkSettings::self()->writeConfig();
}
}
#include "moc_extractiondialog.cpp"