Permalink
Browse files

Pre-select the best jam in the server browser

Automatically select the first jam with at least one user in the jammr
server browser.  If the user is happy with this selection they just need
to press Enter.  This eliminates the extra step of selecting a jam from
the server browser.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
  • Loading branch information...
stefanha committed Jul 15, 2017
1 parent 812ddf8 commit 441a70b594c61b5f7aa67525bab8160b8cf2f51d
Showing with 34 additions and 0 deletions.
  1. +19 −0 qtclient/JammrServerBrowser.cpp
  2. +1 −0 qtclient/JammrServerBrowser.h
  3. +13 −0 qtclient/ServerBrowser.cpp
  4. +1 −0 qtclient/ServerBrowser.h
@@ -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
@@ -64,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
@@ -52,6 +52,7 @@ private slots:
protected:
virtual QNetworkReply *sendNetworkRequest(const QUrl &url) = 0;
virtual void selectBestItem();
QNetworkAccessManager *netManager;

0 comments on commit 441a70b

Please sign in to comment.