| 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 |
|
| 61 |
#ifdef WIN32 |
| 62 |
# include "flmsgrc.h" |
| 63 |
# include "compat.h" |
| 64 |
# define dirent fl_dirent_no_thanks |
| 65 |
#endif |
| 66 |
|
| 67 |
#include <FL/filename.H> |
| 68 |
#include "dirent-check.h" |
| 69 |
|
| 70 |
#include <FL/x.H> |
| 71 |
#include <FL/Fl_Pixmap.H> |
| 72 |
#include <FL/Fl_Image.H> |
| 73 |
|
| 74 |
// ics205 fields |
| 75 |
|
| 76 |
// compatibility fields required to read older data files |
| 77 |
|
| 78 |
std::string ics205_name = ":nam:"; |
| 79 |
std::string ics205_dt1 = ":dt1:"; |
| 80 |
std::string ics205_dt2 = ":dt2:"; |
| 81 |
std::string ics205_dt3 = ":dt3:"; |
| 82 |
std::string ics205_func = ":func"; |
| 83 |
std::string ics205_chan = ":chan"; |
| 84 |
std::string ics205_asgn = ":asgn"; |
| 85 |
std::string ics205_rx_freq = ":rxfq"; |
| 86 |
std::string ics205_rx_tone = ":rxtn"; |
| 87 |
std::string ics205_tx_freq = ":txfq"; |
| 88 |
std::string ics205_tx_tone = ":txtn"; |
| 89 |
std::string ics205_mode_adm = ":mode"; |
| 90 |
std::string ics205_rem = ":rmrk"; |
| 91 |
std::string ics205_prep = ":prp:"; |
| 92 |
std::string ics205_county = ":cnty:"; |
| 93 |
std::string ics205_state = ":stat:"; |
| 94 |
std::string ics205_latitude = ":lat:"; |
| 95 |
std::string ics205_longitude = ":lon:"; |
| 96 |
|
| 97 |
|
| 98 |
const char *nbr[] = { |
| 99 |
"00:", "01:", "02:", "03:", "04:", "05:", "06:", "07:", "08:", "09:", |
| 100 |
"10:", "11:", "12:", "13:", "14:", "15:", "16:", "17:", "18:", "19:" }; |
| 101 |
|
| 102 |
std::string s205_name; |
| 103 |
std::string s205_dt_prepared; |
| 104 |
std::string s205_dt_op_from; |
| 105 |
std::string s205_dt_op_to; |
| 106 |
std::string s205_func[20]; |
| 107 |
std::string s205_channel[20]; |
| 108 |
std::string s205_asgn[20]; |
| 109 |
std::string s205_rx_freq[20]; |
| 110 |
std::string s205_rx_tone[20]; |
| 111 |
std::string s205_tx_freq[20]; |
| 112 |
std::string s205_tx_tone[20]; |
| 113 |
std::string s205_mode_adm[20]; |
| 114 |
std::string s205_remarks[20]; |
| 115 |
std::string s205_preparer; |
| 116 |
std::string s205_county; |
| 117 |
std::string s205_state; |
| 118 |
std::string s205_latitude; |
| 119 |
std::string s205_longitude; |
| 120 |
|
| 121 |
std::string buff205; |
| 122 |
std::string def_205_filename = ""; |
| 123 |
std::string base_205_filename = ""; |
| 124 |
std::string def_205_TemplateName = ""; |
| 125 |
bool using_ics205_template = false; |
| 126 |
|
| 127 |
void cb_205_SetDateTime1() |
| 128 |
{ |
| 129 |
txt_205_dt_prepared->value(szDateTime()); |
| 130 |
} |
| 131 |
|
| 132 |
void cb_205_SetDateTime2() |
| 133 |
{ |
| 134 |
txt_205_dt_op_from->value(szDateTime()); |
| 135 |
} |
| 136 |
|
| 137 |
void cb_205_SetDateTime3() |
| 138 |
{ |
| 139 |
txt_205_dt_op_to->value(szDateTime()); |
| 140 |
} |
| 141 |
|
| 142 |
void clear_205fields() |
| 143 |
{ |
| 144 |
s205_name.clear(); |
| 145 |
s205_dt_prepared.clear(); |
| 146 |
s205_dt_op_from.clear(); |
| 147 |
for (int i = 0; i < 20; i++) { |
| 148 |
s205_func[i].clear(); |
| 149 |
s205_channel[i].clear(); |
| 150 |
s205_asgn[i].clear(); |
| 151 |
s205_rx_freq[i].clear(); |
| 152 |
s205_rx_tone[i].clear(); |
| 153 |
s205_tx_freq[i].clear(); |
| 154 |
s205_tx_tone[i].clear(); |
| 155 |
s205_mode_adm[i].clear(); |
| 156 |
s205_remarks[i].clear(); |
| 157 |
} |
| 158 |
s205_preparer.clear(); |
| 159 |
s205_county.clear(); |
| 160 |
s205_state.clear(); |
| 161 |
s205_latitude.clear(); |
| 162 |
s205_longitude.clear(); |
| 163 |
} |
| 164 |
|
| 165 |
bool check_205fields() |
| 166 |
{ |
| 167 |
if (s205_name != txt_205_name->value()) |
| 168 |
return true; |
| 169 |
if (s205_dt_prepared != txt_205_dt_prepared->value()) |
| 170 |
return true; |
| 171 |
if (s205_dt_op_from != txt_205_dt_op_from->value()) |
| 172 |
return true; |
| 173 |
if (s205_dt_op_to != txt_205_dt_op_to->value()) |
| 174 |
return true; |
| 175 |
for (int i = 0; i < 20; i++) { |
| 176 |
if (s205_func[i] != txt_205_func[i]->value()) |
| 177 |
return true; |
| 178 |
if (s205_channel[i] != txt_205_channel[i]->value()) |
| 179 |
return true; |
| 180 |
if (s205_asgn[i] != txt_205_assign[i]->value()) |
| 181 |
return true; |
| 182 |
if (s205_rx_freq[i] != txt_205_rx_freq[i]->value()) |
| 183 |
return true; |
| 184 |
if (s205_rx_tone[i] != txt_205_rx_tone[i]->value()) |
| 185 |
return true; |
| 186 |
if (s205_tx_freq[i] != txt_205_tx_freq[i]->value()) |
| 187 |
return true; |
| 188 |
if (s205_tx_tone[i] != txt_205_tx_tone[i]->value()) |
| 189 |
return true; |
| 190 |
if (s205_mode_adm[i] != txt_205_mode_adm[i]->value()) |
| 191 |
return true; |
| 192 |
if (s205_remarks[i] != txt_205_remarks[i]->value()) |
| 193 |
return true; |
| 194 |
} |
| 195 |
if (s205_preparer != txt_205_preparer->value()) |
| 196 |
return true; |
| 197 |
if (s205_county != txt_205_county->value()) |
| 198 |
return true; |
| 199 |
if (s205_state != txt_205_state->value()) |
| 200 |
return true; |
| 201 |
if (s205_latitude != txt_205_latitude->value()) |
| 202 |
return true; |
| 203 |
if (s205_longitude != txt_205_longitude->value()) |
| 204 |
return true; |
| 205 |
|
| 206 |
return false; |
| 207 |
} |
| 208 |
|
| 209 |
void update_205fields() |
| 210 |
{ |
| 211 |
s205_name = txt_205_name->value(); |
| 212 |
s205_dt_prepared = txt_205_dt_prepared->value(); |
| 213 |
s205_dt_op_from = txt_205_dt_op_from->value(); |
| 214 |
s205_dt_op_to = txt_205_dt_op_to->value(); |
| 215 |
for (int i = 0; i < 20; i++) { |
| 216 |
s205_func[i] = txt_205_func[i]->value(); |
| 217 |
s205_channel[i] = txt_205_channel[i]->value(); |
| 218 |
s205_asgn[i] = txt_205_assign[i]->value(); |
| 219 |
s205_rx_freq[i] = txt_205_rx_freq[i]->value(); |
| 220 |
s205_rx_tone[i] = txt_205_rx_tone[i]->value(); |
| 221 |
s205_tx_freq[i] = txt_205_tx_freq[i]->value(); |
| 222 |
s205_tx_tone[i] = txt_205_tx_tone[i]->value(); |
| 223 |
s205_mode_adm[i] = txt_205_mode_adm[i]->value(); |
| 224 |
s205_remarks[i] = txt_205_remarks[i]->value(); |
| 225 |
} |
| 226 |
s205_preparer = txt_205_preparer->value(); |
| 227 |
s205_county = txt_205_county->value(); |
| 228 |
s205_state = txt_205_state->value(); |
| 229 |
s205_latitude = txt_205_latitude->value(); |
| 230 |
s205_longitude = txt_205_longitude->value(); |
| 231 |
} |
| 232 |
|
| 233 |
void update_205form() |
| 234 |
{ |
| 235 |
txt_205_name->value(s205_name.c_str()); |
| 236 |
txt_205_dt_prepared->value(s205_dt_prepared.c_str()); |
| 237 |
txt_205_dt_op_from->value(s205_dt_op_from.c_str()); |
| 238 |
txt_205_dt_op_to->value(s205_dt_op_to.c_str()); |
| 239 |
for (int i = 0; i < 20; i++) { |
| 240 |
txt_205_func[i]->value(s205_func[i].c_str()); |
| 241 |
txt_205_channel[i]->value(s205_channel[i].c_str()); |
| 242 |
txt_205_assign[i]->value(s205_asgn[i].c_str()); |
| 243 |
txt_205_rx_freq[i]->value(s205_rx_freq[i].c_str()); |
| 244 |
txt_205_rx_tone[i]->value(s205_rx_tone[i].c_str()); |
| 245 |
txt_205_tx_freq[i]->value(s205_tx_freq[i].c_str()); |
| 246 |
txt_205_tx_tone[i]->value(s205_tx_tone[i].c_str()); |
| 247 |
txt_205_mode_adm[i]->value(s205_mode_adm[i].c_str()); |
| 248 |
txt_205_remarks[i]->value(s205_remarks[i].c_str()); |
| 249 |
} |
| 250 |
txt_205_preparer->value(s205_preparer.c_str()); |
| 251 |
txt_205_county->value(s205_county.c_str()); |
| 252 |
txt_205_state->value(s205_state.c_str()); |
| 253 |
txt_205_latitude->value(s205_latitude.c_str()); |
| 254 |
txt_205_longitude->value(s205_longitude.c_str()); |
| 255 |
} |
| 256 |
|
| 257 |
void clear_205_form() |
| 258 |
{ |
| 259 |
clear_205fields(); |
| 260 |
txt_205_name->value(""); |
| 261 |
txt_205_dt_prepared->value(""); |
| 262 |
txt_205_dt_op_from->value(""); |
| 263 |
txt_205_dt_op_to->value(""); |
| 264 |
for (int i = 0; i < 20; i++) { |
| 265 |
txt_205_func[i]->value(""); |
| 266 |
txt_205_channel[i]->value(""); |
| 267 |
txt_205_assign[i]->value(""); |
| 268 |
txt_205_rx_freq[i]->value(""); |
| 269 |
txt_205_rx_tone[i]->value(""); |
| 270 |
txt_205_tx_freq[i]->value(""); |
| 271 |
txt_205_tx_tone[i]->value(""); |
| 272 |
txt_205_mode_adm[i]->value(""); |
| 273 |
txt_205_remarks[i]->value(""); |
| 274 |
} |
| 275 |
txt_205_preparer->value(""); |
| 276 |
txt_205_county->value(""); |
| 277 |
txt_205_state->value(""); |
| 278 |
txt_205_latitude->value(""); |
| 279 |
txt_205_longitude->value(""); |
| 280 |
} |
| 281 |
|
| 282 |
void make_buff205(bool compress = false) |
| 283 |
{ |
| 284 |
std::string mbuff; |
| 285 |
std::string temp; |
| 286 |
mbuff.clear(); |
| 287 |
mbuff.append( lineout( ics205_name, s205_name ) ); |
| 288 |
mbuff.append( lineout( ics205_dt1, s205_dt_prepared ) ); |
| 289 |
mbuff.append( lineout( ics205_dt2, s205_dt_op_from ) ); |
| 290 |
mbuff.append( lineout( ics205_dt3, s205_dt_op_to ) ); |
| 291 |
|
| 292 |
for (int i = 0; i < 20; i++) { |
| 293 |
temp = ics205_func; temp.append(nbr[i]); |
| 294 |
mbuff.append( lineout ( temp, s205_func[i] ) ); |
| 295 |
|
| 296 |
temp = ics205_chan; temp.append(nbr[i]); |
| 297 |
mbuff.append( lineout ( temp, s205_channel[i] ) ); |
| 298 |
|
| 299 |
temp = ics205_asgn; temp.append(nbr[i]); |
| 300 |
mbuff.append( lineout ( temp, s205_asgn[i] ) ); |
| 301 |
|
| 302 |
temp = ics205_rx_freq; temp.append(nbr[i]); |
| 303 |
mbuff.append( lineout ( temp, s205_rx_freq[i] ) ); |
| 304 |
|
| 305 |
temp = ics205_rx_tone; temp.append(nbr[i]); |
| 306 |
mbuff.append( lineout ( temp, s205_rx_tone[i] ) ); |
| 307 |
|
| 308 |
temp = ics205_tx_freq; temp.append(nbr[i]); |
| 309 |
mbuff.append( lineout ( temp, s205_tx_freq[i] ) ); |
| 310 |
|
| 311 |
temp = ics205_tx_tone; temp.append(nbr[i]); |
| 312 |
mbuff.append( lineout ( temp, s205_tx_tone[i] ) ); |
| 313 |
|
| 314 |
temp = ics205_mode_adm; temp.append(nbr[i]); |
| 315 |
mbuff.append( lineout ( temp, s205_mode_adm[i] ) ); |
| 316 |
|
| 317 |
temp = ics205_rem; temp.append(nbr[i]); |
| 318 |
mbuff.append( lineout ( temp, s205_remarks[i] ) ); |
| 319 |
} |
| 320 |
mbuff.append( lineout ( ics205_prep, s205_preparer ) ); |
| 321 |
mbuff.append( lineout ( ics205_county, s205_county ) ); |
| 322 |
mbuff.append( lineout ( ics205_state, s205_state ) ); |
| 323 |
mbuff.append( lineout ( ics205_latitude, s205_latitude ) ); |
| 324 |
mbuff.append( lineout ( ics205_longitude, s205_longitude ) ); |
| 325 |
|
| 326 |
if (compress) compress_maybe(mbuff); |
| 327 |
buff205.append(mbuff); |
| 328 |
} |
| 329 |
|
| 330 |
void read_205_buffer(std::string data) |
| 331 |
{ |
| 332 |
std::string temp; |
| 333 |
clear_205fields(); |
| 334 |
read_header(data); |
| 335 |
|
| 336 |
s205_name = findstr(data, ics205_name); |
| 337 |
s205_dt_prepared = findstr(data, ics205_dt1); |
| 338 |
s205_dt_op_from = findstr(data, ics205_dt2); |
| 339 |
s205_dt_op_to = findstr(data, ics205_dt3); |
| 340 |
for (int i = 0; i < 20; i++) { |
| 341 |
temp = ics205_func; temp.append(nbr[i]); |
| 342 |
s205_func[i] = findstr(data, temp); |
| 343 |
|
| 344 |
temp = ics205_chan; temp.append(nbr[i]); |
| 345 |
s205_channel[i] = findstr(data, temp); |
| 346 |
|
| 347 |
temp = ics205_asgn; temp.append(nbr[i]); |
| 348 |
s205_asgn[i] = findstr(data, temp); |
| 349 |
|
| 350 |
temp = ics205_rx_freq; temp.append(nbr[i]); |
| 351 |
s205_rx_freq[i] = findstr(data, temp); |
| 352 |
|
| 353 |
temp = ics205_rx_tone; temp.append(nbr[i]); |
| 354 |
s205_rx_tone[i] = findstr(data, temp); |
| 355 |
|
| 356 |
temp = ics205_tx_freq; temp.append(nbr[i]); |
| 357 |
s205_tx_freq[i] = findstr(data, temp); |
| 358 |
|
| 359 |
temp = ics205_tx_tone; temp.append(nbr[i]); |
| 360 |
s205_tx_tone[i] = findstr(data, temp); |
| 361 |
|
| 362 |
temp = ics205_mode_adm; temp.append(nbr[i]); |
| 363 |
s205_mode_adm[i] = findstr(data, temp); |
| 364 |
|
| 365 |
temp = ics205_rem; temp.append(nbr[i]); |
| 366 |
s205_remarks[i] = findstr(data, temp); |
| 367 |
} |
| 368 |
s205_preparer = findstr(data, ics205_prep); |
| 369 |
s205_county = findstr(data, ics205_county); |
| 370 |
s205_state = findstr(data, ics205_state); |
| 371 |
s205_latitude = findstr(data, ics205_latitude); |
| 372 |
s205_longitude = findstr(data, ics205_longitude); |
| 373 |
|
| 374 |
update_205form(); |
| 375 |
} |
| 376 |
|
| 377 |
void cb_205_new() |
| 378 |
{ |
| 379 |
if (check_205fields()) { |
| 380 |
if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 1) { |
| 381 |
update_header(CHANGED); |
| 382 |
cb_205_save(); |
| 383 |
} |
| 384 |
} |
| 385 |
clear_205_form(); |
| 386 |
clear_header(); |
| 387 |
def_205_filename = ICS_msg_dir; |
| 388 |
def_205_filename.append("new").append(F205_EXT); |
| 389 |
show_filename(def_205_filename); |
| 390 |
using_ics205_template = false; |
| 391 |
} |
| 392 |
|
| 393 |
void cb_205_import() |
| 394 |
{ |
| 395 |
fl_alert2("Not implemented"); |
| 396 |
} |
| 397 |
|
| 398 |
void cb_205_export() |
| 399 |
{ |
| 400 |
fl_alert2("Not implemented"); |
| 401 |
} |
| 402 |
|
| 403 |
void cb_205_wrap_import(std::string wrapfilename, std::string inpbuffer) |
| 404 |
{ |
| 405 |
clear_205_form(); |
| 406 |
read_205_buffer(inpbuffer); |
| 407 |
def_205_filename = ICS_msg_dir; |
| 408 |
def_205_filename.append(wrapfilename); |
| 409 |
show_filename(def_205_filename); |
| 410 |
using_ics205_template = false; |
| 411 |
} |
| 412 |
|
| 413 |
int eval_205_fsize() |
| 414 |
{ |
| 415 |
Ccrc16 chksum; |
| 416 |
evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn "); |
| 417 |
evalstr.append(base_205_filename).append("]"); |
| 418 |
update_205fields(); |
| 419 |
update_header(FROM); |
| 420 |
evalstr.append(header("<ics205>")); |
| 421 |
buff205.clear(); |
| 422 |
make_buff205(true); |
| 423 |
if (buff205.empty()) return 0; |
| 424 |
compress_maybe( buff205 ); |
| 425 |
evalstr.append( buff205 ); |
| 426 |
evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]"); |
| 427 |
return evalstr.length(); |
| 428 |
} |
| 429 |
|
| 430 |
void cb_205_wrap_export() |
| 431 |
{ |
| 432 |
if (check_205fields()) { |
| 433 |
if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0) |
| 434 |
return; |
| 435 |
update_header(CHANGED); |
| 436 |
} |
| 437 |
update_205fields(); |
| 438 |
|
| 439 |
if (base_205_filename == std::string("new").append(F205_EXT) || |
| 440 |
base_205_filename == std::string("default").append(F205_EXT) ) |
| 441 |
if (!cb_205_save_as()) return; |
| 442 |
|
| 443 |
std::string wrapfilename = WRAP_send_dir; |
| 444 |
wrapfilename.append(base_205_filename); |
| 445 |
wrapfilename.append(".wrap"); |
| 446 |
const char *p = FSEL::saveas( |
| 447 |
"Save as wrap file", |
| 448 |
"Wrap file\t*.{wrap,WRAP}", |
| 449 |
wrapfilename.c_str()); |
| 450 |
if (p) { |
| 451 |
std::string pext = fl_filename_ext(p); |
| 452 |
wrapfilename = p; |
| 453 |
update_header(FROM); |
| 454 |
buff205.assign(header("<ics205>")); |
| 455 |
make_buff205(true); |
| 456 |
export_wrapfile(base_205_filename, wrapfilename, buff205, pext != ".wrap"); |
| 457 |
|
| 458 |
buff205.assign(header("<ics205>")); |
| 459 |
make_buff205(false); |
| 460 |
write_205(def_205_filename); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
void cb_205_wrap_autosend() |
| 465 |
{ |
| 466 |
if (check_205fields()) { |
| 467 |
if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0) |
| 468 |
return; |
| 469 |
update_header(CHANGED); |
| 470 |
} |
| 471 |
update_205fields(); |
| 472 |
|
| 473 |
if (base_205_filename == std::string("new").append(F205_EXT) || |
| 474 |
base_205_filename == std::string("default").append(F205_EXT) ) |
| 475 |
if (!cb_205_save_as()) return; |
| 476 |
|
| 477 |
update_header(FROM); |
| 478 |
buff205.assign(header("<ics205>")); |
| 479 |
make_buff205(true); |
| 480 |
xfr_via_socket(base_205_filename, buff205); |
| 481 |
|
| 482 |
buff205.assign(header("<ics205>")); |
| 483 |
make_buff205(false); |
| 484 |
write_205(def_205_filename); |
| 485 |
} |
| 486 |
|
| 487 |
void cb_205_load_template() |
| 488 |
{ |
| 489 |
std::string def_205_filename = def_205_TemplateName; |
| 490 |
const char *p = FSEL::select( |
| 491 |
"Open template file", |
| 492 |
std::string("Template file\t*").append(T205_EXT).c_str(), |
| 493 |
def_205_filename.c_str()); |
| 494 |
if (p) { |
| 495 |
clear_205_form(); |
| 496 |
read_data_file(p); |
| 497 |
def_205_TemplateName = p; |
| 498 |
show_filename(def_205_TemplateName); |
| 499 |
using_ics205_template = true; |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
void cb_205_save_template() |
| 504 |
{ |
| 505 |
if (!using_ics205_template) { |
| 506 |
cb_205_save_as_template(); |
| 507 |
return; |
| 508 |
} |
| 509 |
std::string def_205_filename = def_205_TemplateName; |
| 510 |
const char *p = FSEL::saveas( |
| 511 |
"Save template file", |
| 512 |
std::string("Template file\t*").append(T205_EXT).c_str(), |
| 513 |
def_205_filename.c_str()); |
| 514 |
if (p) { |
| 515 |
update_header(CHANGED); |
| 516 |
buff205.assign(header("<ics205>")); |
| 517 |
make_buff205(); |
| 518 |
write_205(p); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
void cb_205_save_as_template() |
| 523 |
{ |
| 524 |
std::string def_205_filename = def_205_TemplateName; |
| 525 |
const char *p = FSEL::saveas( |
| 526 |
"Save as template file", |
| 527 |
std::string("Template file\t*").append(T205_EXT).c_str(), |
| 528 |
def_205_filename.c_str()); |
| 529 |
if (p) { |
| 530 |
const char *pext = fl_filename_ext(p); |
| 531 |
def_205_TemplateName = p; |
| 532 |
if (strlen(pext) == 0) def_205_TemplateName.append(T205_EXT); |
| 533 |
remove_spaces_from_filename(def_205_TemplateName); |
| 534 |
clear_header(); |
| 535 |
update_header(CHANGED); |
| 536 |
buff205.assign(header("<ics205>")); |
| 537 |
make_buff205(); |
| 538 |
write_205(def_205_TemplateName); |
| 539 |
show_filename(def_205_TemplateName); |
| 540 |
using_ics205_template = true; |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
void cb_205_open() |
| 545 |
{ |
| 546 |
const char *p = FSEL::select( |
| 547 |
_("Open data file"), |
| 548 |
std::string("ICS-205\t*").append(F205_EXT).c_str(), |
| 549 |
def_205_filename.c_str()); |
| 550 |
if (!p) return; |
| 551 |
if (strlen(p) == 0) return; |
| 552 |
clear_205_form(); |
| 553 |
read_data_file(p); |
| 554 |
using_ics205_template = false; |
| 555 |
def_205_filename = p; |
| 556 |
show_filename(def_205_filename); |
| 557 |
} |
| 558 |
|
| 559 |
void write_205(std::string s) |
| 560 |
{ |
| 561 |
FILE *file205 = fopen(s.c_str(), "w"); |
| 562 |
if (!file205) return; |
| 563 |
|
| 564 |
fwrite(buff205.c_str(), buff205.length(), 1, file205); |
| 565 |
fclose(file205); |
| 566 |
} |
| 567 |
|
| 568 |
bool cb_205_save_as() |
| 569 |
{ |
| 570 |
const char *p; |
| 571 |
std::string newfilename; |
| 572 |
|
| 573 |
std::string name = named_file(); |
| 574 |
if (!name.empty()) { |
| 575 |
name.append(F205_EXT); |
| 576 |
newfilename = ICS_msg_dir; |
| 577 |
newfilename.append(name); |
| 578 |
} else |
| 579 |
newfilename = def_205_filename; |
| 580 |
|
| 581 |
p = FSEL::saveas( |
| 582 |
_("Save data file"), |
| 583 |
std::string("ICS-205\t*").append(F205_EXT).c_str(), |
| 584 |
newfilename.c_str()); |
| 585 |
|
| 586 |
if (!p) return false; |
| 587 |
if (strlen(p) == 0) return false; |
| 588 |
|
| 589 |
if (progStatus.sernbr_fname) update_sernbr(); |
| 590 |
|
| 591 |
const char *pext = fl_filename_ext(p); |
| 592 |
def_205_filename = p; |
| 593 |
if (strlen(pext) == 0) def_205_filename.append(F205_EXT); |
| 594 |
|
| 595 |
remove_spaces_from_filename(def_205_filename); |
| 596 |
update_205fields(); |
| 597 |
clear_header(); |
| 598 |
update_header(CHANGED); |
| 599 |
buff205.assign(header("<ics205>")); |
| 600 |
make_buff205(); |
| 601 |
write_205(def_205_filename); |
| 602 |
|
| 603 |
using_ics205_template = false; |
| 604 |
show_filename(def_205_filename); |
| 605 |
return true; |
| 606 |
} |
| 607 |
|
| 608 |
void cb_205_save() |
| 609 |
{ |
| 610 |
if (base_205_filename == std::string("new").append(F205_EXT) || |
| 611 |
base_205_filename == std::string("default").append(F205_EXT) || |
| 612 |
using_ics205_template == true) { |
| 613 |
cb_205_save_as(); |
| 614 |
return; |
| 615 |
} |
| 616 |
if (check_205fields()) update_header(CHANGED); |
| 617 |
update_205fields(); |
| 618 |
buff205.assign(header("<ics205>")); |
| 619 |
make_buff205(); |
| 620 |
write_205(def_205_filename); |
| 621 |
using_ics205_template = false; |
| 622 |
} |
| 623 |
|
| 624 |
void cb_205_html() |
| 625 |
{ |
| 626 |
std::string temp; |
| 627 |
std::string fname_name = fl_filename_name(def_205_filename.c_str()); |
| 628 |
size_t p = fname_name.rfind('.'); |
| 629 |
if (p != std::string::npos) fname_name.erase(p); |
| 630 |
|
| 631 |
std::string ics205_fname = ICS_dir; |
| 632 |
ics205_fname.append(fname_name); |
| 633 |
ics205_fname.append(".html"); |
| 634 |
|
| 635 |
std::string html_text = ""; |
| 636 |
|
| 637 |
update_205fields(); |
| 638 |
std::string form205 = ics205_html_template; |
| 639 |
|
| 640 |
replacestr(form205, TITLE, fname_name); |
| 641 |
replacestr(form205, ics205_name, s205_name); |
| 642 |
replacestr(form205, ics205_dt1, s205_dt_prepared); |
| 643 |
replacestr(form205, ics205_dt2, s205_dt_op_from); |
| 644 |
replacestr(form205, ics205_dt3, s205_dt_op_to); |
| 645 |
for (int i = 0; i < 20; i++) { |
| 646 |
temp = ics205_func; temp.append(nbr[i]); replacestr(form205, temp, s205_func[i]); |
| 647 |
temp = ics205_chan; temp.append(nbr[i]); replacestr(form205, temp, s205_channel[i]); |
| 648 |
temp = ics205_asgn; temp.append(nbr[i]); replacestr(form205, temp, s205_asgn[i]); |
| 649 |
temp = ics205_rx_freq; temp.append(nbr[i]); replacestr(form205, temp, s205_rx_freq[i]); |
| 650 |
temp = ics205_rx_tone; temp.append(nbr[i]); replacestr(form205, temp, s205_rx_tone[i]); |
| 651 |
temp = ics205_tx_freq; temp.append(nbr[i]); replacestr(form205, temp, s205_tx_freq[i]); |
| 652 |
temp = ics205_tx_tone; temp.append(nbr[i]); replacestr(form205, temp, s205_tx_tone[i]); |
| 653 |
temp = ics205_mode_adm; temp.append(nbr[i]); replacestr(form205, temp, s205_mode_adm[i]); |
| 654 |
temp = ics205_rem; temp.append(nbr[i]); replacestr(form205, temp, s205_remarks[i]); |
| 655 |
} |
| 656 |
replacestr(form205, ics205_prep, s205_preparer); |
| 657 |
replacestr(form205, ics205_county, s205_county); |
| 658 |
replacestr(form205, ics205_state, s205_state); |
| 659 |
replacestr(form205, ics205_latitude, s205_latitude); |
| 660 |
replacestr(form205, ics205_longitude, s205_longitude); |
| 661 |
|
| 662 |
FILE *file205 = fopen(ics205_fname.c_str(), "w"); |
| 663 |
fprintf(file205,"%s", form205.c_str()); |
| 664 |
fclose(file205); |
| 665 |
|
| 666 |
open_url(ics205_fname.c_str()); |
| 667 |
} |
| 668 |
|
| 669 |
void cb_205_msg_type() |
| 670 |
{ |
| 671 |
if (tabs_msg_type->value() == tab_ics205 ) { |
| 672 |
show_filename(def_205_filename); |
| 673 |
} else { |
| 674 |
show_filename(def_rg_filename); |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
void cb_205_textout() |
| 679 |
{ |
| 680 |
std::string fld = ""; |
| 681 |
std::string temp = ""; |
| 682 |
std::string ics205_fname = ICS_dir; |
| 683 |
ics205_fname.append("ics205.txt"); |
| 684 |
|
| 685 |
update_205fields(); |
| 686 |
std::string form205 = ics205_text_template; |
| 687 |
|
| 688 |
replacestr(form205, ics205_name, s205_name); |
| 689 |
replacestr(form205, ics205_dt1, s205_dt_prepared); |
| 690 |
replacestr(form205, ics205_dt2, s205_dt_op_from); |
| 691 |
replacestr(form205, ics205_dt3, s205_dt_op_to); |
| 692 |
for (int i = 0; i < 20; i++) { |
| 693 |
fld = ics205_func; fld.append(nbr[i]); replacestr(form205, fld, s205_func[i]); |
| 694 |
fld = ics205_chan; fld.append(nbr[i]); replacestr(form205, fld, s205_channel[i]); |
| 695 |
fld = ics205_asgn; fld.append(nbr[i]); replacestr(form205, fld, s205_asgn[i]); |
| 696 |
fld = ics205_rx_freq; fld.append(nbr[i]); replacestr(form205, fld, s205_rx_freq[i]); |
| 697 |
fld = ics205_rx_tone; fld.append(nbr[i]); replacestr(form205, fld, s205_rx_tone[i]); |
| 698 |
fld = ics205_tx_freq; fld.append(nbr[i]); replacestr(form205, fld, s205_tx_freq[i]); |
| 699 |
fld = ics205_tx_tone; fld.append(nbr[i]); replacestr(form205, fld, s205_tx_tone[i]); |
| 700 |
fld = ics205_mode_adm; fld.append(nbr[i]); replacestr(form205, fld, s205_mode_adm[i]); |
| 701 |
fld = ics205_rem; fld.append(nbr[i]); temp = s205_remarks[i]; |
| 702 |
replacelf(temp); replacestr(form205, fld, temp); |
| 703 |
} |
| 704 |
replacestr(form205, ics205_prep, s205_preparer); |
| 705 |
replacestr(form205, ics205_county, s205_county); |
| 706 |
replacestr(form205, ics205_state, s205_state); |
| 707 |
replacestr(form205, ics205_latitude, s205_latitude); |
| 708 |
replacestr(form205, ics205_longitude, s205_longitude); |
| 709 |
|
| 710 |
FILE *file205 = fopen(ics205_fname.c_str(), "w"); |
| 711 |
fprintf(file205,"%s", form205.c_str()); |
| 712 |
fclose(file205); |
| 713 |
|
| 714 |
open_url(ics205_fname.c_str()); |
| 715 |
} |