Changeset View
Changeset View
Standalone View
Standalone View
src/tools/balooctl/main.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 66 | { | |||
---|---|---|---|---|---|
72 | KAboutData::setApplicationData(aboutData); | 72 | KAboutData::setApplicationData(aboutData); | ||
73 | 73 | | |||
74 | QCommandLineParser parser; | 74 | QCommandLineParser parser; | ||
75 | parser.addPositionalArgument(QStringLiteral("command"), i18n("The command to execute")); | 75 | parser.addPositionalArgument(QStringLiteral("command"), i18n("The command to execute")); | ||
76 | 76 | | |||
77 | parser.addPositionalArgument(QStringLiteral("status"), i18n("Print the status of the indexer")); | 77 | parser.addPositionalArgument(QStringLiteral("status"), i18n("Print the status of the indexer")); | ||
78 | parser.addPositionalArgument(QStringLiteral("enable"), i18n("Enable the file indexer")); | 78 | parser.addPositionalArgument(QStringLiteral("enable"), i18n("Enable the file indexer")); | ||
79 | parser.addPositionalArgument(QStringLiteral("disable"), i18n("Disable the file indexer")); | 79 | parser.addPositionalArgument(QStringLiteral("disable"), i18n("Disable the file indexer")); | ||
80 | parser.addPositionalArgument(QStringLiteral("start"), i18n("Start the file indexer")); | 80 | parser.addPositionalArgument(QStringLiteral("purge"), i18n("Remove the index database")); | ||
81 | parser.addPositionalArgument(QStringLiteral("stop"), i18n("Stop the file indexer")); | | |||
82 | parser.addPositionalArgument(QStringLiteral("restart"), i18n("Restart the file indexer")); | | |||
83 | parser.addPositionalArgument(QStringLiteral("suspend"), i18n("Suspend the file indexer")); | 81 | parser.addPositionalArgument(QStringLiteral("suspend"), i18n("Suspend the file indexer")); | ||
84 | parser.addPositionalArgument(QStringLiteral("resume"), i18n("Resume the file indexer")); | 82 | parser.addPositionalArgument(QStringLiteral("resume"), i18n("Resume the file indexer")); | ||
85 | parser.addPositionalArgument(QStringLiteral("check"), i18n("Check for any unindexed files and index them")); | 83 | parser.addPositionalArgument(QStringLiteral("check"), i18n("Check for any unindexed files and index them")); | ||
86 | parser.addPositionalArgument(QStringLiteral("index"), i18n("Index the specified files")); | 84 | parser.addPositionalArgument(QStringLiteral("index"), i18n("Index the specified files")); | ||
87 | parser.addPositionalArgument(QStringLiteral("clear"), i18n("Forget the specified files")); | 85 | parser.addPositionalArgument(QStringLiteral("clear"), i18n("Forget the specified files")); | ||
88 | parser.addPositionalArgument(QStringLiteral("config"), i18n("Modify the Baloo configuration")); | 86 | parser.addPositionalArgument(QStringLiteral("config"), i18n("Modify the Baloo configuration")); | ||
89 | parser.addPositionalArgument(QStringLiteral("monitor"), i18n("Monitor the file indexer")); | 87 | parser.addPositionalArgument(QStringLiteral("monitor"), i18n("Monitor the file indexer")); | ||
90 | parser.addPositionalArgument(QStringLiteral("indexSize"), i18n("Display the disk space used by index")); | 88 | parser.addPositionalArgument(QStringLiteral("indexSize"), i18n("Display the disk space used by index")); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 131 | if (command == QLatin1String("enable") || command == QLatin1String("disable")) { | |||
138 | else if (command == QLatin1String("disable")) { | 136 | else if (command == QLatin1String("disable")) { | ||
139 | isEnabled = false; | 137 | isEnabled = false; | ||
140 | } | 138 | } | ||
141 | 139 | | |||
142 | IndexerConfig cfg; | 140 | IndexerConfig cfg; | ||
143 | cfg.setFileIndexingEnabled(isEnabled); | 141 | cfg.setFileIndexingEnabled(isEnabled); | ||
144 | 142 | | |||
145 | if (isEnabled) { | 143 | if (isEnabled) { | ||
146 | out << "Enabling the File Indexer\n"; | 144 | bool running = mainInterface.isValid(); | ||
147 | 145 | if (running) { | |||
148 | cfg.setFirstRun(true); | 146 | out << "File Indexer already running\n"; | ||
147 | } else { | ||||
148 | out << "Enabling and starting the File Indexer\n"; | ||||
149 | start(); | 149 | start(); | ||
150 | } | ||||
150 | } else { | 151 | } else { | ||
151 | out << "Disabling the File Indexer\n"; | 152 | out << "Disabling and stopping the File Indexer\n"; | ||
152 | 153 | | |||
153 | mainInterface.quit(); | 154 | mainInterface.quit(); | ||
154 | const QString path = fileIndexDbPath() + QStringLiteral("/index"); | | |||
155 | QFile(path).remove(); | | |||
156 | } | 155 | } | ||
157 | 156 | | |||
158 | return 0; | 157 | return 0; | ||
159 | } | 158 | } | ||
160 | 159 | | |||
161 | if (command == QLatin1String("start") || command == QLatin1String("stop") || | 160 | if (command == QLatin1String("purge")) { | ||
162 | command == QLatin1String("restart")) { | 161 | bool running = mainInterface.isValid(); | ||
163 | bool shouldStart = false; | | |||
164 | bool shouldStop = false; | | |||
165 | | ||||
166 | if (command == QLatin1String("start")) | | |||
167 | shouldStart = true; | | |||
168 | else if (command == QLatin1String("stop")) | | |||
169 | shouldStop = true; | | |||
170 | else if (command == QLatin1String("restart")) { | | |||
171 | shouldStart = true; | | |||
172 | shouldStop = true; | | |||
173 | } | | |||
174 | 162 | | |||
175 | if (shouldStop) | 163 | if (running) { | ||
176 | mainInterface.quit(); | 164 | mainInterface.quit(); | ||
177 | if (shouldStart) | 165 | out << "Stopping the File Indexer ..."; | ||
166 | for (int i = 5 * 60; i; --i) { | ||||
167 | QCoreApplication::processEvents(); | ||||
168 | if (!mainInterface.isValid()) { | ||||
169 | break; | ||||
170 | } | ||||
171 | out << "." << flush; | ||||
172 | QThread::msleep(200); | ||||
173 | } | ||||
174 | if (!mainInterface.isValid()) { | ||||
175 | out << " - done\n"; | ||||
176 | } else { | ||||
177 | out << " - failed to stop!\n"; | ||||
178 | return 1; | ||||
179 | } | ||||
180 | } | ||||
181 | | ||||
182 | const QString path = fileIndexDbPath() + QStringLiteral("/index"); | ||||
183 | QFile(path).remove(); | ||||
184 | out << "Deleted the index database\n"; | ||||
185 | | ||||
186 | if (running) { | ||||
178 | start(); | 187 | start(); | ||
188 | out << "Restarting the File Indexer\n"; | ||||
189 | } | ||||
179 | 190 | | |||
180 | return 0; | 191 | return 0; | ||
181 | } | 192 | } | ||
182 | 193 | | |||
183 | if (command == QStringLiteral("suspend")) { | 194 | if (command == QStringLiteral("suspend")) { | ||
184 | schedulerinterface.suspend(); | 195 | schedulerinterface.suspend(); | ||
185 | out << "File Indexer suspended\n"; | 196 | out << "File Indexer suspended\n"; | ||
186 | return 0; | 197 | return 0; | ||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |