From 79f24c5718dbb595cf7e95e6b42d46b869f71e8d Mon Sep 17 00:00:00 2001 From: Lars Doelle Date: Fri, 30 Oct 1998 21:25:28 +0000 Subject: [PATCH] problems with partial installed konsole fixed. svn path=/trunk/kdebase/konsole/; revision=11936 --- include/TEShell.h | 4 +- include/main.h | 8 +- include/session.h | 17 ++-- src/TEShell.C | 11 ++- src/main.C | 198 +++++++++++++++++++++++++++------------------- src/session.C | 47 ++++++++--- 6 files changed, 177 insertions(+), 108 deletions(-) diff --git a/include/TEShell.h b/include/TEShell.h index a3f476548..f425fcbdc 100644 --- a/include/TEShell.h +++ b/include/TEShell.h @@ -35,9 +35,9 @@ Q_OBJECT int run(char* argv[], const char* term); signals: - void done(); + void done(int status); public: - void doneShell(); + void doneShell(int status); public: void send_byte(char s); diff --git a/include/main.h b/include/main.h index 4b23173e8..2672478bb 100644 --- a/include/main.h +++ b/include/main.h @@ -41,7 +41,7 @@ class TEDemo : public KTMainWindow public: - TEDemo(char* args[]); + TEDemo(const char* args[]); ~TEDemo(); private slots: @@ -49,7 +49,7 @@ private slots: void scrollbar_menu_activated(int item); void activateSession(int); - void doneSession(TESession*); + void doneSession(TESession*,int); void opt_menu_activated(int item); void font_menu_activated(int item); void size_menu_activated(int item); @@ -77,7 +77,7 @@ private: void makeMenu(); void makeStatusbar(); - void addSession(TESession* s, char* title); + void addSession(TESession* s); void setColorPixmaps(); void setColLin(int columns, int lines); @@ -85,6 +85,7 @@ private: void loadAllSchemas(); void setSchema(const char* path); void setSchema(const ColorSchema* s); + void setFont(int fontno); ColorSchema* readSchema(const char* path); ColorSchema* defaultSchema(); @@ -117,6 +118,7 @@ private: int n_scroll; QString s_schema; int n_render; + QSize lincol0; //FIXME: something is messed up initializing the size (event handling) QSize lincol; QString pmPath; // pixmap path diff --git a/include/session.h b/include/session.h index 14c5a7765..55aa883db 100644 --- a/include/session.h +++ b/include/session.h @@ -25,7 +25,7 @@ class TESession : QObject public: - TESession(KTMainWindow* main, TEWidget* w, char* args[], const char* term); + TESession(KTMainWindow* main, TEWidget* w, const char* args[], const char* term); ~TESession(); public: @@ -37,18 +37,22 @@ public: int schemaNo(); int fontNo(); - const char* term(); + const char* emuName(); + const char* Title(); void setSchemaNo(int sn); void setFontNo(int fn); + void setTitle(const char* title); + + void run(); public slots: - void done(); + void done(int status); signals: - void done(TESession*); + void done(TESession*, int); private: @@ -58,7 +62,10 @@ private: int schema_no; // no exactly the right place int font_no; // no exactly the right place - QString emuname; + + char* term; + char** args; + QString title; }; #endif diff --git a/src/TEShell.C b/src/TEShell.C index f812b14e6..642a9d501 100644 --- a/src/TEShell.C +++ b/src/TEShell.C @@ -61,19 +61,18 @@ static QIntDict shells; static void catchChild(int) // Catch a SIGCHLD signal and exit if the child has died. -{ pid_t pid; - pid = wait((int *)NULL); -//fprintf(stdout,"%s(%d): child %d died.\n",__FILE__,__LINE__,pid); +{ pid_t pid; int status; + pid = wait(&status); Shell* sh = shells.find(pid); if (sh) { - shells.remove(pid); sh->doneShell(); + shells.remove(pid); sh->doneShell(status); } } -void Shell::doneShell() +void Shell::doneShell(int status) { - emit done(); + emit done(status); } int Shell::run(char* argv[], const char* term) diff --git a/src/main.C b/src/main.C index 398112a42..7743efc14 100644 --- a/src/main.C +++ b/src/main.C @@ -39,6 +39,8 @@ #include #include +#include +#include #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) @@ -53,7 +55,16 @@ char *fonts[] = {"6x13", "5x7", "6x10", "7x13", "9x15", "10x20", "linux8x16"}; //"vga"}; -TEDemo::TEDemo(char* args[]) : KTMainWindow() +static QIntDict no2session; +static QPtrDict session2no; +static int session_no = 0; + +static QIntDict no2command; +static int cmd_serial = 0; + +static int schema_serial = 1; + +TEDemo::TEDemo(const char* args[]) : KTMainWindow() { se = NULL; title = PACKAGE; @@ -83,24 +94,29 @@ TEDemo::TEDemo(char* args[]) : KTMainWindow() curr_schema = 0; loadAllSchemas(); - setSchema(s_schema); - // set options ////////////////////////////////////////////////////////////// +//FIXME: we should build a complete session before running it. + + // set global options /////////////////////////////////////////////////////// if (b_menuvis) menubar->show(); else menubar->hide(); te->setFrameStyle( b_framevis ? QFrame::WinPanel | QFrame::Sunken : QFrame::NoFrame ); te->setScrollbarLocation(n_scroll); - m_font->setItemChecked(n_font,TRUE); //Note: font set in ::TEDemo - font_menu_activated(n_font); + + // construct initial session /////////////////////////////////////////////// + + TESession* initial = new TESession(this,te,args,"xterm"); + initial->setFontNo(n_font); + initial->setSchemaNo(path2schema.find(s_schema)->numb); + initial->setTitle(args[0]); // start first session ///////////////////////////////////////////////////// - addSession(new TESession(this,te,args,"xterm"),args[0]); - se->setFontNo(n_font); - setSchema(s_schema); - setColLin(lincol.width(),lincol.height()); + addSession(initial); + + setColLin(lincol0.width(),lincol0.height()); } /*! @@ -273,10 +289,10 @@ void TEDemo::readProperties(KConfig* config) b_menuvis = config->readBoolEntry("menubar visible",TRUE); b_framevis = config->readBoolEntry("has frame",TRUE); b_bshack = config->readBoolEntry("BS hack",TRUE); - n_font = MIN(config->readUnsignedNumEntry("font",0),6); + n_font = MIN(config->readUnsignedNumEntry("font",3),6); n_scroll = MIN(config->readUnsignedNumEntry("scrollbar",SCRRIGHT),2); s_schema = config->readEntry("schema",""); - lincol = config->readSizeEntry("size",&dftSize); //FIXME: to be replaced by window size + lincol0 = config->readSizeEntry("size",&dftSize); //FIXME: to be replaced by window size QString entry = config->readEntry("kmenubar"); if (!entry.isEmpty() && entry == "floating") @@ -344,21 +360,30 @@ void TEDemo::scrollbar_menu_activated(int item) void TEDemo::font_menu_activated(int item) { - QFont f( fonts[item] ); + n_font = item; + if (se) + { + se->setFontNo(item); + activateSession((int)session2no.find(se)); // for attribute change + } +} + +void TEDemo::setFont(int fontno) +{ + QFont f( fonts[fontno] ); f.setRawMode( TRUE ); if ( !f.exactMatch() ) KMsgBox::message ( this, - "Error", QString("Font '") + fonts[item] + "' not found.", + "Error", QString("Font '") + fonts[fontno] + "' not found.", KMsgBox::EXCLAMATION ); else { te->setVTFont(f); - if (se) se->setFontNo(item); - m_font->setItemChecked(n_font,FALSE); - m_font->setItemChecked(item, TRUE); - n_font = item; } + m_font->setItemChecked(n_font,FALSE); + m_font->setItemChecked(fontno, TRUE); + n_font = fontno; } void TEDemo::opt_menu_activated(int item) @@ -472,10 +497,6 @@ void TEDemo::tecRef() /* --| sessions |------------------------------------------------------------ */ -static QIntDict no2session; -static QPtrDict session2no; -static int session_no = 0; - //FIXME: activating sessions creates a lot flicker in the moment. // it comes from setting the attributes of a session individually. // ONE setImage call should actually be enough to match all cases. @@ -488,8 +509,6 @@ static int session_no = 0; void TEDemo::activateSession(int sn) { TESession* s = no2session.find(sn); - if (s == se) return; // don't bother - if (!s) return; // oops if (se) { se->setConnect(FALSE); @@ -497,14 +516,20 @@ void TEDemo::activateSession(int sn) m_sessions->setItemChecked(no,FALSE); } se = s; - se->setConnect(TRUE); // does a bulkShow (setImage) + if (!s) return; // oops m_sessions->setItemChecked(sn,TRUE); -/*FIXME: creates flicker*/ - setSchema(s->schemaNo()); - font_menu_activated(s->fontNo()); + setSchema(s->schemaNo()); //FIXME: creates flicker? Do only if differs +//Set Font. Now setConnect should do the appropriate action. +//if the size has changed, a resize event (noticable to the application) +//should happen. Else, we could even start the application + s->setConnect(TRUE); // does a bulkShow (setImage) + setFont(s->fontNo()); //FIXME: creates flicker? + //FIXME: check here if we're still alife. + // if not, quit, otherwise, + // start propagating quit. } -void TEDemo::addSession(TESession* s, char* title) +void TEDemo::addSession(TESession* s) { //FIXME: not quite the right place ... if (b_bshack) @@ -512,28 +537,78 @@ void TEDemo::addSession(TESession* s, char* title) else ((VT102Emulation*)s->getEmulation())->resetMode(MODE_BsHack); - if (se) - { - se->setConnect(FALSE); - int no = (int)session2no.find(se); - m_sessions->setItemChecked(no,FALSE); - } - se = s; - se->setConnect(TRUE); session_no += 1; - no2session.insert(session_no,se); - session2no.insert(se,(void*)session_no); - m_sessions->insertItem(title, session_no); - m_sessions->setItemChecked(session_no,TRUE); + no2session.insert(session_no,s); + session2no.insert(s,(void*)session_no); + m_sessions->insertItem(s->Title(), session_no); + + activateSession(session_no); + + s->run(); } -void TEDemo::doneSession(TESession* s) +void TEDemo::newSession(int i) { + char* shell = getenv("SHELL"); + if (shell == NULL || *shell == '\0') shell = "/bin/sh"; + + KSimpleConfig* co = no2command.find(i); + if (!co) return; // oops + + assert( se ); //FIXME: careful here. + + QString cmd = co->readEntry("Exec"); // not null + QString nam = co->readEntry("Name"); // not null + QString emu = co->readEntry("Term"); + QString sch = co->readEntry("Schema"); + QString txt = co->readEntry("Comment"); // not null + int fno = MIN(co->readUnsignedNumEntry("Font",se->fontNo()),6); + + ColorSchema* schema = sch.isNull()?numb2schema.find(se->schemaNo()):path2schema.find(sch); + int schmno = schema->numb; + + if (emu.isEmpty()) emu = se->emuName(); + + const char* args[4]; + args[0] = shell; + args[1] = "-c"; + args[2] = cmd.data(); + args[3] = NULL; + + TESession* s = new TESession(this,te,args,emu.data()); + s->setFontNo(fno); + s->setSchemaNo(schmno); + s->setTitle(txt.data()); + + addSession(s); // runs session +} + +//FIXME: If a child dies during session swap, +// this routine might be called before +// session swap is completed. + +void TEDemo::doneSession(TESession* s, int status) +{ +//printf("%s(%d): Exited:%d ExitStatus:%d\n",__FILE__,__LINE__,WIFEXITED(status),WEXITSTATUS(status)); + if (!WIFEXITED(status) || WEXITSTATUS(status)) + { + QString str = QString("`") + QString(s->Title()) + "' terminated abnormally."; + if (WIFEXITED(status)) + { char rcs[100]; sprintf(rcs,"%d.\n",WEXITSTATUS(status)); + str = str + "\nReturn code = " + rcs; + } + KMsgBox::message( this, "Error", str, KMsgBox::EXCLAMATION ); + + } int no = (int)session2no.find(s); if (!no) return; // oops no2session.remove(no); session2no.remove(s); m_sessions->removeItem(no); + + s->setConnect(FALSE); + delete s; + if (s == se) { // pick a new session se = NULL; @@ -580,7 +655,6 @@ void TEDemo::setSchema(const ColorSchema* s) if (se) se->setSchemaNo(s->numb); } -static int schema_serial = 1; ColorSchema* TEDemo::readSchema(const char* path) { FILE* sysin = fopen(path,"r"); @@ -708,9 +782,6 @@ void TEDemo::loadAllSchemas() addSchema(readSchema(fi->filePath())); } -static QIntDict no2command; -static int cmd_serial = 0; - void TEDemo::addSessionCommand(const char* path) { KSimpleConfig* co = new KSimpleConfig(path,TRUE); @@ -742,39 +813,6 @@ void TEDemo::loadSessionCommands() addSessionCommand(fi->filePath()); } -// menu stuff //////////////// - -void TEDemo::newSession(int i) -{ - char* shell = getenv("SHELL"); - if (shell == NULL || *shell == '\0') shell = "/bin/sh"; - - KSimpleConfig* co = no2command.find(i); - if (!co) return; // oops - - QString cmd = co->readEntry("Exec"); - QString nam = co->readEntry("Name"); - QString emu = co->readEntry("Term"); - QString sch = co->readEntry("Schema"); - - int fontno = MIN(co->readUnsignedNumEntry("Font",se->fontNo()),6); - int schmno = se->schemaNo(); - - if (emu.isEmpty()) emu = se->term(); - - char* args[4]; - args[0] = shell; - args[1] = "-c"; - args[2] = cmd.data(); - args[3] = NULL; - - addSession(new TESession(this,te,args,emu.data()),nam.data()); - -/*FIXME: creates flicker*/ - font_menu_activated(fontno); - if (sch.isEmpty()) setSchema(schmno); else setSchema(sch.data()); -} - /* --| main |---------------------------------------------------------------- */ static void usage() @@ -817,7 +855,7 @@ int main(int argc, char* argv[]) QString fg = ""; QString bg = ""; - char** eargs = (char**)malloc(3*sizeof(char*)); + const char** eargs = (const char**)malloc(3*sizeof(char*)); eargs[0] = shell; eargs[1] = NULL; KApplication a(argc, argv, PACKAGE); @@ -826,7 +864,7 @@ int main(int argc, char* argv[]) { if (!strcmp(argv[i],"-e") && i+1 < argc) // handle command { free(eargs); - eargs = (char**)malloc((argc-i+1)*sizeof(char*)); + eargs = (const char**)malloc((argc-i+1)*sizeof(char*)); for (int j = 0; j+i < argc; j++) eargs[j] = argv[i+j+1]; break; } diff --git a/src/session.C b/src/session.C index c7e2844c9..23b7db3b1 100644 --- a/src/session.C +++ b/src/session.C @@ -2,12 +2,19 @@ #include -TESession::TESession(KTMainWindow* main, TEWidget* te, char* args[], const char* term) +TESession::TESession(KTMainWindow* main, TEWidget* te, const char* args[], const char* term) { sh = new Shell(); em = new VT102Emulation(te,term); - emuname = term; + this->term = strdup(term); + + { int i; + for (i = 0; args[i]; i++); + this->args = (char**)malloc(sizeof(char*)*(i+1)); + for (i = 0; args[i]; i++) this->args[i] = strdup(args[i]); + this->args[i] = NULL; + } sh->setSize(te->Lines(),te->Columns()); // not absolutely nessesary QObject::connect( sh,SIGNAL(block_in(const char*,int)), @@ -22,18 +29,24 @@ TESession::TESession(KTMainWindow* main, TEWidget* te, char* args[], const char* main,SLOT(changeColumns(int)) ); QObject::connect( em,SIGNAL(changeTitle(int, char*)), main,SLOT(changeTitle(int, char*)) ); - QObject::connect( this,SIGNAL(done(TESession*)), - main,SLOT(doneSession(TESession*)) ); - QObject::connect( sh,SIGNAL(done()), this,SLOT(done()) ); + QObject::connect( this,SIGNAL(done(TESession*,int)), + main,SLOT(doneSession(TESession*,int)) ); + QObject::connect( sh,SIGNAL(done(int)), this,SLOT(done(int)) ); //FIXME: note the right place QObject::connect( te,SIGNAL(configureRequest(TEWidget*,int,int,int)), main,SLOT(configureRequest(TEWidget*,int,int,int)) ); +} +void TESession::run() +{ sh->run(args,term); } TESession::~TESession() -{ +{ int i; + free(term); + for (i = 0; args[i]; i++) free(args[i]); + free(args); delete em; delete sh; } @@ -43,11 +56,11 @@ void TESession::setConnect(bool c) em->setConnect(c); } -void TESession::done() +void TESession::done(int status) { - setConnect(FALSE); - emit done(this); - delete this; +//setConnect(FALSE); + emit done(this,status); +//delete this; } Emulation* TESession::getEmulation() @@ -67,9 +80,9 @@ int TESession::fontNo() return font_no; } -const char* TESession::term() +const char* TESession::emuName() { - return emuname.data(); + return term; } void TESession::setSchemaNo(int sn) @@ -82,5 +95,15 @@ void TESession::setFontNo(int fn) font_no = fn; } +void TESession::setTitle(const char* title) +{ + this->title = title; +} + +const char* TESession::Title() +{ + return title.data(); +} + #include "session.moc"