Changeset View
Changeset View
Standalone View
Standalone View
src/qml/experimental/monitor.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | void Monitor::newFile(const QString& filePath) | 79 | void Monitor::newFile(const QString& filePath) | ||
80 | { | 80 | { | ||
81 | if (m_totalFiles == 0) { | 81 | if (m_totalFiles == 0) { | ||
82 | fetchTotalFiles(); | 82 | fetchTotalFiles(); | ||
83 | } | 83 | } | ||
84 | m_filePath = filePath; | 84 | m_filePath = filePath; | ||
85 | if (++m_filesIndexed == m_totalFiles) { | 85 | ++m_filesIndexed; | ||
86 | m_filePath = QStringLiteral("Done"); | | |||
87 | } | | |||
88 | Q_EMIT newFileIndexed(); | 86 | Q_EMIT newFileIndexed(); | ||
89 | 87 | | |||
90 | if (m_filesIndexed % 100 == 0) { | 88 | if (m_remainingTimeTimer.elapsed() > 1000) { | ||
91 | updateRemainingTime(); | 89 | updateRemainingTime(); | ||
90 | m_remainingTimeTimer.restart(); | ||||
92 | } | 91 | } | ||
93 | } | 92 | } | ||
94 | 93 | | |||
95 | QString Monitor::suspendState() const | 94 | QString Monitor::suspendState() const | ||
96 | { | 95 | { | ||
97 | return m_indexerState == Baloo::Suspended ? QStringLiteral("Resume") : QStringLiteral("Suspend"); | 96 | return m_indexerState == Baloo::Suspended ? QStringLiteral("Resume") : QStringLiteral("Suspend"); | ||
98 | } | 97 | } | ||
99 | 98 | | |||
100 | void Monitor::toggleSuspendState() | 99 | void Monitor::toggleSuspendState() | ||
101 | { | 100 | { | ||
102 | Q_ASSERT(m_scheduler != nullptr); | | |||
103 | | ||||
104 | if (m_indexerState == Baloo::Suspended) { | 101 | if (m_indexerState == Baloo::Suspended) { | ||
105 | m_scheduler->resume(); | 102 | m_scheduler->resume(); | ||
106 | } else { | 103 | } else { | ||
107 | m_scheduler->suspend(); | 104 | m_scheduler->suspend(); | ||
108 | } | 105 | } | ||
109 | } | 106 | } | ||
110 | 107 | | |||
111 | void Monitor::balooStarted(const QString& service) | 108 | void Monitor::balooStarted(const QString& service) | ||
112 | { | 109 | { | ||
113 | Q_ASSERT(service == QLatin1String("org.kde.baloo")); | 110 | Q_ASSERT(service == QLatin1String("org.kde.baloo")); | ||
114 | 111 | | |||
115 | m_balooRunning = true; | 112 | m_balooRunning = true; | ||
116 | m_fileindexer->registerMonitor(); | 113 | m_fileindexer->registerMonitor(); | ||
117 | 114 | | |||
118 | slotIndexerStateChanged(m_scheduler->state()); | 115 | slotIndexerStateChanged(m_scheduler->state()); | ||
119 | // qDebug() << "fetched suspend state"; | | |||
120 | fetchTotalFiles(); | | |||
121 | if (m_indexerState == Baloo::ContentIndexing) { | | |||
122 | m_filePath = m_fileindexer->currentFile(); | | |||
123 | updateRemainingTime(); | | |||
124 | } | | |||
125 | Q_EMIT balooStateChanged(); | 116 | Q_EMIT balooStateChanged(); | ||
126 | } | 117 | } | ||
127 | 118 | | |||
128 | void Monitor::fetchTotalFiles() | 119 | void Monitor::fetchTotalFiles() | ||
129 | { | 120 | { | ||
130 | Baloo::Database *db = Baloo::globalDatabaseInstance(); | 121 | Baloo::Database *db = Baloo::globalDatabaseInstance(); | ||
131 | if (db->open(Baloo::Database::ReadOnlyDatabase)) { | 122 | if (db->open(Baloo::Database::ReadOnlyDatabase)) { | ||
132 | Baloo::Transaction tr(db, Baloo::Transaction::ReadOnly); | 123 | Baloo::Transaction tr(db, Baloo::Transaction::ReadOnly); | ||
133 | m_totalFiles = tr.size(); | 124 | m_totalFiles = tr.size(); | ||
134 | m_filesIndexed = tr.size() - tr.phaseOneSize(); | 125 | m_filesIndexed = tr.size() - tr.phaseOneSize(); | ||
135 | Q_EMIT totalFilesChanged(); | 126 | Q_EMIT totalFilesChanged(); | ||
127 | Q_EMIT newFileIndexed(); | ||||
136 | } | 128 | } | ||
137 | } | 129 | } | ||
138 | 130 | | |||
139 | void Monitor::startBaloo() | 131 | void Monitor::startBaloo() | ||
140 | { | 132 | { | ||
141 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | 133 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("baloo_file")); | ||
142 | QProcess::startDetached(exe); | 134 | QProcess::startDetached(exe); | ||
143 | } | 135 | } | ||
144 | 136 | | |||
145 | void Monitor::updateRemainingTime() | 137 | void Monitor::updateRemainingTime() | ||
146 | { | 138 | { | ||
147 | m_remainingTime = KFormat().formatSpelloutDuration(m_scheduler->getRemainingTime()); | 139 | m_remainingTime = KFormat().formatSpelloutDuration(m_scheduler->getRemainingTime()); | ||
148 | Q_EMIT remainingTimeChanged(); | 140 | Q_EMIT remainingTimeChanged(); | ||
149 | } | 141 | } | ||
150 | 142 | | |||
151 | void Monitor::slotIndexerStateChanged(int state) | 143 | void Monitor::slotIndexerStateChanged(int state) | ||
152 | { | 144 | { | ||
153 | Baloo::IndexerState newState = static_cast<Baloo::IndexerState>(state); | 145 | Baloo::IndexerState newState = static_cast<Baloo::IndexerState>(state); | ||
154 | 146 | | |||
155 | if (m_indexerState != newState) { | 147 | if (m_indexerState != newState) { | ||
156 | m_indexerState = newState; | 148 | m_indexerState = newState; | ||
157 | Q_EMIT indexerStateChanged(); | 149 | Q_EMIT indexerStateChanged(); | ||
158 | fetchTotalFiles(); | 150 | fetchTotalFiles(); | ||
151 | if (m_indexerState == Baloo::ContentIndexing) { | ||||
152 | m_remainingTimeTimer.start(); | ||||
153 | } else { | ||||
154 | m_filePath = QString(); | ||||
155 | } | ||||
159 | } | 156 | } | ||
160 | } | 157 | } | ||
161 | 158 | |