Changeset View
Changeset View
Standalone View
Standalone View
addons/project/kateprojectinfoviewcodeanalysis.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | |||||
103 | 103 | | |||
104 | KateProjectInfoViewCodeAnalysis::~KateProjectInfoViewCodeAnalysis() | 104 | KateProjectInfoViewCodeAnalysis::~KateProjectInfoViewCodeAnalysis() | ||
105 | { | 105 | { | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | void KateProjectInfoViewCodeAnalysis::slotToolSelectionChanged(int) | 108 | void KateProjectInfoViewCodeAnalysis::slotToolSelectionChanged(int) | ||
109 | { | 109 | { | ||
110 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | 110 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | ||
111 | m_toolInfoText = i18n("The selected tool will be run on all project files which match this list of file extensions:<br/><b>%1</b>", | 111 | m_toolInfoText = i18n("%1<br/><br/>The tool will be run on all project files which match this list of file extensions:<br/><br/><b>%2</b>", | ||
112 | m_analysisTool->description(), | ||||
112 | m_analysisTool->fileExtensions()); | 113 | m_analysisTool->fileExtensions()); | ||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | void KateProjectInfoViewCodeAnalysis::slotStartStopClicked() | 116 | void KateProjectInfoViewCodeAnalysis::slotStartStopClicked() | ||
116 | { | 117 | { | ||
117 | /** | 118 | /** | ||
118 | * get files for the external tool | 119 | * get files for the external tool | ||
119 | */ | 120 | */ | ||
120 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | 121 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | ||
121 | m_analysisTool->setProject(m_project); | 122 | m_analysisTool->setProject(m_project); | ||
122 | 123 | | |||
123 | /** | 124 | /** | ||
124 | * clear existing entries | 125 | * clear existing entries | ||
125 | */ | 126 | */ | ||
126 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | 127 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | ||
127 | 128 | | |||
128 | /** | 129 | /** | ||
129 | * launch cppcheck | 130 | * launch selected tool | ||
130 | */ | 131 | */ | ||
131 | m_analyzer = new QProcess(this); | 132 | m_analyzer = new QProcess(this); | ||
132 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | 133 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | ||
133 | 134 | | |||
134 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | 135 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | ||
135 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | 136 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | ||
136 | this, &KateProjectInfoViewCodeAnalysis::finished); | 137 | this, &KateProjectInfoViewCodeAnalysis::finished); | ||
137 | 138 | | |||
Show All 9 Lines | 146 | if (!m_analyzer->waitForStarted()) { | |||
147 | m_messageWidget->setCloseButtonVisible(true); | 148 | m_messageWidget->setCloseButtonVisible(true); | ||
148 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 149 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
149 | m_messageWidget->setWordWrap(false); | 150 | m_messageWidget->setWordWrap(false); | ||
150 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | 151 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | ||
151 | static_cast<QVBoxLayout *>(layout())->addWidget(m_messageWidget); | 152 | static_cast<QVBoxLayout *>(layout())->addWidget(m_messageWidget); | ||
152 | m_messageWidget->animatedShow(); | 153 | m_messageWidget->animatedShow(); | ||
153 | return; | 154 | return; | ||
154 | } | 155 | } | ||
156 | | ||||
157 | m_startStopAnalysis->setEnabled(false); | ||||
158 | | ||||
155 | /** | 159 | /** | ||
156 | * write files list and close write channel | 160 | * write files list and close write channel | ||
157 | */ | 161 | */ | ||
158 | const QString stdinMessage = m_analysisTool->stdinMessages(); | 162 | const QString stdinMessage = m_analysisTool->stdinMessages(); | ||
159 | if (!stdinMessage.isEmpty()) { | 163 | if (!stdinMessage.isEmpty()) { | ||
160 | m_analyzer->write(stdinMessage.toLocal8Bit()); | 164 | m_analyzer->write(stdinMessage.toLocal8Bit()); | ||
161 | } | 165 | } | ||
162 | m_analyzer->closeWriteChannel(); | 166 | m_analyzer->closeWriteChannel(); | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 209 | { | |||
225 | int line = m_model->item(index.row(), 1)->text().toInt(); | 229 | int line = m_model->item(index.row(), 1)->text().toInt(); | ||
226 | if (line >= 1) { | 230 | if (line >= 1) { | ||
227 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | 231 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | ||
228 | } | 232 | } | ||
229 | } | 233 | } | ||
230 | 234 | | |||
231 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | 235 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | ||
232 | { | 236 | { | ||
237 | m_startStopAnalysis->setEnabled(true); | ||||
238 | | ||||
233 | m_messageWidget = new KMessageWidget(); | 239 | m_messageWidget = new KMessageWidget(); | ||
234 | m_messageWidget->setCloseButtonVisible(true); | 240 | m_messageWidget->setCloseButtonVisible(true); | ||
235 | m_messageWidget->setWordWrap(false); | 241 | m_messageWidget->setWordWrap(false); | ||
236 | 242 | | |||
237 | if (exitCode == 0) { | 243 | if (m_analysisTool->isSuccessfulExitCode(exitCode)) { | ||
244 | // normally 0 is successful but there are exceptions | ||||
238 | m_messageWidget->setMessageType(KMessageWidget::Information); | 245 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||
239 | m_messageWidget->setText(i18n("Analysis finished.")); | 246 | m_messageWidget->setText(i18np("Analysis on %1 file finished.", "Analysis on %1 files 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 { | 247 | } else { | ||
241 | // unfortunately, output was eaten by slotReadyRead() | 248 | // unfortunately, output was eaten by slotReadyRead() | ||
242 | // TODO: get stderr output, show it here | 249 | // TODO: get stderr output, show it here | ||
243 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 250 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
244 | m_messageWidget->setText(i18n("Analysis failed!")); | 251 | m_messageWidget->setText(i18np("Analysis on %1 file failed with exit code %2.", "Analysis on %1 files failed with exit code %2.", m_analysisTool->getActualFilesCount(), exitCode)); | ||
245 | } | 252 | } | ||
246 | static_cast<QVBoxLayout*>(layout ())->addWidget(m_messageWidget); | 253 | static_cast<QVBoxLayout*>(layout())->addWidget(m_messageWidget); | ||
247 | m_messageWidget->animatedShow (); | 254 | m_messageWidget->animatedShow(); | ||
248 | } | 255 | } |
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.