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