summaryrefslogtreecommitdiff
path: root/map65/mainwindow.cpp
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2021-09-28 10:23:10 +0200
committerChristoph Berg <christoph.berg@credativ.de>2021-09-28 10:23:10 +0200
commit6ec76defdb6622d379e68ee4a4d45f8c9758bb1f (patch)
tree0278146fe55991c45982b83f28a11a13b23bcd7e /map65/mainwindow.cpp
parent85895feeaf88bcde26bbfc71e8f6b2047c0f5f41 (diff)
New upstream version 2.5.0+repackupstream/2.5.0+repack
Diffstat (limited to 'map65/mainwindow.cpp')
-rw-r--r--map65/mainwindow.cpp83
1 files changed, 44 insertions, 39 deletions
diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp
index 48eaf946..5814dca2 100644
--- a/map65/mainwindow.cpp
+++ b/map65/mainwindow.cpp
@@ -1864,6 +1864,8 @@ void MainWindow::doubleClickOnMessages(QString hiscall, QString t2, bool ctrl)
void MainWindow::genStdMsgs(QString rpt) //genStdMsgs()
{
+ if(rpt.left(2)==" -") rpt="-0"+rpt.mid(2,1);
+ if(rpt.left(2)==" +") rpt="+0"+rpt.mid(2,1);
QString hiscall=ui->dxCallEntry->text().toUpper().trimmed();
ui->dxCallEntry->setText(hiscall);
QString t0=hiscall + " " + m_myCall + " ";
@@ -1968,58 +1970,61 @@ void MainWindow::on_addButton_clicked() //Add button
<< endl
#endif
;
- f1.close();
- f1.open(QIODevice::ReadOnly | QIODevice::Text);
+ f1.seek (0);
}
QString tmpFile = m_appDir + "/CALL3.TMP";
QFile f2(tmpFile);
- if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ if(!f2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
msgBox("Cannot open " + tmpFile);
return;
}
- QTextStream in(&f1);
- QTextStream out(&f2);
- QString hc=hiscall;
- QString hc1="";
- QString hc2="000000";
- QString s;
- do {
- s=in.readLine();
- hc1=hc2;
- if(s.mid(0,2)=="//") {
- out << s + "\n";
- } else {
- int i1=s.indexOf(",");
- hc2=s.mid(0,i1);
- if(hc>hc1 && hc<hc2) {
- out << newEntry + "\n";
+ {
+ QTextStream in(&f1);
+ QTextStream out(&f2);
+ QString hc=hiscall;
+ QString hc1="";
+ QString hc2="000000";
+ QString s;
+ do {
+ s=in.readLine();
+ hc1=hc2;
+ if(s.mid(0,2)=="//") {
out << s + "\n";
- m_call3Modified=true;
- } else if(hc==hc2) {
- QString t=s + "\n\n is already in CALL3.TXT\n" +
- "Do you wish to replace it?";
- int ret = QMessageBox::warning(this, "Add",t,
- QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
- if(ret==QMessageBox::Yes) {
+ } else {
+ int i1=s.indexOf(",");
+ hc2=s.mid(0,i1);
+ if(hc>hc1 && hc<hc2) {
out << newEntry + "\n";
+ out << s + "\n";
m_call3Modified=true;
+ } else if(hc==hc2) {
+ QString t=s + "\n\n is already in CALL3.TXT\n" +
+ "Do you wish to replace it?";
+ int ret = QMessageBox::warning(this, "Add",t,
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+ if(ret==QMessageBox::Yes) {
+ out << newEntry + "\n";
+ m_call3Modified=true;
+ }
+ } else {
+ if(s!="") out << s + "\n";
}
- } else {
- if(s!="") out << s + "\n";
}
- }
- } while(!s.isNull());
-
- f1.close();
- if(hc>hc1 && !m_call3Modified) out << newEntry + "\n";
+ } while(!s.isNull());
+ if(hc>hc1 && !m_call3Modified) out << newEntry + "\n";
+ }
+
if(m_call3Modified) {
- QFile f0(m_appDir + "/CALL3.OLD");
- if(f0.exists()) f0.remove();
- QFile f1(m_appDir + "/CALL3.TXT");
- f1.rename(m_appDir + "/CALL3.OLD");
- f2.rename(m_appDir + "/CALL3.TXT");
- f2.close();
+ auto const& old_path = m_appDir + "/CALL3.OLD";
+ QFile f0 {old_path};
+ if (f0.exists ()) f0.remove ();
+ f1.copy (old_path); // copying as we want to preserve
+ // symlinks
+ f1.open (QFile::WriteOnly | QFile::Text); // truncates
+ f2.seek (0);
+ f1.write (f2.readAll ()); // copy contents
+ f2.remove ();
}
}