File indexing completed on 2025-01-19 04:46:44
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "akonadidatabasetoolsjob.h" 0007 #include "akonadidatasetools_debug.h" 0008 #include <QProcess> 0009 #include <QStandardPaths> 0010 0011 AkonadiDatabaseToolsJob::AkonadiDatabaseToolsJob(QObject *parent) 0012 : QObject{parent} 0013 { 0014 } 0015 0016 AkonadiDatabaseToolsJob::~AkonadiDatabaseToolsJob() = default; 0017 0018 bool AkonadiDatabaseToolsJob::canStart() const 0019 { 0020 return !akonadiProcessPath().isEmpty() && (mTool != AkonadiDatabaseToolsUtils::AkonadiDatabaseTool::Unknown); 0021 } 0022 0023 QString AkonadiDatabaseToolsJob::akonadiProcessPath() const 0024 { 0025 return QStandardPaths::findExecutable(QStringLiteral("akonadictl")); 0026 } 0027 0028 void AkonadiDatabaseToolsJob::setTool(AkonadiDatabaseToolsUtils::AkonadiDatabaseTool newTool) 0029 { 0030 mTool = newTool; 0031 } 0032 0033 void AkonadiDatabaseToolsJob::start() 0034 { 0035 if (!canStart()) { 0036 deleteLater(); 0037 return; 0038 } 0039 switch (mTool) { 0040 case AkonadiDatabaseToolsUtils::Unknown: 0041 qCWarning(AKONADIDATABASETOOLS_LOG) << "mTool is unknown it's a bug! "; 0042 break; 0043 case AkonadiDatabaseToolsUtils::Vacuum: { 0044 mProcess = new QProcess(this); 0045 mProcess->setProgram(akonadiProcessPath()); 0046 mProcess->setArguments(QStringList() << QStringLiteral("vacuum")); 0047 connect(mProcess, &QProcess::finished, this, [this]() { 0048 Q_EMIT finished(); 0049 deleteLater(); 0050 }); 0051 connect(mProcess, &QProcess::readyReadStandardError, this, [this]() { 0052 Q_EMIT receivedStandardError(QLatin1StringView(mProcess->readAllStandardError())); 0053 }); 0054 connect(mProcess, &QProcess::readyReadStandardOutput, this, [this]() { 0055 Q_EMIT receivedStandardOutput(QLatin1StringView(mProcess->readAllStandardOutput())); 0056 }); 0057 mProcess->start(); 0058 break; 0059 } 0060 case AkonadiDatabaseToolsUtils::Fsck: { 0061 mProcess = new QProcess(this); 0062 mProcess->setProgram(akonadiProcessPath()); 0063 mProcess->setArguments(QStringList() << QStringLiteral("fsck")); 0064 connect(mProcess, &QProcess::finished, this, [this]() { 0065 Q_EMIT finished(); 0066 deleteLater(); 0067 }); 0068 connect(mProcess, &QProcess::readyReadStandardError, this, [this]() { 0069 Q_EMIT receivedStandardError(QLatin1StringView(mProcess->readAllStandardError())); 0070 }); 0071 connect(mProcess, &QProcess::readyReadStandardOutput, this, [this]() { 0072 Q_EMIT receivedStandardOutput(QLatin1StringView(mProcess->readAllStandardOutput())); 0073 }); 0074 mProcess->start(); 0075 break; 0076 } 0077 } 0078 } 0079 0080 #include "moc_akonadidatabasetoolsjob.cpp"