/
mainwindow.cpp
826 lines (709 loc) · 24.8 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/*
*=BEGIN GPL
*
* This file is part of the QtShowRunner program.
*
* Copyright(c) 2020 Darrell Duffy
* http://www.windyweather.net/
*
* This file may be licensed under the terms of of the
* GNU General Public License Version 3 (the ``GPL'').
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the GPL for the specific language
* governing rights and limitations.
*
* For a copy of the GPL please visit https://www.gnu.org/licenses/gpl-3.0.en.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*=END GPL
*/
/*
* QtShowRunner is a program to chain together multiple LibreOffice impress slide shows.
* The problem being solved is that when slide shows are displayed, they stop at the end
* with a "mostly" black screen and require user interaction to exit.
* So, in order to "chain" together multiple shows, and loop them around, something external
* is required to sense that a show has ended so the next one can be started.
*
* ScreenShot Looking for Black Attempt
*
* A ScreenShot approach was tried to watch for the black end screen and terminating the
* impress program. This worked on a Windows 10 system with an Nvidia 2060 card, but failed
* on a Gbrix Intel CPU with integrated graphics. The program worked as follows:
* QtShowRunner watches the screen by taking periodic screenshots and looking at the right
* 80% of the screen to see if it is totally black. When a slide show ends and the
* message is displayed at the top the left 20% or so of the screen is
* apparently remains as the background of the master slide. The screenshot does not capture
* the message. Apparently this is displayed as an overlay window that is invisible to the
* screenshot.
*
* Also, during the display of the slideshow, the screen apparently flashes black, which
* causes single screen shots to erroneously detect end of show, so, the screen is watched
* repeatedly over about 5 seconds time to see if it remains black and then the show is
* "terminated" or in severe cases "killed" and the next show is then displayed.
* The process tree of Impress is so complicated that QProcess::terminate or QProcess::kill
* does not work. Killing the parent process - soffice.exe - is a bad idea since that
* causes impress to want to "recover" the file it was just displaying.
* This screenshot attempt has been abandended.
*
* Mouse Click Solution
*
* The solution that does work is sending a key to the top window on the screen, which
* triggers the end of show and causes impress and soffice to cleanly exit.
* The QtShowRunner program just clicks the mouse every few seconds during the entire show.
* This requires that the show settings disable "Click Mouse to Advance Slide".
* This solution works on both the Windows 10 Nvidia and Windows 10 Intel Integrated Graphics
* systems.
*
* This complicated process gets around the fact that LibreOffice Impress apparently has no
* options or scripting features available to accomplish chaining and looping of multiple
* slide shows together.
*
* The reason for wanting to chain multiple shows is that after 100 or so slides with images
* the save times and editing for shows becomes cumbersome. This is quite reasonable for at this
* point the show file size may become 100MB or more.
*
* Thanks to the many and several folks who provided the very nice Qt Development environment and
* Qt example code on which this program is based. And note that this program is Open Source and
* GPL so feel free to use these ideas to solve your own problems and pass along the ideas.
*
* enjoy.
* April 2020
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <aboutdialog.h>
#include <helpdialog.h>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfoList>
#include <QTextStream>
#include <QMessageBox>
#include <QModelIndexList>
#include <QWindow>
#include <QScreen>
#include <QDir>
#include <QDebug>
// support mouse click
#include <mouseclick.h>
//
// Slideshows are stopped by just clicking the mouse every few seconds
// during the whole show. And the show must be set to not advance
// on mouse clicks. Click this often. Allow some time to grab mouse
// to stop the shows inbetween clicks.
//
#define WAIT_SECONDS 5 // seconds to wait between mouse clicks
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
showsBusy = false; // no shows running
showIndex = 0; // do we have shows in list?
showStopper = false; // not stopping shows
if (!mouseopen() )
{
setStatus(tr("Mouse Not Opened"));
}
#ifdef Q_OS_LINUX
ui->le_ImpressPath->setText(tr("libreoffice"));
ui->le_ShowOption->setText(tr("--impress --show"));
ui->le_ShowPath->setText(tr("/home/darrell/ImpressTests"));
#endif // Q_OS_LINUX
#ifdef Q_OS_WIN
ui->le_ImpressPath->setText(tr("C:/Program Files/LibreOffice/program/soffice.exe"));
ui->le_ShowOption->setText(tr("--impress --show"));
ui->le_ShowPath->setText(tr("C:/Pictures/ImpressSlideShows"));
#endif
restoreDefaults();
}
MainWindow::~MainWindow()
{
saveDefaults();
mouseclose();
delete ui;
}
//
// Settings files are .ini file format and are stored per user
// We store the site list, including the last state of the site and the last date/time checked.
//
#define SETTINGS_VERSION "100"
#define SETTINGS_VERSION_LAST "100"
void MainWindow::createDefaults()
{
// QSettings ( Format format, Scope scope, const QString & organization, const QString & application = QString(), QObject * parent = 0 )
m_pSettings = new QSettings( QSettings::IniFormat, QSettings::UserScope,
QString("WindyWeather"), QString("QtShowRunner") );
QString sFile = m_pSettings->fileName();
qDebug()<<"Defaults filepath "<<sFile;
}
//
// save paths to the impress program, options and the path we
// were last using for shows. Show lists are saved in their own
// files, so we don't store those here.
// No warning on unsaved show lists on exit.
//
void MainWindow::saveDefaults()
{
createDefaults();
qDebug()<<"MainWindow::saveDefaults saveDefaults";
m_pSettings->beginGroup("WindowSettings");
m_pSettings->setValue("size", this->size());
m_pSettings->setValue("pos", this->pos());
m_pSettings->endGroup();
m_pSettings->beginGroup("Global");
m_pSettings->setValue("version", SETTINGS_VERSION );
m_pSettings->endGroup();
m_pSettings->beginGroup("Defaults");
m_pSettings->setValue("version", SETTINGS_VERSION );
m_pSettings->setValue( "impress_path", ui->le_ImpressPath->text());
m_pSettings->setValue( "show_option", ui->le_ShowOption->text());
m_pSettings->setValue( "show_path", ui->le_ShowPath->text());
qDebug()<<"saveDefaults ShowPath saved as "<<ui->le_ShowPath->text();
m_pSettings->endGroup();
delete m_pSettings;
m_pSettings = NULL;
}
//
// restore everything we saved
// take care of the case that we didn't save a file. First Time we Run
// so we don't blow away the programmed defaults. After that they are restored
// from last exit.
//
void MainWindow::restoreDefaults()
{
createDefaults();
#if 0 // let's wait a bit on this
// Get the size and position of the window as it is first created
// as the default.
QSize defSize = this->size();
QPoint defPos = this->pos();
m_pSettings->beginGroup("WindowSettings");
this->resize(m_pSettings->value("size", defSize ).toSize());
this->move(m_pSettings->value("pos", defPos ).toPoint());
m_pSettings->endGroup();
qDebug("MainWindow::restoreDefaults - Window restored");
#endif //wait a bit
m_pSettings->beginGroup("Global");
QString versionParams = m_pSettings->value("version", QString("") ).toString();
m_pSettings->endGroup();
if (versionParams.count() == 0 )
{
// not an error, just don't foul up the program defaults the first time
qDebug()<<"MainWindow::restoreDefaults - no default settings";
delete m_pSettings;
m_pSettings = NULL;
return;
}
m_pSettings->beginGroup("Defaults");
QString versionSites = m_pSettings->value("version", QString(SETTINGS_VERSION) ).toString();
setStatus(QString("Restoring Defaults"));
qDebug() << "MainWindow::restoreDefaults - Restoring Defaults";
ui->le_ImpressPath->setText( m_pSettings->value( "impress_path", "" ).toString() );
ui->le_ShowOption->setText( m_pSettings->value( "show_option", "" ).toString() );
ui->le_ShowPath->setText( m_pSettings->value( "show_path", "" ).toString() );
qDebug()<<"MainWindow::restoreDefaults found show_path as "<<m_pSettings->value( "show_path", "" ).toString();
m_pSettings->endGroup();
delete m_pSettings;
m_pSettings = NULL;
setStatus(QString("Restored Defaults"));
qDebug()<<"MainWindow::restoreDefaults - Restored Defaults";
}
void MainWindow::on_actionOpen_triggered()
{
if ( showsBusy )
{
setStatus(tr("Stop Shows First"));
return;
}
restoreShow();
}
void MainWindow::on_actionSave_triggered()
{
if ( showsBusy )
{
setStatus(tr("Stop Shows First"));
return;
}
saveShow();
}
//
// Save the list of shows as an ini file with the count and
// list of shows.
//
void MainWindow::saveShow()
{
if ( ui->lw_ShowList->count() == 0)
{
setStatus(tr("No shows to save"));
return;
}
// Get file name to save the show list
// default dir is where the shows are
QDir d = QFileInfo(ui->le_ShowPath->text()).absoluteDir();
QString absolute=d.absolutePath();
QFileDialog saveFileDlg;
saveFileDlg.setDefaultSuffix("show");
QString sShowFile = saveFileDlg.getSaveFileName(this,
tr("Save Show File"),
absolute,
tr("ShowFile(*.show);;All Files(*.*)"));
if ( 0 == sShowFile.count() )
{
// file dialog cancelled
return;
}
// tidy up the filename by adding the suffix. Seems to be there on Windows but now Linux
// but do it anyway for everyone.
if ( !sShowFile.contains(tr(".show"),Qt::CaseInsensitive) )
{
sShowFile += tr(".show"); // add the missing suffix
}
// make our own private file, but using the INI format and settings
// class to make this easy.
QSettings* pShowFile = new QSettings( sShowFile, QSettings::IniFormat);
qDebug() <<"MainWindow::saveShow "<<sShowFile;
pShowFile->beginGroup("Global");
pShowFile->setValue("version", SETTINGS_VERSION );
pShowFile->endGroup();
pShowFile->beginGroup("Show");
pShowFile->setValue("version", SETTINGS_VERSION );
int shows = ui->lw_ShowList->count();
pShowFile->setValue( "show_count", shows);
for (int i=0; i<shows; i++)
{
QString showpath;
QString key = QString("show_%1").arg(i);
showpath = ui->lw_ShowList->item(i)->text();
pShowFile->setValue( key, showpath );
}
pShowFile->endGroup();
delete pShowFile;
pShowFile = NULL;
setStatus(tr("Show Saved"));
qDebug("MainWindow::saveShow - Show saved");
}
//
// Restore a show list from an INI settings file.
//
void MainWindow::restoreShow()
{
// Get file name to restore the show list
// default dir is where the shows are
QDir d = QFileInfo(ui->le_ShowPath->text()).absoluteDir();
QString absolute=d.absolutePath();
QString sShowFile = QFileDialog::getOpenFileName(this,
tr("Open Show File"),
absolute,
tr("ShowFiles(*.show);;All Files(*.*)"));
if ( 0 == sShowFile.count() )
{
// user just cancelled out of the open dialog
return;
}
// use the handy settings class
QSettings* pShowFile = new QSettings( sShowFile, QSettings::IniFormat);
qDebug() <<"MainWindow::restoreShow "<<sShowFile;
// someday we might check the settings format and refuse, but just ignore for now
pShowFile->beginGroup("Global");
QString versionParams = pShowFile->value("version", QString(SETTINGS_VERSION) ).toString();
pShowFile->endGroup();
pShowFile->beginGroup("Show");
QString versionSites = pShowFile->value("version", QString(SETTINGS_VERSION) ).toString();
ui->lw_ShowList->clear();
int nItems = pShowFile->value("show_count", 0 ).toInt();
qDebug()<<QString("Restoring %1 shows").arg(nItems);
for ( int i=0; i < nItems; i++ )
{
QString showpath;
QString key = QString("show_%1").arg(i);
showpath = pShowFile->value( key, "" ).toString();
ui->lw_ShowList->addItem(showpath);
}
pShowFile->endGroup();
delete pShowFile;
pShowFile = NULL;
setStatus(tr("Restored %1 shows").arg(nItems));
qDebug()<<QString("Restored %1 shows").arg(nItems);
}
void MainWindow::on_actionQuit_triggered()
{
close();
}
void MainWindow::on_pb_BrowseShowPath_clicked()
{
if ( showsBusy )
{
setStatus(tr("Stop shows first"));
return;
}
setStatus(tr("Find an Impress slide show"));
QString showfile = QFileDialog::getOpenFileName(this, tr("Impress Slide Show"),
ui->le_ShowPath->text(),
tr("Impress (*.odp);;All Files(*.*)"));
if ( showfile.count() != 0 ) // if cancel, then empty string
{
ui->le_ShowPath->setText(showfile);
setStatus(tr("Impress slide show file set"));
}
else
{
setStatus(tr(""));
}
}
void MainWindow::on_pb_AddShow_clicked()
{
if ( showsBusy )
{
setStatus(tr("Stop shows first"));
return;
}
if ( ui->le_ShowPath->text().count() != 0 ) // if path set
{
ui->lw_ShowList->addItem(ui->le_ShowPath->text());
setStatus(tr("Impress slide show added"));
}
else
{
setStatus(tr("Use (...) to find a slide show"));
}
}
void MainWindow::on_pb_RemoveShow_clicked()
{
if ( showsBusy )
{
setStatus(tr("Stop shows first"));
return;
}
int selectedRow = ui->lw_ShowList->currentRow();
if ( selectedRow != -1 )
{
QListWidgetItem* removedRow = ui->lw_ShowList->takeItem(selectedRow);
delete removedRow;
setStatus(tr("Show removed from list"));
}
else
{
setStatus(tr("Select a show in the list Ffirst"));
}
}
void MainWindow::on_pb_StartShows_clicked()
{
if (showsBusy)
{
setStatus(tr("Stop Shows First"));
return;
}
if ( ui->lw_ShowList->count() == 0) // any shows in list
{
setStatus(tr("Add some shows to list first"));
return;
}
showStopper = false;
showsBusy = true;
showIndex = 0; // start with first show
setStatus(tr("Starting first show"));
startNextShow(); // starting first as next
}
void MainWindow::on_pb_StopShow_clicked()
{
if ( !showsBusy )
{
setStatus(tr("Shows not running"));
return;
}
setStatus(tr("Stopping shows"));
showStopper = true;
if ( theShow.state() == QProcess::Running )
{
endOfShow(); // stop current show
}
showsBusy = false; // shows are not running
}
void MainWindow::on_pb_BrowseImpressPath_clicked()
{
if (showsBusy)
{
setStatus(tr("Shows are running. Stop first."));
return;
}
setStatus(tr("Browse for Impress Program"));
QString impressexe = QFileDialog::getOpenFileName(this, tr("Impress Program"),
ui->le_ImpressPath->text(),
tr("Executable (*.exe)"));
if ( impressexe.count() != 0 ) // if cancel, then empty string
{
ui->le_ImpressPath->setText(impressexe);
setStatus(tr("Impress program path set"));
}
else
{
setStatus(tr("Use (...) to find simpress.exe"));
}
}
void MainWindow::on_pb_RemoveAllShows_clicked()
{
if ( showsBusy )
{
setStatus(tr("Stop shows first"));
return;
}
ui->lw_ShowList->clear();
setStatus(tr("All Shows Removed from the List"));
}
//
// Top, Up, Down
//
// Reorder the list items with some buttons.
//
void MainWindow::on_bMoveShowToTop_clicked()
{
QListWidgetItem* item = ui->lw_ShowList->currentItem();
if ( item == NULL )
{
setStatus(tr("Select a Show first."));
return; // no current item apparently || item == (void) -1
}
int row = ui->lw_ShowList->currentRow();
if ( row <= 0 )
{
setStatus(tr("Show is already at the top"));
return;
}
QListWidgetItem* newItem = new QListWidgetItem();
*newItem = *item; // copy the item so we don't lose it
// remove the old item and then insert the new one at row zero so it is first in the list
ui->lw_ShowList->takeItem(row);
ui->lw_ShowList->insertItem(0, newItem);
ui->lw_ShowList->scrollToTop();
ui->lw_ShowList->setCurrentRow( 0 ); // Update the pair data to top row
setStatus(tr("Show moved to top"));
}
void MainWindow::on_bMoveShowUp_clicked()
{
QListWidgetItem* item = ui->lw_ShowList->currentItem();
if ( item == NULL )
{
setStatus(tr("Select a show first."));
return; // no current item apparently || item == (void) -1
}
int row = ui->lw_ShowList->currentRow();
if ( row <= 0 )
{
setStatus(tr("Show is at the top"));
return;
}
QListWidgetItem* newItem = new QListWidgetItem();
*newItem = *item; // copy the item so we don't lose it
// remove the old item and then insert the new one at row above so it is moved up
ui->lw_ShowList->takeItem(row);
ui->lw_ShowList->insertItem(row-1, newItem);
ui->lw_ShowList->scrollToItem(newItem);
ui->lw_ShowList->setCurrentRow( row-1 ); // Update the pair data to correct row
setStatus(tr("Show moved up"));
}
void MainWindow::on_bMoveShowDown_clicked()
{
QListWidgetItem* item = ui->lw_ShowList->currentItem();
if ( item == NULL )
{
setStatus(tr("Select a show first."));
return; // no current item apparently
}
int row = ui->lw_ShowList->currentRow();
int rows = ui->lw_ShowList->count();
#if 0
QString msg;
msg = tr("Row %1 of %2").arg(row).arg(rows);
setStatus(msg);
return;
#endif
// row numbers start with zero
if ( row == (rows-1) )
{
setStatus(tr("Show is at the bottom"));
return;
}
QListWidgetItem* newItem = new QListWidgetItem();
*newItem = *item; // copy the item so we don't lose it
// remove the old item and then insert the new one at row above so it is moved up
ui->lw_ShowList->takeItem(row);
ui->lw_ShowList->insertItem(row+1, newItem);
ui->lw_ShowList->scrollToItem(newItem);
ui->lw_ShowList->setCurrentRow( row+1 ); // Update the pair data to correct row
setStatus(tr("Show moved down"));
}
void MainWindow::on_actionAbout_triggered()
{
AboutDialog dialog(this);
dialog.exec(); // show the About box as a modal dialog to keep it simple
}
void MainWindow::on_actionHelp_triggered()
{
HelpDialog dialog(this);
dialog.exec(); // show the About box as a modal dialog to keep it simple
}
//
// Just start clicking the mouse until the show ends
//
void MainWindow::clickingToEndShow()
{
setStatus(tr("Waiting for show to end"));
endOfShowSeen = false;
stopClicking = false; // don't stop clicking now
// kick the whole thing off with a timer
QTimer::singleShot(WAIT_SECONDS * 1000, this, &MainWindow::clickToEnd);
}
//
// Look for black screen every few seconds.
// End of an impress slide show is an almost completely black screen
//
void MainWindow::clickToEnd()
{
if ( stopClicking || showStopper )
{
setStatus(tr("Mouse clicks stopped"));
return;
}
//
// eventually the show will end when we click on the black screen
//
if ( theShow.state() != QProcess::Running )
{
if (ui->cbBeepOnShowEnd->isChecked())
{
QApplication::beep();
}
setStatus(tr("Show end"));
endOfShowSeen = true;
endOfShow(); // start next show
return;
}
// click the mouse every WAIT_SECONDS and eventually
// the show will end.
mouseClick();
QTimer::singleShot(WAIT_SECONDS * 1000, this, &MainWindow::clickToEnd);
}
//
// we have seen end of a show
//
void MainWindow::endOfShow()
{
if ( !showsBusy )
{
setStatus(tr("endOfShow - but not showsBusy"));
return;
}
// clobber the show if we have one.
if ( theShow.state() == QProcess::Running )
{
if ( !theShow.waitForFinished( 5*1000 ) )
{
// if it won't stop, try one last time
if ( theShow.state() == QProcess::Running )
{
theShow.kill();
theShow.waitForFinished( 5*1000 );
}
}
}
// if we are stopping shows, then clean up
if ( showStopper )
{
showsBusy = false;
showStopper = false;
setStatus(tr("Shows manually stopped"));
return;
}
showIndex++;
// any more shows left? If Not, then just loop back and play again
if ( showIndex >= ui->lw_ShowList->count() )
{
setStatus(tr("End of show list. Looping."));
showIndex = 0;
}
// Wait a few seconds and then start next show
int secsToWait = ui->sb_BlackSeconds->value();
QTimer::singleShot(secsToWait * 1000, this, &MainWindow::startNextShow);
}
//
// time to start the next show
//
void MainWindow::startNextShow()
{
if ( !showsBusy )
{
setStatus(tr("startNextShow bad trigger at %1").arg(showIndex));
return; // not supposed to be here now
}
// any show here to play?
if ( showIndex >= ui->lw_ShowList->count() )
{
setStatus(tr("Can't start show at %1").arg(showIndex));
showIndex = 0;
return;
}
// launch the show and start waiting on black screen that is
// end of a show.
QString showName = ui->lw_ShowList->item(showIndex)->text();
QString impress = ui->le_ImpressPath->text();
QStringList option = ui->le_ShowOption->text().split(tr(" "));
QStringList args = option << showName;
setStatus(tr("Starting show %1").arg(showName));
// start a child process of us - not working well
// If we start it this way, we can't terminate it
// but if we just keep clicking the mouse, and set the show to
// not advance on mouse clicks, then it will eventually
// stop by itself and we will see that.
theShow.start(impress, args, QProcess::ReadWrite );
// if it didn't start after 10 sec, it's an error
theShow.waitForStarted(10*1000);
if ( theShow.state() != QProcess::Running )
{
setStatus(tr("Show didn't start %1").arg(showName));
showsBusy = false;
return;
}
// just keep clicking mouse to end show eventually
QTimer::singleShot(WAIT_SECONDS * 1000, this, &MainWindow::clickingToEndShow);
}
//
// Set the slide show to not advance on mouse clicks
// and then just click away every second until at the
// end of the show, it terminates and exits itself.
// What we do to make it work. Wheeew.
//
#ifdef Q_OS_LINUX // Linux
void MainWindow::mouseClick()
{
// On Linux there is a command line tool to click the mouse
// let's use that since nothing else freaking works.
//
// Launch the cmd line tool and wait for it to finish.
// Should not take very long.
// BTW, you'll need to
// sudo apt-get install -y xdotool
// to make sure you have the tool
//
QProcess cmd;
cmd.execute(QString(tr("xdotool click 1")));
// wait until that finishes, since it won't take very long
// nothing else to do anyway, the show is running
}
#endif // Q_OS_LINUX
#ifdef Q_OS_WINDOWS // Windows Only
void MainWindow::mouseClick()
{
// use the windows OS solution for mouse clicks that does work
if (!mouseclick())
{
setStatus(tr("mouseclick failed"));
qDebug()<<"mouseclick failed";
}
}
#endif // Q_OS_WINDOWS