Changeset View
Changeset View
Standalone View
Standalone View
addons/project/kateprojectinfoviewcodeanalysis.cpp
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | 116 | { | |||
---|---|---|---|---|---|
121 | m_analysisTool->setProject(m_project); | 121 | m_analysisTool->setProject(m_project); | ||
122 | 122 | | |||
123 | /** | 123 | /** | ||
124 | * clear existing entries | 124 | * clear existing entries | ||
125 | */ | 125 | */ | ||
126 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | 126 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | ||
127 | 127 | | |||
128 | /** | 128 | /** | ||
129 | * launch cppcheck | 129 | * launch selected tool | ||
130 | */ | 130 | */ | ||
131 | m_analyzer = new QProcess(this); | 131 | m_analyzer = new QProcess(this); | ||
132 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | 132 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | ||
133 | 133 | | |||
134 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | 134 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | ||
135 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | 135 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | ||
136 | this, &KateProjectInfoViewCodeAnalysis::finished); | 136 | this, &KateProjectInfoViewCodeAnalysis::finished); | ||
137 | 137 | | |||
Show All 9 Lines | 145 | if (!m_analyzer->waitForStarted()) { | |||
147 | m_messageWidget->setCloseButtonVisible(true); | 147 | m_messageWidget->setCloseButtonVisible(true); | ||
148 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 148 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
149 | m_messageWidget->setWordWrap(false); | 149 | m_messageWidget->setWordWrap(false); | ||
150 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | 150 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | ||
151 | static_cast<QVBoxLayout *>(layout())->addWidget(m_messageWidget); | 151 | static_cast<QVBoxLayout *>(layout())->addWidget(m_messageWidget); | ||
152 | m_messageWidget->animatedShow(); | 152 | m_messageWidget->animatedShow(); | ||
153 | return; | 153 | return; | ||
154 | } | 154 | } | ||
155 | | ||||
156 | m_startStopAnalysis->setEnabled(false); | ||||
157 | | ||||
155 | /** | 158 | /** | ||
156 | * write files list and close write channel | 159 | * write files list and close write channel | ||
157 | */ | 160 | */ | ||
158 | const QString stdinMessage = m_analysisTool->stdinMessages(); | 161 | const QString stdinMessage = m_analysisTool->stdinMessages(); | ||
159 | if (!stdinMessage.isEmpty()) { | 162 | if (!stdinMessage.isEmpty()) { | ||
160 | m_analyzer->write(stdinMessage.toLocal8Bit()); | 163 | m_analyzer->write(stdinMessage.toLocal8Bit()); | ||
161 | } | 164 | } | ||
162 | m_analyzer->closeWriteChannel(); | 165 | m_analyzer->closeWriteChannel(); | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 208 | { | |||
225 | int line = m_model->item(index.row(), 1)->text().toInt(); | 228 | int line = m_model->item(index.row(), 1)->text().toInt(); | ||
226 | if (line >= 1) { | 229 | if (line >= 1) { | ||
227 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | 230 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | ||
228 | } | 231 | } | ||
229 | } | 232 | } | ||
230 | 233 | | |||
231 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | 234 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | ||
232 | { | 235 | { | ||
236 | m_startStopAnalysis->setEnabled(true); | ||||
237 | | ||||
233 | m_messageWidget = new KMessageWidget(); | 238 | m_messageWidget = new KMessageWidget(); | ||
234 | m_messageWidget->setCloseButtonVisible(true); | 239 | m_messageWidget->setCloseButtonVisible(true); | ||
235 | m_messageWidget->setWordWrap(false); | 240 | m_messageWidget->setWordWrap(false); | ||
236 | 241 | | |||
237 | if (exitCode == 0) { | 242 | if (m_analysisTool->isSuccessfulExitCode(exitCode)) { | ||
243 | // normally 0 is successful but there are exceptions | ||||
238 | m_messageWidget->setMessageType(KMessageWidget::Information); | 244 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||
239 | m_messageWidget->setText(i18n("Analysis finished.")); | 245 | m_messageWidget->setText(i18n("Analysis on %1 file(s) finished.", m_analysisTool->getActualFilesCount())); | ||
dhaumann: Instead of writing file(s) you could also use the i18np form to get a better translation: https… | |||||
240 | } else { | 246 | } else { | ||
241 | // unfortunately, output was eaten by slotReadyRead() | 247 | // unfortunately, output was eaten by slotReadyRead() | ||
242 | // TODO: get stderr output, show it here | 248 | // TODO: get stderr output, show it here | ||
243 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 249 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
244 | m_messageWidget->setText(i18n("Analysis failed!")); | 250 | m_messageWidget->setText(i18n("Analysis on %1 file(s) failed with exit code %2.", m_analysisTool->getActualFilesCount(), exitCode)); | ||
245 | } | 251 | } | ||
246 | static_cast<QVBoxLayout*>(layout ())->addWidget(m_messageWidget); | 252 | static_cast<QVBoxLayout*>(layout())->addWidget(m_messageWidget); | ||
247 | m_messageWidget->animatedShow (); | 253 | m_messageWidget->animatedShow(); | ||
248 | } | 254 | } |
Instead of writing file(s) you could also use the i18np form to get a better translation: https://techbase.kde.org/Development/Tutorials/Localization/i18n#Plurals
Think of languages where it's not possible to simply add a "(s)" to imply a correct plural form. Even in German it already starts to look awkward: "Analyse für 13 Datai(en) beendet" or so...
Same below.