Diffstat (limited to 'noncore/apps/opie-console/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 87 |
1 files changed, 54 insertions, 33 deletions
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 @@ -11,4 +11,7 @@ #include <qpe/resource.h> +#include <qpe/qpeapplication.h> +#include <qpe/filemanager.h> +#include <qpe/mimetype.h> #include <opie/ofiledialog.h> @@ -45,4 +48,5 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow( initUI(); populateProfiles(); + populateScripts(); } void MainWindow::initUI() { @@ -57,4 +61,5 @@ void MainWindow::initUI() { m_scripts = new QPopupMenu( this ); m_sessionsPop= new QPopupMenu( this ); + m_scriptsPop = new QPopupMenu( this ); /* add a toolbar for icons */ @@ -151,4 +156,7 @@ 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); @@ -159,7 +167,4 @@ void MainWindow::initUI() { 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())); /* @@ -217,7 +222,7 @@ void MainWindow::initUI() { 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 ); @@ -250,4 +255,19 @@ 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() { delete m_factory; @@ -280,4 +300,6 @@ void MainWindow::slotRecordScript() { if (currentSession()) { currentSession()->emulationHandler()->startRecording(); + m_saveScript->setEnabled(true); + m_recordScript->setEnabled(false); } } @@ -285,31 +307,31 @@ void MainWindow::slotRecordScript() { 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); } } @@ -326,6 +348,5 @@ void MainWindow::slotConnect() { m_transfer->setEnabled( true ); m_recordScript->setEnabled( true ); - m_saveScript->setEnabled( true ); - m_runScript->setEnabled( true ); + m_scripts->setItemEnabled(m_runScript_id, true); } } @@ -340,5 +361,5 @@ void MainWindow::slotDisconnect() { m_recordScript->setEnabled( false); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); } } @@ -391,5 +412,5 @@ void MainWindow::slotClose() { 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 ); @@ -434,5 +455,5 @@ void MainWindow::create( const Profile& prof ) { 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 @@ -488,7 +509,7 @@ void MainWindow::slotSessionChanged( Session* ses ) { 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 ); @@ -496,5 +517,5 @@ void MainWindow::slotSessionChanged( Session* ses ) { m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); - m_runScript->setEnabled( false ); + m_scripts->setItemEnabled(m_runScript_id, false); } |