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 @@ -65,3 +65,2 @@ void EmulationHandler::recvEmulation(const char* src, int len ) { memcpy(ar.data(), src, sizeof(char) * len ); - if (isRecording()) 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 @@ -12,2 +12,5 @@ #include <qpe/resource.h> +#include <qpe/qpeapplication.h> +#include <qpe/filemanager.h> +#include <qpe/mimetype.h> @@ -46,2 +49,3 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow( populateProfiles(); + populateScripts(); } @@ -58,2 +62,3 @@ void MainWindow::initUI() { m_sessionsPop= new QPopupMenu( this ); + m_scriptsPop = new QPopupMenu( this ); @@ -152,2 +157,5 @@ void MainWindow::initUI() { */ + 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); @@ -160,5 +168,2 @@ void MainWindow::initUI() { - 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())); @@ -218,5 +223,5 @@ void MainWindow::initUI() { 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 ); @@ -251,2 +256,17 @@ void MainWindow::populateProfiles() { } + +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() { @@ -281,2 +301,4 @@ void MainWindow::slotRecordScript() { currentSession()->emulationHandler()->startRecording(); + m_saveScript->setEnabled(true); + m_recordScript->setEnabled(false); } @@ -286,12 +308,18 @@ 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(); } @@ -300,15 +328,9 @@ void MainWindow::slotSaveScript() { -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); } @@ -327,4 +349,3 @@ void MainWindow::slotConnect() { m_recordScript->setEnabled( true ); - m_saveScript->setEnabled( true ); - m_runScript->setEnabled( true ); + m_scripts->setItemEnabled(m_runScript_id, true); } @@ -341,3 +362,3 @@ void MainWindow::slotDisconnect() { m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); } @@ -392,3 +413,3 @@ void MainWindow::slotClose() { m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); m_fullscreen->setEnabled( false ); @@ -435,3 +456,3 @@ void MainWindow::create( const Profile& prof ) { m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); @@ -489,5 +510,5 @@ void MainWindow::slotSessionChanged( Session* ses ) { 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 { @@ -497,3 +518,3 @@ void MainWindow::slotSessionChanged( Session* ses ) { m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, 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 @@ -23,3 +23,3 @@ class FunctionKeyboard; class FKey; - +class DocLnk; @@ -67,3 +67,3 @@ private slots: void slotSaveScript(); - void slotRunScript(); + void slotRunScript(int); void slotFullscreen(); @@ -82,2 +82,3 @@ private: void populateProfiles(); + void populateScripts(); void create( const Profile& ); @@ -92,2 +93,3 @@ private: QList<Session> m_sessions; + QList<DocLnk> m_scriptsData; @@ -107,2 +109,3 @@ private: QPopupMenu* m_sessionsPop; + QPopupMenu* m_scriptsPop; QPopupMenu* m_scripts; @@ -117,3 +120,2 @@ private: QAction* m_saveScript; - QAction* m_runScript; QAction* m_fullscreen; @@ -122,2 +124,3 @@ private: FunctionKeyboard *m_kb; + int m_runScript_id; bool m_isFullscreen; |