Changeset View
Changeset View
Standalone View
Standalone View
src/tools/baloodb/main.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 45 | const auto options = QList<QCommandLineOption>{ | |||
---|---|---|---|---|---|
56 | QCommandLineOption{ | 56 | QCommandLineOption{ | ||
57 | QStringList{QStringLiteral("D"), QStringLiteral("dry-run")}, | 57 | QStringList{QStringLiteral("D"), QStringLiteral("dry-run")}, | ||
58 | i18n("Print results of a prune operation, but do not change anything." | 58 | i18n("Print results of a prune operation, but do not change anything." | ||
59 | "\nOnly applies to \"%1\" command", QStringLiteral("prune")) | 59 | "\nOnly applies to \"%1\" command", QStringLiteral("prune")) | ||
60 | }, | 60 | }, | ||
61 | QCommandLineOption{ | 61 | QCommandLineOption{ | ||
62 | QStringList{QStringLiteral("m"), QStringLiteral("missing-only")}, | 62 | QStringList{QStringLiteral("m"), QStringLiteral("missing-only")}, | ||
63 | i18n("List only inaccessible entries.\nOnly applies to \"%1\"", QStringLiteral("list")) | 63 | i18n("List only inaccessible entries.\nOnly applies to \"%1\"", QStringLiteral("list")) | ||
64 | }, | ||||
65 | QCommandLineOption{ | ||||
66 | QStringList{QStringLiteral("u"), QStringLiteral("mounted-only")}, | ||||
67 | i18n("Act only on item on mounted devices") | ||||
64 | } | 68 | } | ||
65 | }; | 69 | }; | ||
66 | 70 | | |||
67 | const auto commands = std::vector<Command>{ | 71 | const auto commands = std::vector<Command>{ | ||
68 | Command{ | 72 | Command{ | ||
69 | QStringLiteral("list"), | 73 | QStringLiteral("list"), | ||
70 | i18n("List database contents. Use a regular expression as argument to filter output"), | 74 | i18n("List database contents. Use a regular expression as argument to filter output"), | ||
71 | QStringList{ | 75 | QStringList{ | ||
Show All 25 Lines | 99 | QStringList{ | |||
97 | QStringLiteral("device-id") | 101 | QStringLiteral("device-id") | ||
98 | } | 102 | } | ||
99 | }, | 103 | }, | ||
100 | */ | 104 | */ | ||
101 | Command{ | 105 | Command{ | ||
102 | QStringLiteral("devices"), | 106 | QStringLiteral("devices"), | ||
103 | i18n("List devices"), | 107 | i18n("List devices"), | ||
104 | QStringList{}, | 108 | QStringList{}, | ||
105 | QStringList{QStringLiteral("missing-only")} | 109 | QStringList{QStringLiteral("missing-only"), QStringLiteral("mounted-only")} | ||
106 | } | 110 | } | ||
107 | }; | 111 | }; | ||
108 | 112 | | |||
109 | const QStringList allowedCommands() | 113 | const QStringList allowedCommands() | ||
110 | { | 114 | { | ||
111 | QStringList names; | 115 | QStringList names; | ||
112 | for (const auto& c : commands) { | 116 | for (const auto& c : commands) { | ||
113 | names.append(c.name); | 117 | names.append(c.name); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 160 | { | |||
200 | 204 | | |||
201 | const auto optNames = parser.optionNames(); | 205 | const auto optNames = parser.optionNames(); | ||
202 | const auto allowedOptions = getOptions(command); | 206 | const auto allowedOptions = getOptions(command); | ||
203 | 207 | | |||
204 | QVector<qint64> deviceIds; | 208 | QVector<qint64> deviceIds; | ||
205 | for (const auto& dev : parser.values(QStringLiteral("device-id"))) { | 209 | for (const auto& dev : parser.values(QStringLiteral("device-id"))) { | ||
206 | deviceIds.append(dev.toInt()); | 210 | deviceIds.append(dev.toInt()); | ||
207 | } | 211 | } | ||
208 | const bool missingOnly = parser.isSet(QStringLiteral("missing-only")); | 212 | const DatabaseSanitizer::ItemAccessFilters accessFilter = ( | ||
213 | parser.isSet(QStringLiteral("missing-only")) | ||||
214 | ? DatabaseSanitizer::IgnoreAvailable | ||||
215 | : DatabaseSanitizer::IgnoreNone | ||||
216 | ) | ( | ||||
217 | parser.isSet(QStringLiteral("mounted-only")) | ||||
218 | ? DatabaseSanitizer::IgnoreUnmounted | ||||
219 | : DatabaseSanitizer::IgnoreNone | ||||
220 | ); | ||||
209 | const QString pattern = args.isEmpty() | 221 | const QString pattern = args.isEmpty() | ||
210 | ? QString() | 222 | ? QString() | ||
211 | : args.at(0); | 223 | : args.at(0); | ||
212 | const QSharedPointer<QRegularExpression> urlFilter(pattern.isEmpty() | 224 | const QSharedPointer<QRegularExpression> urlFilter(pattern.isEmpty() | ||
213 | ? nullptr | 225 | ? nullptr | ||
214 | : new QRegularExpression{pattern}); | 226 | : new QRegularExpression{pattern}); | ||
215 | 227 | | |||
216 | auto db = globalDatabaseInstance(); | 228 | auto db = globalDatabaseInstance(); | ||
217 | QTextStream err(stderr); | 229 | QTextStream err(stderr); | ||
218 | QElapsedTimer timer; | 230 | QElapsedTimer timer; | ||
219 | timer.start(); | 231 | timer.start(); | ||
220 | 232 | | |||
221 | if (command == QStringLiteral("list")) { | 233 | if (command == QStringLiteral("list")) { | ||
222 | if (!db->open(Database::ReadOnlyDatabase)) { | 234 | if (!db->open(Database::ReadOnlyDatabase)) { | ||
223 | err << i18n("Baloo Index could not be opened") << endl; | 235 | err << i18n("Baloo Index could not be opened") << endl; | ||
224 | return 1; | 236 | return 1; | ||
225 | } | 237 | } | ||
226 | DatabaseSanitizer san(db, Transaction::ReadOnly); | 238 | DatabaseSanitizer san(db, Transaction::ReadOnly); | ||
227 | err << i18n("Listing database contents...") << endl; | 239 | err << i18n("Listing database contents...") << endl; | ||
228 | san.printList(deviceIds, missingOnly, urlFilter); | 240 | san.printList(deviceIds, accessFilter, urlFilter); | ||
229 | } else if (command == QStringLiteral("devices")) { | 241 | } else if (command == QStringLiteral("devices")) { | ||
230 | if (!db->open(Database::ReadOnlyDatabase)) { | 242 | if (!db->open(Database::ReadOnlyDatabase)) { | ||
231 | err << i18n("Baloo Index could not be opened") << endl; | 243 | err << i18n("Baloo Index could not be opened") << endl; | ||
232 | return 1; | 244 | return 1; | ||
233 | } | 245 | } | ||
234 | DatabaseSanitizer san(db, Transaction::ReadOnly); | 246 | DatabaseSanitizer san(db, Transaction::ReadOnly); | ||
235 | err << i18n("Listing database contents...") << endl; | 247 | err << i18n("Listing database contents...") << endl; | ||
236 | san.printDevices(deviceIds, missingOnly); | 248 | san.printDevices(deviceIds, accessFilter); | ||
237 | 249 | | |||
238 | } else if (command == QStringLiteral("clean")) { | 250 | } else if (command == QStringLiteral("clean")) { | ||
239 | /* TODO: add prune command */ | 251 | /* TODO: add prune command */ | ||
240 | parser.showHelp(1); | 252 | parser.showHelp(1); | ||
241 | 253 | | |||
242 | } else if (command == QStringLiteral("check")) { | 254 | } else if (command == QStringLiteral("check")) { | ||
243 | parser.showHelp(1); | 255 | parser.showHelp(1); | ||
244 | /* TODO: After check methods are improved | 256 | /* TODO: After check methods are improved | ||
Show All 21 Lines |