diff --git a/ChangeLog b/ChangeLog index fe08657e..a8fde241 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15358,3 +15358,5 @@ 'utils/rdclilogedit/parser.cpp'. 2016-07-21 Fred Gleason * Refactored rdclilogedit(1) to use synchronous input. +2016-07-21 Fred Gleason + * Added a 'new' command to rdclilogedit(1). diff --git a/utils/rdclilogedit/help.cpp b/utils/rdclilogedit/help.cpp index 532c8a3a..31fc7fee 100644 --- a/utils/rdclilogedit/help.cpp +++ b/utils/rdclilogedit/help.cpp @@ -28,7 +28,7 @@ void MainObject::Help(const QStringList &cmds) const printf("\n"); printf("The following commands are available:\n"); printf("?, addcart, addchain, addmarker, addtrack, bye, exit, help, list, listlogs,\n"); - printf("load, quit, remove, save, saveas, setcart, setcomment, setlabel, settime\n"); + printf("load, new, quit, remove, save, saveas, setcart, setcomment, setlabel, settime\n"); printf("settrans, unload\n"); printf("\n"); printf("Enter \"? \" for specific help.\n"); @@ -101,6 +101,14 @@ void MainObject::Help(const QStringList &cmds) const printf("\n"); processed=true; } + if(verb=="new") { + printf("\n"); + printf(" new \n"); + printf("\n"); + printf("Create a new, empty log called in the edit buffer.\n"); + printf("\n"); + processed=true; + } if(verb=="remove") { printf("\n"); printf(" remove \n"); diff --git a/utils/rdclilogedit/operations.cpp b/utils/rdclilogedit/operations.cpp index 9c91c7a0..a06e8666 100644 --- a/utils/rdclilogedit/operations.cpp +++ b/utils/rdclilogedit/operations.cpp @@ -102,6 +102,7 @@ void MainObject::ListLogs() const void MainObject::Load(const QString &logname) { + printf("LOAD\n"); if(edit_log!=NULL) { delete edit_log; edit_log=NULL; @@ -211,6 +212,26 @@ QString MainObject::ListLine(RDLogEvent *evt,int line) const } +void MainObject::New(const QString &logname) +{ + if(edit_log!=NULL) { + delete edit_log; + } + if(edit_log_event!=NULL) { + delete edit_log_event; + } + edit_log=new RDLog(logname); + if(!edit_log->exists()) { + edit_log_event=new RDLogEvent(RDLog::tableName(logname)); + edit_new_log=true; + edit_modified=false; + } + else { + fprintf(stderr,"new: log already exists\n"); + } +} + + void MainObject::Remove(int line) { edit_log_event->remove(line,1); @@ -220,10 +241,15 @@ void MainObject::Remove(int line) void MainObject::Save() { - edit_log_event->save(); - edit_log-> - setModifiedDatetime(QDateTime(QDate::currentDate(),QTime::currentTime())); - edit_modified=false; + if(edit_new_log) { + Saveas(edit_log->name()); + } + else { + edit_log_event->save(); + edit_log-> + setModifiedDatetime(QDateTime(QDate::currentDate(),QTime::currentTime())); + edit_modified=false; + } } @@ -234,15 +260,33 @@ void MainObject::Saveas(const QString &logname) RDLog *log=new RDLog(logname); if(!log->exists()) { - sql=QString("insert into LOGS set ")+ - "NAME=\""+RDEscapeString(logname)+"\","+ - "TYPE=0,"+ - "DESCRIPTION=\""+"Copy of "+RDEscapeString(edit_log->name())+"\","+ - "ORIGIN_USER=\""+RDEscapeString(edit_user->name())+"\","+ - "ORIGIN_DATETIME=now(),"+ - "LINK_DATETIME=now(),"+ - "MODIFIED_DATETIME=now(),"+ - "SERVICE=\""+edit_log->service()+"\""; + if(edit_log->exists()) { + sql=QString("insert into LOGS set ")+ + "NAME=\""+RDEscapeString(logname)+"\","+ + "TYPE=0,"+ + "DESCRIPTION=\""+"Copy of "+RDEscapeString(edit_log->name())+"\","+ + "ORIGIN_USER=\""+RDEscapeString(edit_user->name())+"\","+ + "ORIGIN_DATETIME=now(),"+ + "LINK_DATETIME=now(),"+ + "MODIFIED_DATETIME=now(),"+ + "SERVICE=\""+edit_log->service()+"\""; + } + else { + sql=QString("select NAME from SERVICES"); + q=new RDSqlQuery(sql); + if(q->first()) { + sql=QString("insert into LOGS set ")+ + "NAME=\""+RDEscapeString(logname)+"\","+ + "TYPE=0,"+ + "DESCRIPTION=\""+RDEscapeString(logname+" log")+"\","+ + "ORIGIN_USER=\""+RDEscapeString(edit_user->name())+"\","+ + "ORIGIN_DATETIME=now(),"+ + "LINK_DATETIME=now(),"+ + "MODIFIED_DATETIME=now(),"+ + "SERVICE=\""+RDEscapeString(q->value(0).toString())+"\""; + } + delete q; + } q=new RDSqlQuery(sql); delete q; RDCreateLogTable(RDLog::tableName(logname)); @@ -251,6 +295,7 @@ void MainObject::Saveas(const QString &logname) delete edit_log; edit_log=log; edit_modified=false; + edit_new_log=false; } else { fprintf(stderr,"saveas: log already exists\n"); @@ -337,6 +382,7 @@ void MainObject::Settrans(int line,RDLogLine::TransType type) void MainObject::Unload() { + printf("UNLOAD\n"); if(edit_log!=NULL) { delete edit_log; edit_log=NULL; diff --git a/utils/rdclilogedit/parser.cpp b/utils/rdclilogedit/parser.cpp index 26112b04..9eb09e85 100644 --- a/utils/rdclilogedit/parser.cpp +++ b/utils/rdclilogedit/parser.cpp @@ -80,6 +80,21 @@ void MainObject::DispatchCommand(QString cmd) processed=true; } + if(verb=="new") { + if(overwrite) { + if(cmds.size()==2) { + New(cmds[1]); + } + else { + fprintf(stderr,"new: invalid command arguments\n"); + } + } + else { + OverwriteError("new"); + } + processed=true; + } + // // These need a log loaded // diff --git a/utils/rdclilogedit/rdclilogedit.cpp b/utils/rdclilogedit/rdclilogedit.cpp index 16e56af6..d17c663e 100644 --- a/utils/rdclilogedit/rdclilogedit.cpp +++ b/utils/rdclilogedit/rdclilogedit.cpp @@ -40,6 +40,7 @@ MainObject::MainObject(QObject *parent) edit_log=NULL; edit_log_event=NULL; edit_modified=false; + edit_new_log=false; // // Read Command Options diff --git a/utils/rdclilogedit/rdclilogedit.h b/utils/rdclilogedit/rdclilogedit.h index 52cccd6a..10b84910 100644 --- a/utils/rdclilogedit/rdclilogedit.h +++ b/utils/rdclilogedit/rdclilogedit.h @@ -52,6 +52,7 @@ class MainObject : public QObject void ListLogs() const; void Load(const QString &logname); void List(); + void New(const QString &logname); void Remove(int line); void Save(); void Saveas(const QString &logname); @@ -67,6 +68,7 @@ class MainObject : public QObject void PrintPrompt() const; QString edit_accum; bool edit_modified; + bool edit_new_log; RDLog *edit_log; RDLogEvent *edit_log_event; RDUser *edit_user;