00001 #include "TEmulation.h"
00002 #include "profileeditordialog.h"
00003 #include "configdialog.h"
00004 #include "default.h"
00005 #include "profilemanager.h"
00006 #include "mainwindow.h"
00007 #include "tabwidget.h"
00008 #include "transferdialog.h"
00009 #include "function_keyboard.h"
00010 #include "emulation_handler.h"
00011 #include "script.h"
00012 #include "fixit.h"
00013
00014
00015 #include <opie2/ofiledialog.h>
00016 #include <opie2/oresource.h>
00017 #include <qpe/filemanager.h>
00018 using namespace Opie::Ui;
00019
00020
00021 #include <qaction.h>
00022 #include <qmenubar.h>
00023 #include <qtoolbar.h>
00024 #include <qmessagebox.h>
00025 #include <qwhatsthis.h>
00026 #include <qfileinfo.h>
00027
00028
00029 #include <assert.h>
00030
00031 #include <opie2/oconfig.h>
00032
00033 MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
00034
00035 #ifdef FSCKED_DISTRI
00036 FixIt fix;
00037 fix.fixIt();
00038 #endif
00039
00040 setCaption(QObject::tr("Opie Console") );
00041 KeyTrans::loadAll();
00042 for (int i = 0; i < KeyTrans::count(); i++ ) {
00043 KeyTrans* s = KeyTrans::find(i );
00044 assert( s );
00045 }
00046 m_factory = new MetaFactory();
00047 Default def(m_factory);
00048 m_sessions.setAutoDelete( TRUE );
00049 m_curSession = 0;
00050 m_manager = new ProfileManager( m_factory );
00051 m_manager->load();
00052 m_scriptsData.setAutoDelete(TRUE);
00053
00054 initUI();
00055 populateProfiles();
00056 populateScripts();
00057 }
00058
00059 void MainWindow::initUI() {
00060
00061 setToolBarsMovable( FALSE );
00062
00063
00064 m_tool = new QToolBar( this );
00065 m_tool->setHorizontalStretchable( TRUE );
00066
00067 m_bar = new QMenuBar( m_tool );
00068 m_console = new QPopupMenu( this );
00069 m_scripts = new QPopupMenu( this );
00070 m_sessionsPop= new QPopupMenu( this );
00071 m_scriptsPop = new QPopupMenu( this );
00072 m_scrollbar = new QPopupMenu( this );
00073
00074
00075 m_icons = new QToolBar(this);
00076
00077
00078
00079
00080 m_setProfiles = new QAction(tr("Configure Profiles"),
00081 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
00082 QString::null, 0, this, 0);
00083 m_setProfiles->addTo( m_console );
00084 connect( m_setProfiles, SIGNAL(activated() ),
00085 this, SLOT(slotConfigure() ) );
00086
00087 m_console->insertSeparator();
00088
00089
00090
00091 QAction* newCon = new QAction(tr("New Profile"),
00092 Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00093 QString::null, 0, this, 0);
00094 newCon->addTo( m_console );
00095 connect( newCon, SIGNAL(activated() ),
00096 this, SLOT(slotNew() ) );
00097
00098 m_console->insertSeparator();
00099
00100 QAction *saveCon = new QAction( tr("Save Profile" ),
00101 Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), QString::null,
00102 0, this, 0 );
00103 saveCon->addTo( m_console );
00104 connect( saveCon, SIGNAL(activated() ),
00105 this, SLOT(slotSaveSession() ) );
00106 m_console->insertSeparator();
00107
00108
00109
00110
00111 m_connect = new QAction( tr("Connect"), Opie::Core::OResource::loadPixmap("console/connected",
00112 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00113 m_connect->addTo( m_console );
00114 connect(m_connect, SIGNAL(activated() ),
00115 this, SLOT(slotConnect() ) );
00116
00117
00118
00119
00120 m_disconnect = new QAction( tr("Disconnect"), Opie::Core::OResource::loadPixmap("console/notconnected",
00121 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00122 m_disconnect->addTo( m_console );
00123 connect(m_disconnect, SIGNAL(activated() ),
00124 this, SLOT(slotDisconnect() ) );
00125
00126 m_console->insertSeparator();
00127
00128 #ifndef EAST
00129 m_quickLaunch = new QAction( tr("QuickLaunch"),
00130 Opie::Core::OResource::loadPixmap("console/konsole_mini", Opie::Core::OResource::SmallIcon ),
00131 QString::null, 0, this, 0 );
00132 m_quickLaunch->addTo( m_icons );
00133 connect( m_quickLaunch, SIGNAL( activated() ),
00134 this, SLOT( slotQuickLaunch() ) );
00135 #endif
00136
00137 QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) );
00138
00139 m_transfer = new QAction( tr("Transfer file..."), Opie::Core::OResource::loadPixmap("pass", Opie::Core::OResource::SmallIcon ),
00140 QString::null, 0, this, 0 );
00141 m_transfer->addTo( m_console );
00142 connect(m_transfer, SIGNAL(activated() ),
00143 this, SLOT(slotTransfer() ) );
00144
00145
00146
00147
00148
00149
00150 m_isWrapped = true;
00151 m_wrap = new QAction( tr("Line wrap"), Opie::Core::OResource::loadPixmap( "linewrap", Opie::Core::OResource::SmallIcon ),
00152 QString::null, 0, this, 0, true );
00153 m_wrap->addTo( m_console );
00154 m_wrap->setOn( true );
00155 connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) );
00156
00157
00158
00159
00160 m_isFullscreen = false;
00161
00162 m_fullscreen = new QAction( tr("Full screen"), Opie::Core::OResource::loadPixmap( "fullscreen",
00163 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00164 m_fullscreen->addTo( m_console );
00165 connect( m_fullscreen, SIGNAL( activated() ),
00166 this, SLOT( slotFullscreen() ) );
00167
00168
00169
00170
00171 sm_none = m_scrollbar->insertItem(tr( "None" ));
00172 sm_left = m_scrollbar->insertItem(tr( "Left" ));
00173 sm_right = m_scrollbar->insertItem(tr( "Right" ));
00174
00175 m_console->insertItem(tr("Scrollbar"), m_scrollbar, -1, 0);
00176 connect( m_scrollbar, SIGNAL(activated(int)),
00177 this, SLOT(slotScrollbarSelected(int)));
00178
00179 m_console->insertSeparator();
00180
00181 m_recordLog = new QAction();
00182 m_recordLog->setText( tr("Start log") );
00183 m_recordLog->addTo( m_console );
00184 connect(m_recordLog, SIGNAL(activated() ),
00185 this, SLOT( slotSaveLog() ) );
00186 m_recordingLog = false;
00187
00188 QAction *a = new QAction();
00189 a->setText( tr("Save history") );
00190 a->addTo( m_console );
00191 connect(a, SIGNAL(activated() ),
00192 this, SLOT(slotSaveHistory() ) );
00193
00194
00195
00196 m_terminate = new QAction();
00197 m_terminate->setText( tr("Terminate") );
00198 m_terminate->addTo( m_console );
00199 connect(m_terminate, SIGNAL(activated() ),
00200 this, SLOT(slotTerminate() ) );
00201
00202 m_closewindow = new QAction();
00203 m_closewindow->setText( tr("Close Window") );
00204 m_closewindow->addTo( m_console );
00205 connect( m_closewindow, SIGNAL(activated() ),
00206 this, SLOT(slotClose() ) );
00207
00208
00209
00210
00211
00212 m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0);
00213 connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int)));
00214
00215 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
00216 m_recordScript->addTo(m_scripts);
00217 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
00218
00219 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
00220 m_saveScript->addTo(m_scripts);
00221 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
00222
00223
00224
00225
00226
00227
00228
00229 m_openKeys = new QAction (tr("Open Keyboard..."),
00230 Opie::Core::OResource::loadPixmap( "console/keys/keyboard_icon", Opie::Core::OResource::SmallIcon ),
00231 QString::null, 0, this, 0);
00232 m_openKeys->setToggleAction(true);
00233 connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool)));
00234
00235
00236 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
00237 -1, 0);
00238
00239
00240 m_bar->insertItem( tr("Connection"), m_console );
00241
00242
00243 #ifdef EAST
00244 Opie::Core::OConfig cfg("opie-console");
00245 cfg.setGroup("10east");
00246 if( !cfg.readEntry("scripthide",0) ) {
00247 m_bar->insertItem( tr("Scripts"), m_scripts );
00248 }
00249 #endif
00250
00251
00252 m_keyBar = new QToolBar(this);
00253 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
00254 m_keyBar->setHorizontalStretchable( TRUE );
00255 m_keyBar->hide();
00256
00257 m_kb = new FunctionKeyboard(m_keyBar);
00258 connect(m_kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)),
00259 this, SLOT(slotKeyReceived(FKey,ushort,ushort,bool)));
00260
00261
00262 a = new QAction(tr("Copy"),
00263 Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ), QString::null,
00264 0, this, 0 );
00265
00266 connect( a, SIGNAL(activated() ),
00267 this, SLOT(slotCopy() ) );
00268
00269 QAction *paste = new QAction(tr("Paste"),
00270 Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ), QString::null,
00271 0, this, 0 );
00272 connect( paste, SIGNAL(activated() ),
00273 this, SLOT(slotPaste() ) );
00274
00275
00276 newCon->addTo( m_icons );
00277
00278 paste->addTo( m_icons );
00279 m_openKeys->addTo(m_icons);
00280 m_fullscreen->addTo( m_icons );
00281
00282 m_connect->setEnabled( false );
00283 m_disconnect->setEnabled( false );
00284 m_terminate->setEnabled( false );
00285 m_transfer->setEnabled( false );
00286 m_scripts->setItemEnabled(m_runScript_id, false);
00287 m_recordScript->setEnabled( false );
00288 m_saveScript->setEnabled( false );
00289 m_fullscreen->setEnabled( false );
00290 m_closewindow->setEnabled( false );
00291 m_wrap->setEnabled( false );
00292
00293
00294
00295
00296 connect( m_sessionsPop, SIGNAL(activated(int) ),
00297 this, SLOT(slotProfile(int) ) );
00298
00299 m_consoleWindow = new TabWidget( this, "blah");
00300 connect(m_consoleWindow, SIGNAL(activated(Session*) ),
00301 this, SLOT(slotSessionChanged(Session*) ) );
00302 setCentralWidget( m_consoleWindow );
00303
00304 slotQuickLaunch();
00305 }
00306
00307 ProfileManager* MainWindow::manager() {
00308 return m_manager;
00309 }
00310 TabWidget* MainWindow::tabWidget() {
00311 return m_consoleWindow;
00312 }
00313 void MainWindow::populateProfiles() {
00314 m_sessionsPop->clear();
00315 Profile::ValueList list = manager()->all();
00316 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
00317 m_sessionsPop->insertItem( (*it).name() );
00318 }
00319
00320 }
00321
00322 void MainWindow::populateScripts() {
00323 m_scriptsPop->clear();
00324 m_scriptsData.clear();
00325 DocLnkSet files(QPEApplication::documentDir(), "text/plain");
00326 QListIterator<DocLnk> dit(files.children());
00327 for (; dit.current(); ++dit) {
00328 if (*dit && (*dit)->name().length()>0) {
00329 QFileInfo info((*dit)->file());
00330 if (info.extension(false) == "script") {
00331 m_scriptsData.append(new DocLnk(**dit));
00332 m_scriptsPop->insertItem((*dit)->name());
00333 }
00334 }
00335 }
00336
00337 }
00338
00339 MainWindow::~MainWindow() {
00340 delete m_factory;
00341 manager()->save();
00342 #ifdef FSCKED_DISTRI
00343 FixIt fix;
00344 fix.breakIt();
00345 #endif
00346 }
00347
00348 MetaFactory* MainWindow::factory() {
00349 return m_factory;
00350 }
00351
00352 Session* MainWindow::currentSession() {
00353 return m_curSession;
00354 }
00355
00356 QList<Session> MainWindow::sessions() {
00357 return m_sessions;
00358 }
00359
00360 void MainWindow::slotNew() {
00361 ProfileEditorDialog dlg(factory() );
00362 dlg.setCaption( tr("New Connection") );
00363 int ret = QPEApplication::execDialog( &dlg );
00364
00365 if ( ret == QDialog::Accepted ) {
00366 create( dlg.profile() );
00367 }
00368 }
00369
00370 void MainWindow::slotRecordScript() {
00371 if (currentSession()) {
00372 currentSession()->emulationHandler()->startRecording();
00373 m_saveScript->setEnabled(true);
00374 m_recordScript->setEnabled(false);
00375 }
00376 }
00377
00378 void MainWindow::slotSaveScript() {
00379 if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
00380 QMap<QString, QStringList> map;
00381 QStringList text;
00382 text << "text/plain";
00383 map.insert(tr("Script"), text );
00384 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
00385 if (!filename.isEmpty()) {
00386 QFileInfo info(filename);
00387 if (info.extension(FALSE) != "script")
00388 filename += ".script";
00389 DocLnk nf;
00390 nf.setType("text/plain");
00391 nf.setFile(filename);
00392 nf.setName(info.fileName());
00393 FileManager fm;
00394 fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
00395 currentSession()->emulationHandler()->clearScript();
00396 m_saveScript->setEnabled(false);
00397 m_recordScript->setEnabled(true);
00398 populateScripts();
00399 }
00400 }
00401 }
00402
00403 void MainWindow::slotRunScript(int id) {
00404 if (currentSession()) {
00405 int index = m_scriptsPop->indexOf(id);
00406 DocLnk *lnk = m_scriptsData.at(index);
00407 QString filePath = lnk->file();
00408 Script script(filePath);
00409 currentSession()->emulationHandler()->runScript(&script);
00410 }
00411 }
00412
00413 void MainWindow::slotConnect() {
00414 if ( currentSession() ) {
00415 bool ret = currentSession()->layer()->open();
00416 if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
00417 QObject::tr("Failed"),
00418 QObject::tr("Connecting failed for this session."));
00419 else {
00420 m_connect->setEnabled( false );
00421 m_disconnect->setEnabled( true );
00422
00423
00424 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
00425 m_transfer->setEnabled( false );
00426 } else {
00427 m_transfer->setEnabled( true );
00428 }
00429
00430 m_recordScript->setEnabled( true );
00431 m_scripts->setItemEnabled(m_runScript_id, true);
00432 }
00433 }
00434 }
00435
00436 void MainWindow::slotDisconnect() {
00437 if ( currentSession() ) {
00438 currentSession()->layer()->close();
00439 m_connect->setEnabled( true );
00440 m_disconnect->setEnabled( false );
00441 m_transfer->setEnabled( false );
00442 m_recordScript->setEnabled( false);
00443 m_saveScript->setEnabled( false );
00444 m_scripts->setItemEnabled(m_runScript_id, false);
00445 }
00446 }
00447
00448 void MainWindow::slotTerminate() {
00449 if ( currentSession() )
00450 currentSession()->layer()->close();
00451
00452 slotClose();
00453
00454 }
00455
00456
00457
00458 void MainWindow::slotQuickLaunch() {
00459
00460 Profile prof = manager()->profile( "default" );
00461 if ( prof.name() == "default" ) {
00462 create( prof );
00463 } else {
00464 #ifndef EAST
00465 Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 );
00466 newProf.setAutoConnect( true );
00467 create( newProf );
00468 slotSaveSession();
00469 #endif
00470 }
00471 }
00472
00473 void MainWindow::slotConfigure() {
00474 ConfigDialog conf( manager()->all(), factory() );
00475
00476 int ret = QPEApplication::execDialog( &conf );
00477
00478 if ( QDialog::Accepted == ret ) {
00479 manager()->setProfiles( conf.list() );
00480 manager()->save();
00481 populateProfiles();
00482 }
00483 }
00484
00485
00486
00487
00488
00489
00490
00491 void MainWindow::slotClose() {
00492 if (!currentSession() )
00493 return;
00494
00495 Session* ses = currentSession();
00496
00497 m_curSession = NULL;
00498 tabWidget()->remove( ses );
00499
00500 m_sessions.remove( ses );
00501
00502 if (!currentSession() ) {
00503 m_connect->setEnabled( false );
00504 m_disconnect->setEnabled( false );
00505 m_terminate->setEnabled( false );
00506 m_transfer->setEnabled( false );
00507 m_recordScript->setEnabled( false );
00508 m_saveScript->setEnabled( false );
00509 m_scripts->setItemEnabled(m_runScript_id, false);
00510 m_fullscreen->setEnabled( false );
00511 m_wrap->setEnabled( false );
00512 m_closewindow->setEnabled( false );
00513 }
00514
00515 m_kb->loadDefaults();
00516 }
00517
00518
00519
00520
00521
00522
00523 void MainWindow::slotProfile( int id) {
00524 Profile prof = manager()->profile( m_sessionsPop->text( id) );
00525 create( prof );
00526 }
00527
00528
00529
00530 void MainWindow::create( const Profile& prof ) {
00531 char *homeDir = getenv("HOME");
00532
00533 if ( homeDir )
00534 ::chdir( homeDir );
00535
00536 if(m_curSession)
00537 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
00538
00539 Session *ses = manager()->fromProfile( prof, tabWidget() );
00540
00541 if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
00542 {
00543 QMessageBox::warning(this,
00544 QObject::tr("Session failed"),
00545 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
00546
00547 return;
00548 }
00549
00550 m_sessions.append( ses );
00551 tabWidget()->add( ses );
00552 tabWidget()->repaint();
00553 m_curSession = ses;
00554
00555
00556 m_connect->setEnabled( true );
00557 m_disconnect->setEnabled( false );
00558 m_terminate->setEnabled( true );
00559 m_fullscreen->setEnabled( true );
00560 m_wrap->setEnabled( true );
00561 m_closewindow->setEnabled( true );
00562 m_transfer->setEnabled( false );
00563 m_recordScript->setEnabled( false );
00564 m_saveScript->setEnabled( false );
00565 m_scripts->setItemEnabled(m_runScript_id, false);
00566
00567
00568
00569 if (prof.autoConnect()) {
00570 slotConnect();
00571 }
00572
00573 QWidget *w = currentSession()->widget();
00574 if(w) w->setFocus();
00575
00576 if(currentSession()->profile().readNumEntry("Wrap", 80)){
00577 m_isWrapped = true;
00578 } else {
00579 m_isWrapped = false;
00580 }
00581
00582 m_kb->load(currentSession()->profile());
00583 }
00584
00585 void MainWindow::slotTransfer()
00586 {
00587 if ( currentSession() ) {
00588 Session *mysession = currentSession();
00589 TransferDialog dlg(this, this);
00590 mysession->setTransferDialog(&dlg);
00591
00592
00593 currentSession()->widgetStack()->addWidget(&dlg, -1);
00594 dlg.show();
00595
00596 while(dlg.isRunning()) qApp->processEvents();
00597 mysession->setTransferDialog(0l);
00598 }
00599 }
00600
00601
00602 void MainWindow::slotOpenKeb(bool state) {
00603
00604 if (state) m_keyBar->show();
00605 else m_keyBar->hide();
00606
00607 }
00608
00609
00610 void MainWindow::slotOpenButtons( bool state ) {
00611
00612 if ( state ) {
00613 m_buttonBar->show();
00614 } else {
00615 m_buttonBar->hide();
00616 }
00617 }
00618
00619
00620
00621 void MainWindow::slotSessionChanged( Session* ses ) {
00622 if(m_curSession)
00623 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
00624 if(ses)
00625 if(ses->transferDialog()) ses->transferDialog()->show();
00626
00627 if ( ses ) {
00628 m_curSession = ses;
00629 if ( m_curSession->layer()->isConnected() ) {
00630 m_connect->setEnabled( false );
00631 m_disconnect->setEnabled( true );
00632 m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording());
00633 m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording());
00634 m_scripts->setItemEnabled(m_runScript_id, true);
00635 } else {
00636 m_connect->setEnabled( true );
00637 m_disconnect->setEnabled( false );
00638 m_recordScript->setEnabled( false );
00639 m_saveScript->setEnabled( false );
00640 m_scripts->setItemEnabled(m_runScript_id, false);
00641 }
00642
00643 if ( ( currentSession()->emulationHandler()->isLogging() ) ) {
00644 m_recordLog->setText( tr("Stop log") );
00645 } else {
00646 m_recordLog->setText( tr("Start log") );
00647 }
00648
00649 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
00650 m_transfer->setEnabled( false );
00651 } else {
00652 m_transfer->setEnabled( true );
00653 }
00654
00655 QWidget *w = m_curSession->widget();
00656 if(w) w->setFocus();
00657
00658 if(currentSession()->profile().readNumEntry("Wrap", 80)){
00659 m_isWrapped = true;
00660 } else {
00661 m_isWrapped = false;
00662 }
00663
00664 m_kb->load(currentSession()->profile());
00665 }
00666 }
00667
00668 void MainWindow::slotWrap()
00669 {
00670 if(m_curSession)
00671 {
00672 EmulationHandler *e = m_curSession->emulationHandler();
00673 if(e)
00674 {
00675 e->setWrap( m_isWrapped ? 80:0 );
00676 m_isWrapped = !m_isWrapped;
00677 }
00678 }
00679 }
00680
00681 void MainWindow::slotFullscreen() {
00682
00683
00684
00685 if ( m_isFullscreen ) {
00686 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true );
00687 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() );
00688 ( m_curSession->emulationHandler() )->cornerButton()->hide();
00689 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
00690
00691 } else {
00692 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget();
00693 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
00694 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
00695 , QPoint(0,0), false );
00696 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
00697 ( m_curSession->widgetStack() )->setFocus();
00698 ( m_curSession->widgetStack() )->show();
00699
00700 ( ( m_curSession->emulationHandler() )->cornerButton() )->show();
00701
00702 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
00703 }
00704
00705 m_isFullscreen = !m_isFullscreen;
00706 }
00707
00708 void MainWindow::slotScrollbarSelected(int index)
00709 {
00710 int loc;
00711
00712 Config cfg( "Konsole" );
00713 cfg.setGroup("ScrollBar");
00714 if(index == sm_none)
00715 {
00716 loc = 0;
00717 }
00718 else if(index == sm_left)
00719 {
00720 loc = 1;
00721 }
00722 else if(index == sm_right)
00723 {
00724 loc = 2;
00725 }
00726
00727 cfg.writeEntry("Position", loc);
00728
00729 if (currentSession()) {
00730 currentSession()->emulationHandler()->setScrollbarLocation(loc);
00731 }
00732
00733 m_scrollbar->setItemChecked(sm_none, index == sm_none);
00734 m_scrollbar->setItemChecked(sm_left, index == sm_left);
00735 m_scrollbar->setItemChecked(sm_right, index == sm_right);
00736 }
00737
00738 void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
00739
00740 if ( m_curSession ) {
00741
00742 QEvent::Type state;
00743
00744 if (pressed) state = QEvent::KeyPress;
00745 else state = QEvent::KeyRelease;
00746
00747 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
00748
00749
00750 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
00751 ke.ignore();
00752 }
00753 }
00754 void MainWindow::slotCopy() {
00755 if (!currentSession() ) return;
00756 currentSession()->emulationHandler()->copy();
00757 }
00758 void MainWindow::slotPaste() {
00759 if (!currentSession() ) return;
00760 currentSession()->emulationHandler()->paste();
00761 }
00762
00763
00764
00765
00766
00767 void MainWindow::slotSaveSession() {
00768 if (!currentSession() ) {
00769 QMessageBox::information(this, tr("Save Connection"),
00770 tr("<qt>There is no Connection.</qt>"), 1 );
00771 return;
00772 }
00773 manager()->add( currentSession()->profile() );
00774 manager()->save();
00775 populateProfiles();
00776 }
00777
00778
00779
00780 void MainWindow::slotSaveLog() {
00781
00782 if( currentSession()->emulationHandler()->isLogging() ) {
00783 DocLnk nf;
00784 QString m_logName = currentSession()->emulationHandler()->logFileName();
00785 QFileInfo info(m_logName);
00786 nf.setType("text/plain");
00787 nf.setFile(m_logName);
00788 nf.setName(info.fileName());
00789 nf.writeLink();
00790 m_recordLog->setText( tr("Start log") );
00791 m_recordingLog = false;
00792 currentSession()->emulationHandler()->clearLog();
00793 } else {
00794 QMap<QString, QStringList> map;
00795 QStringList text;
00796 text << "text/plain";
00797 map.insert(tr("Log"), text );
00798 Opie::Core::OConfig cfg("opie-console");
00799 cfg.setGroup("defaults");
00800 QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
00801 QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
00802 if (m_logName.isEmpty() ) return;
00803
00804 m_recordLog->setText( tr("Stop log") );
00805 m_recordingLog = true;
00806 currentSession()->emulationHandler()->startLogging(m_logName);
00807 }
00808 }
00809
00810 void MainWindow::slotSaveHistory() {
00811 QMap<QString, QStringList> map;
00812 QStringList text;
00813 text << "text/plain";
00814 map.insert(tr("History"), text );
00815 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
00816 if (filename.isEmpty() ) return;
00817
00818 QFileInfo info(filename);
00819
00820 DocLnk nf;
00821 nf.setType("text/plain");
00822 nf.setFile(filename);
00823 nf.setName(info.fileName());
00824
00825
00826 QFile file(filename);
00827 file.open(IO_WriteOnly );
00828 QTextStream str(&file );
00829 if ( currentSession() )
00830 currentSession()->emulationHandler()->emulation()->streamHistory(&str);
00831
00832 file.close();
00833 nf.writeLink();
00834 }