author | zecke <zecke> | 2002-10-21 22:35:37 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-21 22:35:37 (UTC) |
commit | d6a40efdb9d81d39972a1304bd62ac60bb45e996 (patch) (unidiff) | |
tree | 47cc96d6457e809621f40610737407532f04f98c | |
parent | 151729eb3e4e4cfbb69db1f027e74188cf55c328 (diff) | |
download | opie-d6a40efdb9d81d39972a1304bd62ac60bb45e996.zip opie-d6a40efdb9d81d39972a1304bd62ac60bb45e996.tar.gz opie-d6a40efdb9d81d39972a1304bd62ac60bb45e996.tar.bz2 |
Fix scriptiong Open the file before reading from it
Add text/all to the mimetypes this makes recording, saving and
running work
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/script.cpp | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index afac542..7ffeca7 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp | |||
@@ -235,142 +235,144 @@ void MainWindow::initUI() { | |||
235 | * connect to the menu activation | 235 | * connect to the menu activation |
236 | */ | 236 | */ |
237 | connect( m_sessionsPop, SIGNAL(activated( int ) ), | 237 | connect( m_sessionsPop, SIGNAL(activated( int ) ), |
238 | this, SLOT(slotProfile( int ) ) ); | 238 | this, SLOT(slotProfile( int ) ) ); |
239 | 239 | ||
240 | m_consoleWindow = new TabWidget( this, "blah"); | 240 | m_consoleWindow = new TabWidget( this, "blah"); |
241 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), | 241 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), |
242 | this, SLOT(slotSessionChanged(Session*) ) ); | 242 | this, SLOT(slotSessionChanged(Session*) ) ); |
243 | setCentralWidget( m_consoleWindow ); | 243 | setCentralWidget( m_consoleWindow ); |
244 | 244 | ||
245 | } | 245 | } |
246 | 246 | ||
247 | ProfileManager* MainWindow::manager() { | 247 | ProfileManager* MainWindow::manager() { |
248 | return m_manager; | 248 | return m_manager; |
249 | } | 249 | } |
250 | TabWidget* MainWindow::tabWidget() { | 250 | TabWidget* MainWindow::tabWidget() { |
251 | return m_consoleWindow; | 251 | return m_consoleWindow; |
252 | } | 252 | } |
253 | void MainWindow::populateProfiles() { | 253 | void MainWindow::populateProfiles() { |
254 | m_sessionsPop->clear(); | 254 | m_sessionsPop->clear(); |
255 | Profile::ValueList list = manager()->all(); | 255 | Profile::ValueList list = manager()->all(); |
256 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { | 256 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { |
257 | m_sessionsPop->insertItem( (*it).name() ); | 257 | m_sessionsPop->insertItem( (*it).name() ); |
258 | } | 258 | } |
259 | 259 | ||
260 | } | 260 | } |
261 | MainWindow::~MainWindow() { | 261 | MainWindow::~MainWindow() { |
262 | delete m_factory; | 262 | delete m_factory; |
263 | manager()->save(); | 263 | manager()->save(); |
264 | } | 264 | } |
265 | 265 | ||
266 | MetaFactory* MainWindow::factory() { | 266 | MetaFactory* MainWindow::factory() { |
267 | return m_factory; | 267 | return m_factory; |
268 | } | 268 | } |
269 | 269 | ||
270 | Session* MainWindow::currentSession() { | 270 | Session* MainWindow::currentSession() { |
271 | return m_curSession; | 271 | return m_curSession; |
272 | } | 272 | } |
273 | 273 | ||
274 | QList<Session> MainWindow::sessions() { | 274 | QList<Session> MainWindow::sessions() { |
275 | return m_sessions; | 275 | return m_sessions; |
276 | } | 276 | } |
277 | 277 | ||
278 | void MainWindow::slotNew() { | 278 | void MainWindow::slotNew() { |
279 | ProfileEditorDialog dlg(factory() ); | 279 | ProfileEditorDialog dlg(factory() ); |
280 | dlg.showMaximized(); | 280 | dlg.showMaximized(); |
281 | int ret = dlg.exec(); | 281 | int ret = dlg.exec(); |
282 | 282 | ||
283 | if ( ret == QDialog::Accepted ) { | 283 | if ( ret == QDialog::Accepted ) { |
284 | create( dlg.profile() ); | 284 | create( dlg.profile() ); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | void MainWindow::slotRecordScript() { | 288 | void MainWindow::slotRecordScript() { |
289 | if (currentSession()) { | 289 | if (currentSession()) { |
290 | currentSession()->emulationHandler()->startRecording(); | 290 | currentSession()->emulationHandler()->startRecording(); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | 293 | ||
294 | void MainWindow::slotSaveScript() { | 294 | void MainWindow::slotSaveScript() { |
295 | if (currentSession() && currentSession()->emulationHandler()->isRecording()) { | 295 | if (currentSession() && currentSession()->emulationHandler()->isRecording()) { |
296 | MimeTypes types; | 296 | MimeTypes types; |
297 | QStringList script; | 297 | QStringList script; |
298 | script << "text/plain"; | 298 | script << "text/plain"; |
299 | script << "text/all"; | ||
299 | types.insert("Script", script); | 300 | types.insert("Script", script); |
300 | QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); | 301 | QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); |
301 | if (!filename.isEmpty()) { | 302 | if (!filename.isEmpty()) { |
302 | currentSession()->emulationHandler()->script()->saveTo(filename); | 303 | currentSession()->emulationHandler()->script()->saveTo(filename); |
303 | currentSession()->emulationHandler()->clearScript(); | 304 | currentSession()->emulationHandler()->clearScript(); |
304 | } | 305 | } |
305 | } | 306 | } |
306 | } | 307 | } |
307 | 308 | ||
308 | void MainWindow::slotRunScript() { | 309 | void MainWindow::slotRunScript() { |
309 | if (currentSession()) { | 310 | if (currentSession()) { |
310 | MimeTypes types; | 311 | MimeTypes types; |
311 | QStringList script; | 312 | QStringList script; |
312 | script << "text/plain"; | 313 | script << "text/plain"; |
314 | script << "text/all"; | ||
313 | types.insert("Script", script); | 315 | types.insert("Script", script); |
314 | QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); | 316 | QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); |
315 | if (!filename.isEmpty()) { | 317 | if (!filename.isEmpty()) { |
316 | Script script(DocLnk(filename).file()); | 318 | Script script(DocLnk(filename).file()); |
317 | currentSession()->emulationHandler()->runScript(&script); | 319 | currentSession()->emulationHandler()->runScript(&script); |
318 | } | 320 | } |
319 | } | 321 | } |
320 | } | 322 | } |
321 | 323 | ||
322 | void MainWindow::slotConnect() { | 324 | void MainWindow::slotConnect() { |
323 | if ( currentSession() ) { | 325 | if ( currentSession() ) { |
324 | bool ret = currentSession()->layer()->open(); | 326 | bool ret = currentSession()->layer()->open(); |
325 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), | 327 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), |
326 | QObject::tr("Failed"), | 328 | QObject::tr("Failed"), |
327 | QObject::tr("Connecting failed for this session.")); | 329 | QObject::tr("Connecting failed for this session.")); |
328 | else { | 330 | else { |
329 | m_connect->setEnabled( false ); | 331 | m_connect->setEnabled( false ); |
330 | m_disconnect->setEnabled( true ); | 332 | m_disconnect->setEnabled( true ); |
331 | } | 333 | } |
332 | } | 334 | } |
333 | } | 335 | } |
334 | 336 | ||
335 | void MainWindow::slotDisconnect() { | 337 | void MainWindow::slotDisconnect() { |
336 | if ( currentSession() ) { | 338 | if ( currentSession() ) { |
337 | currentSession()->layer()->close(); | 339 | currentSession()->layer()->close(); |
338 | m_connect->setEnabled( true ); | 340 | m_connect->setEnabled( true ); |
339 | m_disconnect->setEnabled( false ); | 341 | m_disconnect->setEnabled( false ); |
340 | } | 342 | } |
341 | } | 343 | } |
342 | 344 | ||
343 | void MainWindow::slotTerminate() { | 345 | void MainWindow::slotTerminate() { |
344 | if ( currentSession() ) | 346 | if ( currentSession() ) |
345 | currentSession()->layer()->close(); | 347 | currentSession()->layer()->close(); |
346 | 348 | ||
347 | slotClose(); | 349 | slotClose(); |
348 | /* FIXME move to the next session */ | 350 | /* FIXME move to the next session */ |
349 | } | 351 | } |
350 | 352 | ||
351 | void MainWindow::slotConfigure() { | 353 | void MainWindow::slotConfigure() { |
352 | ConfigDialog conf( manager()->all(), factory() ); | 354 | ConfigDialog conf( manager()->all(), factory() ); |
353 | conf.showMaximized(); | 355 | conf.showMaximized(); |
354 | 356 | ||
355 | int ret = conf.exec(); | 357 | int ret = conf.exec(); |
356 | 358 | ||
357 | if ( QDialog::Accepted == ret ) { | 359 | if ( QDialog::Accepted == ret ) { |
358 | manager()->setProfiles( conf.list() ); | 360 | manager()->setProfiles( conf.list() ); |
359 | manager()->save(); | 361 | manager()->save(); |
360 | populateProfiles(); | 362 | populateProfiles(); |
361 | } | 363 | } |
362 | } | 364 | } |
363 | /* | 365 | /* |
364 | * we will remove | 366 | * we will remove |
365 | * this window from the tabwidget | 367 | * this window from the tabwidget |
366 | * remove it from the list | 368 | * remove it from the list |
367 | * delete it | 369 | * delete it |
368 | * and set the currentSession() | 370 | * and set the currentSession() |
369 | */ | 371 | */ |
370 | void MainWindow::slotClose() { | 372 | void MainWindow::slotClose() { |
371 | if (!currentSession() ) | 373 | if (!currentSession() ) |
372 | return; | 374 | return; |
373 | 375 | ||
374 | Session* ses = currentSession(); | 376 | Session* ses = currentSession(); |
375 | qWarning("removing! currentSession %s", currentSession()->name().latin1() ); | 377 | qWarning("removing! currentSession %s", currentSession()->name().latin1() ); |
376 | /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ | 378 | /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ |
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp index 9cb1cd3..e6e9d6d 100644 --- a/noncore/apps/opie-console/script.cpp +++ b/noncore/apps/opie-console/script.cpp | |||
@@ -1,29 +1,30 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include "script.h" | 3 | #include "script.h" |
4 | 4 | ||
5 | Script::Script() { | 5 | Script::Script() { |
6 | } | 6 | } |
7 | 7 | ||
8 | Script::Script(const QString fileName) { | 8 | Script::Script(const QString fileName) { |
9 | QFile file(fileName); | 9 | QFile file(fileName); |
10 | file.open(IO_ReadOnly ); | ||
10 | m_script = file.readAll(); | 11 | m_script = file.readAll(); |
11 | } | 12 | } |
12 | 13 | ||
13 | void Script::saveTo(const QString fileName) const { | 14 | void Script::saveTo(const QString fileName) const { |
14 | QFile file(fileName); | 15 | QFile file(fileName); |
15 | file.open(IO_WriteOnly); | 16 | file.open(IO_WriteOnly); |
16 | file.writeBlock(m_script); | 17 | file.writeBlock(m_script); |
17 | file.close(); | 18 | file.close(); |
18 | } | 19 | } |
19 | 20 | ||
20 | 21 | ||
21 | void Script::append(const QByteArray &data) { | 22 | void Script::append(const QByteArray &data) { |
22 | int size = m_script.size(); | 23 | int size = m_script.size(); |
23 | m_script.resize(size + data.size()); | 24 | m_script.resize(size + data.size()); |
24 | memcpy(m_script.data() + size, data.data(), data.size()); | 25 | memcpy(m_script.data() + size, data.data(), data.size()); |
25 | } | 26 | } |
26 | 27 | ||
27 | QByteArray Script::script() const { | 28 | QByteArray Script::script() const { |
28 | return m_script; | 29 | return m_script; |
29 | } | 30 | } |