📄 settings.cpp
字号:
attach(logfile_help_button, 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, standard_size/3, standard_size); attach(filler2, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0); logfile_help_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &LoggingTable::show_help), static_cast<int>(LoggingMessages::logfile))); tooltips.set_tip(logfile_help_button, help_messages.get_message(LoggingMessages::logfile)); set_border_width(standard_size/3);}void LoggingTable::show_help(int message_index) { show_help_sig(help_messages.get_message(message_index), help_messages.get_caption(message_index));}void LoggingTable::clear(void) { logfile_entry.set_text("");}PageTable::PageTable(const int standard_size): Gtk::Table(4, 3, false), page_label(gettext("Page Size: ")), res_label(gettext("Sent Fax Resolution: ")), a4_button("A4"), letter_button("Letter"), legal_button("Legal"), standard_button(gettext("Standard")), fine_button(gettext("Fine")), page_box(false, 2), res_box(false, 2) { page_label.set_justify(Gtk::JUSTIFY_RIGHT); res_label.set_justify(Gtk::JUSTIFY_RIGHT); Gtk::RadioButton::Group size_group(a4_button.get_group()); letter_button.set_group(size_group); legal_button.set_group(size_group); a4_button.set_active(true); page_box.pack_start(a4_button, false, false, 10); page_box.pack_start(letter_button, false, false, 10); page_box.pack_start(legal_button, false, false, 10); page_box.pack_start(page_box_filler, true, false, 0); page_frame.add(page_box); Gtk::RadioButton::Group res_group(standard_button.get_group()); fine_button.set_group(res_group); fine_button.set_active(true); res_box.pack_start(standard_button, false, false, 10); res_box.pack_start(fine_button, false, false, 10); res_box.pack_start(res_box_filler, true, false, 0); res_frame.add(res_box); Glib::RefPtr<Gdk::Pixbuf> pixbuf_r(Gdk::Pixbuf::create_from_xpm_data(help_xpm)); Gtk::Image* image_p = manage(new Gtk::Image(pixbuf_r)); page_help_button.add(*image_p); image_p = manage(new Gtk::Image(pixbuf_r)); res_help_button.add(*image_p); attach(filler1, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0); attach(page_label, 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, standard_size/3, standard_size); attach(page_frame, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, standard_size/3, standard_size); attach(page_help_button, 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, standard_size/3, standard_size); attach(res_label, 0, 1, 2, 3, Gtk::SHRINK, Gtk::SHRINK, standard_size/3, standard_size); attach(res_frame, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, standard_size/3, standard_size); attach(res_help_button, 2, 3, 2, 3, Gtk::SHRINK, Gtk::SHRINK, standard_size/3, standard_size); attach(filler2, 1, 2, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0); page_help_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &PageTable::show_help), static_cast<int>(PageMessages::page))); res_help_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &PageTable::show_help), static_cast<int>(PageMessages::res))); tooltips.set_tip(page_help_button, help_messages.get_message(PageMessages::page)); tooltips.set_tip(res_help_button, help_messages.get_message(PageMessages::res)); set_border_width(standard_size/3);}Glib::ustring PageTable::get_page(void) const { Glib::ustring return_val("a4"); if (letter_button.get_active()) return_val = "letter"; else if (legal_button.get_active()) return_val = "legal"; return return_val;}void PageTable::set_page(const Glib::ustring& page_string) { std::string temp(page_string.lowercase()); if (!temp.compare("a4")) a4_button.set_active(true); else if (!temp.compare("letter")) letter_button.set_active(true); else if (!temp.compare("legal")) legal_button.set_active(true);}Glib::ustring PageTable::get_res(void) const { Glib::ustring return_val("fine"); if (standard_button.get_active()) return_val = "standard"; return return_val;}void PageTable::set_res(const Glib::ustring& res_string) { std::string temp(res_string.lowercase()); if (!temp.compare("fine")) fine_button.set_active(true); else if (!temp.compare("standard")) standard_button.set_active(true);}void PageTable::show_help(int message_index) { show_help_sig(help_messages.get_message(message_index), help_messages.get_caption(message_index));}void PageTable::clear(void) { a4_button.set_active(true); fine_button.set_active(true);}SettingsDialog::SettingsDialog(const int size, Gtk::Window& window, bool skip_old_settings): // skip_old_settings has a default value of false Gtk::Window(Gtk::WINDOW_TOPLEVEL), standard_size(size), in_exec_loop(false), is_home_config(false), ok_button(Gtk::Stock::OK), cancel_button(Gtk::Stock::CANCEL), button_box(Gtk::BUTTONBOX_END, standard_size/2), window_table(2, 2, false), parent(window), identity_table(standard_size), modem_table(standard_size), parms_table(standard_size), print_table(standard_size), view_table(standard_size), sock_table(standard_size), receive_table(standard_size), logging_table(standard_size), page_table(standard_size) { // we set skip_old_settings as true in MainWindow::MainWindow(), where no config file has // been found, to prevent that fact being reported twice if (!skip_old_settings) read_config(); if (!is_home_config) { // if skip_old_settings is true, then is_home_config is always false label.set_line_wrap(true); Glib::ustring label_text(gettext("Note: pressing the OK button will save the " "settings in file")); label_text += " ~/." RC_FILE; label.set_text(label_text); } else { Gtk::Button* reset_button_p = manage(new Gtk::Button(gettext("Reset"))); reset_button_p->signal_clicked().connect(sigc::mem_fun(*this, &SettingsDialog::get_reset_settings_prompt)); reset_button_p->set_flags(Gtk::CAN_DEFAULT); button_box.add(*reset_button_p); } button_box.add(cancel_button); button_box.add(ok_button); window_table.attach(notebook, 0, 2, 0, 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL | Gtk::EXPAND, standard_size/2, standard_size/4); window_table.attach(label, 0, 1, 1, 2, Gtk::EXPAND, Gtk::SHRINK, standard_size/2, standard_size/4); window_table.attach(button_box, 1, 2, 1, 2, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK, standard_size/2, standard_size/4); notebook.set_tab_pos(Gtk::POS_TOP); notebook.set_scrollable(true); // set up the notebook pages { using namespace Gtk::Notebook_Helpers; PageList& page_list = notebook.pages(); page_list.push_back(TabElem(identity_table, gettext("Identity"))); page_list.push_back(TabElem(modem_table, gettext("Modem"))); page_list.push_back(TabElem(parms_table, gettext("Params"))); page_list.push_back(TabElem(print_table, gettext("Print"))); page_list.push_back(TabElem(view_table, gettext("View"))); page_list.push_back(TabElem(sock_table, gettext("Socket"))); page_list.push_back(TabElem(receive_table, gettext("Receive"))); page_list.push_back(TabElem(logging_table, gettext("Logging"))); page_list.push_back(TabElem(page_table, gettext("Page"))); } ok_button.set_flags(Gtk::CAN_DEFAULT); cancel_button.set_flags(Gtk::CAN_DEFAULT); ok_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &SettingsDialog::selected), true)); cancel_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &SettingsDialog::selected), false)); identity_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); modem_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); parms_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); print_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); view_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); sock_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); receive_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); logging_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); page_table.show_help_sig.connect(sigc::mem_fun(*this, &SettingsDialog::show_help)); add(window_table); set_title(gettext("efax-gtk: settings")); set_transient_for(parent); set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG); parent.set_sensitive(false); set_modal(true); notebook.set_size_request(standard_size * 22, standard_size * 12); set_border_width(standard_size/2); cancel_button.grab_focus(); set_position(Gtk::WIN_POS_CENTER_ON_PARENT); set_icon(prog_config.window_icon_r); show_all();}void SettingsDialog::selected(bool accept) { bool finish = false; if (accept) { if (write_config()) { parent.set_sensitive(true); // do this before we emit accepted() hide_all(); finish = true; accepted(configure_prog(true)); } } else { parent.set_sensitive(true); hide_all(); finish = true; } if (finish) { if (in_exec_loop) Gtk::Main::quit(); // if we have not called exec(), then this dialog is self-owning and it is safe to call `delete this' else delete this; }}bool SettingsDialog::on_delete_event(GdkEventAny*) { selected(false); return true; // returning true prevents destroy sig being emitted}void SettingsDialog::exec(void) { in_exec_loop = true; Gtk::Main::run();}bool SettingsDialog::write_config(void) { // returns false if any of the entered parameters is invalid, otherwise it returns true bool return_val = true; std::ifstream filein; if (!rcfile.empty()) { filein.open(rcfile.c_str(), std::ios::in); if (!filein) { std::string message("Can't open file "); message += rcfile; message += "\n\n"; write_error(message.c_str()); } } std::vector<std::string> file_list; std::string file_read; Glib::ustring temp; Glib::ustring name_line("NAME: "); temp = identity_table.get_name(); strip(temp); name_line += temp; Glib::ustring number_line("NUMBER: "); temp = identity_table.get_number(); strip(temp); number_line += temp; Glib::ustring device_line; temp = modem_table.get_device(); strip(temp); if (temp.empty()) device_line = "#DEVICE: modem"; else { device_line = "DEVICE: "; device_line += temp; } Glib::ustring lock_line; temp = modem_table.get_lock(); strip(temp); if (temp.empty()) lock_line = "#LOCK: /var/lock"; else { lock_line = "LOCK: "; lock_line += temp; } Glib::ustring class_line; temp = modem_table.get_class(); strip(temp); if (temp.empty()) class_line = "#CLASS: 2"; else { if (temp.compare("1") && temp.compare("2") && temp.compare("2.0")) { class_line = "#CLASS: 2"; return_val = false; InfoDialog dialog(gettext("Invalid modem class specified"), gettext("Config Error"), standard_size, Gtk::MESSAGE_ERROR, *this); dialog.exec(); } else { class_line = "CLASS: "; class_line += temp; } } Glib::ustring page_line; temp = page_table.get_page(); strip(temp); if (temp.empty()) page_line = "#PAGE: a4"; else { if (temp.compare("a4") && temp.compare("letter") && temp.compare("legal")) { page_line = "#PAGE: a4"; return_val = false; InfoDialog dialog(gettext("Invalid page size specified"), gettext("Config Error"), standard_size, Gtk::MESSAGE_ERROR, *this); dialog.exec(); } else { page_line = "PAGE: "; page_line += temp; } } Glib::ustring res_line; temp = page_table.get_res(); strip(temp); if (temp.empty()) res_line = "#RES: fine"; else { if (temp.compare("fine") && temp.compare("standard")) { res_line = "#RES: fine"; return_val = false; InfoDialog dialog(gettext("Invalid sent fax resolution specified"), gettext("Config Error"), standard_size, Gtk::MESSAGE_ERROR, *this); dialog.exec(); } else { res_line = "RES: "; res_line += temp; } } Glib::ustring rings_line; temp = modem_table.get_rings(); strip(temp); if (temp.empty()) rings_line = "#RINGS: 1";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -