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 @@ -60,13 +60,12 @@ 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; 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 @@ -7,12 +7,15 @@ #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" @@ -41,24 +44,26 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow( 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 @@ -147,23 +152,23 @@ void MainWindow::initUI() { 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" ), @@ -213,15 +218,15 @@ void MainWindow::initUI() { 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 */ @@ -246,12 +251,27 @@ void MainWindow::populateProfiles() { 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() { @@ -276,44 +296,46 @@ void MainWindow::slotNew() { } } 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(); @@ -322,27 +344,26 @@ void MainWindow::slotConnect() { 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(); @@ -387,13 +408,13 @@ void MainWindow::slotClose() { 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(); } @@ -430,13 +451,13 @@ void MainWindow::create( const Profile& prof ) { 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(); } @@ -484,21 +505,21 @@ void MainWindow::slotSessionChanged( Session* ses ) { 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 ); 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 @@ -18,13 +18,13 @@ 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(); @@ -62,13 +62,13 @@ private slots: 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(); @@ -77,22 +77,24 @@ private slots: /* 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; @@ -102,27 +104,28 @@ private: 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; }; |