| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2012-2015 Vishesh Handa <me@vhanda.in> |
| 3 | |
| 4 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL |
| 5 | */ |
| 6 | |
| 7 | #include <QFile> |
| 8 | |
| 9 | #include <KLocalizedString> |
| 10 | #include <QFileInfo> |
| 11 | #include <QTextStream> |
| 12 | |
| 13 | #include "command.h" |
| 14 | #include "database.h" |
| 15 | #include "global.h" |
| 16 | #include "transaction.h" |
| 17 | |
| 18 | #include "clearcommand.h" |
| 19 | #include "clearentry.h" |
| 20 | |
| 21 | using namespace Baloo; |
| 22 | |
| 23 | QString ClearCommand::command() |
| 24 | { |
| 25 | return QStringLiteral("clear"); |
| 26 | } |
| 27 | |
| 28 | QString ClearCommand::description() |
| 29 | { |
| 30 | return i18n("Immediately clear entries from the index"); |
| 31 | } |
| 32 | |
| 33 | // ClearCommand::exec |
| 34 | // Sets up output stream and calls clearEntryNow for each of the arguments |
| 35 | |
| 36 | int ClearCommand::exec(const QCommandLineParser &parser) |
| 37 | { |
| 38 | QTextStream out(stdout); |
| 39 | |
| 40 | if (parser.positionalArguments().size() < 2) { |
| 41 | out << "Enter a filename to index\n"; |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | Database *db = globalDatabaseInstance(); |
| 46 | if (db->open(mode: Database::ReadWriteDatabase) != Database::OpenResult::Success) { |
| 47 | out << "Baloo Index could not be opened\n"; |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | ClearEntry collection(db, out); |
| 52 | |
| 53 | for (int i = 1; i < parser.positionalArguments().size(); ++i) { |
| 54 | collection.clearEntryNow(fileName: parser.positionalArguments().at(i)); |
| 55 | } |
| 56 | |
| 57 | collection.commit(); |
| 58 | out << "File(s) cleared\n"; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 |
