1 /*
2  * gtr-close-confirmation-dialog.c
3  * This file is part of gtranslator
4  *
5  * Copyright (C) 2004-2005  GNOME Foundation
6  *               2008 Ignacio Casal Quinteiro
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <glib/gi18n.h>
28 
29 #include "gtr-close-confirmation-dialog.h"
30 #include "gtr-application.h"
31 #include "gtr-utils.h"
32 #include "gtr-window.h"
33 #include "gtr-po.h"
34 
35 
36 /* Properties */
37 enum
38 {
39   PROP_0,
40   PROP_UNSAVED_DOCUMENTS,
41   PROP_LOGOUT_MODE
42 };
43 
44 /* Mode */
45 enum
46 {
47   SINGLE_DOC_MODE,
48   MULTIPLE_DOCS_MODE
49 };
50 
51 /* Columns */
52 enum
53 {
54   SAVE_COLUMN,
55   NAME_COLUMN,
56   DOC_COLUMN,                   /* a handy pointer to the document */
57   N_COLUMNS
58 };
59 
60 typedef struct
61 {
62   gboolean logout_mode;
63 
64   GList *unsaved_documents;
65 
66   GList *selected_documents;
67 
68   GtkTreeModel *list_store;
69 
70   gboolean disable_save_to_disk;
71 } GtrCloseConfirmationDialogPrivate;
72 
73 #define GET_MODE(priv) (((priv->unsaved_documents != NULL) && \
74 			 (priv->unsaved_documents->next == NULL)) ? \
75 			  SINGLE_DOC_MODE : MULTIPLE_DOCS_MODE)
76 
77 G_DEFINE_TYPE_WITH_PRIVATE (GtrCloseConfirmationDialog,
78                             gtr_close_confirmation_dialog,
79                             GTK_TYPE_DIALOG)
80 
81 static void set_unsaved_document (GtrCloseConfirmationDialog *dlg,
82                                   const GList * list);
83 
84 static GList *get_selected_docs (GtkTreeModel * store);
85 
86 /*  Since we connect in the costructor we are sure this handler will be called
87  *  before the user ones
88  */
89 static void
response_cb(GtrCloseConfirmationDialog * dlg,gint response_id,gpointer data)90 response_cb (GtrCloseConfirmationDialog * dlg,
91             gint response_id, gpointer data)
92 {
93   GtrCloseConfirmationDialogPrivate *priv;
94   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
95 
96   g_return_if_fail (GTR_IS_CLOSE_CONFIRMATION_DIALOG (dlg));
97 
98   if (priv->selected_documents != NULL)
99     g_list_free (priv->selected_documents);
100 
101   if (response_id == GTK_RESPONSE_YES)
102     {
103       if (GET_MODE (priv) == SINGLE_DOC_MODE)
104         {
105           priv->selected_documents = g_list_copy (priv->unsaved_documents);
106         }
107       else
108         {
109           g_return_if_fail (priv->list_store);
110 
111           priv->selected_documents = get_selected_docs (priv->list_store);
112         }
113     }
114   else
115     priv->selected_documents = NULL;
116 }
117 
118 static void
set_logout_mode(GtrCloseConfirmationDialog * dlg,gboolean logout_mode)119 set_logout_mode (GtrCloseConfirmationDialog * dlg, gboolean logout_mode)
120 {
121 
122   gtk_dialog_add_button (GTK_DIALOG (dlg),
123                          _("Close _without Saving"), GTK_RESPONSE_NO);
124 
125   gtk_dialog_add_button (GTK_DIALOG (dlg),
126                          _("_Cancel"), GTK_RESPONSE_CANCEL);
127 
128   gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Save"), GTK_RESPONSE_YES);
129 
130   gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_YES);
131 }
132 
133 static void
gtr_close_confirmation_dialog_init(GtrCloseConfirmationDialog * dlg)134 gtr_close_confirmation_dialog_init (GtrCloseConfirmationDialog * dlg)
135 {
136   AtkObject *atk_obj;
137 
138   gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
139   gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 14);
140   gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
141   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), TRUE);
142 
143   gtk_window_set_title (GTK_WINDOW (dlg), "");
144 
145   gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
146   gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE);
147 
148   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dlg));
149   atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
150   atk_object_set_name (atk_obj, _("Question"));
151 
152   g_signal_connect (dlg, "response", G_CALLBACK (response_cb), NULL);
153 }
154 
155 static void
gtr_close_confirmation_dialog_finalize(GObject * object)156 gtr_close_confirmation_dialog_finalize (GObject * object)
157 {
158   GtrCloseConfirmationDialogPrivate *priv;
159   priv = gtr_close_confirmation_dialog_get_instance_private (GTR_CLOSE_CONFIRMATION_DIALOG (object));
160 
161   if (priv->unsaved_documents != NULL)
162     g_list_free (priv->unsaved_documents);
163 
164   if (priv->selected_documents != NULL)
165     g_list_free (priv->selected_documents);
166 
167   /* Call the parent's destructor */
168   G_OBJECT_CLASS (gtr_close_confirmation_dialog_parent_class)->finalize
169     (object);
170 }
171 
172 static void
gtr_close_confirmation_dialog_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)173 gtr_close_confirmation_dialog_set_property (GObject * object,
174                                             guint prop_id,
175                                             const GValue * value,
176                                             GParamSpec * pspec)
177 {
178   GtrCloseConfirmationDialog *dlg;
179 
180   dlg = GTR_CLOSE_CONFIRMATION_DIALOG (object);
181 
182   switch (prop_id)
183     {
184     case PROP_UNSAVED_DOCUMENTS:
185       set_unsaved_document (dlg, g_value_get_pointer (value));
186       break;
187 
188     case PROP_LOGOUT_MODE:
189       set_logout_mode (dlg, g_value_get_boolean (value));
190       break;
191 
192     default:
193       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
194       break;
195     }
196 }
197 
198 static void
gtr_close_confirmation_dialog_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)199 gtr_close_confirmation_dialog_get_property (GObject * object,
200                                             guint prop_id,
201                                             GValue * value,
202                                             GParamSpec * pspec)
203 {
204   GtrCloseConfirmationDialogPrivate *priv;
205   priv = gtr_close_confirmation_dialog_get_instance_private (GTR_CLOSE_CONFIRMATION_DIALOG (object));
206 
207   switch (prop_id)
208     {
209     case PROP_UNSAVED_DOCUMENTS:
210       g_value_set_pointer (value, priv->unsaved_documents);
211       break;
212 
213     case PROP_LOGOUT_MODE:
214       g_value_set_boolean (value, priv->logout_mode);
215       break;
216 
217     default:
218       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
219       break;
220     }
221 }
222 
223 static void
gtr_close_confirmation_dialog_class_init(GtrCloseConfirmationDialogClass * klass)224   gtr_close_confirmation_dialog_class_init
225   (GtrCloseConfirmationDialogClass * klass)
226 {
227   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
228 
229   gobject_class->set_property = gtr_close_confirmation_dialog_set_property;
230   gobject_class->get_property = gtr_close_confirmation_dialog_get_property;
231   gobject_class->finalize = gtr_close_confirmation_dialog_finalize;
232 
233   g_object_class_install_property (gobject_class,
234                                    PROP_UNSAVED_DOCUMENTS,
235                                    g_param_spec_pointer ("unsaved_documents",
236                                                          "Unsaved Documents",
237                                                          "List of Unsaved Documents",
238                                                          (G_PARAM_READWRITE |
239                                                           G_PARAM_CONSTRUCT_ONLY)));
240 
241   g_object_class_install_property (gobject_class,
242                                    PROP_LOGOUT_MODE,
243                                    g_param_spec_boolean ("logout_mode",
244                                                          "Logout Mode",
245                                                          "Whether the dialog is in logout mode",
246                                                          FALSE,
247                                                          (G_PARAM_READWRITE |
248                                                           G_PARAM_CONSTRUCT_ONLY)));
249 }
250 
251 static GList *
get_selected_docs(GtkTreeModel * store)252 get_selected_docs (GtkTreeModel * store)
253 {
254   GList *list;
255   gboolean valid;
256   GtkTreeIter iter;
257 
258   list = NULL;
259   valid = gtk_tree_model_get_iter_first (store, &iter);
260 
261   while (valid)
262     {
263       gboolean to_save;
264       GtrPo *doc;
265 
266       gtk_tree_model_get (store, &iter,
267                           SAVE_COLUMN, &to_save, DOC_COLUMN, &doc, -1);
268       if (to_save)
269         list = g_list_prepend (list, doc);
270 
271       valid = gtk_tree_model_iter_next (store, &iter);
272     }
273 
274   list = g_list_reverse (list);
275 
276   return list;
277 }
278 
gtr_close_confirmation_dialog_get_selected_documents(GtrCloseConfirmationDialog * dlg)279 GList *gtr_close_confirmation_dialog_get_selected_documents
280   (GtrCloseConfirmationDialog * dlg)
281 {
282   GtrCloseConfirmationDialogPrivate *priv;
283   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
284   g_return_val_if_fail (GTR_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL);
285 
286   return g_list_copy (priv->selected_documents);
287 }
288 
289 GtkWidget *
gtr_close_confirmation_dialog_new(GtkWindow * parent,GList * unsaved_documents,gboolean logout_mode)290 gtr_close_confirmation_dialog_new (GtkWindow * parent,
291                                    GList * unsaved_documents,
292                                    gboolean logout_mode)
293 {
294   GtkWidget *dlg;
295   g_return_val_if_fail (unsaved_documents != NULL, NULL);
296 
297   dlg = GTK_WIDGET (g_object_new (GTR_TYPE_CLOSE_CONFIRMATION_DIALOG,
298                                   "unsaved_documents", unsaved_documents,
299                                   "logout_mode", logout_mode, NULL));
300   g_return_val_if_fail (dlg != NULL, NULL);
301 
302   if (parent != NULL)
303     {
304       gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
305     }
306 
307   return dlg;
308 }
309 
310 GtkWidget *
gtr_close_confirmation_dialog_new_single(GtkWindow * parent,GtrPo * doc,gboolean logout_mode)311 gtr_close_confirmation_dialog_new_single (GtkWindow * parent,
312                                           GtrPo * doc, gboolean logout_mode)
313 {
314   GtkWidget *dlg;
315   GList *unsaved_documents;
316   g_return_val_if_fail (doc != NULL, NULL);
317 
318   unsaved_documents = g_list_prepend (NULL, doc);
319 
320   dlg = gtr_close_confirmation_dialog_new (parent,
321                                            unsaved_documents, logout_mode);
322 
323   g_list_free (unsaved_documents);
324 
325   return dlg;
326 }
327 
328 static void
build_single_doc_dialog(GtrCloseConfirmationDialog * dlg)329 build_single_doc_dialog (GtrCloseConfirmationDialog * dlg)
330 {
331   GtkWidget *hbox;
332   GtkWidget *vbox;
333   GtkWidget *primary_label;
334   GtkWidget *image;
335   GtrPo *doc;
336   GFile *location;
337   gchar *doc_name;
338   gchar *str;
339   gchar *markup_str;
340   GtrCloseConfirmationDialogPrivate *priv;
341   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
342 
343   g_return_if_fail (priv->unsaved_documents->data != NULL);
344   doc = GTR_PO (priv->unsaved_documents->data);
345 
346   /* Image */
347   image = gtk_image_new_from_icon_name ("dialog-warning-symbolic",
348                                         GTK_ICON_SIZE_DIALOG);
349   gtk_widget_set_halign (image, 0.5);
350   gtk_widget_set_valign (image, 0.0);
351 
352   /* Primary label */
353   primary_label = gtk_label_new (NULL);
354   gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
355   gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
356   gtk_label_set_xalign (GTK_LABEL (primary_label) , 0.0);
357   gtk_label_set_yalign (GTK_LABEL (primary_label) , 0.5);
358   gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
359 
360   location = gtr_po_get_location (doc);
361   doc_name = g_file_get_path (location);
362   g_object_unref (location);
363 
364   str =
365     g_markup_printf_escaped (_
366                              ("Save the changes to document “%s” before closing?"),
367                              doc_name);
368   g_free (doc_name);
369 
370   markup_str =
371     g_strconcat ("<span weight=\"bold\" size=\"larger\">", str, "</span>",
372                  NULL);
373   g_free (str);
374 
375   gtk_label_set_markup (GTK_LABEL (primary_label), markup_str);
376   g_free (markup_str);
377 
378   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
379   gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
380 
381   gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
382 
383   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
384 
385   gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
386 
387   gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0);
388 
389   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
390                       hbox, FALSE, FALSE, 0);
391 
392   gtk_widget_show_all (hbox);
393 }
394 
395 static void
populate_model(GtkTreeModel * store,GList * docs)396 populate_model (GtkTreeModel * store, GList * docs)
397 {
398   GtkTreeIter iter;
399 
400   while (docs != NULL)
401     {
402       GtrPo *po;
403       GFile *location;
404       gchar *name;
405 
406       po = GTR_PO (docs->data);
407 
408       location = gtr_po_get_location (po);
409       name = g_file_get_path (location);
410       g_object_unref (location);
411 
412       gtk_list_store_append (GTK_LIST_STORE (store), &iter);
413       gtk_list_store_set (GTK_LIST_STORE (store), &iter,
414                           SAVE_COLUMN, TRUE,
415                           NAME_COLUMN, name, DOC_COLUMN, po, -1);
416 
417       g_free (name);
418       docs = g_list_next (docs);
419     }
420 }
421 
422 static void
save_toggled(GtkCellRendererToggle * renderer,gchar * path_str,GtkTreeModel * store)423 save_toggled (GtkCellRendererToggle * renderer,
424               gchar * path_str, GtkTreeModel * store)
425 {
426   GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
427   GtkTreeIter iter;
428   gboolean active;
429 
430   gtk_tree_model_get_iter (store, &iter, path);
431   gtk_tree_model_get (store, &iter, SAVE_COLUMN, &active, -1);
432 
433   active ^= 1;
434 
435   gtk_list_store_set (GTK_LIST_STORE (store), &iter, SAVE_COLUMN, active, -1);
436 
437   gtk_tree_path_free (path);
438 }
439 
440 static GtkWidget *
create_treeview(GtrCloseConfirmationDialogPrivate * priv)441 create_treeview (GtrCloseConfirmationDialogPrivate * priv)
442 {
443   GtkListStore *store;
444   GtkWidget *treeview;
445   GtkCellRenderer *renderer;
446   GtkTreeViewColumn *column;
447 
448   treeview = gtk_tree_view_new ();
449   gtk_widget_set_size_request (treeview, 260, 120);
450   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
451   gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
452 
453   /* Create and populate the model */
454   store = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN,
455                               G_TYPE_STRING, G_TYPE_POINTER);
456   populate_model (GTK_TREE_MODEL (store), priv->unsaved_documents);
457 
458   /* Set model to the treeview */
459   gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
460   g_object_unref (store);
461 
462   priv->list_store = GTK_TREE_MODEL (store);
463 
464   /* Add columns */
465   if (!priv->disable_save_to_disk)
466     {
467       renderer = gtk_cell_renderer_toggle_new ();
468       g_signal_connect (renderer, "toggled",
469                         G_CALLBACK (save_toggled), store);
470 
471       column = gtk_tree_view_column_new_with_attributes ("Save?",
472                                                          renderer,
473                                                          "active",
474                                                          SAVE_COLUMN, NULL);
475       gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
476     }
477 
478   renderer = gtk_cell_renderer_text_new ();
479   column = gtk_tree_view_column_new_with_attributes ("Name",
480                                                      renderer,
481                                                      "text",
482                                                      NAME_COLUMN, NULL);
483   gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
484 
485   return treeview;
486 }
487 
488 static void
build_multiple_docs_dialog(GtrCloseConfirmationDialog * dlg)489 build_multiple_docs_dialog (GtrCloseConfirmationDialog * dlg)
490 {
491   GtrCloseConfirmationDialogPrivate *priv;
492   GtkWidget *hbox;
493   GtkWidget *image;
494   GtkWidget *vbox;
495   GtkWidget *primary_label;
496   GtkWidget *vbox2;
497   GtkWidget *select_label;
498   GtkWidget *scrolledwindow;
499   GtkWidget *treeview;
500   GtkWidget *secondary_label;
501   gchar *str;
502   gchar *markup_str;
503   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
504 
505   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
506   gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
507   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 0);
508 
509   /* Image */
510   image = gtk_image_new_from_icon_name ("dialog-warning-symbolic",
511                                         GTK_ICON_SIZE_DIALOG);
512   gtk_widget_set_halign (image, 0.5);
513   gtk_widget_set_valign (image, 0.0);
514   gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
515 
516   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
517   gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
518 
519   /* Primary label */
520   primary_label = gtk_label_new (NULL);
521   gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
522   gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
523   gtk_label_set_xalign (GTK_LABEL (primary_label), 0.0);
524   gtk_label_set_yalign (GTK_LABEL (primary_label), 0.5);
525   gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
526 
527   if (priv->disable_save_to_disk)
528     str =
529       g_strdup_printf (ngettext
530                        ("Changes to %d document will be permanently lost.",
531                         "Changes to %d documents will be permanently lost.",
532                         g_list_length (priv->unsaved_documents)),
533                        g_list_length (priv->unsaved_documents));
534   else
535     str =
536       g_strdup_printf (ngettext
537                        ("There is %d document with unsaved changes. "
538                         "Save changes before closing?",
539                         "There are %d documents with unsaved changes. "
540                         "Save changes before closing?",
541                         g_list_length (priv->unsaved_documents)),
542                        g_list_length (priv->unsaved_documents));
543 
544   markup_str =
545     g_strconcat ("<span weight=\"bold\" size=\"larger\">", str, "</span>",
546                  NULL);
547   g_free (str);
548 
549   gtk_label_set_markup (GTK_LABEL (primary_label), markup_str);
550   g_free (markup_str);
551   gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0);
552 
553   vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
554   gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
555 
556   if (priv->disable_save_to_disk)
557     select_label =
558       gtk_label_new_with_mnemonic (_("Docum_ents with unsaved changes:"));
559   else
560     select_label =
561       gtk_label_new_with_mnemonic (_
562                                    ("S_elect the documents you want to save:"));
563 
564   gtk_box_pack_start (GTK_BOX (vbox2), select_label, FALSE, FALSE, 0);
565   gtk_label_set_line_wrap (GTK_LABEL (select_label), TRUE);
566   gtk_label_set_xalign (GTK_LABEL (select_label), 0.0);
567   gtk_label_set_yalign (GTK_LABEL (select_label), 0.5);
568 
569   scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
570   gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0);
571   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
572                                        GTK_SHADOW_IN);
573 
574   treeview = create_treeview (priv);
575   gtk_container_add (GTK_CONTAINER (scrolledwindow), treeview);
576 
577   /* Secondary label */
578   if (priv->disable_save_to_disk)
579     secondary_label =
580       gtk_label_new (_
581                      ("Saving has been disabled by the system administrator."));
582   else
583     secondary_label = gtk_label_new (_("If you don’t save, "
584                                        "all your changes will be permanently lost."));
585 
586   gtk_box_pack_start (GTK_BOX (vbox2), secondary_label, FALSE, FALSE, 0);
587   gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
588   gtk_label_set_xalign (GTK_LABEL (secondary_label), 0.0);
589   gtk_label_set_yalign (GTK_LABEL (secondary_label), 0.5);
590   gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
591 
592   gtk_label_set_mnemonic_widget (GTK_LABEL (select_label), treeview);
593 
594   gtk_widget_show_all (hbox);
595 }
596 
597 static void
set_unsaved_document(GtrCloseConfirmationDialog * dlg,const GList * list)598 set_unsaved_document (GtrCloseConfirmationDialog * dlg, const GList * list)
599 {
600   GtrCloseConfirmationDialogPrivate *priv;
601   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
602 
603   g_return_if_fail (list != NULL);
604 
605   g_return_if_fail (priv->unsaved_documents == NULL);
606 
607   priv->unsaved_documents = g_list_copy ((GList *) list);
608 
609   if (GET_MODE (priv) == SINGLE_DOC_MODE)
610     {
611       build_single_doc_dialog (dlg);
612     }
613   else
614     {
615       build_multiple_docs_dialog (dlg);
616     }
617 }
618 
gtr_close_confirmation_dialog_get_unsaved_documents(GtrCloseConfirmationDialog * dlg)619 const GList *gtr_close_confirmation_dialog_get_unsaved_documents
620   (GtrCloseConfirmationDialog * dlg)
621 {
622   GtrCloseConfirmationDialogPrivate *priv;
623   priv = gtr_close_confirmation_dialog_get_instance_private (dlg);
624   g_return_val_if_fail (GTR_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL);
625 
626   return priv->unsaved_documents;
627 }
628