Save/Open Session: Save only owned ports if some ports are reserved - corresponding open session code not to overwrite a owned port is pending
This commit is contained in:
parent
b8db66a2d5
commit
294d1c80a1
@ -206,6 +206,17 @@ void MainWindow::on_actionSaveSession_triggered()
|
||||
if (fileName.isEmpty())
|
||||
goto _exit;
|
||||
|
||||
if (portsWindow->reservedPortCount()) {
|
||||
QString myself = appSettings->value(kUserKey, kUserDefaultValue)
|
||||
.toString();
|
||||
if (QMessageBox::question(this,
|
||||
tr("Save Session"),
|
||||
QString("Some ports are reserved!\n\nOnly ports reserved by %1 will be saved. Proceed?").arg(myself),
|
||||
QMessageBox::Yes | QMessageBox::No,
|
||||
QMessageBox::No) == QMessageBox::No)
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (!saveSession(fileName, fileType, errorStr))
|
||||
QMessageBox::critical(this, qApp->applicationName(), errorStr);
|
||||
else if (!errorStr.isEmpty())
|
||||
|
@ -110,6 +110,16 @@ void PortGroup::setConfigAtConnect(const OstProto::PortGroupContent *config)
|
||||
atConnectConfig_->CopyFrom(*config);
|
||||
}
|
||||
|
||||
int PortGroup::numReservedPorts() const
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < mPorts.size(); i++)
|
||||
{
|
||||
if (!mPorts[i]->userName().isEmpty())
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
// Slots
|
||||
// ------------------------------------------------
|
||||
|
@ -93,6 +93,7 @@ public:
|
||||
void setConfigAtConnect(const OstProto::PortGroupContent *config);
|
||||
|
||||
int numPorts() const { return mPorts.size(); }
|
||||
int numReservedPorts() const;
|
||||
quint32 id() const { return mPortGroupId; }
|
||||
|
||||
const QString& userAlias() const { return mUserAlias; }
|
||||
|
@ -178,6 +178,17 @@ int PortsWindow::portGroupCount()
|
||||
return plm->numPortGroups();
|
||||
}
|
||||
|
||||
int PortsWindow::reservedPortCount()
|
||||
{
|
||||
int count = 0;
|
||||
int n = portGroupCount();
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
count += plm->portGroupByIndex(i).numReservedPorts();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//! Always return true
|
||||
bool PortsWindow::openSession(
|
||||
const OstProto::SessionContent *session,
|
||||
@ -206,6 +217,8 @@ bool PortsWindow::openSession(
|
||||
/*!
|
||||
* Prepare content to be saved for a session
|
||||
*
|
||||
* If port reservation is in use, saves only 'my' reserved ports
|
||||
*
|
||||
* Returns false, if user cancels op; true, otherwise
|
||||
*/
|
||||
bool PortsWindow::saveSession(
|
||||
@ -214,12 +227,16 @@ bool PortsWindow::saveSession(
|
||||
QProgressDialog *progress)
|
||||
{
|
||||
int n = portGroupCount();
|
||||
QString myself;
|
||||
|
||||
if (progress) {
|
||||
progress->setLabelText("Preparing Ports and PortGroups ...");
|
||||
progress->setRange(0, n);
|
||||
}
|
||||
|
||||
if (reservedPortCount())
|
||||
myself = appSettings->value(kUserKey, kUserDefaultValue).toString();
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
PortGroup &pg = plm->portGroupByIndex(i);
|
||||
@ -230,6 +247,9 @@ bool PortsWindow::saveSession(
|
||||
|
||||
for (int j = 0; j < pg.numPorts(); j++)
|
||||
{
|
||||
if (myself != pg.mPorts.at(j)->userName())
|
||||
continue;
|
||||
|
||||
OstProto::PortContent *pc = pgc->add_ports();
|
||||
OstProto::Port *p = pc->mutable_port_config();
|
||||
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
~PortsWindow();
|
||||
|
||||
int portGroupCount();
|
||||
int reservedPortCount();
|
||||
|
||||
bool openSession(const OstProto::SessionContent *session,
|
||||
QString &error);
|
||||
|
Loading…
Reference in New Issue
Block a user