| 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 <FL/Fl_Multi_Browser.H> |
| 22 |
|
| 23 |
#include "gettext.h" |
| 24 |
#include "status.h" |
| 25 |
#include "util.h" |
| 26 |
|
| 27 |
#include "flmsg_dialog.h" |
| 28 |
#include "flmsg.h" |
| 29 |
#include "fileselect.h" |
| 30 |
|
| 31 |
extern Fl_Double_Window* mars_army_list_dialog(); |
| 32 |
extern Fl_Double_Window *mars_army_list_window; |
| 33 |
extern Fl_Multi_Browser *brws_mars_army_list; |
| 34 |
extern std::string mars_army_list_text; |
| 35 |
extern bool mars_army_list_ok; |
| 36 |
|
| 37 |
Fl_Group *tab_mars_army = (Fl_Group *)0; |
| 38 |
|
| 39 |
Fl_Tabs *tab_mars_army_type = (Fl_Tabs *)0; |
| 40 |
|
| 41 |
//---------------------------------------------------------------------- |
| 42 |
|
| 43 |
Fl_Group *tab_mars_army_1 = (Fl_Group *)0; |
| 44 |
Fl_Group *tab_mars_army_2 = (Fl_Group *)0; |
| 45 |
|
| 46 |
Fl_Input2 *txt_mars_army_dtg = (Fl_Input2 *)0; |
| 47 |
Fl_Input2 *txt_mars_army_fm = (Fl_Input2 *)0; |
| 48 |
Fl_Input2 *txt_mars_army_de = (Fl_Input2 *)0; |
| 49 |
Fl_Input2 *txt_mars_army_nbr = (Fl_Input2 *)0; |
| 50 |
Fl_Input2 *txt_mars_army_subj = (Fl_Input2 *)0; |
| 51 |
|
| 52 |
Fl_Button *btn_mars_army_dtg = (Fl_Button *)0; |
| 53 |
Fl_Button *btn_mars_army_pick_fm = (Fl_Button *)0; |
| 54 |
Fl_Button *btn_mars_army_pick_to = (Fl_Button *)0; |
| 55 |
Fl_Button *btn_mars_army_pick_info = (Fl_Button *)0; |
| 56 |
|
| 57 |
FTextEdit *txt_mars_army_to = (FTextEdit *)0; |
| 58 |
FTextEdit *txt_mars_army_info = (FTextEdit *)0; |
| 59 |
FTextEdit *txt_mars_army_text = (FTextEdit *)0; |
| 60 |
|
| 61 |
Fl_Button *btn_mars_army_de_me = (Fl_Button *)0; |
| 62 |
|
| 63 |
Fl_ListBox *sel_mars_army_prec = (Fl_ListBox *)0; |
| 64 |
|
| 65 |
//---------------------------------------------------------------------- |
| 66 |
|
| 67 |
// widget callbacks & support |
| 68 |
bool get_mars_army_list_text() |
| 69 |
{ |
| 70 |
if (!mars_army_list_window) mars_army_list_window = mars_army_list_dialog(); |
| 71 |
brws_mars_army_list->deselect(); |
| 72 |
mars_army_list_window->show(); |
| 73 |
while (mars_army_list_window->visible()) Fl::wait(); |
| 74 |
return mars_army_list_ok; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
void cb_btn_mars_army_pick_fm(Fl_Widget *w, void *d) |
| 79 |
{ |
| 80 |
if (!get_mars_army_list_text()) return; |
| 81 |
std::string s = mars_army_list_text; |
| 82 |
size_t p; |
| 83 |
if ((p = s.find('\n')) != std::string::npos) s.erase(p); |
| 84 |
txt_mars_army_fm->value(s.c_str()); |
| 85 |
estimate(); |
| 86 |
} |
| 87 |
|
| 88 |
void cb_btn_mars_army_pick_to(Fl_Widget *w, void *d) |
| 89 |
{ |
| 90 |
if (!get_mars_army_list_text()) return; |
| 91 |
std::string s = txt_mars_army_to->buffer()->text(); |
| 92 |
if (s.length()) s += '\n'; |
| 93 |
s.append(mars_army_list_text); |
| 94 |
txt_mars_army_to->clear(); |
| 95 |
txt_mars_army_to->add(s.c_str()); |
| 96 |
estimate(); |
| 97 |
} |
| 98 |
|
| 99 |
void cb_btn_mars_army_pick_info(Fl_Widget *w, void *d) |
| 100 |
{ |
| 101 |
if (!get_mars_army_list_text()) return; |
| 102 |
std::string s = txt_mars_army_info->buffer()->text(); |
| 103 |
if (s.length()) s += '\n'; |
| 104 |
s.append(mars_army_list_text); |
| 105 |
txt_mars_army_info->clear(); |
| 106 |
txt_mars_army_info->add(s.c_str()); |
| 107 |
estimate(); |
| 108 |
} |
| 109 |
|
| 110 |
void cb_btn_mars_army_dtg(Fl_Widget *w, void *d) |
| 111 |
{ |
| 112 |
txt_mars_army_dtg->value(szMarsDateTime()); |
| 113 |
estimate(); |
| 114 |
} |
| 115 |
|
| 116 |
void cb_btn_mars_army_de_me(Fl_Widget *w, void *d) |
| 117 |
{ |
| 118 |
txt_mars_army_de->value(progStatus.my_call.c_str()); |
| 119 |
estimate(); |
| 120 |
} |
| 121 |
|
| 122 |
void create_mars_army() |
| 123 |
{ |
| 124 |
int Y = tab_top; |
| 125 |
tab_mars_army = new Fl_Group(0, Y, 570, 390); |
| 126 |
tab_mars_army->align(FL_ALIGN_TOP); |
| 127 |
|
| 128 |
tab_mars_army_type = new Fl_Tabs(0, Y+2, 570, 387); |
| 129 |
|
| 130 |
tab_mars_army_1 = new Fl_Group(0, Y+25, 570, 360, _("Header")); |
| 131 |
|
| 132 |
Y += 35; |
| 133 |
|
| 134 |
txt_mars_army_de = new Fl_Input2(50, Y, 200, 24, _("DE")); |
| 135 |
txt_mars_army_de->tooltip(_("")); |
| 136 |
txt_mars_army_de->callback((Fl_Callback*)cb_mars_fl_input2); |
| 137 |
txt_mars_army_de->when(FL_WHEN_CHANGED); |
| 138 |
|
| 139 |
btn_mars_army_de_me = new Fl_Button(252, Y, 30, 24, _("ME")); |
| 140 |
btn_mars_army_de_me->callback((Fl_Callback*)cb_btn_mars_army_de_me); |
| 141 |
btn_mars_army_de_me->tooltip(_("insert operator callsign")); |
| 142 |
|
| 143 |
txt_mars_army_nbr = new Fl_Input2(320, Y, 150, 24, _("NR")); |
| 144 |
txt_mars_army_nbr->tooltip(_("")); |
| 145 |
txt_mars_army_nbr->callback((Fl_Callback*)cb_mars_fl_input2); |
| 146 |
txt_mars_army_nbr->when(FL_WHEN_CHANGED); |
| 147 |
|
| 148 |
Y += 35; |
| 149 |
sel_mars_army_prec = new Fl_ListBox(50, Y, 45, 24, _("PREC")); |
| 150 |
sel_mars_army_prec->tooltip( |
| 151 |
_("R - Routine\nP - Priority\nO - Immediate\nZ - Flash")); |
| 152 |
sel_mars_army_prec->add("R|P|O|Z"); |
| 153 |
sel_mars_army_prec->align(FL_ALIGN_LEFT); |
| 154 |
sel_mars_army_prec->index(0); |
| 155 |
|
| 156 |
txt_mars_army_dtg = new Fl_Input2(135, Y, 150, 24, _("DTG")); |
| 157 |
txt_mars_army_dtg->tooltip(_("")); |
| 158 |
|
| 159 |
btn_mars_army_dtg = new Fl_Button(285, Y, 22, 24, _("...")); |
| 160 |
btn_mars_army_dtg->tooltip(_("Set Date/Time Group")); |
| 161 |
btn_mars_army_dtg->callback((Fl_Callback*)cb_btn_mars_army_dtg); |
| 162 |
|
| 163 |
Y += 26; |
| 164 |
btn_mars_army_pick_fm = new Fl_Button(4, Y, 44, 24, _("FM")); |
| 165 |
btn_mars_army_pick_fm->tooltip(_("Select from list")); |
| 166 |
btn_mars_army_pick_fm->callback((Fl_Callback*)cb_btn_mars_army_pick_fm); |
| 167 |
|
| 168 |
txt_mars_army_fm = new Fl_Input2(50, Y, 500, 24, _("")); |
| 169 |
txt_mars_army_fm->tooltip(_("use pick list button")); |
| 170 |
txt_mars_army_fm->callback((Fl_Callback*)cb_mars_fl_input2); |
| 171 |
txt_mars_army_fm->when(FL_WHEN_CHANGED); |
| 172 |
|
| 173 |
Y += 26; |
| 174 |
btn_mars_army_pick_to = new Fl_Button(4, Y, 44, 24, _("TO")); |
| 175 |
btn_mars_army_pick_to->tooltip(_("Select from list")); |
| 176 |
btn_mars_army_pick_to->callback((Fl_Callback*)cb_btn_mars_army_pick_to); |
| 177 |
|
| 178 |
txt_mars_army_to = new FTextEdit(50, Y, 500, 100, _("")); |
| 179 |
txt_mars_army_to->tooltip(_("use pick list button")); |
| 180 |
txt_mars_army_to->textfont(FL_HELVETICA); |
| 181 |
txt_mars_army_to->box(FL_DOWN_FRAME); |
| 182 |
txt_mars_army_to->color((Fl_Color)FL_BACKGROUND2_COLOR); |
| 183 |
txt_mars_army_to->selection_color((Fl_Color)FL_SELECTION_COLOR); |
| 184 |
txt_mars_army_to->labeltype(FL_NORMAL_LABEL); |
| 185 |
txt_mars_army_to->labelfont(0); |
| 186 |
txt_mars_army_to->labelsize(14); |
| 187 |
txt_mars_army_to->labelcolor((Fl_Color)FL_FOREGROUND_COLOR); |
| 188 |
txt_mars_army_to->align(FL_ALIGN_TOP_LEFT); |
| 189 |
txt_mars_army_to->callback((Fl_Callback*)cb_mars_text); |
| 190 |
txt_mars_army_to->when(FL_WHEN_CHANGED); |
| 191 |
|
| 192 |
Y += 102; |
| 193 |
btn_mars_army_pick_info = new Fl_Button(4, Y, 44, 24, _("INFO")); |
| 194 |
btn_mars_army_pick_info->tooltip(_("Select from list")); |
| 195 |
btn_mars_army_pick_info->callback((Fl_Callback*)cb_btn_mars_army_pick_info); |
| 196 |
|
| 197 |
txt_mars_army_info = new FTextEdit(50, Y, 500, 100, _("")); |
| 198 |
txt_mars_army_info->tooltip(_("use pick list button")); |
| 199 |
txt_mars_army_info->textfont(FL_HELVETICA); |
| 200 |
txt_mars_army_info->box(FL_DOWN_FRAME); |
| 201 |
txt_mars_army_info->color((Fl_Color)FL_BACKGROUND2_COLOR); |
| 202 |
txt_mars_army_info->selection_color((Fl_Color)FL_SELECTION_COLOR); |
| 203 |
txt_mars_army_info->labeltype(FL_NORMAL_LABEL); |
| 204 |
txt_mars_army_info->labelfont(0); |
| 205 |
txt_mars_army_info->labelsize(14); |
| 206 |
txt_mars_army_info->labelcolor((Fl_Color)FL_FOREGROUND_COLOR); |
| 207 |
txt_mars_army_info->align(FL_ALIGN_TOP_LEFT); |
| 208 |
txt_mars_army_info->callback((Fl_Callback*)cb_mars_text); |
| 209 |
txt_mars_army_info->when(FL_WHEN_CHANGED); |
| 210 |
|
| 211 |
Y += 102; |
| 212 |
Fl_Box *label = new Fl_Box(0, Y, 50, 24, "SUBJ"); |
| 213 |
label->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE); |
| 214 |
|
| 215 |
txt_mars_army_subj = new Fl_Input2(50, Y, 500, 24, _("")); |
| 216 |
txt_mars_army_subj->tooltip(_("message subject")); |
| 217 |
txt_mars_army_subj->callback((Fl_Callback*)cb_mars_fl_input2); |
| 218 |
txt_mars_army_subj->when(FL_WHEN_CHANGED); |
| 219 |
|
| 220 |
tab_mars_army_1->end(); |
| 221 |
|
| 222 |
Y = tab_top; |
| 223 |
|
| 224 |
tab_mars_army_2 = new Fl_Group(0, Y+25, 570, 355, _("Body")); |
| 225 |
|
| 226 |
Y += 30; |
| 227 |
txt_mars_army_text = new FTextEdit(2, Y, 566, 350, ""); |
| 228 |
txt_mars_army_text->tooltip("enter text of message"); |
| 229 |
txt_mars_army_text->textfont(FL_HELVETICA); |
| 230 |
txt_mars_army_text->box(FL_DOWN_FRAME); |
| 231 |
txt_mars_army_text->color((Fl_Color)FL_BACKGROUND2_COLOR); |
| 232 |
txt_mars_army_text->selection_color((Fl_Color)FL_SELECTION_COLOR); |
| 233 |
txt_mars_army_text->labeltype(FL_NORMAL_LABEL); |
| 234 |
txt_mars_army_text->labelfont(0); |
| 235 |
txt_mars_army_text->labelsize(14); |
| 236 |
txt_mars_army_text->labelcolor((Fl_Color)FL_FOREGROUND_COLOR); |
| 237 |
txt_mars_army_text->align(FL_ALIGN_TOP_LEFT); |
| 238 |
txt_mars_army_text->callback((Fl_Callback*)cb_mars_text); |
| 239 |
txt_mars_army_text->when(FL_WHEN_CHANGED); |
| 240 |
|
| 241 |
tab_mars_army_2->end(); |
| 242 |
|
| 243 |
tab_mars_army_type->end(); |
| 244 |
|
| 245 |
tab_mars_army->end(); |
| 246 |
|
| 247 |
tab_mars_army->hide(); |
| 248 |
}; |
| 249 |
|
| 250 |
//====================================================================== |
| 251 |
//====================================================================== |
| 252 |
Fl_Double_Window *mars_army_list_window = 0; |
| 253 |
Fl_Multi_Browser *brws_mars_army_list = (Fl_Multi_Browser *)0; |
| 254 |
|
| 255 |
const int mars_army_list_widths[] = {80, 170, 30, 0}; |
| 256 |
|
| 257 |
std::string mars_army_list_text; |
| 258 |
bool mars_army_list_ok = false; |
| 259 |
|
| 260 |
void cb_army_list_ok(Fl_Widget *w, void *d) |
| 261 |
{ |
| 262 |
std::string retstr; |
| 263 |
mars_army_list_text.clear(); |
| 264 |
size_t p; |
| 265 |
for (int i = 1; i <= brws_mars_army_list->size(); i++) { |
| 266 |
if (brws_mars_army_list->selected(i)) { |
| 267 |
if (mars_army_list_text.length()) mars_army_list_text += '\n'; |
| 268 |
retstr = brws_mars_army_list->text(i); |
| 269 |
p = retstr.find('\t'); |
| 270 |
mars_army_list_text.append(retstr.substr(0, p)); |
| 271 |
retstr.erase(0,p+1); |
| 272 |
p = retstr.find('\t'); |
| 273 |
retstr.erase(0,p+1); |
| 274 |
mars_army_list_text.append(" ").append(retstr); |
| 275 |
} |
| 276 |
} |
| 277 |
mars_army_list_window->hide(); |
| 278 |
mars_army_list_ok = true; |
| 279 |
} |
| 280 |
|
| 281 |
void cb_army_list_cancel(Fl_Widget *w, void *d) |
| 282 |
{ |
| 283 |
mars_army_list_window->hide(); |
| 284 |
mars_army_list_ok = false; |
| 285 |
} |
| 286 |
|
| 287 |
Fl_Double_Window* mars_army_list_dialog() { |
| 288 |
Fl_Double_Window* w = new Fl_Double_Window(452, 280, _("Roster")); |
| 289 |
brws_mars_army_list = new Fl_Multi_Browser(1,1,450,250,""); |
| 290 |
brws_mars_army_list->column_widths(mars_army_list_widths); |
| 291 |
Fl_Button *cancel = new Fl_Button(280, 252, 80, 24, "cancel"); |
| 292 |
cancel->callback((Fl_Callback*)cb_army_list_cancel); |
| 293 |
Fl_Button *ok = new Fl_Button(370, 252, 80, 24, "select"); |
| 294 |
ok->callback((Fl_Callback*)cb_army_list_ok); |
| 295 |
|
| 296 |
FILE *flist = fopen(progStatus.mars_roster_file.c_str(), "r"); |
| 297 |
char *retstr; |
| 298 |
if (flist) { |
| 299 |
char line[80]; |
| 300 |
retstr = fgets(line, 80, flist); // header |
| 301 |
line[0] = 0; |
| 302 |
if (retstr) { |
| 303 |
while(fgets(line, 80, flist)) { |
| 304 |
while( line[strlen(line)-1] == '\n') line[strlen(line)-1] = 0; |
| 305 |
while( line[strlen(line)-1] == '\r') line[strlen(line)-1] = 0; |
| 306 |
for (size_t i = 0; i < strlen(line); i++) |
| 307 |
if (line[i] == ',') line[i] = '\t'; |
| 308 |
if (strlen(line)) brws_mars_army_list->add(line); |
| 309 |
line[0] = 0; |
| 310 |
} |
| 311 |
} |
| 312 |
fclose(flist); |
| 313 |
} else |
| 314 |
printf("could not open %s\n", progStatus.mars_roster_file.c_str()); |
| 315 |
w->set_modal(); |
| 316 |
w->end(); |
| 317 |
return w; |
| 318 |
} |
| 319 |
|