ServerChoice::ServerChoice() { resize(500,450); registry_connection = new Analyzer(true); registry_connection->connectTo("pokemon-online.dynalias.net", 5081); registry_connection->setParent(this); connect(registry_connection, SIGNAL(connectionError(int,QString)), SLOT(connectionError(int , QString))); connect(registry_connection, SIGNAL(serverReceived(QString, QString, quint16,QString,quint16,quint16)), SLOT(addServer(QString, QString, quint16, QString,quint16,quint16))); QVBoxLayout *l = new QVBoxLayout(this); mylist = new QCompactTable(0,3); QStringList horHeaders; horHeaders << tr("Server Name") << tr("Players / Max") << tr("Advanced connection"); mylist->setHorizontalHeaderLabels(horHeaders); mylist->setSelectionBehavior(QAbstractItemView::SelectRows); mylist->setSelectionMode(QAbstractItemView::SingleSelection); mylist->setShowGrid(false); mylist->verticalHeader()->hide(); mylist->horizontalHeader()->resizeSection(0, 150); mylist->horizontalHeader()->setStretchLastSection(true); mylist->setMinimumHeight(200); connect(mylist, SIGNAL(cellActivated(int,int)), SLOT(regServerChosen(int))); connect(mylist, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(showDescription(int))); l->addWidget(mylist, 100); myDesc = new QTextBrowser(); myDesc->setOpenExternalLinks(true); myDesc->setFixedHeight(100); l->addWidget(new QEntitled("Server Description", myDesc)); QSettings settings; myAdvServer = new QLineEdit(settings.value("default_server").toString()); connect(myAdvServer, SIGNAL(returnPressed()), SLOT(advServerChosen())); l->addWidget(new QEntitled("&Advanced Connection", myAdvServer)); QHBoxLayout *hl= new QHBoxLayout(); l->addLayout(hl); QPushButton *cancel = new QPushButton("&Go Back"); QPushButton *ok = new QPushButton("Advanced &Connection"); connect(cancel, SIGNAL(clicked()), SIGNAL(rejected())); connect(ok, SIGNAL(clicked()), SLOT(advServerChosen())); hl->addWidget(cancel); hl->addWidget(ok); }
ServerChoice::ServerChoice(TeamHolder* team) : ui(new Ui::ServerChoice), wasConnected(false), team(team) { ui->setupUi(this); ui->announcement->hide(); ServerChoiceModel *model = new ServerChoiceModel(); model->setParent(ui->serverList); filter = new QSortFilterProxyModel(ui->serverList); filter->setSourceModel(model); filter->setSortRole(ServerChoiceModel::SortRole); ui->serverList->setModel(filter); connect(ui->description, SIGNAL(anchorClicked(QUrl)), SLOT(anchorClicked(QUrl))); QSettings settings; registry_connection = new Analyzer(true); connect(registry_connection, SIGNAL(connected()), SLOT(connected())); registry_connection->connectTo( settings.value("ServerChoice/RegistryServer", "registry.pokemon-online.eu").toString(), settings.value("ServerChoice/RegistryPort", 5090).toUInt() ); registry_connection->setParent(this); ui->switchPort->setIcon(QApplication::style()->standardIcon(QStyle::SP_BrowserReload)); connect(registry_connection, SIGNAL(connectionError(int,QString)), SLOT(connectionError(int , QString))); connect(registry_connection, SIGNAL(regAnnouncementReceived(QString)), ui->announcement, SLOT(setText(QString))); connect(registry_connection, SIGNAL(regAnnouncementReceived(QString)), ui->announcement, SLOT(show())); connect(registry_connection, SIGNAL(serverReceived(ServerInfo)), model, SLOT(addServer(ServerInfo))); connect(this, SIGNAL(clearList()), model, SLOT(clear())); connect(registry_connection, SIGNAL(serverReceived(ServerInfo)), SLOT(serverAdded())); //TO-DO: Make the item 0 un-resizable and unselectable - Latios ui->serverList->setColumnWidth(0, settings.value("ServerChoice/PasswordProtectedWidth", 26).toInt()); ui->serverList->setColumnWidth(1, settings.value("ServerChoice/ServerNameWidth", 152).toInt()); if (settings.contains("ServerChoice/PlayersInfoWidth")) { ui->serverList->setColumnWidth(2, settings.value("ServerChoice/PlayersInfoWidth").toInt()); } ui->serverList->horizontalHeader()->setStretchLastSection(true); connect(ui->serverList, SIGNAL(activated(QModelIndex)), SLOT(regServerChosen(QModelIndex))); connect(ui->serverList, SIGNAL(currentCellChanged(QModelIndex)), SLOT(showDetails(QModelIndex))); ui->nameEdit->setText(team->name()); ui->advServerEdit->addItem(settings.value("ServerChoice/DefaultServer").toString()); connect(ui->nameEdit, SIGNAL(returnPressed()), SLOT(advServerChosen())); connect(ui->advServerEdit->lineEdit(), SIGNAL(returnPressed()), SLOT(advServerChosen())); QCompleter *completer = new QCompleter(ui->advServerEdit); completer->setCaseSensitivity(Qt::CaseInsensitive); QStringList res = settings.value("ServerChoice/SavedServers").toStringList(); foreach (QString r, res) { if (r.contains("-")) { savedServers.push_back(QStringList() << r.section("-", -1).trimmed() << r.section("-", 0, -2).trimmed()); } else { savedServers.push_back(QStringList() << r << ""); } } QStringListModel *m = new QStringListModel(res, completer); completer->setModel(m); ui->advServerEdit->setCompleter(completer); ui->advServerEdit->setModel(m); connect(ui->teambuilder, SIGNAL(clicked()), SIGNAL(teambuilder())); connect(ui->advancedConnection, SIGNAL(clicked()), SLOT(advServerChosen())); QTimer *t = new QTimer(this); t->singleShot(5000, this, SLOT(timeout())); #if QT_VERSION >= QT_VERSION_CHECK(4,8,0) ui->serverList->sortByColumn(ServerChoiceModel::Players, Qt::SortOrder(filter->headerData(ServerChoiceModel::Players, Qt::Horizontal, Qt::InitialSortOrderRole).toInt())); #else ui->serverList->sortByColumn(ServerChoiceModel::Players, Qt::DescendingOrder); #endif }