📄 fax_list_manager.cpp
字号:
for (; folder_iter; folder_iter = folder_iter->parent()) { std::string temp; temp += PATH_DIVIDER; // we don't need a Glib conversion function here - we will use/store the Path to file // in UTF-8 - the std::string is just a transparent container for the encoding temp += Glib::ustring((*folder_iter)[folder_model_columns.name]); pathname.insert(0, temp); } return pathname;}void FaxListManager::display_faxes_slot(void) { fax_list_store_r->clear(); Gtk::TreeModel::iterator row_iter = folder_tree_view.get_selection()->get_selected(); if (!row_iter) return; std::pair<FolderToFaxMap::iterator, FolderToFaxMap::iterator> result(folder_to_fax_map.equal_range(get_pathname_for_folder(row_iter))); if (result.first == result.second) return; // folder without a fax in it std::string dir(prog_config.working_dir); if (mode == FaxListEnum::received) dir += "/faxin"; else dir += "/faxsent"; std::string filename; std::string line; std::ifstream file; FolderToFaxMap::iterator iter; for (iter = result.first; iter != result.second; ++iter) { Gtk::TreeModel::Row item_row = *fax_list_store_r->append(); item_row[fax_model_columns.name] = iter->second; // now see if there is a description filename = dir + '/'; filename += iter->second; filename += "/Description";#ifdef HAVE_IOS_NOCREATE file.open(filename.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 file.open(filename.c_str(), std::ios::in);#endif if (file) { while (std::getline(file, line) && line.empty()); } if (!line.empty()) { try { //Gtk::TreeModel::Row item_row = *tree_store_r->get_iter(row_ref.get_path()); item_row[fax_model_columns.fax_description] = Glib::locale_to_utf8(line); } catch (Glib::ConvertError&) { write_error("UTF-8 conversion error in FaxListDialog::display_faxes_slot()\n"); } } filename = ""; line = ""; file.close(); file.clear(); }}bool FaxListManager::is_folder_empty(void) { bool return_val = false; Gtk::TreeModel::iterator row_iter = folder_tree_view.get_selection()->get_selected(); if (row_iter) { std::string pathname(get_pathname_for_folder(row_iter)); std::pair<FolderToFaxMap::iterator, FolderToFaxMap::iterator> result(folder_to_fax_map.equal_range(pathname)); if (result.first == result.second) { // no faxes in folder const Gtk::TreeModel::Children& children = row_iter->children(); if (!children || children.empty()) return_val = true; // and no child folders } } return return_val;}void FaxListManager::make_folder(const Glib::ustring& folder_name, bool test_valid) { if (!test_valid || folder_name_validator.validate(folder_name).first) { Gtk::TreeModel::Row row = *folder_tree_store_r->append(); row[folder_model_columns.name] = folder_name; // since we are creating a new folder it is not root only // (only Inbox and Sent box are root only) row[folder_model_columns.root_only] = false; row[folder_model_columns.icon] = folder_icon_r; folder_name_validator.insert_folder_name(folder_name); write_path(); }}void FaxListManager::delete_folder(void) { // we should have calld is_folder_empty() before getting here, so all we need // to do is to delete the row in the folder tree store Gtk::TreeModel::iterator row_iter = folder_tree_view.get_selection()->get_selected(); if (row_iter) { folder_name_validator.erase_folder_name(Glib::ustring((*row_iter)[folder_model_columns.name])); folder_tree_store_r->erase(row_iter); write_path(); }}void FaxListManager::delete_fax(void) { Gtk::TreeModel::iterator row_iter = fax_tree_view.get_selection()->get_selected(); if (row_iter) { // get the name of the fax to be moved and the new name std::string old_dirname(prog_config.working_dir); std::string new_dirname(prog_config.working_dir); if (mode == FaxListEnum::received) { old_dirname += "/faxin/"; new_dirname += "/faxin/oldfax/"; } else { old_dirname += "/faxsent/"; new_dirname += "/faxsent/oldfax/"; } // we don't need to use a Glib conversion function here - we know the // fax name is just plain ASCII numbers std::string faxname = Glib::ustring((*row_iter)[fax_model_columns.name]); old_dirname += faxname; new_dirname += faxname; // make a new directory to copy the files into mkdir(new_dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); // it should be possible to use link()/unlink() as the target and source // are sub-directories of $HOME/faxin or $HOME/faxsent. If because of a // very odd filesystem arrangement this won't work, the method will do nothing std::vector<std::string> filelist; struct dirent* direntry; struct stat statinfo; DIR* dir_p; if ((dir_p = opendir(old_dirname.c_str())) == 0) { std::string msg("Can't open directory "); msg += old_dirname; msg += '\n'; write_error(msg.c_str()); } else { chdir(old_dirname.c_str()); while ((direntry = readdir(dir_p)) != 0) { stat(direntry->d_name, &statinfo); if (S_ISREG(statinfo.st_mode)) { filelist.push_back(direntry->d_name); } } closedir(dir_p); bool failure = false; std::vector<std::string>::const_iterator iter; std::string old_filename; std::string new_filename; for (iter = filelist.begin(); iter != filelist.end(); ++iter) { old_filename = old_dirname + '/'; old_filename += *iter; new_filename = new_dirname + '/'; new_filename += *iter; if (link(old_filename.c_str(), new_filename.c_str())) { failure = true; break; } } if (failure) { // recover position std::vector<std::string>::const_iterator recover_iter; for (recover_iter = filelist.begin(); recover_iter != iter; ++recover_iter) { new_filename = new_dirname + '/'; new_filename += *recover_iter; unlink(new_filename.c_str()); } rmdir(new_dirname.c_str()); std::string msg("Can't move directory "); msg += old_dirname; msg += " to "; msg += new_dirname; msg += '\n'; write_error(msg.c_str()); } else { for (iter = filelist.begin(); iter != filelist.end(); ++iter) { old_filename = old_dirname + '/'; old_filename += *iter; unlink(old_filename.c_str()); } if (rmdir(old_dirname.c_str())) { std::string msg("Can't delete directory "); msg += old_dirname; msg += "\nThe contents should have been moved to "; msg += new_dirname; msg += "\nand it should now be empty -- please check\n"; write_error(msg.c_str()); } else { std::string pathname(fax_to_folder_map[faxname]); std::pair<FolderToFaxMap::iterator, FolderToFaxMap::iterator> result(folder_to_fax_map.equal_range(pathname)); if (result.first == result.second) { write_error("Equal range: database mapping error in FaxListManager::delete_fax()\n"); return; } FolderToFaxMap::iterator folder_map_iter = result.first; bool found_it = false; while (!found_it && folder_map_iter != result.second) { if (folder_map_iter->second == faxname) { found_it = true; folder_to_fax_map.erase(folder_map_iter); } else ++folder_map_iter; } if (!found_it) { write_error("Fax to delete not found: database mapping error in FaxListManager::delete_fax()\n"); } FaxToFolderMap::iterator fax_map_iter = fax_to_folder_map.find(faxname); if (fax_map_iter != fax_to_folder_map.end()) fax_to_folder_map.erase(fax_map_iter); else write_error("Database mapping error in FaxListManager::delete_fax()\n"); fax_list_store_r->erase(row_iter); write_path(); } } // reset current directory std::string temp(prog_config.working_dir + "/faxin"); chdir(temp.c_str()); } }}void FaxListManager::refresh(void) { populate_fax_list();}void FaxListManager::write_path(void) { std::string dir(prog_config.working_dir); if (mode == FaxListEnum::received) dir += "/faxin/"; else dir += "/faxsent/"; // first write the path list file for the folders std::string filename(dir); filename += "/PathList"; std::ofstream file(filename.c_str(), std::ios::out); if (file) write_folderpath_for_level(folder_tree_store_r->children(), file); else write_error("Cannot open PathList file for writing in FaxListManager::write_path()\n"); file.close(); file.clear(); // now write out the individual fax path files FaxToFolderMap::iterator iter; for (iter = fax_to_folder_map.begin(); iter != fax_to_folder_map.end(); ++iter) { std::string filename(dir); // we don't need to use a Glib conversion function here - we know the // fax name is just plain ASCII numbers filename += iter->first; filename += "/Path"; file.open(filename.c_str(), std::ios::out); if (file) file << iter->second << std::endl; else { std::string message("Cannot open file "); message += filename; message += '\n'; write_error(message.c_str()); } file.close(); file.clear(); }}void FaxListManager::write_folderpath_for_level(const Gtk::TreeModel::Children& level, std::ofstream& file) { if (level && !level.empty()) { Gtk::TreeModel::Children::iterator row_iter; for (row_iter = level.begin(); row_iter != level.end(); ++row_iter) { std::string pathname = get_pathname_for_folder(row_iter); file << pathname << '\n'; // now recursively work the way up children of this node (if any) write_folderpath_for_level(row_iter->children(), file); } }}void FaxListManager::describe_fax(const Glib::ustring& description) { Gtk::TreeModel::iterator row_iter = fax_tree_view.get_selection()->get_selected(); if (row_iter) { (*row_iter)[fax_model_columns.fax_description] = description; std::string filename(prog_config.working_dir); if (mode == FaxListEnum::received) filename += "/faxin/"; else filename += "/faxsent/"; // we don't need to use a Glib conversion function here - we know the // fax name is just plain ASCII numbers filename += Glib::ustring((*row_iter)[fax_model_columns.name]); filename += "/Description"; std::ofstream file(filename.c_str(), std::ios::out); // this try()/catch() block is ultra-cautious - something has gone seriously // wrong with the program if the UTF-8 conversion fails since the source is // a Gtk::Entry object try { if (file) file << Glib::locale_from_utf8(description); else { std::string msg("Can't open file "); msg += filename; msg += '\n'; write_error(msg.c_str()); } } catch (Glib::ConvertError&) { write_error("UTF-8 conversion error in FaxListDialog::describe_fax()\n"); } }}Glib::ustring FaxListManager::get_fax_number(void) { Glib::ustring return_val; Gtk::TreeModel::iterator row_iter = fax_tree_view.get_selection()->get_selected(); if (row_iter) return_val = (*row_iter)[fax_model_columns.name]; return return_val;}Glib::ustring FaxListManager::get_fax_description(void) { Glib::ustring return_val; Gtk::TreeModel::iterator row_iter = fax_tree_view.get_selection()->get_selected(); if (row_iter) return_val = (*row_iter)[fax_model_columns.fax_description]; return return_val;}Glib::ustring FaxListManager::get_folder_name(void) { Glib::ustring return_val; Gtk::TreeModel::iterator row_iter = folder_tree_view.get_selection()->get_selected(); if (row_iter) return_val = (*row_iter)[folder_model_columns.name]; return return_val;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -