@@ -127,7 +127,13 @@ EmulatorQtWindow::EmulatorQtWindow(QWidget *parent) :
127
127
QObject::connect (QApplication::instance (), &QCoreApplication::aboutToQuit, this , &EmulatorQtWindow::slot_clearInstance);
128
128
129
129
QObject::connect (&mScreencapProcess , SIGNAL (finished (int )), this , SLOT (slot_screencapFinished (int )));
130
+ QObject::connect (&mScreencapPullProcess ,
131
+ SIGNAL (error (QProcess::ProcessError)), this ,
132
+ SLOT (slot_showProcessErrorDialog (QProcess::ProcessError)));
130
133
QObject::connect (&mScreencapPullProcess , SIGNAL (finished (int )), this , SLOT (slot_screencapPullFinished (int )));
134
+ QObject::connect (&mScreencapPullProcess ,
135
+ SIGNAL (error (QProcess::ProcessError)), this ,
136
+ SLOT (slot_showProcessErrorDialog (QProcess::ProcessError)));
131
137
132
138
QObject::connect (mContainer .horizontalScrollBar (), SIGNAL (valueChanged (int )), this , SLOT (slot_horizontalScrollChanged (int )));
133
139
QObject::connect (mContainer .verticalScrollBar (), SIGNAL (valueChanged (int )), this , SLOT (slot_verticalScrollChanged (int )));
@@ -206,6 +212,26 @@ void EmulatorQtWindow::showAvdArchWarning()
206
212
}
207
213
}
208
214
215
+ void EmulatorQtWindow::slot_showProcessErrorDialog (
216
+ QProcess::ProcessError exitStatus) {
217
+ QString msg;
218
+ switch (exitStatus) {
219
+ case QProcess::Timedout:
220
+ // Our wait for process starting is best effort. If we timed out,
221
+ // meh.
222
+ return ;
223
+ case QProcess::FailedToStart:
224
+ msg =
225
+ tr (" Failed to start process.<br/>"
226
+ " Check settings to verify that your chosen SDK path "
227
+ " is valid." );
228
+ break ;
229
+ default :
230
+ msg = tr (" Unexpected error occured while grabbing screenshot." );
231
+ }
232
+ showErrorDialog (msg, tr (" Screenshot" ));
233
+ }
234
+
209
235
void EmulatorQtWindow::slot_startupTick () {
210
236
// It's been a while since we were launched, and the main
211
237
// window still hasn't appeared.
@@ -740,9 +766,12 @@ void EmulatorQtWindow::screenshot()
740
766
mOverlay .showAsFlash ();
741
767
mFlashAnimation .start ();
742
768
743
- // Keep track of this process
744
769
mScreencapProcess .start (command, args);
745
- mScreencapProcess .waitForStarted ();
770
+ // TODO(pprabhu): It is a bad idea to call |waitForStarted| from the GUI
771
+ // thread, because it can freeze the UI till timeout.
772
+ if (!mScreencapProcess .waitForStarted (5000 )) {
773
+ slot_showProcessErrorDialog (mScreencapProcess .error ());
774
+ }
746
775
}
747
776
748
777
@@ -754,7 +783,6 @@ void EmulatorQtWindow::slot_screencapFinished(int exitStatus)
754
783
QString msg = tr (" The screenshot could not be captured. Output:<br/><br/>" ) + QString (er);
755
784
showErrorDialog (msg, tr (" Screenshot" ));
756
785
} else {
757
-
758
786
// Pull the image from its remote location to the desired location
759
787
QStringList args;
760
788
QString command = tool_window->getAdbFullPath (&args);
@@ -777,9 +805,14 @@ void EmulatorQtWindow::slot_screencapFinished(int exitStatus)
777
805
778
806
args << fileName;
779
807
780
- // Use a different process to avoid infinite looping when pulling the file
808
+ // Use a different process to avoid infinite looping when pulling the
809
+ // file.
781
810
mScreencapPullProcess .start (command, args);
782
- mScreencapPullProcess .waitForStarted ();
811
+ // TODO(pprabhu): It is a bad idea to call |waitForStarted| from the GUI
812
+ // thread, because it can freeze the UI till timeout.
813
+ if (!mScreencapPullProcess .waitForStarted (5000 )) {
814
+ slot_showProcessErrorDialog (mScreencapPullProcess .error ());
815
+ }
783
816
}
784
817
}
785
818
0 commit comments