📄 main.cpp
字号:
/* 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 <unistd.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>#if GTKMM_VERSION >= 24#include <gtk/gtkicontheme.h>#include <gtkmm/icontheme.h>#endif#include "mainwindow.h"#include "dialogs.h"#include "window_icon.h"#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 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 (!std::strcmp(argv[1], "--version")) { 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&) { write_error("UTF-8 conversion error in main()\n"); } return 0; } if (!std::strcmp(argv[1], "--help")) { std::string message("efax-gtk-" VERSION "\n"); message += gettext("Usage: efax-gtk [filename]\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&) { write_error("UTF-8 conversion error in main()\n"); } 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.homedir + "/" 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) { const char* filename = 0; if (argc > 1) filename = argv[argc - 1]; MainWindow mainwindow(messages, filename); // everything is set up // now enter the main program loop app.run(mainwindow); // main loop will terminate when mainwindow hides } 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) { // check to see if GPL terms have been accepted char* home = std::getenv("HOME"); if (!home) write_error("Your HOME environmental variable is not defined!\n"); else prog_config.homedir = home; std::string file_name(prog_config.homedir + "/" MAINWIN_SAVE_FILE); int result = access(file_name.c_str(), F_OK); if (!result) prog_config.GPL_flag = true; else prog_config.GPL_flag = false; }// 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.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 = ""; delete[] prog_config.lock_file; } // 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; // set prog_config.lock_file to 0 - it is then safe to apply delete[] to // it as on the re-read test above, even if it is not allocated memory below prog_config.lock_file = 0; 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)); } } // 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -