Skip to content

Commit 3b74fe8

Browse files
committed
Make the server list accessible.
1 parent b448184 commit 3b74fe8

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/connectdlg.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
#include "connectdlg.h"
2626

27+
#if QT_VERSION >= QT_VERSION_CHECK( 6, 8, 0 )
28+
# include <QAccessible>
29+
# include <QAccessibleAnnouncementEvent>
30+
#endif
31+
2732
/* Implementation *************************************************************/
2833

2934
// mapVersionStr - converts a version number to a sortable string
@@ -75,22 +80,22 @@ static QString mapVersionStr ( const QString& versionStr )
7580
// Subclass of QTreeWidgetItem that allows LVC_VERSION to sort by the UserRole data value
7681
CMappedTreeWidgetItem::CMappedTreeWidgetItem ( QTreeWidget* owner ) : QTreeWidgetItem ( owner ), owner ( owner ) {}
7782

78-
bool CMappedTreeWidgetItem::operator<( const QTreeWidgetItem& other ) const
83+
bool CMappedTreeWidgetItem::operator< ( const QTreeWidgetItem& other ) const
7984
{
8085
if ( !owner )
81-
return QTreeWidgetItem::operator<( other );
86+
return QTreeWidgetItem::operator< ( other );
8287

8388
int column = owner->sortColumn();
8489

8590
// we only need this override for comparing server versions
8691
if ( column != CConnectDlg::LVC_VERSION )
87-
return QTreeWidgetItem::operator<( other );
92+
return QTreeWidgetItem::operator< ( other );
8893

8994
QVariant lhs = data ( column, Qt::UserRole );
9095
QVariant rhs = other.data ( column, Qt::UserRole );
9196

9297
if ( !lhs.isValid() || !rhs.isValid() )
93-
return QTreeWidgetItem::operator<( other );
98+
return QTreeWidgetItem::operator< ( other );
9499

95100
return lhs.toString() < rhs.toString();
96101
}
@@ -243,6 +248,7 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
243248

244249
// to get default return key behaviour working
245250
QObject::connect ( lvwServers, &QTreeWidget::activated, this, &CConnectDlg::OnConnectClicked );
251+
QObject::connect ( lvwServers, &QTreeWidget::currentItemChanged, this, &CConnectDlg::OnCurrentServerItemChanged );
246252

247253
// line edit
248254
QObject::connect ( edtFilter, &QLineEdit::textEdited, this, &CConnectDlg::OnFilterTextEdited );
@@ -567,6 +573,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect
567573

568574
if ( vecChanInfo[i].eCountry != QLocale::AnyCountry )
569575
{
576+
pNewChildListViewItem->setData ( LVC_NAME, Qt::UserRole, QLocale::countryToString ( vecChanInfo[i].eCountry ) );
570577
// try to load the country flag icon
571578
QPixmap CountryFlagPixmap ( CLocale::GetCountryFlagIconsResourceReference ( vecChanInfo[i].eCountry ) );
572579

@@ -1106,3 +1113,30 @@ void CConnectDlg::UpdateDirectoryComboBox()
11061113
}
11071114
}
11081115
}
1116+
1117+
void CConnectDlg::OnCurrentServerItemChanged ( QTreeWidgetItem* current, QTreeWidgetItem* )
1118+
{
1119+
#if QT_VERSION >= QT_VERSION_CHECK( 6, 8, 0 )
1120+
if ( !current )
1121+
return;
1122+
1123+
QString announcement;
1124+
if ( current->parent() )
1125+
{
1126+
// It's a client
1127+
announcement = current->text ( LVC_NAME );
1128+
QVariant countryData = current->data ( LVC_NAME, Qt::UserRole );
1129+
if ( countryData.isValid() )
1130+
{
1131+
announcement += ", " + countryData.toString();
1132+
}
1133+
}
1134+
else
1135+
{
1136+
// It's a server
1137+
announcement = current->text ( LVC_NAME ) + ", " + current->text ( LVC_CLIENTS ) + ", " + current->text ( LVC_LOCATION ) + ", " +
1138+
tr ( "Ping" ) + " " + current->text ( LVC_PING );
1139+
}
1140+
QAccessible::updateAccessibility ( new QAccessibleAnnouncementEvent ( lvwServers, announcement ) );
1141+
#endif
1142+
}

src/connectdlg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CMappedTreeWidgetItem : public QTreeWidgetItem
5151
public:
5252
explicit CMappedTreeWidgetItem ( QTreeWidget* owner = nullptr );
5353

54-
bool operator<( const QTreeWidgetItem& other ) const override;
54+
bool operator< ( const QTreeWidgetItem& other ) const override;
5555

5656
private:
5757
QTreeWidget* owner = nullptr;
@@ -132,6 +132,7 @@ public slots:
132132
void OnDeleteServerAddrClicked();
133133
void OnTimerPing();
134134
void OnTimerReRequestServList();
135+
void OnCurrentServerItemChanged ( QTreeWidgetItem* current, QTreeWidgetItem* previous );
135136

136137
signals:
137138
void ReqServerListQuery ( CHostAddress InetAddr );

0 commit comments

Comments
 (0)