Permalink
Browse files

Merge pull request #150 from stefanha/connect-accessibility

* connect-accessibility:
  Fix focus in jammr Connect dialog
  Pre-select the best jam in the server browser
  Enable Connect button on keyboard events too
  • Loading branch information...
stefanha committed Jul 16, 2017
2 parents 44212a5 + 6428135 commit e7af4311b1b651fe3b8b11006d2924d62ad466b6
@@ -26,7 +26,7 @@ ConnectDialog::ConnectDialog(QNetworkAccessManager *netManager, QWidget *parent)
: QDialog(parent)
{
serverBrowser = new NINJAMServerBrowser(netManager, this);
connect(serverBrowser, SIGNAL(serverItemClicked(const QString &)),
connect(serverBrowser, SIGNAL(serverItemSelected(const QString &)),
this, SLOT(setHost(const QString &)));
connect(serverBrowser, SIGNAL(serverItemActivated(const QString &)),
this, SLOT(onServerSelected(const QString &)));
@@ -34,7 +34,7 @@ JammrConnectDialog::JammrConnectDialog(QNetworkAccessManager *netManager_,
upgradeUrl(upgradeUrl_), reply(NULL)
{
serverBrowser = new JammrServerBrowser(netManager, this);
connect(serverBrowser, SIGNAL(serverItemClicked(const QString &)),
connect(serverBrowser, SIGNAL(serverItemSelected(const QString &)),
this, SLOT(setHost(const QString &)));
connect(serverBrowser, SIGNAL(serverItemActivated(const QString &)),
this, SLOT(onServerSelected(const QString &)));
@@ -58,6 +58,9 @@ JammrConnectDialog::JammrConnectDialog(QNetworkAccessManager *netManager_,
layout->addWidget(serverBrowser);
layout->addWidget(buttons);
setLayout(layout);
setTabOrder(serverBrowser, connectButton);
setTabOrder(connectButton, newJamButton);
serverBrowser->setFocus();
setWindowTitle(tr("Connect to server..."));
loadServerList();
}
@@ -38,6 +38,25 @@ QNetworkReply *JammrServerBrowser::sendNetworkRequest(const QUrl &apiUrl)
return netManager->get(request);
}
void JammrServerBrowser::selectBestItem()
{
QTreeWidgetItem *item = NULL;
// Select first jam with at least one user, otherwise select the last jam
for (int i = 0; i < topLevelItemCount(); i++) {
item = topLevelItem(i);
QString users = item->text(3);
if (!users.isEmpty()) {
break;
}
}
if (item) {
setCurrentItem(item);
}
}
void JammrServerBrowser::parseServerList(QTextStream *stream)
{
QJsonParseError err;
@@ -33,6 +33,7 @@ class JammrServerBrowser : public ServerBrowser
protected:
QNetworkReply *sendNetworkRequest(const QUrl &url);
void selectBestItem();
};
#endif /* _JAMMRSERVERBROWSER_H_ */
View
@@ -29,8 +29,8 @@ ServerBrowser::ServerBrowser(QNetworkAccessManager *manager_, QWidget *parent)
setItemsExpandable(false);
setColumnWidth(0, 200);
connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
this, SLOT(onItemClicked(QTreeWidgetItem*,int)));
connect(this, SIGNAL(itemSelectionChanged()),
this, SLOT(onItemSelectionChanged()));
connect(this, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
this, SLOT(onItemActivated(QTreeWidgetItem*,int)));
}
@@ -46,10 +46,16 @@ void ServerBrowser::loadServerList(const QUrl &url)
}
void ServerBrowser::onItemClicked(QTreeWidgetItem *item, int column)
void ServerBrowser::onItemSelectionChanged()
{
Q_UNUSED(column);
emit serverItemClicked(item->data(0, Qt::UserRole).toString());
QTreeWidgetItem *item = currentItem();
QString hostname;
if (item) {
hostname = item->data(0, Qt::UserRole).toString();
}
emit serverItemSelected(hostname);
}
void ServerBrowser::onItemActivated(QTreeWidgetItem *item, int column)
@@ -58,9 +64,22 @@ void ServerBrowser::onItemActivated(QTreeWidgetItem *item, int column)
emit serverItemActivated(item->data(0, Qt::UserRole).toString());
}
void ServerBrowser::selectBestItem()
{
QTreeWidgetItem *item = topLevelItem(0);
if (item) {
setCurrentItem(item);
}
}
void ServerBrowser::completeDownloadServerList()
{
QTextStream stream(reply);
parseServerList(&stream);
if (!currentItem()) {
selectBestItem();
}
}
View
@@ -42,16 +42,17 @@ class ServerBrowser : public QTreeWidget
virtual void parseServerList(QTextStream *stream) = 0;
signals:
void serverItemClicked(const QString &hostname);
void serverItemSelected(const QString &hostname);
void serverItemActivated(const QString &hostname);
private slots:
void completeDownloadServerList();
void onItemClicked(QTreeWidgetItem *item, int column);
void onItemSelectionChanged();
void onItemActivated(QTreeWidgetItem *item, int column);
protected:
virtual QNetworkReply *sendNetworkRequest(const QUrl &url) = 0;
virtual void selectBestItem();
QNetworkAccessManager *netManager;

0 comments on commit e7af431

Please sign in to comment.