-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 @@ -62,9 +62,8 @@ void EmulationHandler::recv( const QByteArray& ar) { 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); } 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 @@ -9,8 +9,11 @@ #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" @@ -43,8 +46,9 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow( m_manager->load(); initUI(); populateProfiles(); + populateScripts(); } void MainWindow::initUI() { setToolBarsMovable( FALSE ); @@ -55,8 +59,9 @@ void MainWindow::initUI() { 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); @@ -149,19 +154,19 @@ void MainWindow::initUI() { /* * 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 */ @@ -215,11 +220,11 @@ void MainWindow::initUI() { 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 ); /* @@ -248,8 +253,23 @@ void MainWindow::populateProfiles() { 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(); } @@ -278,40 +298,42 @@ 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() { @@ -324,10 +346,9 @@ void MainWindow::slotConnect() { 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); } } } @@ -338,9 +359,9 @@ void MainWindow::slotDisconnect() { 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() { @@ -389,9 +410,9 @@ void MainWindow::slotClose() { 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 ); } @@ -432,9 +453,9 @@ void MainWindow::create( const Profile& prof ) { 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()) { @@ -486,17 +507,17 @@ void MainWindow::slotSessionChanged( Session* 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 ); 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 @@ -20,9 +20,9 @@ class TabWidget; class ProfileManager; class Profile; class FunctionKeyboard; class FKey; - +class DocLnk; class MainWindow : public QMainWindow { Q_OBJECT public: @@ -64,9 +64,9 @@ private slots: 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); @@ -79,8 +79,9 @@ private slots: private: void initUI(); void populateProfiles(); + void populateScripts(); void create( const Profile& ); /** * the current session */ @@ -89,8 +90,9 @@ private: /** * the session list */ QList<Session> m_sessions; + QList<DocLnk> m_scriptsData; /** * the metafactory */ @@ -104,8 +106,9 @@ private: 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; @@ -114,13 +117,13 @@ private: 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; }; |