author | wazlaf <wazlaf> | 2002-10-24 19:23:56 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-10-24 19:23:56 (UTC) |
commit | 1fb831ed1804a22455b5e4c9c8d9411e098c17e8 (patch) (side-by-side diff) | |
tree | 6c3eac70c91c5a82b2f010f41c5d1dee09638c7a | |
parent | 2f2f9dc5f45fe7cf194a057e104c2d54394e4cef (diff) | |
download | opie-1fb831ed1804a22455b5e4c9c8d9411e098c17e8.zip opie-1fb831ed1804a22455b5e4c9c8d9411e098c17e8.tar.gz opie-1fb831ed1804a22455b5e4c9c8d9411e098c17e8.tar.bz2 |
scripting changes: scripts are now available in a pop-down menu and are managed using DocLnks
-rw-r--r-- | noncore/apps/opie-console/emulation_handler.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 87 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.h | 9 |
3 files changed, 60 insertions, 37 deletions
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp index b2b107e..e80168d 100644 --- a/noncore/apps/opie-console/emulation_handler.cpp +++ b/noncore/apps/opie-console/emulation_handler.cpp @@ -42,49 +42,48 @@ void EmulationHandler::load( const Profile& prof) { m_teWid->setBackgroundColor(backColor(num) ); int term = prof.readNumEntry("Terminal", 0) ; switch(term) { default: case Profile::VT102: case Profile::VT100: m_teEmu->setKeytrans("vt100.keytab"); break; case Profile::Linux: m_teEmu->setKeytrans("linux.keytab"); break; case Profile::XTerm: m_teEmu->setKeytrans("default.Keytab"); break; } } void EmulationHandler::recv( const QByteArray& ar) { m_teEmu->onRcvBlock(ar.data(), ar.count() ); } void EmulationHandler::recvEmulation(const char* src, int len ) { QByteArray ar(len); memcpy(ar.data(), src, sizeof(char) * len ); - if (isRecording()) m_script->append(ar); emit send(ar); } QWidget* EmulationHandler::widget() { return m_teWid; } /* * allocate a new table of colors */ void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { ColorEntry table[TABLE_COLORS]; const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); for (int i = 0; i < TABLE_COLORS; i++ ) { if ( i == 0 || i == 10 ) { table[i].color = fore; }else if ( i == 1 || i == 11 ) { table[i].color = back; table[i].transparent = 0; }else { table[i].color = defaultCt[i].color; } } diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 44ef458..2e00a07 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp @@ -1,82 +1,87 @@ #include <assert.h> #include <qaction.h> #include <qmenubar.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qtoolbar.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qwhatsthis.h> #include <qpe/resource.h> +#include <qpe/qpeapplication.h> +#include <qpe/filemanager.h> +#include <qpe/mimetype.h> #include <opie/ofiledialog.h> #include "keytrans.h" #include "profileeditordialog.h" #include "configdialog.h" #include "default.h" #include "metafactory.h" #include "profile.h" #include "profilemanager.h" #include "mainwindow.h" #include "tabwidget.h" #include "transferdialog.h" #include "function_keyboard.h" #include "emulation_handler.h" #include "script.h" MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { KeyTrans::loadAll(); for (int i = 0; i < KeyTrans::count(); i++ ) { KeyTrans* s = KeyTrans::find(i ); assert( s ); } m_factory = new MetaFactory(); Default def(m_factory); m_sessions.setAutoDelete( TRUE ); m_curSession = 0; m_manager = new ProfileManager( m_factory ); m_manager->load(); initUI(); populateProfiles(); + populateScripts(); } void MainWindow::initUI() { setToolBarsMovable( FALSE ); /* tool bar for the menu */ m_tool = new QToolBar( this ); m_tool->setHorizontalStretchable( TRUE ); m_bar = new QMenuBar( m_tool ); m_console = new QPopupMenu( this ); m_scripts = new QPopupMenu( this ); m_sessionsPop= new QPopupMenu( this ); + m_scriptsPop = new QPopupMenu( this ); /* add a toolbar for icons */ m_icons = new QToolBar(this); /* * the settings action */ m_setProfiles = new QAction(tr("Configure Profiles"), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0); m_setProfiles->addTo( m_console ); connect( m_setProfiles, SIGNAL(activated() ), this, SLOT(slotConfigure() ) ); m_console->insertSeparator(); /* * new Action for new sessions */ QAction* newCon = new QAction(tr("New Connection"), Resource::loadPixmap( "new" ), QString::null, 0, this, 0); newCon->addTo( m_console ); connect( newCon, SIGNAL(activated() ), this, SLOT(slotNew() ) ); @@ -129,59 +134,59 @@ void MainWindow::initUI() { m_fullscreen->addTo( m_console ); connect( m_fullscreen, SIGNAL( activated() ), this, SLOT( slotFullscreen() ) ); m_console->insertSeparator(); /* * terminate action */ m_terminate = new QAction(); m_terminate->setText( tr("Terminate") ); m_terminate->addTo( m_console ); connect(m_terminate, SIGNAL(activated() ), this, SLOT(slotTerminate() ) ); m_closewindow = new QAction(); m_closewindow->setText( tr("Close Window") ); m_closewindow->addTo( m_console ); connect( m_closewindow, SIGNAL(activated() ), this, SLOT(slotClose() ) ); /* * script actions */ + m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); + connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); + m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); m_recordScript->addTo(m_scripts); connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); m_saveScript->addTo(m_scripts); connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); - m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0); - m_runScript->addTo(m_scripts); - connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript())); /* * action that open/closes the keyboard */ m_openKeys = new QAction (tr("Open Keyboard..."), Resource::loadPixmap( "console/keys/keyboard_icon" ), QString::null, 0, this, 0); m_openKeys->setToggleAction(true); connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); /* insert the submenu */ m_console->insertItem(tr("New from Profile"), m_sessionsPop, -1, 0); /* insert the connection menu */ m_bar->insertItem( tr("Connection"), m_console ); /* the scripts menu */ m_bar->insertItem( tr("Scripts"), m_scripts ); /* and the keyboard */ m_keyBar = new QToolBar(this); addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); m_keyBar->setHorizontalStretchable( TRUE ); @@ -195,172 +200,188 @@ void MainWindow::initUI() { QAction *a = new QAction(tr("Copy"), Resource::loadPixmap("copy"), QString::null, 0, this, 0 ); //a->addTo( m_icons ); connect( a, SIGNAL(activated() ), this, SLOT(slotCopy() ) ); QAction *paste = new QAction(tr("Paste"), Resource::loadPixmap("paste"), QString::null, 0, this, 0 ); connect( paste, SIGNAL(activated() ), this, SLOT(slotPaste() ) ); newCon->addTo( m_icons ); m_setProfiles->addTo( m_icons ); paste->addTo( m_icons ); m_openKeys->addTo(m_icons); m_fullscreen->addTo( m_icons ); m_connect->setEnabled( false ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( false ); m_transfer->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); m_fullscreen->setEnabled( false ); m_closewindow->setEnabled( false ); /* * connect to the menu activation */ connect( m_sessionsPop, SIGNAL(activated( int ) ), this, SLOT(slotProfile( int ) ) ); m_consoleWindow = new TabWidget( this, "blah"); connect(m_consoleWindow, SIGNAL(activated(Session*) ), this, SLOT(slotSessionChanged(Session*) ) ); setCentralWidget( m_consoleWindow ); } ProfileManager* MainWindow::manager() { return m_manager; } TabWidget* MainWindow::tabWidget() { return m_consoleWindow; } void MainWindow::populateProfiles() { m_sessionsPop->clear(); Profile::ValueList list = manager()->all(); for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { m_sessionsPop->insertItem( (*it).name() ); } } + +void MainWindow::populateScripts() { + m_scriptsPop->clear(); + m_scriptsData.clear(); + DocLnkSet files(QPEApplication::documentDir(), "text/plain"); + QListIterator<DocLnk> dit(files.children()); + for (; dit.current(); ++dit) { + if (*dit && (*dit)->name().length()>0) { + m_scriptsData.append((*dit)); + m_scriptsPop->insertItem((*dit)->name()); + } + } + +} + MainWindow::~MainWindow() { delete m_factory; manager()->save(); } MetaFactory* MainWindow::factory() { return m_factory; } Session* MainWindow::currentSession() { return m_curSession; } QList<Session> MainWindow::sessions() { return m_sessions; } void MainWindow::slotNew() { ProfileEditorDialog dlg(factory() ); dlg.showMaximized(); int ret = dlg.exec(); if ( ret == QDialog::Accepted ) { create( dlg.profile() ); } } void MainWindow::slotRecordScript() { if (currentSession()) { currentSession()->emulationHandler()->startRecording(); + m_saveScript->setEnabled(true); + m_recordScript->setEnabled(false); } } void MainWindow::slotSaveScript() { if (currentSession() && currentSession()->emulationHandler()->isRecording()) { - MimeTypes types; - QStringList script; - script << "text/plain"; - script << "text/all"; - script << "application/octet-stream"; - types.insert("Script", script); - QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); + QMap<QString, QStringList> map; + QStringList text; + text << "text/plain"; + map.insert(tr("Script"), text ); + QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); if (!filename.isEmpty()) { - currentSession()->emulationHandler()->script()->saveTo(filename); + DocLnk nf; + nf.setType("text/plain"); + nf.setFile(filename); + nf.setName(filename); + FileManager fm; + fm.saveFile(nf, currentSession()->emulationHandler()->script()->script()); currentSession()->emulationHandler()->clearScript(); + m_saveScript->setEnabled(false); + m_recordScript->setEnabled(true); + populateScripts(); } } } -void MainWindow::slotRunScript() { +void MainWindow::slotRunScript(int id) { if (currentSession()) { - MimeTypes types; - QStringList script; - script << "text/plain"; - script << "text/all"; - script << "application/octet-stream"; - types.insert("Script", script); - QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); - if (!filename.isEmpty()) { - Script script(DocLnk(filename).file()); - currentSession()->emulationHandler()->runScript(&script); - } + DocLnk *lnk = m_scriptsData.at(m_scriptsPop->indexOf(id)); + QString filePath = lnk->file(); + printf("path is : %s\n", filePath.latin1()); + Script script(filePath); + currentSession()->emulationHandler()->runScript(&script); } } void MainWindow::slotConnect() { if ( currentSession() ) { bool ret = currentSession()->layer()->open(); if(!ret) QMessageBox::warning(currentSession()->widgetStack(), QObject::tr("Failed"), QObject::tr("Connecting failed for this session.")); else { m_connect->setEnabled( false ); m_disconnect->setEnabled( true ); m_transfer->setEnabled( true ); m_recordScript->setEnabled( true ); - m_saveScript->setEnabled( true ); - m_runScript->setEnabled( true ); + m_scripts->setItemEnabled(m_runScript_id, true); } } } void MainWindow::slotDisconnect() { if ( currentSession() ) { currentSession()->layer()->close(); m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); } } void MainWindow::slotTerminate() { if ( currentSession() ) currentSession()->layer()->close(); slotClose(); /* FIXME move to the next session */ } void MainWindow::slotConfigure() { ConfigDialog conf( manager()->all(), factory() ); conf.showMaximized(); int ret = conf.exec(); if ( QDialog::Accepted == ret ) { manager()->setProfiles( conf.list() ); manager()->save(); populateProfiles(); } } /* @@ -369,92 +390,92 @@ void MainWindow::slotConfigure() { * remove it from the list * delete it * and set the currentSession() */ void MainWindow::slotClose() { if (!currentSession() ) return; Session* ses = currentSession(); qWarning("removing! currentSession %s", currentSession()->name().latin1() ); /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ m_curSession = NULL; tabWidget()->remove( /*currentSession()*/ses ); /*it's autodelete */ m_sessions.remove( ses ); qWarning("after remove!!"); if (!currentSession() ) { m_connect->setEnabled( false ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( false ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); m_fullscreen->setEnabled( false ); m_closewindow->setEnabled( false ); } m_kb->loadDefaults(); } /* * We will get the name * Then the profile * and then we will make a profile */ void MainWindow::slotProfile( int id) { Profile prof = manager()->profile( m_sessionsPop->text( id) ); create( prof ); } void MainWindow::create( const Profile& prof ) { Session *ses = manager()->fromProfile( prof, tabWidget() ); if((!ses) || (!ses->layer()) || (!ses->widgetStack())) { QMessageBox::warning(this, QObject::tr("Session failed"), QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); //if(ses) delete ses; return; } m_sessions.append( ses ); tabWidget()->add( ses ); tabWidget()->repaint(); m_curSession = ses; // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( true ); m_fullscreen->setEnabled( true ); m_closewindow->setEnabled( true ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); // is io_layer wants direct connection, then autoconnect //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { if (prof.autoConnect()) { slotConnect(); } QWidget *w = currentSession()->widget(); if(w) w->setFocus(); m_kb->load(currentSession()->profile()); } void MainWindow::slotTransfer() { if ( currentSession() ) { TransferDialog dlg(currentSession()->widgetStack(), this); dlg.showMaximized(); //currentSession()->widgetStack()->add(dlg); dlg.exec(); } } @@ -466,57 +487,57 @@ void MainWindow::slotOpenKeb(bool state) { else m_keyBar->hide(); } void MainWindow::slotOpenButtons( bool state ) { if ( state ) { m_buttonBar->show(); } else { m_buttonBar->hide(); } } void MainWindow::slotSessionChanged( Session* ses ) { qWarning("changed!"); if ( ses ) { m_curSession = ses; qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) ); if ( m_curSession->layer()->isConnected() ) { m_connect->setEnabled( false ); m_disconnect->setEnabled( true ); - m_recordScript->setEnabled( true ); - m_saveScript->setEnabled( true ); - m_runScript->setEnabled( true ); + m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording()); + m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording()); + m_scripts->setItemEnabled(m_runScript_id, true); } else { m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); } if ( ( m_curSession->layer() )->supports()[1] == 0 ) { m_transfer->setEnabled( false ); } else { m_transfer->setEnabled( true ); } QWidget *w = m_curSession->widget(); if(w) w->setFocus(); m_kb->load(currentSession()->profile()); } } void MainWindow::slotFullscreen() { if ( m_isFullscreen ) { diff --git a/noncore/apps/opie-console/mainwindow.h b/noncore/apps/opie-console/mainwindow.h index 19d3a3d..3b16f0a 100644 --- a/noncore/apps/opie-console/mainwindow.h +++ b/noncore/apps/opie-console/mainwindow.h @@ -1,129 +1,132 @@ #ifndef OPIE_MAIN_WINDOW_H #define OPIE_MAIN_WINDOW_H #include <qmainwindow.h> #include <qlist.h> #include "session.h" /** * this is the MainWindow of the new opie console * it's also the dispatcher between the different * actions supported by the gui */ class QToolBar; class QToolButton; class QMenuBar; class QAction; class MetaFactory; class TabWidget; class ProfileManager; class Profile; class FunctionKeyboard; class FKey; - +class DocLnk; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow( QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ); ~MainWindow(); /** * our factory to generate IOLayer and so on * */ MetaFactory* factory(); /** * A session contains a QWidget*, * an IOLayer* and some infos for us */ Session* currentSession(); /** * the session list */ QList<Session> sessions(); /** * */ ProfileManager* manager(); TabWidget* tabWidget(); private slots: void slotNew(); void slotConnect(); void slotDisconnect(); void slotTerminate(); void slotConfigure(); void slotClose(); void slotProfile(int); void slotTransfer(); void slotOpenKeb(bool); void slotOpenButtons(bool); void slotRecordScript(); void slotSaveScript(); - void slotRunScript(); + void slotRunScript(int); void slotFullscreen(); void slotSessionChanged( Session* ); void slotKeyReceived(FKey, ushort, ushort, bool); /* what could these both slot do? */ void slotCopy(); void slotPaste(); /* save the currentSession() to Profiles */ void slotSaveSession(); private: void initUI(); void populateProfiles(); + void populateScripts(); void create( const Profile& ); /** * the current session */ Session* m_curSession; /** * the session list */ QList<Session> m_sessions; + QList<DocLnk> m_scriptsData; /** * the metafactory */ MetaFactory* m_factory; ProfileManager* m_manager; TabWidget* m_consoleWindow; QToolBar* m_tool; QToolBar* m_icons; QToolBar* m_keyBar; QToolBar* m_buttonBar; QMenuBar* m_bar; QPopupMenu* m_console; QPopupMenu* m_sessionsPop; + QPopupMenu* m_scriptsPop; QPopupMenu* m_scripts; QAction* m_connect; QAction* m_disconnect; QAction* m_terminate; QAction* m_transfer; QAction* m_setProfiles; QAction* m_openKeys; QAction* m_openButtons; QAction* m_recordScript; QAction* m_saveScript; - QAction* m_runScript; QAction* m_fullscreen; QAction* m_closewindow; FunctionKeyboard *m_kb; + int m_runScript_id; bool m_isFullscreen; QWidget* savedParentFullscreen; }; #endif |