File: errorcheckingpreferences.h

package info (click to toggle)
subtitleeditor 0.56.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,880 kB
  • sloc: cpp: 26,446; makefile: 1,713; perl: 434; sh: 259; xml: 149
file content (141 lines) | stat: -rw-r--r-- 5,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#pragma once

// subtitleeditor -- a tool to create or edit subtitle
//
// https://subtitleeditor.github.io/subtitleeditor/
// https://github.com/subtitleeditor/subtitleeditor/
//
// Copyright @ 2005-2018, kitone
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <gtkmm_utility.h>
#include <widget_config_utility.h>

#include <memory>

#include "errorchecking.h"

class DialogErrorCheckingPreferences : public Gtk::Dialog {
   class Column : public Gtk::TreeModel::ColumnRecord {
     public:
      Column() {
         add(enabled);
         add(label);
         add(name);
         add(checker);
      }
      Gtk::TreeModelColumn<bool> enabled;            // is activated ?
      Gtk::TreeModelColumn<Glib::ustring> label;     // human label
      Gtk::TreeModelColumn<Glib::ustring> name;      // internal name
      Gtk::TreeModelColumn<ErrorChecking*> checker;  // internal name
   };

  public:
   DialogErrorCheckingPreferences(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder) : Gtk::Dialog(cobject) {
      utility::set_transient_parent(*this);

      builder->get_widget("treeview-plugins", m_treeviewPlugins);

      get_and_init_widget(builder, "spin-min-characters-per-second", "timing", "min-characters-per-second");
      get_and_init_widget(builder, "spin-max-characters-per-second", "timing", "max-characters-per-second");
      get_and_init_widget(builder, "spin-min-gap-between-subtitles", "timing", "min-gap-between-subtitles");
      get_and_init_widget(builder, "spin-min-display", "timing", "min-display");
      get_and_init_widget(builder, "spin-max-characters-per-line", "timing", "max-characters-per-line");
      get_and_init_widget(builder, "spin-max-line-per-subtitle", "timing", "max-line-per-subtitle");

      create_treeview();
   }

   static void create(Gtk::Window& parent, std::vector<ErrorChecking*>& list) {
      std::unique_ptr<DialogErrorCheckingPreferences> dialog(gtkmm_utility::get_widget_derived<DialogErrorCheckingPreferences>(
         SE_DEV_VALUE(SE_PLUGIN_PATH_UI, SE_PLUGIN_PATH_DEV), "dialog-error-checking-preferences.ui", "dialog-error-checking-preferences"));

      dialog->set_transient_for(parent);
      dialog->init_treeview(list);
      dialog->run();
   }
   void get_and_init_widget(const Glib::RefPtr<Gtk::Builder>& builder,
                            const Glib::ustring& widget_name,
                            const Glib::ustring& config_group,
                            const Glib::ustring& config_key) {
      Gtk::Widget* widget = NULL;

      builder->get_widget(widget_name, widget);

      widget_config::read_config_and_connect(widget, config_group, config_key);
   }

   void create_treeview() {
      // create the model
      m_model = Gtk::ListStore::create(m_column);
      m_treeviewPlugins->set_model(m_model);

      Gtk::TreeViewColumn* column = NULL;
      Gtk::CellRendererToggle* toggle;
      Gtk::CellRendererText* renderer = NULL;

      // enabled column
      column = manage(new Gtk::TreeViewColumn);
      m_treeviewPlugins->append_column(*column);

      //
      toggle = manage(new Gtk::CellRendererToggle);
      toggle->signal_toggled().connect(sigc::mem_fun(*this, &DialogErrorCheckingPreferences::on_enabled_toggled));
      column->pack_start(*toggle, false);
      column->add_attribute(toggle->property_active(), m_column.enabled);

      // label column
      column = manage(new Gtk::TreeViewColumn);
      m_treeviewPlugins->append_column(*column);
      //
      renderer = manage(new Gtk::CellRendererText);
      renderer->property_wrap_mode() = Pango::WRAP_WORD;
      renderer->property_wrap_width() = 300;

      column->pack_start(*renderer, true);
      column->add_attribute(renderer->property_markup(), m_column.label);

      // set treeview property
      m_treeviewPlugins->set_rules_hint(true);
      m_treeviewPlugins->show_all();
   }

   void init_treeview(std::vector<ErrorChecking*>& list) {
      for (const auto& checker : list) {
         Gtk::TreeIter it = m_model->append();
         (*it)[m_column.enabled] = checker->get_active();
         (*it)[m_column.name] = checker->get_name();
         (*it)[m_column.label] = build_message("<b>%s</b>\n%s", checker->get_label().c_str(), checker->get_description().c_str());
         (*it)[m_column.checker] = checker;
      }
   }

   void on_enabled_toggled(const Glib::ustring& path) {
      Gtk::TreeIter it = m_model->get_iter(path);
      if (it) {
         ErrorChecking* checker = (*it)[m_column.checker];

         (*it)[m_column.enabled] = !static_cast<bool>((*it)[m_column.enabled]);

         // save on config
         checker->set_active((*it)[m_column.enabled]);
      }
   }

  protected:
   Gtk::TreeView* m_treeviewPlugins;
   Glib::RefPtr<Gtk::ListStore> m_model;
   Column m_column;
};