Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the troubleshoot issues that are not functioning properly #391

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions 3rdparty/terminalwidget/lib/ProcessInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,7 @@ bool LinuxProcessInfo::readProcInfo(int pid)
}
} while (!statusLine.isNull() && uidLine.isNull());

uidStrings << uidLine.split(QLatin1Char('\t'),
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QString::SkipEmptyParts);
#else
Qt::SkipEmptyParts);
#endif
uidStrings << uidLine.split(QLatin1Char('\t'));
// Must be 5 entries: 'Uid: %d %d %d %d' and
// uid string must be less than 5 chars (uint)
if (uidStrings.size() == 5) {
Expand Down
22 changes: 22 additions & 0 deletions 3rdparty/terminalwidget/lib/Pty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,28 @@ Pty::Pty(QObject *parent)

void Pty::init()
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
// Must call parent class child process modifier, as it sets file descriptors ...etc
auto parentChildProcModifier = KPtyProcess::childProcessModifier();
setChildProcessModifier([parentChildProcModifier = std::move(parentChildProcModifier)]() {
if (parentChildProcModifier) {
parentChildProcModifier();
}

// reset all signal handlers
// this ensures that terminal applications respond to
// signals generated via key sequences such as Ctrl+C
// (which sends SIGINT)
struct sigaction action;
sigemptyset(&action.sa_mask);
action.sa_handler = SIG_DFL;
action.sa_flags = 0;
for (int signal = 1; signal < NSIG; signal++) {
sigaction(signal, &action, nullptr);
}
});
#endif

_windowColumns = 0;
_windowLines = 0;
_eraseChar = 0;
Expand Down
6 changes: 4 additions & 2 deletions 3rdparty/terminalwidget/lib/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,10 @@ int Screen::copyLineToStream(int line ,
std::copy(data + start, data + end, characterBuffer);
}

// count cannot be any greater than length
count = qBound(0, count, length - start);
if (length > start) {
// count cannot be any greater than length
count = qBound(0, count, length - start);
}

Q_ASSERT(screenLine < _lineProperties.count());
currentLineProperties |= _lineProperties[screenLine];
Expand Down
10 changes: 5 additions & 5 deletions 3rdparty/terminalwidget/lib/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,13 +1269,13 @@ void TerminalDisplay::showResizeNotification()
}
if (!_resizeWidget)
{
const QString label = tr("Size: XXX x XXX");
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
const QString label = tr("Size: XXX x XXX");
_resizeWidget = new QLabel(label, this);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
int width = _resizeWidget->fontMetrics().width(label);
#else
#else
int width = _resizeWidget->fontMetrics().horizontalAdvance(label);
#endif
_resizeWidget = new QLabel(label, this);
#endif
_resizeWidget->setMinimumWidth(width);
_resizeWidget->setMinimumHeight(_resizeWidget->sizeHint().height());
_resizeWidget->setAlignment(Qt::AlignCenter);
Expand Down
48 changes: 39 additions & 9 deletions 3rdparty/terminalwidget/lib/kptyprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,52 @@
#include <QDebug>

KPtyProcess::KPtyProcess(QObject *parent) :
KProcess(new KPtyProcessPrivate, parent)
KPtyProcess(-1, parent)
{
Q_D(KPtyProcess);

d->pty = new KPtyDevice(this);
// d->pty = new KPtyDevice(this);
d->pty = std::make_unique<KPtyDevice>(this);
d->pty->open();
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
SLOT(_k_onStateChanged(QProcess::ProcessState)));
}

KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
KProcess(new KPtyProcessPrivate, parent)
KProcess(parent),
d_ptr(new KPtyProcessPrivate)
{
Q_D(KPtyProcess);

d->pty = new KPtyDevice(this);
d->pty->open(ptyMasterFd);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
setChildProcessModifier([d]() {
d->pty->setCTty();
#if 0
if (d->addUtmp) {
d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().constData(), qgetenv("DISPLAY").constData());
}
#endif
if (d->ptyChannels & StdinChannel) {
dup2(d->pty->slaveFd(), 0);
}
if (d->ptyChannels & StdoutChannel) {
dup2(d->pty->slaveFd(), 1);
}
if (d->ptyChannels & StderrChannel) {
dup2(d->pty->slaveFd(), 2);
}
});
#endif

//d->pty = new KPtyDevice(this);
d->pty = std::make_unique<KPtyDevice>(this);

if (ptyMasterFd == -1) {
d->pty->open();
} else {
d->pty->open(ptyMasterFd);
}

connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
SLOT(_k_onStateChanged(QProcess::ProcessState)));
}
Expand All @@ -66,13 +95,14 @@ KPtyProcess::~KPtyProcess()
if (state() != QProcess::NotRunning)
{
if (d->addUtmp)
{
d->pty->logout();
{
d->pty->logout();
disconnect(SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(_k_onStateChanged(QProcess::ProcessState)));
}
}
delete d->pty;
// delete d->pty;
d->pty.release();
waitForFinished(300); // give it some time to finish
if (state() != QProcess::NotRunning)
{
Expand Down Expand Up @@ -116,7 +146,7 @@ KPtyDevice *KPtyProcess::pty() const
{
Q_D(const KPtyProcess);

return d->pty;
return d->pty.get();
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand Down
16 changes: 8 additions & 8 deletions 3rdparty/terminalwidget/lib/kptyprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "kptydevice.h"

#include <csignal>
#include <memory>

class KPtyDevice;

Expand Down Expand Up @@ -145,23 +146,22 @@ class KPtyProcess : public KProcess
* @reimp
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void setupChildProcess() override;
void setupChildProcess() override;
#endif

private:
Q_PRIVATE_SLOT(d_func(), void _k_onStateChanged(QProcess::ProcessState))
std::unique_ptr<KPtyProcessPrivate> const d_ptr;
};


//////////////////
// private data //
//////////////////

class KPtyProcessPrivate : public KProcessPrivate {
class KPtyProcessPrivate {
public:
KPtyProcessPrivate() :
ptyChannels(KPtyProcess::NoChannels),
addUtmp(false)
KPtyProcessPrivate()
{
}

Expand All @@ -171,9 +171,9 @@ class KPtyProcessPrivate : public KProcessPrivate {
pty->logout();
}

KPtyDevice *pty;
KPtyProcess::PtyChannels ptyChannels;
bool addUtmp : 1;
std::unique_ptr<KPtyDevice> pty;
KPtyProcess::PtyChannels ptyChannels = KPtyProcess::NoChannels;
bool addUtmp = false;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(KPtyProcess::PtyChannels)
Expand Down
4 changes: 0 additions & 4 deletions 3rdparty/terminalwidget/lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,7 @@ void QTermWidget::startTerminalTeletype()
void QTermWidget::init(int startnow)
{
m_layout = new QVBoxLayout();
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
m_layout->setMargin(0);
#else
m_layout->setContentsMargins(0, 0, 0, 0);
#endif
setLayout(m_layout);

// translations
Expand Down
59 changes: 5 additions & 54 deletions src/views/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@
#include "termwidget.h"
#include "termwidgetpage.h"
#include "windowsmanager.h"
#include "terminalapplication.h"

Check warning on line 11 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "terminalapplication.h" not found.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "private/qtabbar_p.h"
#else
// Qt6 compatibility layer
class QTabBarPrivateCompat
{
public:
static void initBasicStyleOption(QStyleOptionTab *option, int tabIndex, const QTabBar *tabBar)
{
option->initFrom(tabBar);
option->state &= ~QStyle::State_HasFocus;
option->rect = tabBar->tabRect(tabIndex);
option->text = tabBar->tabText(tabIndex);
option->icon = tabBar->tabIcon(tabIndex);
option->iconSize = tabBar->iconSize();
}
};
#endif

#include <DApplication>

Check warning on line 16 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>
#include <DFontSizeManager>
#include <DLog>
Expand All @@ -37,16 +22,14 @@
#include <DWindowManagerHelper>

#include <QStyleOption>
#include <QStyleOptionTab>

Check warning on line 25 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStyleOptionTab> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStylePainter>

Check warning on line 26 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStylePainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 27 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
// #include <QDesktopWidget>
#include <QPainterPath>

Check warning on line 28 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainterPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMimeData>

Check warning on line 29 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMimeData> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTabBar>

#ifdef DTKWIDGET_CLASS_DSizeMode
#include <DSizeMode>

Check warning on line 32 in src/views/tabbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSizeMode> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif
#include <QLoggingCategory>

Expand Down Expand Up @@ -142,6 +125,7 @@
}
//TermTabStyle 结束

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*******************************************************************************
1. @函数: initStyleOption
2. @作者: ut000610 daizhengwen
Expand All @@ -150,15 +134,11 @@
*******************************************************************************/
void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Q_D(const QTabBar);
d->initBasicStyleOption(option, tabIndex);
#else
QTabBarPrivateCompat::initBasicStyleOption(option, tabIndex, this);
#endif

QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this);
option->text = fontMetrics().elidedText(option->text, elideMode(), textRect.width(),
option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(),
Qt::TextShowMnemonic);

/*********** Modify by ut000438 王亮 2020-11-25:fix bug 55813: 拖拽终端标签页终端闪退 ***********/
Expand All @@ -169,6 +149,7 @@
option->row = tabIndex;
}
}
#endif

TabBar::TabBar(QWidget *parent) : DTabBar(parent), m_rightClickTab(-1)
{
Expand Down Expand Up @@ -314,6 +295,7 @@
return -1;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
Removes the tab at position \a index.

Expand All @@ -327,7 +309,6 @@
*******************************************************************************/
void QTabBar::removeTab(int index)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Q_D(QTabBar);
if (d->validIndex(index)) {
if (d->dragInProgress)
Expand Down Expand Up @@ -407,41 +388,11 @@
}
tabRemoved(index);
}
#else
if (index < 0 || index >= count())
return;

// Remove tab data
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
removeTabData(index);
#else
// Qt6下不需要调用removeTabData
#endif

// Remove tab
QTabBar::removeTab(index);

// Update current index if needed
if (index == currentIndex()) {
int newIndex = -1;
if (count() > 0) {
newIndex = qBound(0, index, count() - 1);
setCurrentIndex(newIndex);
} else {
emit currentChanged(-1);
}
} else if (index < currentIndex()) {
setCurrentIndex(currentIndex() - 1);
}

update();
#endif

TabBar *tabBar = qobject_cast<TabBar *>(this->parent());

if (tabBar && tabBar->isEnableCloseTabAnimation()) {
//tab关闭动画
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (d->rightB->isVisible()) {
for (int i = 0; i < index; i++) {
QTabBarPrivate::Tab *tab = &d->tabList[i];
Expand All @@ -455,9 +406,9 @@
tab->animation->start();
}
}
#endif
}
}
#endif

void TabBar::removeTab(const QString &tabIdentifier)
{
Expand Down
Loading