// rdclilogedit.cpp // // A command-line log editor for Rivendell // // (C) Copyright 2016-2018 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // #include #include #include #include #include #include #include #include #include #include #include #include #include "rdclilogedit.h" MainObject::MainObject(QObject *parent) :QObject(parent) { QString err_msg; edit_quiet_option=false; edit_log=NULL; edit_log_event=NULL; edit_modified=false; edit_log_lock=NULL; // // Open the Database // rda=new RDApplication("rdclilogedit","rdclilogedit",RDCLILOGEDIT_USAGE,this); if(!rda->open(&err_msg)) { fprintf(stderr,"rdclilogedit: %s\n",(const char *)err_msg); exit(1); } // // Read Command Options // for(unsigned i=0;icmdSwitch()->keys();i++) { if((rda->cmdSwitch()->key(i)=="-n")||(rda->cmdSwitch()->key(i)=="--quiet")|| (rda->cmdSwitch()->key(i)=="--silent")) { edit_quiet_option=true; rda->cmdSwitch()->setProcessed(i,true); } if(!rda->cmdSwitch()->processed(i)) { fprintf(stderr,"rdclilogedit: unknown command option \"%s\"\n", (const char *)rda->cmdSwitch()->key(i)); exit(2); } } // // RIPC Connection // connect(rda,SIGNAL(userChanged()),this,SLOT(userData())); rda->ripc()-> connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password()); } void MainObject::userData() { char data[1024]; int n; // // Get User Context // disconnect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData())); // // Start up command processor // PrintPrompt(); while((n=read(0,data,1024))>0) { for(int i=0;itryLock(&username,&stationname,&addr); if(!ret) { QString msg="log \""+logname+"\" in use by "+username+"@"+stationname; if(stationname!=addr.toString()) { msg+=" ["+addr.toString()+"]"; } fprintf(stderr,"%s\n",(const char *)msg); } return ret; } void MainObject::OverwriteError(const QString &cmd) const { fprintf(stderr,"%s: buffer not saved (append \"!\" to override)\n", (const char *)cmd); } void MainObject::PrintPrompt() const { if(!edit_quiet_option) { if(edit_log==NULL) { printf("logedit> "); } else { if(edit_modified) { printf("logedit[%s*]> ",(const char *)edit_log->name()); } else { printf("logedit[%s]> ",(const char *)edit_log->name()); } } fflush(stdout); } } void MainObject::SendNotification(RDNotification::Action action, const QString &logname) { RDNotification *notify=new RDNotification(RDNotification::LogType, action,QVariant(logname)); rda->ripc()->sendNotification(*notify); qApp->processEvents(); delete notify; } int main(int argc,char *argv[]) { QApplication a(argc,argv,false); new MainObject(); return a.exec(); }