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

📄 main.cpp

📁 linux pritner GUI
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2001 to 2004 Chris VineThis program is distributed under the General Public Licence, version 2.For particulars of this and relevant disclaimers see the fileCOPYING distributed with the source files.*/#include "prog_defs.h"#include <sys/types.h>#include <unistd.h>#include <sys/stat.h>#include <errno.h>#include <cstdlib>#include <fstream>#include <string>#include <cstring>#include <gtkmm/main.h>#include <glibmm/ustring.h>#include <glibmm/convert.h>#include <glibmm/thread.h>#include <gdk/gdkx.h>#include <X11/Xlib.h>#include "mainwindow.h"#include "dialogs.h"#include "window_icon.h"#if GTKMM_VERSION >= 24#include <gtk/gtkicontheme.h>#include <gtkmm/icontheme.h>#include "gtk_icon_info_handle.h"#endif#ifdef ENABLE_NLS#include <locale.h>#include <libintl.h>#endifProg_config prog_config;bool get_prog_parm(const char*, std::string&, Glib::ustring&, Glib::ustring(*)(const std::string&));inline bool get_prog_parm(const char* name, std::string& line, Glib::ustring& result) {  return get_prog_parm(name, line, result, Glib::locale_to_utf8);}void get_fonts(void);void get_window_icon(void);int mkdir_with_parent(const std::string&);bool is_arg(const char*, int, char*[]);int main(int argc, char* argv[]) {  // set up the locale for gettext() and base locale domain name of this program#ifdef ENABLE_NLS  bindtextdomain("efax-gtk", DATADIR "/locale");  bind_textdomain_codeset("efax-gtk", "UTF-8");  textdomain("efax-gtk");  setlocale(LC_ALL,"");#endif  if (argc > 1) {    if (is_arg("--version", argc, argv)) {      std::string message("efax-gtk-" VERSION "\n");      message += gettext("Copyright (C) 2001 - 2004 Chris Vine\n"			 "This program is released under the "			 "GNU General Public License, version 2\n");      try {	message = Glib::locale_from_utf8(message);	write(1, message.data(), message.size());      }      catch (Glib::ConvertError&) {	std::string err_message("UTF-8 conversion error in main()\n");	write(2, err_message.data(), err_message.size());      }      return 0;    }	    if (is_arg("--help", argc, argv)) {      std::string message("efax-gtk-" VERSION "\n");      message += gettext("Usage: efax-gtk [options] [filename]\n"			 "Options:\n"			 "\t-r  Start the program in receive standby mode\n"			 "\t-s  Start the program hidden in the system tray\n"			 "See the README file which comes with the distribution\n"			 "for further details\n");      try {	message = Glib::locale_from_utf8(message);	write(1, message.data(), message.size());      }      catch  (Glib::ConvertError&) {	std::string err_message("UTF-8 conversion error in main()\n");	write(2, err_message.data(), err_message.size());      }      return 0;    }  }  Glib::thread_init();  prog_config.mutex_p = new Glib::Mutex;  std::string messages(configure_prog(false));  Gtk::Main app(argc, argv);  get_fonts();  get_window_icon();  if (!prog_config.GPL_flag) {    GplDialog gpl_dialog(24);    int result = gpl_dialog.exec();    if (result == GplDialog::accepted) {      std::string file_name(prog_config.working_dir + "/" MAINWIN_SAVE_FILE);      std::ofstream file(file_name.c_str(), std::ios::out);      prog_config.GPL_flag = true;    }    else beep();  }  if (prog_config.GPL_flag) {    bool start_in_standby = false;    bool start_hidden = false;    int opt_result;    while ((opt_result = getopt(argc, argv, "rs-:")) != -1) {      switch(opt_result) {      case 'r':	start_in_standby = true;	break;      case 's':	start_hidden = true;	break;      case '-':	std::string message(argv[0]);	message += ": ";	message += gettext("Invalid option.  Options are:\n");	message += "  -r\n"	           "  -s\n"		   "  --help\n"		   "  --version\n";	write(2, message.data(), message.size());	break;      }    }    const char* filename = 0;    if (optind < argc) filename = argv[optind];        MainWindow mainwindow(messages, start_hidden, start_in_standby, filename);    // everything is set up    // now enter the main program loop    app.run();  }  delete prog_config.mutex_p;  return 0;}Glib::ustring configure_prog(bool reread) {  // lock the Prog_config object while we modify it  Glib::Mutex::Lock lock(*prog_config.mutex_p);  if (!reread) {    char* home = std::getenv("HOME");    if (!home) write_error("Your HOME environmental variable is not defined!\n");    else {      prog_config.homedir = home;      prog_config.working_dir = home;    }  }// now find rc file  prog_config.found_rcfile = false;  std::ifstream filein;  std::string rcfile;  Glib::ustring return_val;  if (!prog_config.homedir.empty()) {    rcfile = prog_config.homedir;    rcfile += "/." RC_FILE;#ifdef HAVE_IOS_NOCREATE    filein.open(rcfile.c_str(), std::ios::in | std::ios::nocreate);#else    // we must have Std C++ so we probably don't need a ios::nocreate    // flag on a read open to ensure uniqueness    filein.open(rcfile.c_str(), std::ios::in);#endif    if (filein) prog_config.found_rcfile = true;    else filein.clear();  }  if (!prog_config.found_rcfile) {    rcfile = RC_DIR "/" RC_FILE;#ifdef HAVE_IOS_NOCREATE    filein.open(rcfile.c_str(), std::ios::in | std::ios::nocreate);#else    // we must have Std C++ so we probably don't need a ios::nocreate    // flag on a read open to ensure uniqueness    filein.open(rcfile.c_str(), std::ios::in);#endif    if (filein) prog_config.found_rcfile = true;    else filein.clear();  }  if (!prog_config.found_rcfile && std::strcmp(RC_DIR, "/etc")) {    rcfile = "/etc/" RC_FILE;#ifdef HAVE_IOS_NOCREATE    filein.open(rcfile.c_str(), std::ios::in | std::ios::nocreate);#else    // we must have Std C++ so we probably don't need a ios::nocreate    // flag on a read open to ensure uniqueness    filein.open(rcfile.c_str(), std::ios::in);#endif    if (filein) prog_config.found_rcfile = true;    else filein.clear();  }  if (!prog_config.found_rcfile) {    return_val = "Can't find or open file " RC_DIR "/"  RC_FILE ",\n";    if (std::strcmp(RC_DIR, "/etc")) {      return_val += "/etc/" RC_FILE ", ";    }    if (!prog_config.homedir.empty()) {      try {	Glib::ustring temp(Glib::filename_to_utf8(prog_config.homedir));	return_val +=  "or ";	return_val += temp;	return_val += "/." RC_FILE;      }      catch (Glib::ConvertError&) {	write_error("UTF-8 conversion error in configure_prog()\n");      }    }    return_val += "\n";  }    else {    // if we are re-reading efax-gtkrc, we need to clear the old settings    if (reread) {      prog_config.lock_file = "";      prog_config.my_name = "";      prog_config.my_number = "";      prog_config.parms.clear();      prog_config.page_size = "";      prog_config.page_dim = "";      prog_config.resolution = "";      prog_config.print_cmd = "";      prog_config.print_shrink = "";      prog_config.ps_view_cmd = "";      prog_config.sock_server_port = "";      prog_config.fax_received_prog = "";      prog_config.logfile_name = "";    }    // if we are setting up for first time, initialise prog_config.receive_dirname    else *prog_config.receive_dirname = 0;// now extract settings from file    std::string file_read;    Glib::ustring device;    Glib::ustring lock_file;    Glib::ustring modem_class;    Glib::ustring rings;    Glib::ustring dialmode;    Glib::ustring init;    Glib::ustring reset;    Glib::ustring capabilities;    Glib::ustring extra_parms;    Glib::ustring print_popup;    Glib::ustring sock_server;    Glib::ustring sock_popup;    Glib::ustring sock_client_address;    Glib::ustring sock_other_addresses;    Glib::ustring fax_received_popup;    Glib::ustring fax_received_exec;    Glib::ustring work_subdir;        while (std::getline(filein, file_read)) {      if (!file_read.empty() && file_read[0] != '#') { // valid line to check	// now check for other comment markers	std::string::size_type pos = file_read.find_first_of('#');	if (pos != std::string::npos) file_read.resize(pos); // truncate		// look for "NAME:"	if (get_prog_parm("NAME:", file_read, prog_config.my_name));		// look for "NUMBER:"	else if (get_prog_parm("NUMBER:", file_read, prog_config.my_number));		// look for "DEVICE:"	else if (get_prog_parm("DEVICE:", file_read, device));		// look for "LOCK:"	else if (get_prog_parm("LOCK:", file_read, lock_file,			       Glib::filename_to_utf8));	// look for "CLASS:"	else if (get_prog_parm("CLASS:", file_read, modem_class));	// look for "PAGE:"	else if (get_prog_parm("PAGE:", file_read, prog_config.page_size));	// look for "RES:"	else if (get_prog_parm("RES:", file_read, prog_config.resolution));		// look for "RINGS:"	else if (get_prog_parm("RINGS:", file_read, rings));		// look for "DIALMODE:"	else if (get_prog_parm("DIALMODE:", file_read, dialmode));		// look for "INIT:"	else if (get_prog_parm("INIT:", file_read, init));		// look for "RESET:"	else if (get_prog_parm("RESET:", file_read, reset));	// look for "CAPABILITIES:"	else if (get_prog_parm("CAPABILITIES:", file_read, capabilities));	// look for "PARMS:"	else if (get_prog_parm("PARMS:", file_read, extra_parms));	// look for "PRINT_CMD:"	else if (get_prog_parm("PRINT_CMD:", file_read, prog_config.print_cmd));	// look for "PRINT_SHRINK:"	else if (get_prog_parm("PRINT_SHRINK:", file_read, prog_config.print_shrink));	// look for "PRINT_POPUP:"	else if (get_prog_parm("PRINT_POPUP:", file_read, print_popup));	// look for "PS_VIEWER:"	else if (get_prog_parm("PS_VIEWER:", file_read, prog_config.ps_view_cmd));	// look for "SOCK_SERVER:"	else if (get_prog_parm("SOCK_SERVER:", file_read, sock_server));	// look for "SOCK_POPUP:"	else if (get_prog_parm("SOCK_POPUP:", file_read, sock_popup));	// look for "SOCK_SERVER_PORT:"	else if (get_prog_parm("SOCK_SERVER_PORT:", file_read, prog_config.sock_server_port));	// look for "SOCK_CLIENT_ADDRESS:"	else if (get_prog_parm("SOCK_CLIENT_ADDRESS:", file_read, sock_client_address));	// look for "SOCK_OTHER_ADDRESSES:"	else if (get_prog_parm("SOCK_OTHER_ADDRESSES:", file_read, sock_other_addresses));	// look for "FAX_RECEIVED_POPUP:"	else if (get_prog_parm("FAX_RECEIVED_POPUP:", file_read, fax_received_popup));	// look for "FAX_RECEIVED_EXEC:"	else if (get_prog_parm("FAX_RECEIVED_EXEC:", file_read, fax_received_exec));	// look for "FAX_RECEIVED_PROG:"	else if (get_prog_parm("FAX_RECEIVED_PROG:", file_read, prog_config.fax_received_prog,			       Glib::filename_to_utf8));	// look for "LOG_FILE:"	else if (get_prog_parm("LOG_FILE:", file_read, prog_config.logfile_name,			       Glib::filename_to_utf8));	// look for "WORK_SUBDIR:"	else if (get_prog_parm("WORK_SUBDIR:", file_read, work_subdir,			       Glib::filename_to_utf8));      }    }    // we have finished reading the configuration file        // now enter parameters common to send and receive of faxes	    prog_config.parms.push_back("efax-0.9a");    prog_config.parms.push_back("-vew");  // stderr -- errors and warnings        prog_config.parms.push_back("-vin");  // stdin -- information and negotiations    //prog_config.parms.push_back("-vina");  // this will also report the parameters passed to efax                                             // uncomment it and comment out preceding line for debugging        std::string temp;    if (!prog_config.my_number.empty()) {      temp = "-l";      temp += prog_config.my_number;      prog_config.parms.push_back(temp);    }    if (!init.empty()) {      std::string::size_type start = 0;      std::string::size_type end;            while (start != std::string::npos) {	temp = "-i";	end = init.find_first_of(" \t", start);	if (end != std::string::npos) {	  temp.append(init, start, end - start);	  start = init.find_first_not_of(" \t", end); // prepare for the next iteration	}	else {

⌨️ 快捷键说明

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