[easytag/wip/application-window: 52/52] Move application quit code to EtApplicationWindow
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/application-window: 52/52] Move application quit code to EtApplicationWindow
- Date: Wed, 3 Sep 2014 18:56:29 +0000 (UTC)
commit 6cac0d2bef04bb3ecd023aa9cd5000be34d073e2
Author: David King <amigadave amigadave com>
Date: Wed Sep 3 18:32:31 2014 +0100
Move application quit code to EtApplicationWindow
src/application.c | 7 ++-
src/application_window.c | 119 +++++++++++++++++++++++++++++++++++++++++++++-
src/application_window.h | 1 +
src/easytag.c | 115 --------------------------------------------
src/easytag.h | 1 -
5 files changed, 123 insertions(+), 120 deletions(-)
---
diff --git a/src/application.c b/src/application.c
index e88074b..041717c 100644
--- a/src/application.c
+++ b/src/application.c
@@ -84,7 +84,11 @@ on_quit (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- Quit_MainWindow ();
+ GList *windows;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
+
+ et_application_window_quit (windows->data);
}
static const GActionEntry actions[] =
@@ -508,7 +512,6 @@ et_application_open (GApplication *self,
static void
et_application_shutdown (GApplication *application)
{
- ET_Core_Destroy ();
Charset_Insert_Locales_Destroy ();
G_APPLICATION_CLASS (et_application_parent_class)->shutdown (application);
diff --git a/src/application_window.c b/src/application_window.c
index ee529c8..e5f053e 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -81,10 +81,10 @@ on_main_window_delete_event (GtkWidget *window,
GdkEvent *event,
gpointer user_data)
{
- Quit_MainWindow ();
+ et_application_window_quit (ET_APPLICATION_WINDOW (window));
/* Handled the event, so stop propagation. */
- return TRUE;
+ return GDK_EVENT_STOP;
}
static void
@@ -1580,6 +1580,8 @@ et_application_window_dispose (GObject *object)
save_state (self);
+ ET_Core_Destroy ();
+
if (priv->cddb_dialog)
{
gtk_widget_destroy (priv->cddb_dialog);
@@ -2586,3 +2588,116 @@ et_application_window_browser_refresh_sort (EtApplicationWindow *self)
et_browser_refresh_sort (ET_BROWSER (priv->browser));
}
+
+static void
+quit_confirmed (EtApplicationWindow *self)
+{
+ /* Save the configuration when exiting. */
+ et_application_window_apply_changes (self);
+
+ /* Quit EasyTAG. */
+ Log_Print (LOG_OK, _("EasyTAG: Normal exit."));
+
+ gtk_widget_destroy (GTK_WIDGET (self));
+}
+
+static void
+save_and_quit (EtApplicationWindow *self)
+{
+ /* Save modified tags */
+ if (Save_All_Files_With_Answer (FALSE) == -1)
+ return;
+
+ quit_confirmed (self);
+}
+
+void
+et_application_window_quit (EtApplicationWindow *self)
+{
+ GtkWidget *msgbox;
+ gint response;
+
+ /* If you change the displayed data and quit immediately */
+ if (ETCore->ETFileList)
+ {
+ ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+ }
+
+ /* Check if all files have been saved before exit */
+ if (g_settings_get_boolean (MainSettings, "confirm-when-unsaved-files")
+ && ET_Check_If_All_Files_Are_Saved () != TRUE)
+ {
+ /* Some files haven't been saved */
+ msgbox = gtk_message_dialog_new (GTK_WINDOW (self),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ "%s",
+ _("Some files have been modified but not saved"));
+ gtk_dialog_add_buttons (GTK_DIALOG (msgbox), _("_Discard"),
+ GTK_RESPONSE_NO, _("_Cancel"),
+ GTK_RESPONSE_CANCEL, _("_Save"),
+ GTK_RESPONSE_YES, NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
+ GTK_RESPONSE_YES);
+ gtk_window_set_title (GTK_WINDOW (msgbox), _("Quit"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgbox),
+ "%s",
+ _("Do you want to save them before quitting?"));
+ response = gtk_dialog_run (GTK_DIALOG (msgbox));
+ gtk_widget_destroy (msgbox);
+
+ switch (response)
+ {
+ case GTK_RESPONSE_YES:
+ save_and_quit (self);
+ break;
+ case GTK_RESPONSE_NO:
+ quit_confirmed (self);
+ break;
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT:
+ return;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ }
+ else if (g_settings_get_boolean (MainSettings, "confirm-quit"))
+ {
+ msgbox = gtk_message_dialog_new (GTK_WINDOW (self),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ "%s",
+ _("Do you really want to quit?"));
+ gtk_dialog_add_buttons (GTK_DIALOG (msgbox), _("_Cancel"),
+ GTK_RESPONSE_CANCEL, _("_Quit"),
+ GTK_RESPONSE_CLOSE, NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
+ GTK_RESPONSE_CLOSE);
+ gtk_window_set_title (GTK_WINDOW (msgbox), _("Quit"));
+ response = gtk_dialog_run (GTK_DIALOG (msgbox));
+ gtk_widget_destroy (msgbox);
+
+ switch (response)
+ {
+ case GTK_RESPONSE_CLOSE:
+ quit_confirmed (self);
+ break;
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT:
+ return;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ }
+ else
+ {
+ quit_confirmed (self);
+ }
+}
diff --git a/src/application_window.h b/src/application_window.h
index 2b6a225..64ddcde 100644
--- a/src/application_window.h
+++ b/src/application_window.h
@@ -91,6 +91,7 @@ void et_application_window_scan_dialog_update_previews (EtApplicationWindow *sel
void et_application_window_progress_set_fraction (EtApplicationWindow *self, gdouble fraction);
void et_application_window_progress_set_text (EtApplicationWindow *self, const gchar *text);
void et_application_window_status_bar_message (EtApplicationWindow *self, const gchar *message, gboolean
with_timer);
+void et_application_window_quit (EtApplicationWindow *self);
G_END_DECLS
diff --git a/src/easytag.c b/src/easytag.c
index 0ef3f3b..ac1393f 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -83,7 +83,6 @@ static gint Save_Selected_Files_With_Answer (gboolean force_saving_files);
static gint Save_List_Of_Files (GList *etfilelist,
gboolean force_saving_files);
-static void EasyTAG_Exit (void);
static gboolean et_rename_file (const char *old_filepath,
const char *new_filepath, GError **error);
static GList *read_directory_recursively (GList *file_list,
@@ -1216,117 +1215,3 @@ void Action_Main_Stop_Button_Pressed (void)
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
Main_Stop_Button_Pressed = TRUE;
}
-
-/*
- * Exit the program
- */
-static void
-EasyTAG_Exit (void)
-{
- Log_Print(LOG_OK,_("EasyTAG: Normal exit."));
-
- gtk_widget_destroy (MainWindow);
-}
-
-static void
-Quit_MainWindow_Confirmed (void)
-{
- /* Save the configuration when exiting. */
- et_application_window_apply_changes (ET_APPLICATION_WINDOW (MainWindow));
-
- // Quit EasyTAG
- EasyTAG_Exit();
-}
-
-static void
-Quit_MainWindow_Save_And_Quit (void)
-{
- /* Save modified tags */
- if (Save_All_Files_With_Answer(FALSE) == -1)
- return;
- Quit_MainWindow_Confirmed();
-}
-
-void Quit_MainWindow (void)
-{
- GtkWidget *msgbox;
- gint response;
-
- /* If you change the displayed data and quit immediately */
- if (ETCore->ETFileList)
- ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed); // To detect change before exiting
-
- /* Check if all files have been saved before exit */
- if (g_settings_get_boolean (MainSettings, "confirm-when-unsaved-files")
- && ET_Check_If_All_Files_Are_Saved () != TRUE)
- {
- /* Some files haven't been saved */
- msgbox = gtk_message_dialog_new(GTK_WINDOW(MainWindow),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- "%s",
- _("Some files have been modified but not saved"));
- gtk_dialog_add_buttons (GTK_DIALOG (msgbox), _("_Discard"),
- GTK_RESPONSE_NO, _("_Cancel"),
- GTK_RESPONSE_CANCEL, _("_Save"),
- GTK_RESPONSE_YES, NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
- GTK_RESPONSE_YES);
- gtk_window_set_title(GTK_WINDOW(msgbox),_("Quit"));
- gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msgbox),"%s",_("Do you want to save them
before quitting?"));
- response = gtk_dialog_run(GTK_DIALOG(msgbox));
- gtk_widget_destroy(msgbox);
- switch (response)
- {
- case GTK_RESPONSE_YES:
- Quit_MainWindow_Save_And_Quit();
- break;
- case GTK_RESPONSE_NO:
- Quit_MainWindow_Confirmed();
- break;
- case GTK_RESPONSE_CANCEL:
- case GTK_RESPONSE_DELETE_EVENT:
- return;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- }
- else if (g_settings_get_boolean (MainSettings, "confirm-quit"))
- {
- msgbox = gtk_message_dialog_new(GTK_WINDOW(MainWindow),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- "%s",
- _("Do you really want to quit?"));
- gtk_dialog_add_buttons (GTK_DIALOG (msgbox), _("_Cancel"),
- GTK_RESPONSE_CANCEL, _("_Quit"),
- GTK_RESPONSE_CLOSE, NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
- GTK_RESPONSE_CLOSE);
- gtk_window_set_title(GTK_WINDOW(msgbox),_("Quit"));
- response = gtk_dialog_run(GTK_DIALOG(msgbox));
- gtk_widget_destroy(msgbox);
- switch (response)
- {
- case GTK_RESPONSE_CLOSE:
- Quit_MainWindow_Confirmed();
- break;
- case GTK_RESPONSE_CANCEL:
- case GTK_RESPONSE_DELETE_EVENT:
- return;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }else
- {
- Quit_MainWindow_Confirmed();
- }
-
-}
diff --git a/src/easytag.h b/src/easytag.h
index 4f0936d..124558d 100644
--- a/src/easytag.h
+++ b/src/easytag.h
@@ -61,6 +61,5 @@ gint Save_All_Files_With_Answer (gboolean force_saving_files);
void Action_Main_Stop_Button_Pressed (void);
gboolean Read_Directory (gchar *path);
-void Quit_MainWindow (void);
#endif /* __EASYTAG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]