📄 mainwindow.cpp
字号:
// notify dialog socket_server.fax_to_send_notify.connect(sigc::mem_fun(*this, &MainWindow::fax_to_send_notify_slot)); // this connects the SigC object which indicates that a fax has been received // from the modem by the EfaxController object efax_controller.fax_received_notify.connect(sigc::mem_fun(*this, &MainWindow::fax_received_notify_slot)); // start the socket server if (prog_config.sock_server && !prog_config.sock_server_port.empty()) { socket_server.start(std::string(prog_config.sock_server_port), prog_config.other_sock_client_address); } tray_item.left_button_pressed.connect(sigc::mem_fun(*this, &MainWindow::tray_icon_left_clicked_slot)); tray_item.menu_item_chosen.connect(sigc::mem_fun(*this, &MainWindow::tray_icon_menu_slot)); tray_item.get_state.connect(sigc::mem_fun(efax_controller, &EfaxController::get_state)); efax_controller.write_state.connect(sigc::mem_fun(tray_item, &TrayItem::set_tooltip_slot)); // enable visibility events, so that the action when left clicking on the // tray icon is correct add_events(Gdk::VISIBILITY_NOTIFY_MASK); // the notifed_fax pair is used by sendfax_slot() if no number is shown // to dial, for use if the option to send on an open connection without // dialling is refused and sendfax_slot() was called by a // SocketNotifyDialog::sendfax_sig signal, so that a SocketNotifyDialog // dialog can be brought up again for the user to have another chance to // choose what he/she wants to do. When the second member of the // notified_fax pair is not 0, then that indicates that sendfax_slot() // was called by a SocketNotifyDialog object (it is normally set to 0 and // only holds another value when set in MainWindow::fax_to_send_dialog()) notified_fax.second = 0; // if the -r option has been chosen, start the program in Receive Standby mode if (start_in_standby) receive_slot(EfaxController::receive_standby);}MainWindow::~MainWindow(void) { save_window_settings(); delete write_error_mutex_p;}bool MainWindow::on_key_press_event(GdkEventKey* event_p) { if (event_p->keyval == GDK_F1) helpfile_slot(); else Gtk::Window::on_key_press_event(event_p); return true; // processing stops here}void MainWindow::get_window_settings(void) { int width = 0; int height = 0; int socket_val = 0; std::string file_name(prog_config.working_dir + "/" MAINWIN_SAVE_FILE); std::ifstream file(file_name.c_str(), std::ios::in); if (!file) write_error("Can't get mainwindow settings from file\n"); else { file >> width >> height >> socket_val; if (width > 0 && height > 0) { socket_button.set_active(socket_val); set_default_size(width, height); } }}void MainWindow::save_window_settings(void) { std::string file_name(prog_config.working_dir + "/" MAINWIN_SAVE_FILE); std::ofstream file(file_name.c_str(), std::ios::out); if (!file) write_error("Can't save mainwindow settings to file\n"); else { int width; int height; get_size(width, height); int socket_val = socket_button.get_active(); file << width << ' ' << height << ' ' << socket_val << std::endl; }}bool MainWindow::read_error_slot(Glib::IOCondition) { char pipe_buffer[PIPE_BUF + 1]; ssize_t result; while ((result = error_pipe.read(pipe_buffer, PIPE_BUF)) > 0) { pipe_buffer[result] = 0; text_window.write_red_slot(pipe_buffer); } return true; // retain connection for further reads}bool MainWindow::on_delete_event(GdkEventAny* event_p) { if (tray_item.is_embedded()) hide(); else close_slot(); return true;}void MainWindow::close_slot(void) { // close down socket server socket_server.stop(); // make sure we close down efax() if it is active // (the EfaxController::ready_to_quit_notify signal is connected to // quit_slot() below and will end the main program loop once any efax // session running has been dealt with) efax_controller.efax_closedown();}void MainWindow::quit_slot(void) { Gtk::Main::quit();}void MainWindow::sendfax_slot(void) { // Fax_item is defined in efax_controller.h Fax_item fax_item; try { fax_item.number = Glib::locale_from_utf8(number_entry.get_text()); } catch (Glib::ConvertError&) { write_error("UTF-8 conversion error in sendfax_slot()\n"); beep(); return; } // eliminate leading or trailing spaces so that we can check for an empty string strip(fax_item.number); if (fax_item.number.empty()) { PromptDialog dialog(gettext("No fax number specified. Do you want to send the fax " "on an open connection?"), gettext("Telephone number"), standard_size, *this); if (!dialog.exec()) { if (notified_fax.second) { // we must have got here by a SocketNotifyDialog::sendfax_sig signal set_files_slot(""); selected_socket_list_file = ""; fax_to_send_dialog(notified_fax); } return; } } notified_fax.second = 0; present(); fax_item.is_socket_file = false; std::string files; try { files = Glib::filename_from_utf8(file_entry.get_text()); } catch (Glib::ConvertError&) { write_error("UTF-8 conversion error in sendfax_slot()\n"); beep(); return; } const char* separators = ",;"; // split the files string into separate file names std::string::size_type pos1, pos2; pos1 = files.find_first_not_of(separators); while (pos1 != std::string::npos) { pos2 = files.find_first_of(separators, pos1); if (pos2 != std::string::npos) { std::string file_item(files.substr(pos1, pos2 - pos1)); strip(file_item); fax_item.file_list.push_back(file_item); pos1 = files.find_first_not_of(separators, pos2); } else { std::string file_item(files.substr(pos1)); strip(file_item); fax_item.file_list.push_back(file_item); pos1 = std::string::npos; } } if (!prog_config.found_rcfile) { text_window.write_red_slot("Can't send fax -- no efax-gtkrc configuration file found\n\n"); beep(); } else if (prog_config.lock_file.empty()) { // if there is no lock file, then it means no // serial device has been specified (the lock // file dir defaults to /var/lock) text_window.write_red_slot("Can't send fax -- no valid serial device specified\n\n"); beep(); } else if (fax_item.file_list.empty()) beep(); else { // if this is a fax received from the socket and entered via the socket faxes // list, then "*** " will form the first part of the "file" displayed in the file // entry box - so test for it to see if we are sending a file received via the // socket rather than a regular file if (fax_item.file_list.size() > 0 && fax_item.file_list[0].substr(0,4) == std::string("*** ")) { fax_item.file_list.clear(); fax_item.file_list.push_back(selected_socket_list_file); fax_item.is_socket_file = true; } efax_controller.sendfax(fax_item); }}void MainWindow::receive_slot(int mode) { if (!prog_config.found_rcfile) { text_window.write_red_slot("Can't receive fax -- no efax-gtkrc configuration file found\n\n"); beep(); } else if (prog_config.lock_file.empty()) { // if there is no lock file, then it means no // serial device has been specified (the lock // file dir defaults to /var/lock) text_window.write_red_slot("Can't receive fax -- no valid serial device specified\n\n"); beep(); } else efax_controller.receive(mode);}bool MainWindow::timer_event_handler(void) { if (close_flag) { close_slot(); // we must have picked up an external kill signal // so we need an orderly close down close_flag = false; } efax_controller.timer_event(); return true; // we want a multi-shot timer}bool MainWindow::start_hidden_check_handler(void) { if (!tray_item.is_embedded()) { // the user has goofed - he has set the program to start hidden in the system tray // but has no system tray running! write_error(gettext("The program has been started with the -s option but there is no system tray!\n")); present(); } return false; // this only fires once}void MainWindow::get_file_slot(void) { FileReadSelectDialog file_dialog(standard_size, false, *this); std::vector<Glib::ustring> file_result = file_dialog.exec(); if (!file_result.empty()) { set_files_slot(file_result[0]); number_entry.grab_focus(); }}void MainWindow::set_files_slot(const Glib::ustring& files) { file_entry.set_text(files);}void MainWindow::fax_list_slot(FaxListEnum::Mode mode) { if (mode == FaxListEnum::received) { if (!FaxListDialog::get_is_fax_received_list()) { received_fax_list_p = new FaxListDialog(mode, standard_size); } else { received_fax_list_p->refresh_slot(); received_fax_list_p->present(); } } else if (mode == FaxListEnum::sent) { if (!FaxListDialog::get_is_fax_sent_list()) { sent_fax_list_p = new FaxListDialog(mode, standard_size); } else { sent_fax_list_p->refresh_slot(); sent_fax_list_p->present(); } } // there is no memory leak -- FaxListDialog is modeless and will delete its own memory // when it is closed}void MainWindow::socket_list_slot(void) { // this method will launch the dialog listing queued faxes received from // the socket_server (a SocketListDialog object) if (!SocketListDialog::get_is_socket_list()) { // get the filenames pair - the mutex lock will automatically release when filenames_pair (and // so the shared pointer holding the lock) goes out of scope at the end of the if block (we want to keep // the shared_ptr alive until after we have set up the connection to update the socket list std::pair<Shared_ptr<FilenamesList>, Shared_ptr<Glib::Mutex::Lock> > filenames_pair(socket_server.get_filenames()); socket_list_p = new SocketListDialog(filenames_pair, standard_size); // now connect up the dialog to relevant slots and signals update_socket_list_connection = update_socket_list.connect(sigc::mem_fun(*socket_list_p, &SocketListDialog::set_socket_list_rows)); socket_dialog_connection = close_socket_list_dialog.connect(sigc::mem_fun(*socket_list_p, &SocketListDialog::close_slot)); socket_list_p->selected_fax.connect(sigc::mem_fun(*this, &MainWindow::enter_socket_file_slot)); socket_list_p->remove_from_socket_server_filelist.connect(sigc::mem_fun(*this, &MainWindow::remove_from_socket_server_filelist)); socket_list_p->dialog_closed.connect(sigc::mem_fun(*this, &MainWindow::socket_filelist_closed_slot)); // there is no memory leak -- SocketListDialog is modeless and will delete its own memory // when it is closed } else socket_list_p->present();}void MainWindow::socket_filelist_changed_notify_slot(void) { // this slot is connected to the socket_server object, and is called // by a Glib::Dispatcher object whenever the socket server gets a new // fax to send // update_socket_list is a signal, connected to SocketListDialog::set_socket_list_rows // and it will enter the new fax file received from the socket server into the list of // queued faxes to be sent maintained by the SocketListDialog object update_socket_list(socket_server.get_filenames()); draw_fax_from_socket_notifier(0);}void MainWindow::socket_filelist_closed_slot(void) { update_socket_list_connection.disconnect(); socket_dialog_connection.disconnect();}void MainWindow::fax_to_send_notify_slot() { fax_to_send_dialog(socket_server.get_fax_to_send());}void MainWindow::fax_to_send_dialog(const std::pair<std::string, unsigned int>& fax_pair) { if (prog_config.sock_popup) { if (is_sensitive() && (efax_controller.get_state() == EfaxController::inactive || (efax_controller.get_state() == EfaxController::receive_standby && !efax_controller.is_receiving_fax()))) { notified_fax = fax_pair; SocketNotifyDialog* dialog_p = new SocketNotifyDialog(standard_size, fax_pair, *this, false); // not modal dialog_p->fax_name_sig.connect(sigc::mem_fun(*this, &MainWindow::enter_socket_file_slot)); dialog_p->fax_number_sig.connect(sigc::mem_fun(*this, &MainWindow::set_number_slot)); dialog_p->sendfax_sig.connect(sigc::mem_fun(*this, &MainWindow::sendfax_slot)); dialog_p->present(); } else { InfoDialog* dialog_p = new InfoDialog(gettext("A print job has been received on socket"), gettext("efax-gtk socket"), standard_size, Gtk::MESSAGE_INFO, *this, !is_sensitive()); 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::fax_received_notify_slot(void) { if (prog_config.fax_received_exec && !prog_config.fax_received_prog.empty()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -