📄 konsole.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS and its licensors.** All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.** See below for additional copyright and license information**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//* ---------------------------------------------------------------------- *//* *//* [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> *//* *//* ---------------------------------------------------------------------- *///// Konsole ported to Qt/Embedded by Trolltech// 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 dynamically generated from the bash history// file of the user.static 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 <a href="mailto:lars.doelle@on-line.de">Lars Doelle</a>.*/// QDOC_SKIP_BEGIN#include <qfile.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl){ const char* shell = getenv("SHELL"); if (shell == NULL || *shell == '\0'){#if !defined (_OS_WIN32_) shell = "/bin/sh"; // No tr // sh is completely broken on familiar. Let's try to get something better if ( qstrcmp( shell, "/bin/shell" ) == 0 && QFile::exists( "/bin/bash" ) ) shell = "/bin/bash";#else shell ="command"; // No tr#endif } QStrList args; init(shell,args);}/* not usedKonsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) : QMainWindow(0, name){ init(_pgm,_args);}*/void Konsole::init(const char* _pgm, QStrList & _args){#if !defined (_OS_WIN32_) setuid(getuid()); setgid(getgid()); // drop privileges#endif#ifdef FAKE_CTRL_AND_ALT QPEApplication::grabKeyboard(); // for CTRL and ALT#endif putenv((char*)"COLORTERM="); // to trigger mc's color detection setCaption( Konsole::tr("Terminal") ); setMinimumSize(200, 200); b_scroll = TRUE; // histon; n_keytab = 0; n_render = 0; setCaption( tr("Terminal") ); 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("Default")); 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 newAct = new QAction( tr("New"), Resource::loadIconSet( "konsole" ), QString::null, 0, this, 0 ); connect( newAct, SIGNAL( activated() ), this, SLOT( newSession() ) ); newAct->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( "space" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); a = new QAction( tr("Tab"), Resource::loadIconSet( "tab" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); 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 ); 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();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -