summaryrefslogtreecommitdiff
authorwazlaf <wazlaf>2002-10-24 19:23:56 (UTC)
committer wazlaf <wazlaf>2002-10-24 19:23:56 (UTC)
commit1fb831ed1804a22455b5e4c9c8d9411e098c17e8 (patch) (side-by-side diff)
tree6c3eac70c91c5a82b2f010f41c5d1dee09638c7a
parent2f2f9dc5f45fe7cf194a057e104c2d54394e4cef (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/emulation_handler.cpp1
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp87
-rw-r--r--noncore/apps/opie-console/mainwindow.h9
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
@@ -63,7 +63,6 @@ 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
@@ -10,6 +10,9 @@
#include <qwhatsthis.h>
#include <qpe/resource.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/filemanager.h>
+#include <qpe/mimetype.h>
#include <opie/ofiledialog.h>
@@ -44,6 +47,7 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(
initUI();
populateProfiles();
+ populateScripts();
}
void MainWindow::initUI() {
setToolBarsMovable( FALSE );
@@ -56,6 +60,7 @@ void MainWindow::initUI() {
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);
@@ -150,6 +155,9 @@ 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()));
@@ -158,9 +166,6 @@ void MainWindow::initUI() {
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
@@ -216,9 +221,9 @@ void MainWindow::initUI() {
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 );
@@ -249,6 +254,21 @@ 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;
manager()->save();
@@ -279,38 +299,40 @@ 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);
}
}
@@ -325,8 +347,7 @@ void MainWindow::slotConnect() {
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);
}
}
}
@@ -339,7 +360,7 @@ void MainWindow::slotDisconnect() {
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false);
m_saveScript->setEnabled( false );
- m_runScript->setEnabled( false );
+ m_scripts->setItemEnabled(m_runScript_id, false);
}
}
@@ -390,7 +411,7 @@ void MainWindow::slotClose() {
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 );
}
@@ -433,7 +454,7 @@ void MainWindow::create( const Profile& prof ) {
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 ) {
@@ -487,15 +508,15 @@ void MainWindow::slotSessionChanged( Session* ses ) {
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 ) {
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
@@ -21,7 +21,7 @@ class ProfileManager;
class Profile;
class FunctionKeyboard;
class FKey;
-
+class DocLnk;
class MainWindow : public QMainWindow {
Q_OBJECT
@@ -65,7 +65,7 @@ private slots:
void slotOpenButtons(bool);
void slotRecordScript();
void slotSaveScript();
- void slotRunScript();
+ void slotRunScript(int);
void slotFullscreen();
void slotSessionChanged( Session* );
void slotKeyReceived(FKey, ushort, ushort, bool);
@@ -80,6 +80,7 @@ private slots:
private:
void initUI();
void populateProfiles();
+ void populateScripts();
void create( const Profile& );
/**
* the current session
@@ -90,6 +91,7 @@ private:
* the session list
*/
QList<Session> m_sessions;
+ QList<DocLnk> m_scriptsData;
/**
* the metafactory
@@ -105,6 +107,7 @@ private:
QMenuBar* m_bar;
QPopupMenu* m_console;
QPopupMenu* m_sessionsPop;
+ QPopupMenu* m_scriptsPop;
QPopupMenu* m_scripts;
QAction* m_connect;
QAction* m_disconnect;
@@ -115,11 +118,11 @@ private:
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;