Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core, add confirmation dialog on exit #208

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/activities/menu/ConfigurationItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ Item {
}
}

GCDialogCheckBox {
id: enableExitDialogBox
text: qsTr("Enable activity Exit confirmation dialog")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm before leaving current activity

checked: isExitDialogEnabled
onCheckedChanged: {
isExitDialogEnabled = checked;
}
}

GCDialogCheckBox {
id: enableFullscreenBox
text: qsTr("Fullscreen")
Expand Down Expand Up @@ -547,6 +556,7 @@ Item {
property bool showLockedActivities: ApplicationSettings.showLockedActivities
property bool isAudioVoicesEnabled: ApplicationSettings.isAudioVoicesEnabled
property bool isAudioEffectsEnabled: ApplicationSettings.isAudioEffectsEnabled
property bool isExitDialogEnabled: ApplicationSettings.isExitDialogEnabled
property bool isFullscreen: ApplicationSettings.isFullscreen
property bool isVirtualKeyboard: ApplicationSettings.isVirtualKeyboard
property bool isAutomaticDownloadsEnabled: ApplicationSettings.isAutomaticDownloadsEnabled
Expand All @@ -565,6 +575,9 @@ Item {
isAudioEffectsEnabled = ApplicationSettings.isAudioEffectsEnabled
enableAudioEffectsBox.checked = isAudioEffectsEnabled

isExitDialogEnabled = ApplicationSettings.isExitDialogEnabled
enableExitDialogBox.checked = isExitDialogEnabled

isFullscreen = ApplicationSettings.isFullscreen
enableFullscreenBox.checked = isFullscreen

Expand Down Expand Up @@ -612,6 +625,7 @@ Item {
ApplicationSettings.showLockedActivities = showLockedActivities
ApplicationSettings.isAudioVoicesEnabled = isAudioVoicesEnabled
ApplicationSettings.isAudioEffectsEnabled = isAudioEffectsEnabled
ApplicationSettings.isExitDialogEnabled = isExitDialogEnabled
ApplicationSettings.isFullscreen = isFullscreen
ApplicationSettings.isVirtualKeyboard = isVirtualKeyboard
ApplicationSettings.isAutomaticDownloadsEnabled = isAutomaticDownloadsEnabled
Expand Down
106 changes: 63 additions & 43 deletions src/activities/menu/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ ActivityBase {
id: activity
focus: true
activityInfo: ActivityInfoTree.rootMenu
// set to true when returned to home from a dialog.
property bool returnFromDialog: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is needed to handle the cases when we close a dialog.
home() is called when we close a dialog, so to prevent the confirmation dialog to pop up, in that case, I have used this variable to handle this.


onBack: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should also be added there (I don't have mouse with back button but I think it will trigger this signal)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This signal is triggered only on back pressed from phones or other touch devices. Currently, back button from the mouse is not enabled.

pageView.pop(to);
// Restore focus that has been taken by the loaded activity
Expand All @@ -58,17 +61,33 @@ ActivityBase {
if(pageView.depth === 1 && !ApplicationSettings.isKioskMode) {
Core.quit(main);
}
else {
// When a dialog box is closed.
else if(returnFromDialog || !ApplicationSettings.isExitDialogEnabled) {
returnFromDialog = false;
pageView.pop();
// Restore focus that has been taken by the loaded activity
if(pageView.currentItem == activity)
focus = true;
}
// A confirmation dialog to quit the current activity is popped.
else {
Core.showMessageDialog(parent,
qsTr("Do you want to leave current activity?"),
qsTr("Yes"), function() { pageView.pop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go back to line for the function if it is not a one line function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is copied/pasted 3 times, can be in a function instead

// Restore focus that has been taken by the loaded activity
if(pageView.currentItem == activity)
focus = true; },
qsTr("No"), null,
null );
}
}

onDisplayDialog: pageView.push(dialog)

onDisplayDialog: {
returnFromDialog = true;
pageView.push(dialog)
}
onDisplayDialogs: {
returnFromDialog = true;
var toPush = new Array();
for (var i = 0; i < dialogs.length; i++) {
toPush.push({item: dialogs[i]});
Expand Down Expand Up @@ -215,12 +234,12 @@ ActivityBase {
model: sections
width: horizontal ? main.width : sectionCellWidth
height: {
if(horizontal)
return sectionCellHeight
else if(activity.currentTag === "search" && ApplicationSettings.isVirtualKeyboard)
return sectionCellHeight * (sections.length+1)
else
return main.height - bar.height
if(horizontal)
return sectionCellHeight
else if(activity.currentTag === "search" && ApplicationSettings.isVirtualKeyboard)
return sectionCellHeight * (sections.length+1)
else
return main.height - bar.height
}
x: ApplicationSettings.sectionVisible ? section.initialX : -sectionCellWidth
y: ApplicationSettings.sectionVisible ? section.initialY : -sectionCellHeight
Expand Down Expand Up @@ -491,9 +510,9 @@ ActivityBase {
visible: false
anchors.fill: activitiesGrid
gradient: Gradient {
GradientStop { position: 0.0; color: "#FFFFFFFF" }
GradientStop { position: 0.92; color: "#FFFFFFFF" }
GradientStop { position: 0.96; color: "#00FFFFFF"}
GradientStop { position: 0.0; color: "#FFFFFFFF" }
GradientStop { position: 0.92; color: "#FFFFFFFF" }
GradientStop { position: 0.96; color: "#00FFFFFF"}
}
}
layer.enabled: ApplicationInfo.useOpenGL
Expand Down Expand Up @@ -622,37 +641,37 @@ ActivityBase {
}
}
function populate() {
var tmplayout = [];
var row = 0;
var offset = 0;
var cols;
while(offset < letter.length-1) {
if(letter.length <= 100) {
cols = Math.ceil((letter.length-offset) / (3 - row));
}
else {
cols = background.horizontal ? (Math.ceil((letter.length-offset) / (15 - row)))
:(Math.ceil((letter.length-offset) / (22 - row)))
if(row == 0) {
tmplayout[row] = new Array();
tmplayout[row].push({ label: keyboard.backspace });
tmplayout[row].push({ label: keyboard.space });
row ++;
}
}

tmplayout[row] = new Array();
for (var j = 0; j < cols; j++)
tmplayout[row][j] = { label: letter[j+offset] };
offset += j;
row ++;
}
if(letter.length <= 100) {
tmplayout[0].push({ label: keyboard.space });
tmplayout[row-1].push({ label: keyboard.backspace });
}
keyboard.layout = tmplayout
}
var tmplayout = [];
var row = 0;
var offset = 0;
var cols;
while(offset < letter.length-1) {
if(letter.length <= 100) {
cols = Math.ceil((letter.length-offset) / (3 - row));
}
else {
cols = background.horizontal ? (Math.ceil((letter.length-offset) / (15 - row)))
:(Math.ceil((letter.length-offset) / (22 - row)))
if(row == 0) {
tmplayout[row] = new Array();
tmplayout[row].push({ label: keyboard.backspace });
tmplayout[row].push({ label: keyboard.space });
row ++;
}
}

tmplayout[row] = new Array();
for (var j = 0; j < cols; j++)
tmplayout[row][j] = { label: letter[j+offset] };
offset += j;
row ++;
}
if(letter.length <= 100) {
tmplayout[0].push({ label: keyboard.space });
tmplayout[row-1].push({ label: keyboard.backspace });
}
keyboard.layout = tmplayout
}
}

Bar {
Expand All @@ -678,6 +697,7 @@ ActivityBase {
dialogActivityConfig.loader.item.loadFromConfig()
displayDialog(dialogActivityConfig)
}
onExitClicked: home()
}

DialogAbout {
Expand Down
8 changes: 4 additions & 4 deletions src/core/ActivityBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ Item {
Keys.onPressed: {
if (event.modifiers === Qt.ControlModifier &&
event.key === Qt.Key_Q) {
// Ctrl+Q exit the application
Core.quit(main);
// Ctrl+Q exit the application without displaying confirmation dialog.
Core.quit(main, true);
} else if (event.modifiers === Qt.ControlModifier &&
event.key === Qt.Key_B) {
event.key === Qt.Key_B) {
// Ctrl+B toggle the bar
ApplicationSettings.isBarHidden = !ApplicationSettings.isBarHidden;
} else if (event.modifiers === Qt.ControlModifier &&
event.key === Qt.Key_F) {
event.key === Qt.Key_F) {
// Ctrl+F toggle fullscreen
ApplicationSettings.isFullscreen = !ApplicationSettings.isFullscreen
} else if (event.modifiers === Qt.ControlModifier &&
Expand Down
11 changes: 10 additions & 1 deletion src/core/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static const QString PREVIOUS_WIDTH_KEY = "previousWidth";
static const QString SHOW_LOCKED_ACTIVITIES_KEY = "showLockedActivities";
static const QString ENABLE_AUDIO_VOICES_KEY = "enableAudioVoices";
static const QString ENABLE_AUDIO_EFFECTS_KEY = "enableAudioEffects";
static const QString ENABLE_EXIT_DIALOG_KEY = "enableExitDialog";
static const QString VIRTUALKEYBOARD_KEY = "virtualKeyboard";
static const QString LOCALE_KEY = "locale";
static const QString FONT_KEY = "font";
Expand Down Expand Up @@ -99,6 +100,7 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
// general group
m_config.beginGroup(GENERAL_GROUP_KEY);
m_isAudioEffectsEnabled = m_config.value(ENABLE_AUDIO_EFFECTS_KEY, true).toBool();
m_isExitDialogEnabled = m_config.value(ENABLE_EXIT_DIALOG_KEY, true).toBool();
m_isFullscreen = m_config.value(FULLSCREEN_KEY, true).toBool();
m_previousHeight = m_config.value(PREVIOUS_HEIGHT_KEY, screenSize.height()).toUInt();
m_previousWidth = m_config.value(PREVIOUS_WIDTH_KEY, screenSize.width()).toUInt();
Expand Down Expand Up @@ -170,7 +172,8 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
connect(this, &ApplicationSettings::showLockedActivitiesChanged, this, &ApplicationSettings::notifyShowLockedActivitiesChanged);
connect(this, &ApplicationSettings::audioVoicesEnabledChanged, this, &ApplicationSettings::notifyAudioVoicesEnabledChanged);
connect(this, &ApplicationSettings::audioEffectsEnabledChanged, this, &ApplicationSettings::notifyAudioEffectsEnabledChanged);
connect(this, &ApplicationSettings::fullscreenChanged, this, &ApplicationSettings::notifyFullscreenChanged);
connect(this, &ApplicationSettings::exitDialogEnabledChanged, this, &ApplicationSettings::notifyExitDialogEnabledChanged);
connect(this, &ApplicationSettings::fullscreenChanged, this, &ApplicationSettings::notifyFullscreenChanged);
connect(this, &ApplicationSettings::previousHeightChanged, this, &ApplicationSettings::notifyPreviousHeightChanged);
connect(this, &ApplicationSettings::previousWidthChanged, this, &ApplicationSettings::notifyPreviousWidthChanged);
connect(this, &ApplicationSettings::localeChanged, this, &ApplicationSettings::notifyLocaleChanged);
Expand Down Expand Up @@ -255,6 +258,12 @@ void ApplicationSettings::notifyAudioEffectsEnabledChanged()
qDebug() << "notifyAudioEffects: " << m_isAudioEffectsEnabled;
}

void ApplicationSettings::notifyExitDialogEnabledChanged()
{
updateValueInConfig(GENERAL_GROUP_KEY, ENABLE_EXIT_DIALOG_KEY, m_isExitDialogEnabled);
qDebug() << "exit dialog Visibilty set to : " << m_isExitDialogEnabled;
}

void ApplicationSettings::notifyLocaleChanged()
{
updateValueInConfig(GENERAL_GROUP_KEY, LOCALE_KEY, m_locale);
Expand Down
14 changes: 14 additions & 0 deletions src/core/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class ApplicationSettings : public QObject
*/
Q_PROPERTY(bool isAudioEffectsEnabled READ isAudioEffectsEnabled WRITE setIsAudioEffectsEnabled NOTIFY audioEffectsEnabledChanged)

/**
* Whether activity exit confirmation dialog should be displayed.
*/
Q_PROPERTY(bool isExitDialogEnabled READ isExitDialogEnabled WRITE setIsExitDialogEnabled NOTIFY exitDialogEnabledChanged)

/**
* Whether GCompris should run in fullscreen mode.
*/
Expand Down Expand Up @@ -285,6 +290,12 @@ class ApplicationSettings : public QObject
emit audioEffectsEnabledChanged();
}

bool isExitDialogEnabled() const { return m_isExitDialogEnabled; }
void setIsExitDialogEnabled(const bool newMode) {
m_isExitDialogEnabled = newMode;
emit exitDialogEnabledChanged();
}

bool isFullscreen() const { return m_isFullscreen; }
void setFullscreen(const bool newMode) {
if(m_isFullscreen != newMode) {
Expand Down Expand Up @@ -472,6 +483,7 @@ protected slots:
Q_INVOKABLE void notifyShowLockedActivitiesChanged();
Q_INVOKABLE void notifyAudioVoicesEnabledChanged();
Q_INVOKABLE void notifyAudioEffectsEnabledChanged();
Q_INVOKABLE void notifyExitDialogEnabledChanged();
Q_INVOKABLE void notifyFullscreenChanged();
Q_INVOKABLE void notifyPreviousHeightChanged();
Q_INVOKABLE void notifyPreviousWidthChanged();
Expand Down Expand Up @@ -541,6 +553,7 @@ public slots:
void showLockedActivitiesChanged();
void audioVoicesEnabledChanged();
void audioEffectsEnabledChanged();
void exitDialogEnabledChanged();
void fullscreenChanged();
void previousHeightChanged();
void previousWidthChanged();
Expand Down Expand Up @@ -579,6 +592,7 @@ public slots:
bool m_showLockedActivities;
bool m_isAudioVoicesEnabled;
bool m_isAudioEffectsEnabled;
bool m_isExitDialogEnabled;
bool m_isFullscreen;
quint32 m_previousHeight;
quint32 m_previousWidth;
Expand Down
10 changes: 9 additions & 1 deletion src/core/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ Item {
*/
signal homeClicked

/**
* Emitted when the exit button was clicked.
*
* Should always be connected to the ActivityBase.home signal and thus
* exits the GCompris after showing exit dialog.
*/
signal exitClicked

/// @cond INTERNAL_DOCS

/*
Expand Down Expand Up @@ -384,7 +392,7 @@ Item {
BarButton {
source: "qrc:/gcompris/src/core/resource/bar_exit.svg";
sourceSize.width: fullButton * barZoom
onClicked: Core.quit(bar.parent.parent);
onClicked: bar.exitClicked()
}
}
Component {
Expand Down
12 changes: 9 additions & 3 deletions src/core/GCDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ Item {
fill: parent
}

onStart: opacity = 1
onStop: opacity = 0
onStart: {
opacity = 1
forceActiveFocus();
}
onStop: {
opacity = 0
parent.currentItem.forceActiveFocus();
}
onClose: destroy()

Behavior on opacity { NumberAnimation { duration: 200 } }
Expand Down Expand Up @@ -158,7 +164,7 @@ Item {
fontSize: regularSize
color: "black"
// @FIXME This property breaks the wrapping
// horizontalAlignment: Text.AlignHCenter
// horizontalAlignment: Text.AlignHCenter
// need to remove the anchors (left and right) else sometimes text is hidden on the side
width: instruction.width - 2*flick.anchors.margins
wrapMode: TextEdit.WordWrap
Expand Down
Loading