1 //  Copyright (C) 2010, 2014, 2020 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #include <config.h>
19 #include <ostream>
20 #include <iostream>
21 #include <sstream>
22 
23 #include <sigc++/functors/mem_fun.h>
24 
25 #include "validation-dialog.h"
26 
27 #include "ucompose.hpp"
28 #include "File.h"
29 #include "defs.h"
30 
31 
ValidationDialog(Gtk::Window & parent,std::list<Glib::ustring> errors,std::list<Glib::ustring> warnings)32 ValidationDialog::ValidationDialog(Gtk::Window &parent, std::list<Glib::ustring> errors, std::list<Glib::ustring> warnings)
33  : LwEditorDialog(parent, "validation-dialog.ui")
34 {
35   std::stringstream ss;
36   ss << std::endl;
37   Glib::ustring newline = ss.str();
38   xml->get_widget("label", label);
39   xml->get_widget("textview", textview);
40   xml->get_widget("scrolledwindow", scrolled_window);
41   if (errors.size() == 0 && warnings.size() == 0)
42     {
43       Glib::ustring msg = _("The scenario is valid.");
44       label->set_markup("<b>" + msg + "</b>");
45       scrolled_window->set_no_show_all (true);
46       scrolled_window->set_visible (false);
47     }
48   else if (errors.size() && warnings.size() == 0)
49     {
50       label->set_text
51         (String::ucompose(ngettext("There is %1 error",
52                                    "There are %1 errors", errors.size()),
53                           errors.size()));
54       Glib::ustring s;
55       for (auto e : errors)
56         s += e + newline;
57       textview->get_buffer()->set_text(s);
58 
59     }
60   else if (errors.size() == 0 && warnings.size())
61     {
62       label->set_text
63       (String::ucompose(ngettext("There is %1 warning",
64                                  "There are %1 warnings", warnings.size()),
65                         warnings.size()));
66       Glib::ustring s;
67       for (auto w : warnings)
68         s += w + newline;
69       textview->get_buffer()->set_text(s);
70     }
71   else if (errors.size() && warnings.size())
72     {
73       Glib::ustring s =
74         String::ucompose(ngettext("There is %1 error",
75                                   "There are %1 errors", errors.size()),
76                          errors.size());
77       s +=
78         String::ucompose(ngettext(", and %1 warning",
79                                   ", and %1 warnings", warnings.size()),
80                          warnings.size());
81       label->set_text(s);
82       s = _("Errors:") + newline;
83       for (auto e : errors)
84         s += e + newline;
85       s+= newline + newline;
86       s = _("Warnings:") + newline;
87       for (auto w : warnings)
88         s += w + newline;
89       textview->get_buffer()->set_text(s);
90     }
91 }
92