diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index b6a42413e..96cc096b4 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -48,6 +48,14 @@ MainWindow::~MainWindow() delete mGameInvoker; } +void MainWindow::addServer(QString addr) +{ + favorites->insertRow(0); + QModelIndex mi = favorites->index(0, ServerData::ADDR); + favorites->setData(mi, addr, Qt::EditRole); + NetController::get()->updateInfo(favorites, mi); +} + void MainWindow::addServer() { int id = tblServerBrowser->selectionModel()->currentIndex().row(); @@ -64,12 +72,7 @@ void MainWindow::addServerByIP() bool ok; QString text = QInputDialog::getText(this, tr("Add Server by address"), tr("Address:"), QLineEdit::Normal, "", &ok); if(ok && !text.isEmpty()) - { - favorites->insertRow(0); - QModelIndex mi = favorites->index(0, ServerData::ADDR); - favorites->setData(mi, text, Qt::EditRole); - NetController::get()->updateInfo(favorites, mi); - } + addServer(text); } void MainWindow::deleteServer() @@ -178,12 +181,7 @@ void MainWindow::loadFavorites() QJsonDocument jsonDoc(QJsonDocument::fromJson(file.readAll())); for(auto server : jsonDoc.array()) - { - favorites->insertRows(0, 1); - QModelIndex mi = favorites->index(0, ServerData::ADDR); - favorites->setData(mi, server.toString(), Qt::EditRole); - NetController::get()->updateInfo(favorites, mi); - } + addServer(server.toString()); file.close(); } \ No newline at end of file diff --git a/apps/browser/MainWindow.hpp b/apps/browser/MainWindow.hpp index df9623a85..e1666c18b 100644 --- a/apps/browser/MainWindow.hpp +++ b/apps/browser/MainWindow.hpp @@ -19,6 +19,7 @@ public: virtual ~MainWindow(); protected: void closeEvent(QCloseEvent * event) Q_DECL_OVERRIDE; + void addServer(QString addr); public slots: bool refresh(); protected slots: