mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 00:36:46 +00:00
Save/Load favorites in browser
This commit is contained in:
parent
777a570d93
commit
ecf82a5df7
3 changed files with 51 additions and 2 deletions
|
@ -5,8 +5,13 @@
|
||||||
#include "MainWindow.hpp"
|
#include "MainWindow.hpp"
|
||||||
#include "NetController.hpp"
|
#include "NetController.hpp"
|
||||||
#include "ServerInfoDialog.hpp"
|
#include "ServerInfoDialog.hpp"
|
||||||
|
#include "components/files/configurationmanager.hpp"
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
using namespace Process;
|
using namespace Process;
|
||||||
|
|
||||||
|
@ -34,6 +39,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(actionPlay, SIGNAL(triggered(bool)), this, SLOT(play()));
|
connect(actionPlay, SIGNAL(triggered(bool)), this, SLOT(play()));
|
||||||
connect(tblServerBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
connect(tblServerBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
||||||
connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
||||||
|
|
||||||
|
loadFavorites();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -58,7 +65,7 @@ void MainWindow::addServerByIP()
|
||||||
QString text = QInputDialog::getText(this, tr("Add Server by address"), tr("Address:"), QLineEdit::Normal, "", &ok);
|
QString text = QInputDialog::getText(this, tr("Add Server by address"), tr("Address:"), QLineEdit::Normal, "", &ok);
|
||||||
if(ok && !text.isEmpty())
|
if(ok && !text.isEmpty())
|
||||||
{
|
{
|
||||||
favorites->insertRows(0, 1);
|
favorites->insertRow(0);
|
||||||
QModelIndex mi = favorites->index(0, ServerData::ADDR);
|
QModelIndex mi = favorites->index(0, ServerData::ADDR);
|
||||||
favorites->setData(mi, text, Qt::EditRole);
|
favorites->setData(mi, text, Qt::EditRole);
|
||||||
NetController::get()->updateInfo(favorites, mi);
|
NetController::get()->updateInfo(favorites, mi);
|
||||||
|
@ -136,5 +143,47 @@ void MainWindow::serverSelected()
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
|
Files::ConfigurationManager cfgMgr;
|
||||||
|
QString cfgPath = (cfgMgr.getUserConfigPath() / "favorites.dat").c_str();
|
||||||
|
|
||||||
|
QJsonArray data;
|
||||||
|
for(auto server : favorites->myData)
|
||||||
|
data.push_back(server.addr);
|
||||||
|
|
||||||
|
QFile file(cfgPath);
|
||||||
|
|
||||||
|
if(!file.open(QIODevice::WriteOnly))
|
||||||
|
{
|
||||||
|
qDebug() << "Cannot save " << cfgPath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(QJsonDocument(data).toJson());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::loadFavorites()
|
||||||
|
{
|
||||||
|
Files::ConfigurationManager cfgMgr;
|
||||||
|
QString cfgPath = (cfgMgr.getUserConfigPath() / "favorites.dat").c_str();
|
||||||
|
|
||||||
|
QFile file(cfgPath);
|
||||||
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() << "Cannot open " << cfgPath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
}
|
}
|
|
@ -32,6 +32,7 @@ private:
|
||||||
Process::ProcessInvoker *mGameInvoker;
|
Process::ProcessInvoker *mGameInvoker;
|
||||||
ServerModel *browser, *favorites;
|
ServerModel *browser, *favorites;
|
||||||
QSortFilterProxyModel *proxyModel;
|
QSortFilterProxyModel *proxyModel;
|
||||||
|
void loadFavorites();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ std::string loadSettings (Settings::Manager & settings)
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Settings::Manager mgr;
|
Settings::Manager mgr;
|
||||||
Files::ConfigurationManager cfgMgr;
|
|
||||||
|
|
||||||
loadSettings(mgr);
|
loadSettings(mgr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue