std::unique_ptr<message_box_type> create_unsupported_format_file_message_box(
     const tetengo2::stdalt::filesystem::path& path,
     abstract_window_type&                     parent) const
 {
     return std::make_unique<message_box_type>(
         parent,
         m_message_catalog.get(TETENGO2_TEXT("App:Bobura")),
         m_message_catalog.get(TETENGO2_TEXT("Message:File:Unsupported format file.")),
         path.template string<typename string_type::value_type>(),
         message_box_type::button_style_type::ok(false),
         message_box_type::icon_style_type::error);
 }
Example #2
0
        void execute(model_type& model, abstract_window_type& parent)
        const
        {
            boost::ignore_unused(model, parent);

            shell_type::instance().execute(string_type{ TETENGO2_TEXT("http://www.tetengo.org/") });
        }
 std::unique_ptr<message_box_type> create_message_box(abstract_window_type& parent) const
 {
     const auto file_path = m_model.has_path() ?
                                m_model.path().template string<typename string_type::value_type>() :
                                m_message_catalog.get(TETENGO2_TEXT("Common:Untitled"));
     return std::make_unique<message_box_type>(
         parent,
         m_message_catalog.get(TETENGO2_TEXT("App:Bobura")),
         m_message_catalog.get(
             TETENGO2_TEXT("Message:File:The file has been changed. Do you want to save the changes?")),
         file_path,
         message_box_type::button_style_type::yes_no(
             true,
             m_message_catalog.get(TETENGO2_TEXT("Message:File:&Save")),
             m_message_catalog.get(TETENGO2_TEXT("Message:File:&Don't save"))),
         message_box_type::icon_style_type::warning);
 }
        std::unique_ptr<button_type> create_ok_button()
        {
            auto p_button = tetengo2::stdalt::make_unique<button_type>(m_base, button_type::style_type::default_);

            p_button->set_text(m_message_catalog.get(TETENGO2_TEXT("Common:OK")));
            p_button->mouse_observer_set().clicked().connect(ok_button_mouse_clicked_observer_type{ m_base });

            return std::move(p_button);
        }
        std::unique_ptr<link_label_type> create_link_label()
        {
            auto p_label =tetengo2::stdalt::make_unique<link_label_type>(m_base);

            p_label->set_text(string_type{ TETENGO2_TEXT("http://www.tetengo.org/") });
            p_label->set_target(p_label->text());

            return std::move(p_label);
        }
        std::unique_ptr<label_type> create_title_label()
        {
            using char_type = typename string_type::value_type;
            std::basic_ostringstream<char_type> title{};
            title <<
                boost::basic_format<char_type>(TETENGO2_TEXT("%s  %s %s")) %
                m_message_catalog.get(TETENGO2_TEXT("App:Bobura")) %
                m_message_catalog.get(TETENGO2_TEXT("Dialog:About:version")) %
                string_type{ TETENGO2_TEXT("0.0.0") };

            auto p_label = tetengo2::stdalt::make_unique<label_type>(m_base);

            p_label->set_text(title.str());
            auto p_background = tetengo2::stdalt::make_unique<transparent_background_type>();
            p_label->set_background(std::move(p_background));

            return std::move(p_label);
        }
Example #7
0
        static std::vector<string_type> make_labels()
        {
            std::vector<string_type> labels{
                { string_type{ TETENGO2_TEXT("10%") } },  { string_type{ TETENGO2_TEXT("25%") } },
                { string_type{ TETENGO2_TEXT("50%") } },  { string_type{ TETENGO2_TEXT("75%") } },
                { string_type{ TETENGO2_TEXT("100%") } }, { string_type{ TETENGO2_TEXT("150%") } },
                { string_type{ TETENGO2_TEXT("200%") } }, { string_type{ TETENGO2_TEXT("400%") } },
            };

            assert(labels.size() == scales().size());
            return labels;
        }
        std::unique_ptr<label_type> create_copyright_label()
        {
            auto p_label = tetengo2::stdalt::make_unique<label_type>(m_base);

            p_label->set_text(string_type{ TETENGO2_TEXT("Copyright (C) 2007-2015 kaoru") });
            auto p_background = tetengo2::stdalt::make_unique<transparent_background_type>();
            p_label->set_background(std::move(p_background));

            return std::move(p_label);
        }
Example #9
0
        void initialize_property_bar(property_bar& self)
        {
            self.set_text(m_message_catalog.get(TETENGO2_TEXT("PropertyBar:Properties")));

            m_p_map_box = tetengo2::stdalt::make_unique<map_box_type>(self);

            self.size_observer_set().resized().connect(resized_observer_type{ self, *m_p_map_box });

            m_p_map_box->mouse_observer_set().pressed().connect(mouse_pressed_observer_type{ *m_p_map_box });

            load_settings(self);
        }
        void initialize_dialog()
        {
            m_base.set_text(m_message_catalog.get(TETENGO2_TEXT("Dialog:About:About")));

            m_p_application_image = create_application_image();
            m_p_title_label = create_title_label();
            m_p_copyright_label = create_copyright_label();
            m_p_link_label = create_link_label();
            m_p_ok_button = create_ok_button();

            locate_controls();
        }
        std::unique_ptr<image_type> create_application_image()
        {
            auto p_image = tetengo2::stdalt::make_unique<image_type>(m_base);

            auto p_icon =
                tetengo2::stdalt::make_unique<icon_type>(
                    m_settings.image_directory_path() / string_type{ TETENGO2_TEXT("bobura_app.ico") },
                    dimension_type{ width_type{ 4 }, height_type{ 4 } }
                );
            p_image->set_icon(std::move(p_icon));

            return std::move(p_image);
        }
        void operator()(
            model_type&                                                           model,
            const tetengo2::stdalt::optional<tetengo2::stdalt::filesystem::path>& given_path,
            abstract_window_type&                                                 parent) const
        {
            if (!m_ask_file_path && !model.has_path() && !given_path)
                return;

            if (!m_confirm_file_save(parent))
                return;

            tetengo2::stdalt::filesystem::path path{};
            if (given_path)
            {
                path = *given_path;
            }
            else if (m_ask_file_path)
            {
                file_open_dialog_type dialog{ m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:Open")),
                                              make_file_filters(),
                                              parent };
                const auto            ok = dialog.do_modal();
                if (!ok)
                    return;

                path = dialog.result();
            }
            else
            {
                assert(model.has_path());
                path = model.path();
            }

            std::ifstream input_stream{ path, std::ios_base::binary };
            if (!input_stream)
            {
                create_cant_open_file_message_box(path, parent)->do_modal();
                return;
            }

            reader_selector_type reader_selector{ reader_set_type::create_readers(
                parent, path.template string<typename string_type::value_type>(), m_message_catalog) };
            const auto           first = tetengo2::iterator::make_observable_forward_iterator(
                boost::spirit::make_default_multi_pass(std::istreambuf_iterator<char>{ input_stream }));
            const auto last = tetengo2::iterator::make_observable_forward_iterator(
                boost::spirit::make_default_multi_pass(std::istreambuf_iterator<char>{}));
            auto error = reader_error_type::none;
            auto p_timetable = reader_selector.read(first, last, error);
            if (!p_timetable)
            {
                switch (error)
                {
                case reader_error_type::canceled:
                    break; // Do nothing.
                case reader_error_type::corrupted:
                    create_file_broken_message_box(path, parent)->do_modal();
                    break;
                case reader_error_type::unsupported:
                    create_unsupported_format_file_message_box(path, parent)->do_modal();
                    break;
                default:
                    assert(false);
                    BOOST_THROW_EXCEPTION(std::logic_error("Unknown reader error."));
                }
                return;
            }

            model.reset_timetable(std::move(p_timetable), path);
        }
 typename file_open_dialog_type::file_filters_type make_file_filters() const
 {
     return {
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:All Timetable Files")),
           string_type{ TETENGO2_TEXT("btt;*.btt_bz2;*.oud;*.dia") } },
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:Timetable Files")),
           string_type{ TETENGO2_TEXT("btt") } },
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:Timetable Files (Compressed)")),
           string_type{ TETENGO2_TEXT("btt_bz2") } },
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:OuDia Files")),
           string_type{ TETENGO2_TEXT("oud") } },
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:WinDIA Files")),
           string_type{ TETENGO2_TEXT("dia") } },
         { m_message_catalog.get(TETENGO2_TEXT("Dialog:FileOpenSave:All Files")),
           string_type{ TETENGO2_TEXT("*") } },
     };
 }
        bool selects_impl(const iterator first, const iterator last)
        {
            if (std::distance(first, last) < 2)
                return false;
            if (input_string_type{ first, boost::next(first, 2) } != input_string_type(TETENGO2_TEXT("BZ")))
                return false;

            const input_string_type input_string{ first, last };
            boost::iostreams::filtering_istream input_stream{ boost::make_iterator_range(input_string) };
            boost::iostreams::filtering_istream filtering_input_stream{};
            filtering_input_stream.push(boost::iostreams::bzip2_decompressor());
            filtering_input_stream.push(input_stream);

            try
            {
                const auto first =
                    tetengo2::make_observable_forward_iterator(
                        boost::spirit::make_default_multi_pass(
                            std::istreambuf_iterator<typename iterator::value_type>{ filtering_input_stream }
                        )
                    );
                const auto last =
                    tetengo2::make_observable_forward_iterator(
                        boost::spirit::make_default_multi_pass(
                            std::istreambuf_iterator<typename iterator::value_type>{}
                        )
                    );
                return m_p_reader->selects(first, last);
            }
            catch (const boost::iostreams::bzip2_error&)
            {
                return false;
            }
            catch (...)
            {
                throw;
            }
        }