Krita Source Code Documentation
Loading...
Searching...
No Matches
DlgAndroidLogcatDumper.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Sharaf Zaman <shzam@sdf.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8
9#include <QDebug>
10#include <QProcess>
11#include <QPushButton>
12#include <QScreen>
13#include <QScrollBar>
14#include <QStandardPaths>
15#include <unistd.h>
16
18 : DlgBugInfo(parent, User3)
19 , m_logcatProcess(parent)
20 , m_updateWidgetCompressor(100, KisSignalCompressor::FIRST_INACTIVE)
21{
22 QString program = "logcat";
23 QStringList arguments = {"-v", "time", "--pid", QString::number(getpid())};
24 m_logcatProcess.start(program, arguments);
25 QString errorOutput = m_logcatProcess.readAllStandardError();
26 if (!errorOutput.isEmpty()) {
27 qWarning() << "Couldn't spawn logcat process" << errorOutput;
28 }
29
30 setButtonText(User3, i18n("Toggle Logging"));
31 button(User3)->setCheckable(true);
32 button(User3)->setChecked(true);
33
35 connect(this, &KoDialog::user3Clicked, this, [this]() {
36 QPushButton *loggingButton = button(User3);
37 if (loggingButton->isChecked()) {
39 } else {
41 }
42 });
43
44 QRect screen_rect = QGuiApplication::primaryScreen()->availableGeometry();
45 int frame_height = parentWidget()->frameGeometry().height() - parentWidget()->size().height();
46 resize(m_page->size().width(), screen_rect.height() - frame_height);
47}
48
54
56{
57 QScrollBar *scrollBar = m_page->txtBugInfo->verticalScrollBar();
58 const bool scrollbarAtBottom = scrollBar->value() >= scrollBar->maximum();
59
60 QByteArray output = m_logcatProcess.readAllStandardOutput();
61
62 // this allows user's movement of the scrollbar
63 QTextCursor tmp(m_page->txtBugInfo->document());
64 tmp.movePosition(QTextCursor::End);
65 tmp.insertText(output);
66
67 // scroll to the bottom if scrollbar is at the bottom
68 if (scrollbarAtBottom) {
69 scrollBar->setValue(scrollBar->maximum());
70 }
71}
72
74{
75 connect(&m_logcatProcess, SIGNAL(readyReadStandardOutput()), &m_updateWidgetCompressor, SLOT(start()),
76 Qt::UniqueConnection);
77 connect(&m_updateWidgetCompressor, SIGNAL(timeout()), this, SLOT(writeTextToWidget()), Qt::UniqueConnection);
78
80}
81
83{
84 disconnect(&m_updateWidgetCompressor, SIGNAL(timeout()), this, SLOT(writeTextToWidget()));
85 disconnect(&m_logcatProcess, SIGNAL(readyReadStandardOutput()), &m_updateWidgetCompressor, SLOT(start()));
86}
87
88QString DlgAndroidLogcatDumper::defaultNewFileName() { return "kritalogcatdump.txt"; }
89
91{
92 return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/krita-logcatdump.log";
93}
94
96{
97 return i18nc("Caption of the dialog with Krita's Android system log for bug reports",
98 "Krita Logcat Dump: please paste this information to the bug report");
99}
100
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QString replacementWarningText() override
DlgAndroidLogcatDumper(QWidget *parent=nullptr)
KisSignalCompressor m_updateWidgetCompressor
QString originalFileName() override
QString defaultNewFileName() override
WdgBugInfo * m_page
Definition dlg_buginfo.h:47
void user3Clicked()
QPushButton * button(ButtonCode id) const
Definition KoDialog.cpp:591
void setButtonText(ButtonCode id, const QString &text)
Definition KoDialog.cpp:648
@ User3
Show User defined button 3.
Definition KoDialog.h:138