| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// Copyright (C) 2014 |
| 3 |
// David Freese, W1HKJ |
| 4 |
// |
| 5 |
// This file is part of flmsg |
| 6 |
// |
| 7 |
// flrig is free software; you can redistribute it and/or modify |
| 8 |
// it under the terms of the GNU General Public License as published by |
| 9 |
// the Free Software Foundation; either version 3 of the License, or |
| 10 |
// (at your option) any later version. |
| 11 |
// |
| 12 |
// flrig is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
// |
| 17 |
// You should have received a copy of the GNU General Public License |
| 18 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
// ---------------------------------------------------------------------------- |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <iostream> |
| 23 |
#include <fstream> |
| 24 |
#include <string> |
| 25 |
#include <cstring> |
| 26 |
#include <ctime> |
| 27 |
#include <sys/types.h> |
| 28 |
#include <sys/stat.h> |
| 29 |
#include <stdio.h> |
| 30 |
#include <errno.h> |
| 31 |
|
| 32 |
#include <FL/Fl.H> |
| 33 |
#include <FL/Enumerations.H> |
| 34 |
#include <FL/Fl_Window.H> |
| 35 |
#include <FL/Fl_Button.H> |
| 36 |
#include <FL/Fl_Group.H> |
| 37 |
#include <FL/Fl_Sys_Menu_Bar.H> |
| 38 |
#include <FL/x.H> |
| 39 |
#include <FL/Fl_Help_Dialog.H> |
| 40 |
#include <FL/Fl_Menu_Item.H> |
| 41 |
#include <FL/Fl_File_Icon.H> |
| 42 |
|
| 43 |
#include "config.h" |
| 44 |
#include "flmsg_config.h" |
| 45 |
|
| 46 |
#include "flmsg.h" |
| 47 |
#include "templates.h" |
| 48 |
#include "debug.h" |
| 49 |
#include "util.h" |
| 50 |
#include "gettext.h" |
| 51 |
#include "flmsg_dialog.h" |
| 52 |
#include "flinput2.h" |
| 53 |
#include "date.h" |
| 54 |
#include "calendar.h" |
| 55 |
#include "icons.h" |
| 56 |
#include "fileselect.h" |
| 57 |
#include "wrap.h" |
| 58 |
#include "status.h" |
| 59 |
#include "parse_xml.h" |
| 60 |
#include "flmsg_strings.h" |
| 61 |
|
| 62 |
#ifdef WIN32 |
| 63 |
# include "flmsgrc.h" |
| 64 |
# include "compat.h" |
| 65 |
# define dirent fl_dirent_no_thanks |
| 66 |
#endif |
| 67 |
|
| 68 |
#include <FL/filename.H> |
| 69 |
#include "dirent-check.h" |
| 70 |
|
| 71 |
#include <FL/x.H> |
| 72 |
#include <FL/Fl_Pixmap.H> |
| 73 |
#include <FL/Fl_Image.H> |
| 74 |
|
| 75 |
std::string f126_base_filename = ""; |
| 76 |
std::string f126_def_filename = ""; |
| 77 |
std::string f126_def_template_name = ""; |
| 78 |
|
| 79 |
static std::string f126_buffer; |
| 80 |
|
| 81 |
// f126_fields |
| 82 |
|
| 83 |
const char *f126_s_prec[] = {"ROUTINE","PRIORITY","IMMEDIATE","FLASH"}; |
| 84 |
const char f126_prec_items[] = "ROUTINE|PRIORITY|IMMEDIATE|FLASH"; |
| 85 |
|
| 86 |
std::string f126_nbr = ":msg nbr:"; |
| 87 |
std::string f126_prec = ":prec:"; |
| 88 |
std::string f126_dtm = ":dtm:"; |
| 89 |
std::string f126_from = ":from:"; |
| 90 |
std::string f126_to = ":to:"; |
| 91 |
std::string f126_info = ":info:"; |
| 92 |
std::string f126_subj = ":subj:"; |
| 93 |
std::string f126_grpcnt = ":grpcnt:"; |
| 94 |
std::string f126_msg = ":msgtxt:"; |
| 95 |
std::string f126_rcvd_fm = ":rcvd_fm:"; |
| 96 |
std::string f126_sent_to = ":sent_to:"; |
| 97 |
std::string f126_rcvd_dtm = ":rcvd_dtm:"; |
| 98 |
std::string f126_sent_dtm = ":sent_dtm:"; |
| 99 |
std::string f126_rcvop = ":rcvop:"; |
| 100 |
std::string f126_sendop = ":sendop:"; |
| 101 |
|
| 102 |
//struct FIELD { std::string f_type; std::string f_data; void **w; char w_type; }; |
| 103 |
FIELD f126_fields[] = { |
| 104 |
{ f126_nbr, "", (void **)&f126_txt_nbr, 't' }, // 0 |
| 105 |
{ f126_prec, "", (void **)&f126_sel_prec, 's' }, // 1 |
| 106 |
{ f126_dtm, "", (void **)&f126_txt_dtm, 't' }, // 2 |
| 107 |
{ f126_from, "", (void **)&f126_txt_from, 't' }, // 3 |
| 108 |
{ f126_to, "", (void **)&f126_txt_to, 't' }, // 4 |
| 109 |
{ f126_info, "", (void **)&f126_txt_info, 't' }, // 5 |
| 110 |
{ f126_subj, "", (void **)&f126_txt_subj, 't' }, // 6 |
| 111 |
{ f126_grpcnt, "", (void **)&f126_txt_grpcnt, 't' }, // 7 |
| 112 |
{ f126_msg, "", (void **)&f126_txt_msg, 'e' }, // 8 |
| 113 |
{ f126_rcvd_fm, "", (void **)&f126_txt_rcvd_fm, 't' }, // 9 |
| 114 |
{ f126_sent_to, "", (void **)&f126_txt_sent_to, 't' }, // 10 |
| 115 |
{ f126_rcvd_dtm, "", (void **)&f126_txt_rcvd_dtm, 't' }, // 11 |
| 116 |
{ f126_sent_dtm, "", (void **)&f126_txt_sent_dtm, 't' }, // 12 |
| 117 |
{ f126_rcvop, "", (void **)&f126_txt_rcvop, 't' }, // 13 |
| 118 |
{ f126_sendop, "", (void **)&f126_txt_sendop, 't' }, // 14 |
| 119 |
}; |
| 120 |
|
| 121 |
bool f126_using_template = false; |
| 122 |
|
| 123 |
int f126_num_fields = sizeof(f126_fields) / sizeof(FIELD); |
| 124 |
|
| 125 |
//====================================================================== |
| 126 |
|
| 127 |
void f126_cb_set_dtm() |
| 128 |
{ |
| 129 |
f126_txt_dtm->value(szCAPDateTime()); |
| 130 |
} |
| 131 |
|
| 132 |
void f126_cb_set_rcvd_dtm() |
| 133 |
{ |
| 134 |
f126_txt_rcvd_dtm->value(szCAPDateTime()); |
| 135 |
} |
| 136 |
|
| 137 |
void f126_cb_set_sent_dtm() |
| 138 |
{ |
| 139 |
f126_txt_sent_dtm->value(szCAPDateTime()); |
| 140 |
} |
| 141 |
|
| 142 |
void f126_cb_nbr(Fl_Widget *wdg) |
| 143 |
{ |
| 144 |
Fl_Input2 *inp = (Fl_Input2 *)wdg; |
| 145 |
std::string s = inp->value(); |
| 146 |
for (size_t n = 0; n < s.length(); n++) |
| 147 |
if (!isdigit(s[n])) s.erase(n,1); |
| 148 |
strip_leading_zeros(s); |
| 149 |
inp->value(s.c_str()); |
| 150 |
} |
| 151 |
|
| 152 |
static char valid_input[] = "0123456789/,; ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; |
| 153 |
|
| 154 |
void f126_cb_filter_input(Fl_Widget *wdg) |
| 155 |
{ |
| 156 |
Fl_Input2 *inp = (Fl_Input2 *)wdg; |
| 157 |
std::string s = inp->value(); |
| 158 |
ucase(s); |
| 159 |
for (size_t n = 0; n < s.length(); n++) |
| 160 |
if (strchr(valid_input, s[n]) == NULL) |
| 161 |
s.erase(n,1); |
| 162 |
inp->value(s.c_str()); |
| 163 |
} |
| 164 |
|
| 165 |
void f126_clear_fields() |
| 166 |
{ |
| 167 |
for (int i = 0; i < f126_num_fields; i++) |
| 168 |
f126_fields[i].f_data.clear(); |
| 169 |
} |
| 170 |
|
| 171 |
static std::string numeric(int n) |
| 172 |
{ |
| 173 |
static char snum[12]; |
| 174 |
snprintf(snum, sizeof(snum), "%d", n); |
| 175 |
return snum; |
| 176 |
} |
| 177 |
|
| 178 |
void f126_set_choices() { |
| 179 |
f126_sel_prec->clear(); |
| 180 |
f126_sel_prec->add(f126_prec_items); |
| 181 |
f126_sel_prec->index(0); |
| 182 |
} |
| 183 |
|
| 184 |
bool f126_check_fields() |
| 185 |
{ |
| 186 |
for (int i = 0; i < f126_num_fields; i++) { |
| 187 |
if (f126_fields[i].w_type == 'd') { |
| 188 |
if (f126_fields[i].f_data != ((Fl_DateInput *)(*f126_fields[i].w))->value()) |
| 189 |
return true; |
| 190 |
} else if (f126_fields[i].w_type == 't') { |
| 191 |
if (f126_fields[i].f_data != ((Fl_Input2 *)(*f126_fields[i].w))->value()) |
| 192 |
return true; |
| 193 |
} else if (f126_fields[i].w_type == 's') { |
| 194 |
int choice = ((Fl_ListBox *)(*f126_fields[i].w))->index(); |
| 195 |
if (choice >= 0) { |
| 196 |
if (f126_fields[i].f_data != numeric(choice)) |
| 197 |
return true; |
| 198 |
} |
| 199 |
} else if (f126_fields[i].w_type == 'e') { |
| 200 |
if (f126_fields[i].f_data != ((FTextEdit *)(*f126_fields[i].w))->buffer()->text()) |
| 201 |
return true; |
| 202 |
} else if (f126_fields[i].w_type == 'b') { |
| 203 |
std::string val = ((Fl_Button *)(*f126_fields[i].w))->value() ? "T" : "F"; |
| 204 |
if (f126_fields[i].f_data != val) |
| 205 |
return true; |
| 206 |
} |
| 207 |
} |
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
void f126_update_fields() |
| 212 |
{ |
| 213 |
for (int i = 0; i < f126_num_fields; i++) { |
| 214 |
if (f126_fields[i].w_type == 'd') { |
| 215 |
f126_fields[i].f_data = ((Fl_DateInput *)(*f126_fields[i].w))->value(); |
| 216 |
} else if (f126_fields[i].w_type == 't') { |
| 217 |
f126_fields[i].f_data = ((Fl_Input2 *)(*f126_fields[i].w))->value(); |
| 218 |
} else if (f126_fields[i].w_type == 's') { |
| 219 |
int choice = ((Fl_ListBox *)(*f126_fields[i].w))->index(); |
| 220 |
if (choice >= 0) { |
| 221 |
f126_fields[i].f_data = numeric(choice); |
| 222 |
} |
| 223 |
} else if (f126_fields[i].w_type == 'e') { |
| 224 |
f126_fields[i].f_data = ((FTextEdit *)(*f126_fields[i].w))->buffer()->text(); |
| 225 |
} else if (f126_fields[i].w_type == 'b') { |
| 226 |
std::string val = ((Fl_Button *)(*f126_fields[i].w))->value() ? "T" : "F"; |
| 227 |
f126_fields[i].f_data = val; |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
void f126_clear_form() |
| 233 |
{ |
| 234 |
f126_clear_fields(); |
| 235 |
|
| 236 |
if (progStatus.rgnbr_fname) |
| 237 |
f126_txt_nbr->value(progStatus.rgnbr.c_str()); |
| 238 |
else |
| 239 |
f126_txt_nbr->value(""); |
| 240 |
|
| 241 |
for (int i = 1; i < f126_num_fields; i++) |
| 242 |
if (f126_fields[i].w_type == 'd') |
| 243 |
((Fl_DateInput *)(*f126_fields[i].w))->value(""); |
| 244 |
else if (f126_fields[i].w_type == 't') |
| 245 |
((Fl_Input2 *)(*f126_fields[i].w))->value(""); |
| 246 |
else if (f126_fields[i].w_type == 's') |
| 247 |
((Fl_ListBox *)(*f126_fields[i].w))->index(0); |
| 248 |
else if (f126_fields[i].w_type == 'e') |
| 249 |
((FTextEdit *)(*f126_fields[i].w))->clear(); |
| 250 |
else if (f126_fields[i].w_type == 'b') |
| 251 |
((Fl_Button *)(*f126_fields[i].w))->value(0); |
| 252 |
f126_update_fields(); |
| 253 |
} |
| 254 |
|
| 255 |
void f126_update_form() |
| 256 |
{ |
| 257 |
for (int i = 0; i < f126_num_fields; i++) { |
| 258 |
if (f126_fields[i].w_type == 'd') |
| 259 |
((Fl_DateInput *)(*f126_fields[i].w))->value(f126_fields[i].f_data.c_str()); |
| 260 |
else if (f126_fields[i].w_type == 't') |
| 261 |
((Fl_Input2 *)(*f126_fields[i].w))->value(f126_fields[i].f_data.c_str()); |
| 262 |
else if (f126_fields[i].w_type == 's') |
| 263 |
((Fl_ListBox *)(*f126_fields[i].w))->index(atoi(f126_fields[i].f_data.c_str())); |
| 264 |
else if (f126_fields[i].w_type == 'e') { |
| 265 |
((FTextEdit *)(*f126_fields[i].w))->clear(); |
| 266 |
((FTextEdit *)(*f126_fields[i].w))->add(f126_fields[i].f_data.c_str()); |
| 267 |
} else if (f126_fields[i].w_type == 'b') |
| 268 |
((Fl_Button *)(*f126_fields[i].w))->value(f126_fields[i].f_data == "T" ? 1 : 0); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
void f126_make_buffer(bool compress) |
| 273 |
{ |
| 274 |
std::string mbuff; |
| 275 |
mbuff.clear(); |
| 276 |
for (int i = 0; i < f126_num_fields; i++) |
| 277 |
mbuff.append( lineout( f126_fields[i].f_type, f126_fields[i].f_data ) ); |
| 278 |
if (compress) compress_maybe(mbuff); |
| 279 |
f126_buffer.append(mbuff); |
| 280 |
} |
| 281 |
|
| 282 |
void f126_read_buffer(std::string data) |
| 283 |
{ |
| 284 |
clear_fields(); |
| 285 |
read_header(data); |
| 286 |
|
| 287 |
for (int i = 0; i < f126_num_fields; i++) |
| 288 |
f126_fields[i].f_data = findstr(data, f126_fields[i].f_type); |
| 289 |
|
| 290 |
f126_update_form(); |
| 291 |
} |
| 292 |
|
| 293 |
void f126_cb_new() |
| 294 |
{ |
| 295 |
if (f126_check_fields()) { |
| 296 |
if (fl_choice2(xMODIFIED, xNO, xYES, NULL) == 1) { |
| 297 |
update_header(CHANGED); |
| 298 |
f126_cb_save(); |
| 299 |
} |
| 300 |
} |
| 301 |
f126_update_fields(); |
| 302 |
f126_clear_form(); |
| 303 |
clear_header(); |
| 304 |
f126_def_filename = ICS_msg_dir; |
| 305 |
f126_def_filename.append(xNEW).append(F126_FILE_EXT); |
| 306 |
f126_using_template = false; |
| 307 |
show_filename(f126_def_filename); |
| 308 |
} |
| 309 |
|
| 310 |
void f126_cb_import() |
| 311 |
{ |
| 312 |
fl_alert2(xNOTIMPLEMENTED); |
| 313 |
} |
| 314 |
|
| 315 |
void f126_cb_export() |
| 316 |
{ |
| 317 |
fl_alert2(xNOTIMPLEMENTED); |
| 318 |
} |
| 319 |
|
| 320 |
void f126_cb_wrap_import(std::string wrapfilename, std::string inpbuffer) |
| 321 |
{ |
| 322 |
f126_clear_form(); |
| 323 |
f126_read_buffer(inpbuffer); |
| 324 |
f126_def_filename = ICS_msg_dir; |
| 325 |
f126_def_filename.append(wrapfilename); |
| 326 |
show_filename(f126_def_filename); |
| 327 |
f126_using_template = false; |
| 328 |
} |
| 329 |
|
| 330 |
int eval_f126_fsize() |
| 331 |
{ |
| 332 |
Ccrc16 chksum; |
| 333 |
evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn "); |
| 334 |
evalstr.append(f126_base_filename).append("]"); |
| 335 |
f126_update_fields(); |
| 336 |
update_header(FROM); |
| 337 |
evalstr.append(header("<f126>")); |
| 338 |
f126_buffer.clear(); |
| 339 |
f126_make_buffer(true); |
| 340 |
if (f126_buffer.empty()) return 0; |
| 341 |
evalstr.append( f126_buffer ); |
| 342 |
evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]"); |
| 343 |
return evalstr.length(); |
| 344 |
} |
| 345 |
|
| 346 |
void f126_cb_wrap_export() |
| 347 |
{ |
| 348 |
if (f126_check_fields()) { |
| 349 |
if (fl_choice2(xMODIFIED, xNO, xYES, NULL) == 0) |
| 350 |
return; |
| 351 |
update_header(CHANGED); |
| 352 |
} |
| 353 |
f126_update_fields(); |
| 354 |
|
| 355 |
if (f126_base_filename == std::string(xNEW).append(F126_FILE_EXT) || |
| 356 |
f126_base_filename == std::string(xDEFAULT).append(F126_FILE_EXT) ) |
| 357 |
if (!f126_cb_save_as()) return; |
| 358 |
|
| 359 |
std::string wrapfilename = WRAP_send_dir; |
| 360 |
wrapfilename.append(f126_base_filename); |
| 361 |
wrapfilename.append(WRAP_EXT); |
| 362 |
const char *p = FSEL::saveas( |
| 363 |
xSAVEASWRAP, |
| 364 |
xWRAPFILE, |
| 365 |
wrapfilename.c_str()); |
| 366 |
if (p) { |
| 367 |
std::string pext = fl_filename_ext(p); |
| 368 |
wrapfilename = p; |
| 369 |
|
| 370 |
update_header(FROM); |
| 371 |
f126_buffer.assign(header("<f126>")); |
| 372 |
f126_make_buffer(true); |
| 373 |
export_wrapfile(f126_base_filename, wrapfilename, f126_buffer, pext != WRAP_EXT); |
| 374 |
|
| 375 |
f126_buffer.assign(header("<f126>")); |
| 376 |
f126_make_buffer(false); |
| 377 |
f126_write(f126_def_filename); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
void f126_cb_wrap_autosend() |
| 382 |
{ |
| 383 |
if (f126_check_fields()) { |
| 384 |
if (fl_choice2(xMODIFIED, xNO, xYES, NULL) == 0) |
| 385 |
return; |
| 386 |
update_header(CHANGED); |
| 387 |
} |
| 388 |
f126_update_fields(); |
| 389 |
|
| 390 |
if (f126_base_filename == std::string(xNEW).append(F126_FILE_EXT) || |
| 391 |
f126_base_filename == std::string(xDEFAULT).append(F126_FILE_EXT) ) |
| 392 |
if (!f126_cb_save_as()) return; |
| 393 |
|
| 394 |
update_header(FROM); |
| 395 |
f126_buffer.assign(header("<f126>")); |
| 396 |
f126_make_buffer(true); |
| 397 |
xfr_via_socket(f126_base_filename, f126_buffer); |
| 398 |
|
| 399 |
f126_buffer.assign(header("<f126>")); |
| 400 |
f126_make_buffer(false); |
| 401 |
f126_write(f126_def_filename); |
| 402 |
} |
| 403 |
|
| 404 |
void f126_cb_load_template() |
| 405 |
{ |
| 406 |
std::string f126_def_filename = f126_def_template_name; |
| 407 |
const char *p = FSEL::select( |
| 408 |
xOPENTEMPLATE, |
| 409 |
std::string(xTEMPLATEFILE).append(F126_TEMP_EXT).c_str(), |
| 410 |
f126_def_filename.c_str()); |
| 411 |
if (p) { |
| 412 |
f126_clear_form(); |
| 413 |
read_data_file(p); |
| 414 |
f126_def_template_name = p; |
| 415 |
show_filename(f126_def_template_name); |
| 416 |
f126_using_template = true; |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
void f126_cb_save_template() |
| 421 |
{ |
| 422 |
if (!f126_using_template) { |
| 423 |
f126_cb_save_as_template(); |
| 424 |
return; |
| 425 |
} |
| 426 |
std::string f126_def_filename = f126_def_template_name; |
| 427 |
const char *p = FSEL::saveas( |
| 428 |
xSAVEASTEMPLATE, |
| 429 |
std::string(xTEMPLATEFILE).append(F126_TEMP_EXT).c_str(), |
| 430 |
f126_def_filename.c_str()); |
| 431 |
if (p) { |
| 432 |
update_header(CHANGED); |
| 433 |
f126_update_fields(); |
| 434 |
f126_buffer.assign(header("<f126>")); |
| 435 |
f126_make_buffer(); |
| 436 |
f126_write(p); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
void f126_cb_save_as_template() |
| 441 |
{ |
| 442 |
std::string f126_def_filename = f126_def_template_name; |
| 443 |
const char *p = FSEL::saveas( |
| 444 |
xSAVEASTEMPLATE, |
| 445 |
std::string(xTEMPLATEFILE).append(F126_TEMP_EXT).c_str(), |
| 446 |
f126_def_filename.c_str()); |
| 447 |
if (p) { |
| 448 |
const char *pext = fl_filename_ext(p); |
| 449 |
f126_def_template_name = p; |
| 450 |
if (strlen(pext) == 0) f126_def_template_name.append(F126_TEMP_EXT); |
| 451 |
remove_spaces_from_filename(f126_def_template_name); |
| 452 |
|
| 453 |
clear_header(); |
| 454 |
update_header(CHANGED); |
| 455 |
f126_update_fields(); |
| 456 |
f126_buffer.assign(header("<f126>")); |
| 457 |
f126_make_buffer(); |
| 458 |
f126_write(f126_def_template_name); |
| 459 |
|
| 460 |
show_filename(f126_def_template_name); |
| 461 |
f126_using_template = true; |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
void f126_cb_open() |
| 466 |
{ |
| 467 |
const char *p = FSEL::select( |
| 468 |
_(xOPENDATAFILE), |
| 469 |
std::string("f126\t*").append(F126_FILE_EXT).c_str(), |
| 470 |
f126_def_filename.c_str()); |
| 471 |
if (!p) return; |
| 472 |
if (strlen(p) == 0) return; |
| 473 |
f126_clear_form(); |
| 474 |
read_data_file(p); |
| 475 |
f126_using_template = false; |
| 476 |
f126_def_filename = p; |
| 477 |
show_filename(f126_def_filename); |
| 478 |
} |
| 479 |
|
| 480 |
void f126_write(std::string s) |
| 481 |
{ |
| 482 |
FILE *f126_file = fopen(s.c_str(), "w"); |
| 483 |
if (!f126_file) return; |
| 484 |
|
| 485 |
fwrite(f126_buffer.c_str(), f126_buffer.length(), 1, f126_file); |
| 486 |
fclose(f126_file); |
| 487 |
} |
| 488 |
|
| 489 |
bool f126_cb_save_as() |
| 490 |
{ |
| 491 |
const char *p; |
| 492 |
std::string newfilename; |
| 493 |
|
| 494 |
std::string name = named_file(); |
| 495 |
if (!name.empty()) { |
| 496 |
name.append(F126_FILE_EXT); |
| 497 |
newfilename = ICS_msg_dir; |
| 498 |
newfilename.append(name); |
| 499 |
} else |
| 500 |
newfilename = f126_def_filename; |
| 501 |
|
| 502 |
p = FSEL::saveas(_(xSAVEDATAFILE), |
| 503 |
std::string("f126\t*").append(F126_FILE_EXT).c_str(), |
| 504 |
newfilename.c_str()); |
| 505 |
|
| 506 |
if (!p) return false; |
| 507 |
if (strlen(p) == 0) return false; |
| 508 |
|
| 509 |
if (progStatus.rgnbr_fname) { |
| 510 |
int n = atoi(progStatus.rgnbr.c_str()); |
| 511 |
n++; |
| 512 |
char szn[12]; |
| 513 |
snprintf(szn, sizeof(szn), "%d", n); |
| 514 |
progStatus.rgnbr = szn; |
| 515 |
txt_rgnbr->value(szn); |
| 516 |
txt_rgnbr->redraw(); |
| 517 |
} else if (progStatus.sernbr_fname) |
| 518 |
update_sernbr(); |
| 519 |
|
| 520 |
const char *pext = fl_filename_ext(p); |
| 521 |
f126_def_filename = p; |
| 522 |
if (strlen(pext) == 0) f126_def_filename.append(F126_FILE_EXT); |
| 523 |
|
| 524 |
remove_spaces_from_filename(f126_def_filename); |
| 525 |
|
| 526 |
update_header(NEW); |
| 527 |
f126_update_fields(); |
| 528 |
f126_buffer.assign(header("<f126>")); |
| 529 |
f126_make_buffer(); |
| 530 |
f126_write(f126_def_filename); |
| 531 |
|
| 532 |
f126_using_template = false; |
| 533 |
show_filename(f126_def_filename); |
| 534 |
return true; |
| 535 |
} |
| 536 |
|
| 537 |
void f126_cb_save() |
| 538 |
{ |
| 539 |
if (f126_base_filename == std::string(xNEW).append(F126_FILE_EXT) || |
| 540 |
f126_base_filename == std::string(xDEFAULT).append(F126_FILE_EXT) || |
| 541 |
f126_using_template == true) { |
| 542 |
f126_cb_save_as(); |
| 543 |
return; |
| 544 |
} |
| 545 |
|
| 546 |
if (f126_check_fields()) update_header(CHANGED); |
| 547 |
f126_update_fields(); |
| 548 |
f126_buffer.assign(header("<f126>")); |
| 549 |
f126_make_buffer(); |
| 550 |
f126_write(f126_def_filename); |
| 551 |
|
| 552 |
f126_using_template = false; |
| 553 |
} |
| 554 |
|
| 555 |
void f126_cb_check() |
| 556 |
{ |
| 557 |
std::string temp = f126_txt_msg->buffer()->text(); |
| 558 |
if (temp.empty()) { |
| 559 |
f126_txt_grpcnt->value(""); |
| 560 |
f126_btn_check->labelcolor(FL_BLACK); |
| 561 |
f126_btn_check->redraw_label(); |
| 562 |
return; |
| 563 |
} |
| 564 |
|
| 565 |
// convert to uppercase |
| 566 |
for (size_t n = 0; n < temp.length(); n++) |
| 567 |
temp[n] = toupper(temp[n]); |
| 568 |
// convert tabs to 5 spaces |
| 569 |
size_t pos = std::string::npos; |
| 570 |
while ((pos = temp.find("\t")) != std::string::npos) |
| 571 |
temp.replace(pos, 1, " "); |
| 572 |
// return converted text to editor |
| 573 |
f126_txt_msg->clear(); |
| 574 |
f126_txt_msg->addstr(temp.c_str()); |
| 575 |
|
| 576 |
// compute word count |
| 577 |
// remove any user inserted end-of-lines |
| 578 |
while ((pos = temp.find('\n')) != std::string::npos) temp[pos] = ' '; |
| 579 |
// only single spaces no trailing spaces, no leading spaces |
| 580 |
while ((pos = temp.find(" ")) != std::string::npos) temp.erase(pos,1); |
| 581 |
while (temp[temp.length() -1] == ' ') temp.erase(temp.length()-1, 1); |
| 582 |
if (temp[0] == ' ') temp.erase(0,1); |
| 583 |
// count number of words in textf126_def_filename |
| 584 |
int numwords = 0; |
| 585 |
if (temp.length()) { |
| 586 |
pos = 0; |
| 587 |
numwords = 1; |
| 588 |
while ((pos = temp.find(" ", pos + 1)) != std::string::npos) numwords++; |
| 589 |
} |
| 590 |
|
| 591 |
char snum[15]; |
| 592 |
snprintf(snum, sizeof(snum), "%d", numwords); |
| 593 |
f126_grpcnt = snum; |
| 594 |
f126_txt_grpcnt->value(snum); |
| 595 |
f126_update_fields(); |
| 596 |
f126_btn_check->labelcolor(FL_BLACK); |
| 597 |
f126_btn_check->redraw_label(); |
| 598 |
} |
| 599 |
|
| 600 |
void f126_cb_html() |
| 601 |
{ |
| 602 |
std::string f126_name; |
| 603 |
std::string html_text; |
| 604 |
unsigned int nbr; |
| 605 |
f126_name = ICS_dir; |
| 606 |
f126_name.append("f126.html"); |
| 607 |
|
| 608 |
f126_update_fields(); |
| 609 |
f126_cb_check(); |
| 610 |
std::string form = f126_html_template; |
| 611 |
|
| 612 |
std::string pg = ":pg:"; |
| 613 |
std::string pgnr = ":npgs:"; |
| 614 |
std::string pgone = "1"; |
| 615 |
replacestr( form, pg, pgone); |
| 616 |
replacestr( form, pgnr, pgone); |
| 617 |
for (int i = 0; i < f126_num_fields; i++) { |
| 618 |
if (f126_fields[i].f_type == f126_prec) { |
| 619 |
sscanf(f126_fields[i].f_data.c_str(), "%u", &nbr); |
| 620 |
if (nbr >= 0 && nbr < (sizeof(f126_s_prec) / sizeof(*f126_s_prec))) |
| 621 |
html_text = f126_s_prec[nbr]; |
| 622 |
else |
| 623 |
html_text = ""; |
| 624 |
replacestr( form, f126_fields[i].f_type, html_text ); |
| 625 |
} else if (f126_fields[i].w_type == 'b') { |
| 626 |
replacestr( form, f126_fields[i].f_type, f126_fields[i].f_data == "T" ? yes : no); |
| 627 |
} else if (f126_fields[i].w_type == 'e') { |
| 628 |
std::string temp = f126_fields[i].f_data; |
| 629 |
size_t p = 0; |
| 630 |
while ( (p = temp.find("\n")) != std::string::npos) |
| 631 |
temp.replace(p, 1, "<br>"); |
| 632 |
replacestr( form, f126_fields[i].f_type, temp); |
| 633 |
} else |
| 634 |
replacestr( form, f126_fields[i].f_type, f126_fields[i].f_data ); |
| 635 |
} |
| 636 |
|
| 637 |
std::string rxstr = ""; |
| 638 |
rxstr.append(progStatus.my_call).append(" ").append(progStatus.my_tel); |
| 639 |
rxstr.append("<br>").append(progStatus.my_name); |
| 640 |
rxstr.append("<br>").append(progStatus.my_addr); |
| 641 |
rxstr.append("<br>").append(progStatus.my_city); |
| 642 |
html_text = ":rx:"; |
| 643 |
replacestr( form, html_text, rxstr); |
| 644 |
|
| 645 |
html_text = ":exp:"; |
| 646 |
std::string arlmsgs = ""; |
| 647 |
if (progStatus.arl_desc) |
| 648 |
arlmsgs = expand_arl(f126_fields[10].f_data); |
| 649 |
replacestr( form, html_text, arlmsgs); |
| 650 |
|
| 651 |
FILE *f126_file = fopen(f126_name.c_str(), "w"); |
| 652 |
fprintf(f126_file,"%s", form.c_str()); |
| 653 |
fclose(f126_file); |
| 654 |
|
| 655 |
open_url(f126_name.c_str()); |
| 656 |
} |
| 657 |
|
| 658 |
void f126_cb_textout() |
| 659 |
{ |
| 660 |
std::string f126_name; |
| 661 |
std::string lines; |
| 662 |
std::string str; |
| 663 |
int nbr = 0; |
| 664 |
f126_name = ICS_dir; |
| 665 |
f126_name.append("f126.txt"); |
| 666 |
|
| 667 |
f126_update_fields(); |
| 668 |
f126_cb_check(); |
| 669 |
|
| 670 |
std::string form = f126_txt_template; |
| 671 |
|
| 672 |
for (int i = 0; i < f126_num_fields; i++) { |
| 673 |
str.clear(); |
| 674 |
if (f126_fields[i].f_type == f126_prec) { |
| 675 |
sscanf(f126_fields[i].f_data.c_str(), "%d", &nbr); |
| 676 |
str = f126_s_prec[nbr]; |
| 677 |
if (str.find("EMERGENCY") == std::string::npos) |
| 678 |
str = str[0]; |
| 679 |
replacestr( form, f126_fields[i].f_type, str); |
| 680 |
} else { |
| 681 |
str = f126_fields[i].f_data; |
| 682 |
// strip_lfs(str); |
| 683 |
replacestr( form, f126_fields[i].f_type, str); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
FILE *f126_file = fopen(f126_name.c_str(), "w"); |
| 688 |
fprintf(f126_file,"%s", form.c_str()); |
| 689 |
fclose(f126_file); |
| 690 |
open_url(f126_name.c_str()); |
| 691 |
} |
| 692 |
|