📄 mainwindow.cpp
字号:
dialog_p->present(); // there is no memory leak - the exec() method has not been called so the dialog // is self-owning and will delete itself when it is closed }}void MainWindow::enter_socket_file_slot(const std::pair<Glib::ustring, std::string>& fax_to_insert) { // this slot is connected to the SocketListDialog::selected_fax signal and is // called (that is, whenever the send fax button is pressed in a dialog object of // that class) // it is also connected to the SocketNotifyDialog::fax_name_sig signal, and is called // when the send fax button is pressed in a dialog object of that class // fax_to_insert.first is the fax label for the fax selected in the SocketListDialog object // and fax_to_insert.second is the real (temporary) file name obtained from mkstemp() // now show the fax label in the "Files to fax" box // in case we are called from SocketNotifyDialog::fax_name_sig (when it // is possible that the file selection buttons will be active) make // sure that the socket button is active // (we do not have to close either file selection dialogs, because if // they were open when fax_to_send_notify_slot() was called then // it would not bring up a SocketNotifyDialog object, and if a file selection // dialog was opened up after a SocketNotifyDialog object was brought up, // it would render the SocketNotifyDialog inoperative by making its parent // (this object) insensitive, so we could not reach here until it is closed) socket_button.set_active(true); // now enter the particulars of the selected file in MainWindow::selected_socket_list_file // (we will use this later to send the fax in MainWindow::sendfax_slot()) selected_socket_list_file = fax_to_insert.second; Glib::ustring socket_file_label("*** "); socket_file_label += fax_to_insert.first; socket_file_label += " ***"; set_files_slot(socket_file_label);}void MainWindow::remove_from_socket_server_filelist(const std::string& file) { socket_server.remove_file(file); // if we have stored the file name for sending, delete it // and remove from the "Fax to send" box if (file == selected_socket_list_file) { selected_socket_list_file = ""; set_files_slot(""); }}void MainWindow::set_file_items_sensitive_slot(void) { single_file_item_p->set_sensitive(true); multiple_file_item_p->set_sensitive(true); single_file_button.set_sensitive(true); multiple_file_button.set_sensitive(true); file_entry.set_editable(true); socket_list_item_p->set_sensitive(false); socket_list_button.set_sensitive(false); set_focus(single_file_button); // we now need to close the socket list dialog (if it is open), empty // the std::string object holding particulars of the currently selected // print job received from the socket server and any print job in the // Gtk::Entry object for that print job close_socket_list_dialog(); selected_socket_list_file = ""; set_files_slot("");}void MainWindow::set_socket_items_sensitive_slot(void) { single_file_item_p->set_sensitive(false); multiple_file_item_p->set_sensitive(false); single_file_button.set_sensitive(false); multiple_file_button.set_sensitive(false); file_entry.set_editable(false); socket_list_item_p->set_sensitive(true); socket_list_button.set_sensitive(true); set_focus(socket_list_button);}void MainWindow::addressbook_slot(void) { if (!AddressBook::get_is_address_list()) { AddressBook* dialog_p = new AddressBook(standard_size, *this); dialog_p->accepted.connect(sigc::mem_fun(*this, &MainWindow::set_number_slot)); // there is no memory leak -- AddressBook will delete its own memory // when it is closed }}void MainWindow::file_list_slot(void) { FileListDialog* dialog_p = new FileListDialog(standard_size, *this); dialog_p->accepted.connect(sigc::mem_fun(*this, &MainWindow::set_files_slot)); // there is no memory leak -- FaxListDialog is modeless and will delete its own memory // when it is closed}void MainWindow::settings_slot(void) { if (efax_controller.get_state() != EfaxController::inactive) { InfoDialog* dialog_p; Glib::ustring message(gettext("Can't change settings unless " "the program is inactive\n" "Press the Stop button to make it inactive")); dialog_p = new InfoDialog(message, "Change settings", standard_size, Gtk::MESSAGE_WARNING, *this); // there is no memory leak -- exec() was not called so InfoDialog // will delete its own memory when it is closed } else { SettingsDialog* dialog_p = new SettingsDialog(standard_size, *this); dialog_p->accepted.connect(sigc::mem_fun(*this, &MainWindow::settings_changed_slot)); // there is no memory leak -- SettingsDialog will delete its own memory // when it is closed }}void MainWindow::settings_changed_slot(const Glib::ustring& messages) { text_window.reset_logfile(); if (!messages.empty()) { try { text_window.write_red_slot(Glib::locale_from_utf8(messages).c_str()); text_window.write_red_slot("\n"); } catch (Glib::ConvertError&) { write_error("UTF-8 conversion error in MainWindow::settings_changed_slot()\n"); } } if ((!prog_config.sock_server || prog_config.sock_server_port.empty()) && socket_server.is_server_running()) { socket_server.stop(); } else if (prog_config.sock_server && !prog_config.sock_server_port.empty() && !socket_server.is_server_running()) { socket_server.start(std::string(prog_config.sock_server_port), prog_config.other_sock_client_address); } else if (socket_server.get_port() != std::string(prog_config.sock_server_port) || socket_server.get_other_sock_client_address() != prog_config.other_sock_client_address) { socket_server.stop(); socket_server.start(std::string(prog_config.sock_server_port), prog_config.other_sock_client_address); }}void MainWindow::helpfile_slot(void) { if (!HelpDialog::get_is_helpfile()) { helpfile_p = new HelpDialog(standard_size); } else helpfile_p->present(); // there is no memory leak -- HelpDialog is modeless and will delete its own memory // when it is closed}void MainWindow::set_number_slot(const Glib::ustring& number) { number_entry.set_text(number); if (file_entry.get_text_length()) { // reset this window as sensitive to make grab_focus() work set_sensitive(true); send_button.grab_focus(); }}void MainWindow::about_slot(bool efax_gtk) { InfoDialog* dialog_p; if (efax_gtk) { Glib::ustring message("efax-gtk-" VERSION "\n"); message += gettext("Copyright (C) 2001 - 2004 Chris Vine\n\n" "This program is released under the " "GNU General Public License, version 2"); dialog_p = new InfoDialog(message, gettext("About efax-gtk"), standard_size, Gtk::MESSAGE_INFO, *this); } else { Glib::ustring message = gettext("This program is a front end for efax.\n" "efax is a program released under the " "GNU General Public License, version 2 by Ed Casas.\n\n" "The copyright to efax is held by Ed Casas " "(the copyright to this program is held by Chris Vine)"); dialog_p = new InfoDialog(message, gettext("About efax"), standard_size, Gtk::MESSAGE_INFO, *this); } // there is no memory leak -- exec() was not called so InfoDialog // will delete its own memory when it is closed}void MainWindow::translations_slot(void) { Glib::ustring message = "Italiano - Luca De Rugeriis\n" "Polski - Paweł Suwiński\n" "Bulgarian - Zdravko Nikolov"; new InfoDialog(message, gettext("Translations"), standard_size, Gtk::MESSAGE_INFO, *this); // there is no memory leak -- InfoDialog is modeless and will delete its own memory // when it is closed}void MainWindow::get_longest_button_text(void) { std::vector<Glib::ustring> text_vec; text_vec.push_back(gettext("Single file")); text_vec.push_back(gettext("Multiple files")); text_vec.push_back(gettext("Socket list")); text_vec.push_back(gettext("Tel number: ")); text_vec.push_back(gettext("Send fax")); text_vec.push_back(gettext("Answer call")); text_vec.push_back(gettext("Take over call")); text_vec.push_back(gettext("Standby")); text_vec.push_back(gettext("Stop")); Gtk::Button button; std::vector<Glib::ustring>::const_iterator temp_iter; std::vector<Glib::ustring>::const_iterator max_width_iter; int width; int height; int max_width; for (temp_iter = text_vec.begin(), max_width_iter = text_vec.begin(), width = 0, height = 0, max_width = 0; temp_iter != text_vec.end(); ++temp_iter) { button.create_pango_layout(*temp_iter)->get_pixel_size(width, height); if (width > max_width) { max_width = width; max_width_iter = temp_iter; } } max_text = *max_width_iter;}void MainWindow::on_style_changed(const Glib::RefPtr<Gtk::Style>& prev_style) { // before we set the buttons, do anything else necessary with the new style Gtk::Window::on_style_changed(prev_style); //now set the buttons in MainWindow int width = 0; int height = 0; Gtk::Button button; button.set_style(get_style()); button.create_pango_layout(max_text)->get_pixel_size(width, height); // add padding width += 18; height += 12; // have some sensible minimum width and height if a very small font chosen const int min_width = standard_size * 4; const int min_height = 30; if (width < min_width) width = min_width; if (height < min_height) height = min_height; single_file_button.set_size_request(width, height); multiple_file_button.set_size_request(width, height); socket_list_button.set_size_request(width, height); number_button.set_size_request(width, height); send_button.set_size_request(width, height); receive_answer_button.set_size_request(width, height); receive_takeover_button.set_size_request(width, height); receive_standby_button.set_size_request(width, height); stop_button.set_size_request(width, height); status_line.set_colour(get_style());}bool MainWindow::draw_fax_from_socket_notifier(GdkEventExpose*) {/* This method displays the "red circle" indicator which shows a fax file received from the socket is awaiting sending. It is is called in the following circumstances: - it is connected to the signal_expose_event signal of MainWindow::drawing_area and is also called in MainWindow::socket_filelist_changed_notify_slot() - MainWindow::socket_filelist_changed_notify_slot() is connected to the Socket_server::filelist_changed_notify signal - the Socket_server::filelist_changed_notify signal is emitted by Socket_server:read_socket() when a new fax file to be sent is received via the socket and also by Socket_server::remove_file() - Socket_server::remove_file() is called by MainWindow::remove_from_socket_server_filelist() - MainWindow::remove_from_socket_server_filelist() is connected to the EfaxController::remove_from_socket_server_filelist signal and to SocketList::remove_from_socket_server_filelist() - the EfaxController::remove_from_socket_server_filelist signal is emitted by EfaxController::timer_event() when a fax derived from the socket list is successfully sent - the Socket_server::remove_from_socket_server_filelist signal is emitted by SocketServer::remove_file() - Socket_server::remove_file() is connected to the PromptDialog::accepted signal (emitted when a user elects to delete a queued fax from the list of files received for faxing from the socket)*/ Glib::RefPtr<Gdk::Window> window_r = drawing_area.get_window(); if (!socket_server.get_filenames().first->empty()) { Gdk::Color red; red.set_rgb_p(0.7, 0, 0); Glib::RefPtr<Gdk::Colormap> colourmap_r = Gtk::Widget::get_default_colormap(); colourmap_r->alloc_color(red); Glib::RefPtr<Gdk::GC> red_graphics_context_r = Gdk::GC::create(window_r); red_graphics_context_r->set_foreground(red); Glib::RefPtr<Gdk::GC> white_graphics_context_r = drawing_area.get_style()->get_white_gc(); window_r->draw_arc(white_graphics_context_r, true, 6, 6, standard_size - 12, standard_size - 12, 0, 64 * 360); window_r->draw_arc(red_graphics_context_r, true, 8, 8, standard_size - 16, standard_size - 16, 0, 64 * 360); } else { Glib::RefPtr<Gdk::GC> background_graphics_context_r = drawing_area.get_style()->get_bg_gc(drawing_area.get_state()); window_r->draw_rectangle(background_graphics_context_r, true, 0, 0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -