File indexing completed on 2024-12-08 06:40:28

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 #include "kbuildsycocaprogressdialog.h"
0008 #include "kio_widgets_debug.h"
0009 
0010 #include <KLocalizedString>
0011 #include <KSycoca>
0012 
0013 #include <QDBusConnection>
0014 #include <QDBusInterface>
0015 #include <QDialogButtonBox>
0016 #include <QProcess>
0017 #include <QStandardPaths>
0018 
0019 class KBuildSycocaProgressDialogPrivate
0020 {
0021 public:
0022     explicit KBuildSycocaProgressDialogPrivate(KBuildSycocaProgressDialog *parent)
0023         : m_parent(parent)
0024     {
0025     }
0026 
0027     KBuildSycocaProgressDialog *const m_parent;
0028 };
0029 
0030 void KBuildSycocaProgressDialog::rebuildKSycoca(QWidget *parent)
0031 {
0032     KBuildSycocaProgressDialog dlg(parent, i18n("Updating System Configuration"), i18n("Updating system configuration…"));
0033 
0034     const QString exec = QStandardPaths::findExecutable(QStringLiteral(KBUILDSYCOCA_EXENAME));
0035     if (exec.isEmpty()) {
0036         qCWarning(KIO_WIDGETS) << "Could not find kbuildsycoca executable:" << KBUILDSYCOCA_EXENAME;
0037         return;
0038     }
0039     QProcess *proc = new QProcess(&dlg);
0040     proc->start(exec, QStringList());
0041     QObject::connect(proc, &QProcess::finished, &dlg, &QWidget::close);
0042 
0043     dlg.exec();
0044 }
0045 
0046 KBuildSycocaProgressDialog::KBuildSycocaProgressDialog(QWidget *_parent, const QString &title, const QString &text)
0047     : QProgressDialog(_parent)
0048     , d(new KBuildSycocaProgressDialogPrivate(this))
0049 {
0050     setWindowTitle(title);
0051     setModal(true);
0052     setLabelText(text);
0053     setRange(0, 0);
0054     setAutoClose(false);
0055     QDialogButtonBox *dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
0056     setCancelButton(dialogButtonBox->button(QDialogButtonBox::Cancel));
0057 }
0058 
0059 KBuildSycocaProgressDialog::~KBuildSycocaProgressDialog() = default;
0060 
0061 #include "moc_kbuildsycocaprogressdialog.cpp"