Skip to content

Commit

Permalink
fix: Fix the troubleshoot issues that are not functioning properly
Browse files Browse the repository at this point in the history
Fix the troubleshoot issues that are not functioning properly when build with Qt6.

Log: Fix the troubleshoot issues that are not functioning properly.
  • Loading branch information
re2zero authored and deepin-bot[bot] committed Jan 9, 2025
1 parent 78b4b78 commit 4f8de62
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 88 deletions.
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 @@ -11,21 +11,6 @@
#include "terminalapplication.h"
#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>
Expand All @@ -40,10 +25,8 @@ class QTabBarPrivateCompat
#include <QStyleOptionTab>
#include <QStylePainter>
#include <QMouseEvent>
// #include <QDesktopWidget>
#include <QPainterPath>
#include <QMimeData>
#include <QTabBar>

#ifdef DTKWIDGET_CLASS_DSizeMode
#include <DSizeMode>
Expand Down Expand Up @@ -142,6 +125,7 @@ void TermTabStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO
}
//TermTabStyle 结束

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*******************************************************************************
1. @函数: initStyleOption
2. @作者: ut000610 daizhengwen
Expand All @@ -150,15 +134,11 @@ void TermTabStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO
*******************************************************************************/
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 @@ void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const
option->row = tabIndex;
}
}
#endif

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

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
Removes the tab at position \a index.
Expand All @@ -327,7 +309,6 @@ int TabBar::getIndexByIdentifier(QString id)
*******************************************************************************/
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 @@ void QTabBar::removeTab(int index)
}
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 @@ void QTabBar::removeTab(int index)
tab->animation->start();
}
}
#endif
}
}
#endif

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

0 comments on commit 4f8de62

Please sign in to comment.