📄 konsole.cpp
字号:
/* ---------------------------------------------------------------------- *//* *//* [main.C] Konsole *//* *//* ---------------------------------------------------------------------- *//* *//* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> *//* *//* This file is part of Konsole, an X terminal. *//* *//* The material contained in here more or less directly orginates from *//* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> *//* *//* ---------------------------------------------------------------------- *///// KDE's Konsole, ported to Qt/Embedded//// Copyright (C) 2000 by John Ryland <jryland@trolltech.com>// some enhancements added by L.J. Potter <ljp@llornkcor.com>//#include <qtopia/resource.h>#include <qdir.h>#include <qevent.h>#include <qdragobject.h>#include <qobjectlist.h>#include <qtoolbutton.h>#include <qtopia/qpetoolbar.h>#include <qpushbutton.h>#include <qfontdialog.h>#include <qglobal.h>#include <qpainter.h>#include <qtopia/qpemenubar.h>#include <qmessagebox.h>#include <qaction.h>#include <qapplication.h>#include <qfontmetrics.h>#include <qcombobox.h>#include <qevent.h>#include <qtabwidget.h>#include <qtabbar.h>#include <qtopia/config.h>#include <qstringlist.h>#include <qpalette.h>#include <qlayout.h>#ifndef Q_OS_WIN32 #include <sys/wait.h>#endif#include <stdio.h>#include <stdlib.h>#include <assert.h>#include "konsole.h"#include "keytrans.h"class EKNumTabBar : public QTabBar {public: void numberTabs() { // Yes, it really is this messy. QTabWidget needs functions // that provide acces to tabs in a sequential way. int m=INT_MIN; for (int i=0; i<count(); i++) { QTab* left=0; QListIterator<QTab> it(*tabList()); int x=INT_MAX; for( QTab* t; (t=it.current()); ++it ) { int tx = t->rect().x(); if ( tx<x && tx>m ) { x = tx; left = t; } } if ( left ) { left->setText(QString::number(i+1)); m = left->rect().x(); } } }};class EKNumTabWidget : public QTabWidget {public: EKNumTabWidget(QWidget* parent) : QTabWidget(parent) { } void addTab(QWidget* w) { QTab* t = new QTab(QString::number(tabBar()->count()+1)); QTabWidget::addTab(w,t); } void removeTab(QWidget* w) { removePage(w); ((EKNumTabBar*)tabBar())->numberTabs(); }};// This could be configurable or dynamicly generated from the bash history// file of the userstatic const char *commonCmds[] ={ "ls ", // I left this here, cause it looks better than the first alpha "cardctl eject", // No tr "cat ", // No tr "cd ", "chmod ", "cp ", "dc ", "df ", "dmesg", "echo ", // No tr "find ", // No tr "free", // No tr "grep ", "ifconfig ", "ipkg ", "mkdir ", "mv ", "nc localhost 7776", "nc localhost 7777", "nslookup ", "ping ", // No tr "ps aux", "pwd ", "rm ", "rmdir ", "route ", // No tr "set ", // No tr "traceroute",/* "gzip", "gunzip", "chgrp", "chown", "date", "dd", "df", "dmesg", "fuser", "hostname", "kill", "killall", "ln", "ping", "mount", "more", "sort", "touch", "umount", "mknod", "netstat",*/ "exit", // No tr NULL};/*! \class Konsole \brief The Konsole class is the top-level widget for the Terminal application. \legalese The Terminal allows command-line access to the system and is used for development and debugging activities. The Terminal (embeddedkonsole) is based on the KDE Konsole application and is distributed under the terms of the GNU General Public License. A primary copyright holder of the code is Lars Doelle <lars.doelle@on-line.de>.*/Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl){ QStrList args; init("/bin/sh",args);}Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) : QMainWindow(0, name){ init(_pgm,_args);}void Konsole::init(const char* _pgm, QStrList & _args){ setMinimumSize(200, 200); b_scroll = TRUE; // histon; n_keytab = 0; n_render = 0; setCaption( tr("Terminal") ); setIcon( Resource::loadPixmap( "konsole" ) ); setBackgroundMode( PaletteButton ); Config cfg("Konsole"); cfg.setGroup("Konsole"); QString tmp; // initialize the list of allowed fonts /////////////////////////////////// cfont = cfg.readNumEntry("FontID", 1); QFont f = QFont("Micro", 4, QFont::Normal); f.setFixedPitch(TRUE); fonts.append(new VTFont(tr("Micro"), f)); f = QFont("Fixed", 7, QFont::Normal); f.setFixedPitch(TRUE); fonts.append(new VTFont(tr("Small Fixed"), f)); f = QFont("Fixed", 12, QFont::Normal); f.setFixedPitch(TRUE); fonts.append(new VTFont(tr("Medium Fixed"), f)); // create terminal emulation framework //////////////////////////////////// nsessions = 0; tab = new EKNumTabWidget(this); connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); // create terminal toolbar //////////////////////////////////////////////// setToolBarsMovable( FALSE ); QPEToolBar *menuToolBar = new QPEToolBar( this ); menuToolBar->setHorizontalStretchable( TRUE ); QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); uint i; fontList = new QPopupMenu( this ); for(i = 0; i < fonts.count(); i++) { VTFont *fnt = fonts.at(i); fontList->insertItem(fnt->getName(), i); } fontChanged(cfont); configMenu = new QPopupMenu( this); colorMenu = new QPopupMenu( this); bool listHidden; cfg.setGroup("Menubar"); if( cfg.readEntry("Hidden","FALSE") == "TRUE") { configMenu->insertItem(tr("Show command list")); listHidden=TRUE; } else { configMenu->insertItem(tr("Hide command list")); listHidden=FALSE; } cfg.setGroup("Tabs"); tmp=cfg.readEntry("Position","Bottom"); if(tmp=="Top") { // No tr tab->setTabPosition(QTabWidget::Top); configMenu->insertItem(tr("Tabs on Bottom")); } else { tab->setTabPosition(QTabWidget::Bottom); configMenu->insertItem(tr("Tabs on Top")); } configMenu->insertSeparator(2); colorMenu->insertItem(tr("Green on Black")); colorMenu->insertItem(tr("Black on White")); colorMenu->insertItem(tr("White on Black")); colorMenu->insertItem(tr("Black on Transparent")); colorMenu->insertItem(tr("Black on Red")); colorMenu->insertItem(tr("Red on Black")); colorMenu->insertItem(tr("Green on Yellow")); colorMenu->insertItem(tr("Blue on Magenta")); colorMenu->insertItem(tr("Magenta on Blue")); colorMenu->insertItem(tr("Cyan on White")); colorMenu->insertItem(tr("White on Cyan")); colorMenu->insertItem(tr("Blue on Black")); configMenu->insertItem(tr("Colors"),colorMenu); connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuSelected(int) )); menuBar->insertItem( tr("Font"), fontList ); menuBar->insertItem( tr("Options"), configMenu ); QPEToolBar *toolbar = new QPEToolBar( this ); QAction *a; // Button Commands a = new QAction( tr("New"), Resource::loadIconSet( "konsole" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); a = new QAction( tr("Enter"), Resource::loadIconSet( "konsole/enter" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); a = new QAction( tr("Space"), Resource::loadIconSet( "konsole/space" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); a = new QAction( tr("Tab"), Resource::loadIconSet( "konsole/tab" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); a = new QAction( tr("Up"), Resource::loadIconSet( "konsole/up" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); a = new QAction( tr("Down"), Resource::loadIconSet( "konsole/down" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); a = new QAction( tr("Paste"), Resource::loadIconSet( "paste" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar );/* a = new QAction( tr("Up"), Resource::loadIconSet( "up" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); a = new QAction( tr("Down"), Resource::loadIconSet( "down" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );*/ secondToolBar = new QPEToolBar( this ); commonCombo = new QComboBox( secondToolBar ); if( listHidden) secondToolBar->hide(); configMenu->insertItem(tr("Edit Command List")); cfg.setGroup("Commands"); commonCombo->setInsertionPolicy(QComboBox::AtCurrent); for (i = 0; commonCmds[i] != NULL; i++) { commonCombo->insertItem( commonCmds[i], i ); tmp = cfg.readEntry( QString::number(i),""); if(tmp != "") commonCombo->changeItem( tmp,i ); } connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); // create applications ///////////////////////////////////////////////////// setCentralWidget(tab); // load keymaps //////////////////////////////////////////////////////////// KeyTrans::loadAll(); for (int i = 0; i < KeyTrans::count(); i++) { KeyTrans* s = KeyTrans::find(i); assert( s ); } se_pgm = _pgm; se_args = _args; // read and apply default values /////////////////////////////////////////// resize(321, 321); // Dummy. QSize currentSize = size(); if (currentSize != size()) defaultSize = size(); if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { configMenu->setItemChecked(-20,TRUE); commonCombo->setEditable( TRUE ); } else { configMenu->setItemChecked(-20,FALSE); commonCombo->setEditable( FALSE ); } configMenu->setItemEnabled(-20,!secondToolBar->isHidden()); layout()->setResizeMode(QLayout::FreeResize);}void Konsole::show(){ if ( !nsessions ) { newSession(); } QMainWindow::show();}void Konsole::initSession(const char*, QStrList &){ QMainWindow::show();}Konsole::~Konsole(){ while (nsessions > 0) { doneSession(getTe()->currentSession, 0); } Config cfg("Konsole"); cfg.setGroup("Konsole"); cfg.writeEntry("FontID", cfont);}void Konsole::fontChanged(int f){ VTFont* font = fonts.at(f); if (font != 0) { for(uint i = 0; i < fonts.count(); i++) { fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -