⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cpp

📁 用于使用moden进行传真的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  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.homedir + "/" 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.homedir + "/" 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}void MainWindow::quit_slot(void) {  // close down socket server  socket_server.stop();  // make sure we close down efax() if it is active  efax_controller.efax_closedown();  // now quit  hide(); // hiding the main program window will cause the program to terminate}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, false); // not modal    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 = " \t,";  // 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) {      fax_item.file_list.push_back(files.substr(pos1, pos2 - pos1));      pos1 = files.find_first_not_of(separators, pos2);    }    else {      fax_item.file_list.push_back(files.substr(pos1));      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) { // 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 "word" displayed in the file    // entry box, and this "word" will be the first string in the fax_item.file_list    // container - 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] == 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) { // 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) quit_slot(); // we must have picked up an external kill signal                               // so we need an orderly close down  else efax_controller.timer_event();  return true; // we want a multi-shot timer}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(FaxListDialog::Mode mode) {  if (mode == FaxListDialog::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 == FaxListDialog::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 (efax_controller.get_state() != EfaxController::inactive	|| !is_sensitive()) {      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();    }    else {      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();    }  }  // 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()) {    // get the program name for the exec() call below (because this is a    // multi-threaded program, we must do this before fork()ing because    // we use functions to get the argument which is not async-signal-safe)    std::string cmd;    try {      cmd.assign(Glib::filename_from_utf8(prog_config.fax_received_prog));    }    catch (Glib::ConvertError&) {      write_error("UTF-8 conversion error in MainWindow::fax_received_notify_slot()\n");      cmd.assign(prog_config.fax_received_prog);    }    // we can use the raw output of cmd.c_str() here - it will remain valid at the execlp() call    const char* prog_name = cmd.c_str();    pid_t pid = fork();        if (pid == -1) {      write_error("Fork error - exiting\n");      std::exit(FORK_ERROR);    }    if (!pid) {  // child process - as soon as everything is set up we are going to do an exec()            // now we have forked, we can connect MainWindow::error_pipe to stderr      connect_to_stderr();      execlp (prog_name, prog_name, prog_config.receive_dirname, 0);      // if we reached this point, then the execlp() call must have failed      // report error and end process - use _exit() and not exit()      write_error("Can't find the program to execute when a fax is received.\n"		  "Please check your installation and the PATH environmental variable\n");      _exit(EXEC_ERROR);     } // end of child process  }  if (prog_config.fax_received_popup) {    InfoDialog* dialog_p = new InfoDialog(gettext("A fax has been received by efax-gtk"), 					  gettext("efax-gtk: fax received"),					  standard_size, Gtk::MESSAGE_INFO,					  *this, !is_sensitive());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -