+ NetworkInfo newNetworkInfo = info;
+ newNetworkInfo.networkId = networkId;
+ updateNetwork(user, newNetworkInfo);
+ }
+ return networkId;
+}
+
+bool SqliteStorage::updateNetwork(UserId user, const NetworkInfo &info) {
+ if(!isValidNetwork(user, info.networkId))
+ return false;
+
+ QSqlQuery updateQuery(logDb());
+ updateQuery.prepare(queryString("update_network"));
+ updateQuery.bindValue(":networkname", info.networkName);
+ updateQuery.bindValue(":identityid", info.identity.toInt());
+ updateQuery.bindValue(":usecustomencoding", info.useCustomEncodings ? 1 : 0);
+ updateQuery.bindValue(":encodingcodec", QString(info.codecForEncoding));
+ updateQuery.bindValue(":decodingcodec", QString(info.codecForDecoding));
+ updateQuery.bindValue(":servercodec", QString(info.codecForServer));
+ updateQuery.bindValue(":userandomserver", info.useRandomServer ? 1 : 0);
+ updateQuery.bindValue(":perform", info.perform.join("\n"));
+ updateQuery.bindValue(":useautoidentify", info.useAutoIdentify ? 1 : 0);
+ updateQuery.bindValue(":autoidentifyservice", info.autoIdentifyService);
+ updateQuery.bindValue(":autoidentifypassword", info.autoIdentifyPassword);
+ updateQuery.bindValue(":useautoreconnect", info.useAutoReconnect ? 1 : 0);
+ updateQuery.bindValue(":autoreconnectinterval", info.autoReconnectInterval);
+ updateQuery.bindValue(":autoreconnectretries", info.autoReconnectRetries);
+ updateQuery.bindValue(":unlimitedconnectretries", info.unlimitedReconnectRetries ? 1 : 0);
+ updateQuery.bindValue(":rejoinchannels", info.rejoinChannels ? 1 : 0);
+ updateQuery.bindValue(":networkid", info.networkId.toInt());
+ safeExec(updateQuery);
+ if(!watchQuery(updateQuery))
+ return false;
+
+ QSqlQuery dropServersQuery(logDb());
+ dropServersQuery.prepare("DELETE FROM ircserver WHERE networkid = :networkid");
+ dropServersQuery.bindValue(":networkid", info.networkId.toInt());
+ safeExec(dropServersQuery);
+ if(!watchQuery(dropServersQuery))
+ return false;
+
+ QSqlQuery insertServersQuery(logDb());
+ insertServersQuery.prepare(queryString("insert_server"));
+ foreach(Network::Server server, info.serverList) {
+ insertServersQuery.bindValue(":userid", user.toInt());
+ insertServersQuery.bindValue(":networkid", info.networkId.toInt());
+ insertServersQuery.bindValue(":hostname", server.host);
+ insertServersQuery.bindValue(":port", server.port);
+ insertServersQuery.bindValue(":password", server.password);
+ insertServersQuery.bindValue(":ssl", server.useSsl ? 1 : 0);
+ insertServersQuery.bindValue(":sslversion", server.sslVersion);
+ insertServersQuery.bindValue(":useproxy", server.useProxy ? 1 : 0);
+ insertServersQuery.bindValue(":proxytype", server.proxyType);
+ insertServersQuery.bindValue(":proxyhost", server.proxyHost);
+ insertServersQuery.bindValue(":proxyport", server.proxyPort);
+ insertServersQuery.bindValue(":proxyuser", server.proxyUser);
+ insertServersQuery.bindValue(":proxypass", server.proxyPass);
+
+ safeExec(insertServersQuery);
+ if(!watchQuery(insertServersQuery))
+ return false;
+ }
+
+ return true;
+}
+
+bool SqliteStorage::removeNetwork(UserId user, const NetworkId &networkId) {
+ if(!isValidNetwork(user, networkId))
+ return false;
+
+ bool withTransaction = logDb().driver()->hasFeature(QSqlDriver::Transactions);
+ if(withTransaction) {
+ sync();
+ if(!logDb().transaction()) {
+ qWarning() << "SqliteStorage::removeNetwork(): cannot start transaction. continuing with out rollback support!";
+ withTransaction = false;
+ }
+ }
+
+ QSqlQuery deleteBacklogQuery(logDb());
+ deleteBacklogQuery.prepare(queryString("delete_backlog_for_network"));
+ deleteBacklogQuery.bindValue(":networkid", networkId.toInt());
+ safeExec(deleteBacklogQuery);
+ if(!watchQuery(deleteBacklogQuery)) {
+ if(withTransaction)
+ logDb().rollback();
+ return false;