More aggressive saving of changes to the connections. Also remove connection

now removes the connection from the file.
This commit is contained in:
Eelke Klein 2017-01-18 20:48:31 +01:00
parent ea30dd9c0e
commit 163bb1d513
11 changed files with 258 additions and 8 deletions

View file

@ -119,7 +119,9 @@ bool ConnectionListModel::setData(const QModelIndex &index, const QVariant &valu
if (role == Qt::EditRole) {
int row = index.row();
int col = index.column();
ConnectionConfig& cfg = m_connections.at(row).m_config;
auto& elem = m_connections.at(row);
elem.m_dirty = true;
ConnectionConfig& cfg = elem.m_config;
if (col > 0) {
result = true;
}
@ -200,9 +202,16 @@ bool ConnectionListModel::removeRows(int row, int count, const QModelIndex &pare
{
bool result = false;
if (row >= 0 && row < m_connections.size()) {
beginRemoveRows(parent, row, row + count -1);
SCOPE_EXIT { endRemoveRows(); };
auto f = m_connections.begin() + row;
m_connections.erase(f, f + count);
auto l = f + count;
deleteFromIni(f, l);
m_connections.erase(f, l);
result = true;
}
return result;
}
@ -242,10 +251,35 @@ void ConnectionListModel::save()
{
QString file_name = iniFileName();
QSettings settings(file_name, QSettings::IniFormat);
for (auto e : m_connections) {
for (auto& e : m_connections) {
settings.beginGroup(e.m_uuid.toString());
SCOPE_EXIT { settings.endGroup(); };
SaveConnectionConfig(settings, e.m_config);
}
}
void ConnectionListModel::save(int index)
{
if (index >= 0 && index < m_connections.size()) {
auto& e = m_connections[index];
if (e.m_dirty) {
QString file_name = iniFileName();
QSettings settings(file_name, QSettings::IniFormat);
settings.beginGroup(e.m_uuid.toString());
SaveConnectionConfig(settings, e.m_config);
settings.sync();
e.m_dirty = false;
}
}
}
void ConnectionListModel::deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end)
{
QString file_name = iniFileName();
QSettings settings(file_name, QSettings::IniFormat);
for (auto i = begin; i != end; ++i) {
settings.remove(i->m_uuid.toString());
}
}