karchivemanager: add pattern for all archive MIME types

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-17 14:27:33 +03:00
parent 09bc8ddd10
commit bc53a4961f

View file

@ -29,48 +29,18 @@
#include "karchiveapp.hpp" #include "karchiveapp.hpp"
#include "ui_karchiveapp.h" #include "ui_karchiveapp.h"
static const QStringList s_readwritemimes = QStringList() class KArchiveAppPrivate
<< "application/x-archive" {
<< "application/x-deb" public:
<< "application/x-cd-image" Ui_KArchiveAppWindow ui;
<< "application/x-bcpio"
<< "application/x-cpio"
<< "application/x-cpio-compressed"
<< "application/x-sv4cpio"
<< "application/x-sv4crc"
<< "application/x-rpm"
<< "application/x-source-rpm"
<< "application/vnd.ms-cab-compressed"
<< "application/x-servicepack"
<< "application/x-lzop"
<< "application/x-lz4"
<< "application/x-tar"
<< "application/zstd"
<< "application/x-zstd-compressed-tar"
<< "application/x-compressed-tar"
<< "application/x-bzip-compressed-tar"
<< "application/x-gzip-compressed-tar"
<< "application/x-tarz"
<< "application/x-xz"
<< "application/x-xz-compressed-tar"
<< "application/x-lzma-compressed-tar"
<< "application/x-java-archive"
<< "application/zip"
<< "application/x-7z-compressed"
<< "application/x-iso9660-image"
<< "application/x-raw-disk-image";
class KArchiveAppPrivate { KArchiveModel m_model;
KArchive *m_archive;
public:
Ui_KArchiveAppWindow ui;
KArchiveModel m_model;
KArchive *m_archive;
}; };
KArchiveApp::KArchiveApp() KArchiveApp::KArchiveApp()
: d(new KArchiveAppPrivate()) { : d(new KArchiveAppPrivate())
{
// setupUi() will set the object name required by KSettings save/restore // setupUi() will set the object name required by KSettings save/restore
d->ui.setupUi(this); d->ui.setupUi(this);
@ -94,7 +64,8 @@ KArchiveApp::KArchiveApp()
connect(&d->m_model, SIGNAL(loadFinished()), this, SLOT(slotLoadFinished())); connect(&d->m_model, SIGNAL(loadFinished()), this, SLOT(slotLoadFinished()));
} }
KArchiveApp::~KArchiveApp() { KArchiveApp::~KArchiveApp()
{
KSettings settings("karchivemanagerrc", KSettings::SimpleConfig); KSettings settings("karchivemanagerrc", KSettings::SimpleConfig);
settings.save(this); settings.save(this);
@ -104,7 +75,8 @@ KArchiveApp::~KArchiveApp() {
delete d; delete d;
} }
void KArchiveApp::changePath(const QString path) { void KArchiveApp::changePath(const QString path)
{
if (d->m_archive) { if (d->m_archive) {
delete d->m_archive; delete d->m_archive;
} }
@ -121,29 +93,47 @@ void KArchiveApp::changePath(const QString path) {
d->ui.actionExtract->setEnabled(isreadable); d->ui.actionExtract->setEnabled(isreadable);
} }
void KArchiveApp::slotOpenAction() { void KArchiveApp::slotOpenAction()
{
QString mimespattern; QString mimespattern;
foreach(const QString &mimetype, s_readwritemimes) { QString allmimespattern;
foreach(const QString &mimetype, KArchive::readableMimeTypes()) {
const KMimeType::Ptr mime = KMimeType::mimeType(mimetype); const KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
if (mime) { if (mime) {
if (!mimespattern.isEmpty()) { if (!mimespattern.isEmpty()) {
mimespattern.append(" "); mimespattern.append("\n");
} }
mimespattern.append(mime->patterns().join(" ")); if (!allmimespattern.isEmpty()) {
allmimespattern.append(" ");
}
const QString patterns = mime->patterns().join(" ");
mimespattern.append(patterns + QLatin1Char('|') + mime->comment());
allmimespattern.append(patterns);
} }
} }
const QString path = KFileDialog::getOpenFileName(KUrl("kfiledialog:///KArchiveManager"), mimespattern, this, i18n("Archive path")); if (!allmimespattern.isEmpty()) {
mimespattern.prepend(allmimespattern + QLatin1Char('|') + i18n("All Archives") + "\n");
}
const QString path = KFileDialog::getOpenFileName(
KUrl("kfiledialog:///KArchiveManager"),
mimespattern,
this,
i18n("Archive path")
);
if (!path.isEmpty()) { if (!path.isEmpty()) {
changePath(path); changePath(path);
} }
} }
void KArchiveApp::slotQuitAction() { void KArchiveApp::slotQuitAction()
{
qApp->quit(); qApp->quit();
} }
void KArchiveApp::slotAddAction() { void KArchiveApp::slotAddAction()
{
QFileDialog opendialog(this, windowTitle()); QFileDialog opendialog(this, windowTitle());
opendialog.setFileMode(QFileDialog::ExistingFiles); opendialog.setFileMode(QFileDialog::ExistingFiles);
opendialog.exec(); opendialog.exec();
@ -164,7 +154,8 @@ void KArchiveApp::slotAddAction() {
d->m_model.loadArchive(d->m_archive); d->m_model.loadArchive(d->m_archive);
} }
void KArchiveApp::slotRemoveAction() { void KArchiveApp::slotRemoveAction()
{
QStringList selected; QStringList selected;
foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) { foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) {
selected += d->m_model.paths(item); selected += d->m_model.paths(item);
@ -184,7 +175,8 @@ void KArchiveApp::slotRemoveAction() {
d->m_model.loadArchive(d->m_archive); d->m_model.loadArchive(d->m_archive);
} }
void KArchiveApp::slotExtractAction() { void KArchiveApp::slotExtractAction()
{
QStringList selected; QStringList selected;
foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) { foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) {
selected += d->m_model.paths(item); selected += d->m_model.paths(item);
@ -199,7 +191,8 @@ void KArchiveApp::slotExtractAction() {
d->m_archive->extract(selected, destination, true); d->m_archive->extract(selected, destination, true);
} }
void KArchiveApp::slotSelectionChanged(const QItemSelection &current, const QItemSelection &previous) { void KArchiveApp::slotSelectionChanged(const QItemSelection &current, const QItemSelection &previous)
{
Q_UNUSED(previous); Q_UNUSED(previous);
d->ui.menuAction->setEnabled(true); d->ui.menuAction->setEnabled(true);
@ -208,7 +201,8 @@ void KArchiveApp::slotSelectionChanged(const QItemSelection &current, const QIte
} }
} }
void KArchiveApp::slotLoadStarted() { void KArchiveApp::slotLoadStarted()
{
d->ui.menuAction->setEnabled(false); d->ui.menuAction->setEnabled(false);
d->ui.archiveView->setEnabled(false); d->ui.archiveView->setEnabled(false);
d->ui.progressBar->setRange(0, 0); d->ui.progressBar->setRange(0, 0);
@ -220,7 +214,8 @@ void KArchiveApp::slotLoadStarted() {
} }
} }
void KArchiveApp::slotLoadFinished() { void KArchiveApp::slotLoadFinished()
{
d->ui.archiveView->setEnabled(true); d->ui.archiveView->setEnabled(true);
d->ui.progressBar->setRange(0, 1); d->ui.progressBar->setRange(0, 1);
d->ui.progressBar->setVisible(false); d->ui.progressBar->setVisible(false);