1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
/*
* twlog: A basic ham loging program using Motif
* Copyright (C) 1997 Ted Williams WA0EIR (ted@bluestone.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have recieved a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge. MA 02139,
* USA. See the COPYING file in this directory.
*
* Versions: 1.2 - Nov 1998
*/
/*
* TWLOG CALLBACKS FUNCTIONS
*/
#include "twlog.h"
#define APPEND 0
#define EDIT 1
#define PRINT 2
#define NEW 3
#define QRT 4
#define ABOUT 0
#define HELP 1
/*
* dateCB Callback
* Puts the date into the date text field and forces
* focus to the startPB.
*/
void dateCB (Widget w, XtPointer cdata, XtPointer cbs)
{
Cdata *wids = (Cdata *) cdata;
time_t current;
struct tm *timestruct = NULL;
char date[20];
time(¤t);
timestruct = localtime (¤t);
strftime (date, sizeof(date), "%d %b %Y", timestruct);
XtVaSetValues (wids->TF1,
XmNvalue, date,
NULL);
XmProcessTraversal (wids->next, XmTRAVERSE_CURRENT);
}
/*
* startCB Callback
* Puts the date and time into the date and start time text fields
* and forces focus to the Call text field.
*/
void startCB (Widget w, XtPointer cdata, XtPointer cbs)
{
Cdata *wids = (Cdata *)cdata;
time_t current;
struct tm *timestruct = NULL;
char date[20];
char stime[20];
time(¤t);
timestruct = localtime (¤t);
strftime (date, sizeof(date), "%d %b %Y", timestruct);
strftime (stime, sizeof(stime), "%H%M %Z", timestruct);
XtVaSetValues (wids->TF1,
XmNvalue, date,
NULL);
XtVaSetValues (wids->TF2,
XmNvalue, stime,
NULL);
XmProcessTraversal (wids->next, XmTRAVERSE_CURRENT);
}
/*
* callsignCB Callback
* modify/verify callback changes all key strokes in CallTF to upper case
* activate callback - Moves focus to next tab group, the Band Menu.
*/
void callsignCB (Widget w, XtPointer cdata, XtPointer cbstruct)
{
int i;
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *) cbstruct;
switch (cbs->reason)
{
case XmCR_MODIFYING_TEXT_VALUE:
for (i = 0; i < cbs->text->length; i++) /* all to upper case */
{
cbs->text->ptr[i] = toupper (cbs->text->ptr[i]);
}
break;
case XmCR_ACTIVATE:
XmProcessTraversal (w, XmTRAVERSE_NEXT_TAB_GROUP);
break;
}
}
/*
* endCB Callback
* Puts the time into the End Time text field
* and moves the focus to the Date Pushbutton.
*/
void endCB (Widget w, XtPointer cdata, XtPointer cbs)
{
Cdata *wids = (Cdata *) cdata;
time_t current;
struct tm *timestruct = NULL;
char stime[20];
time(¤t);
timestruct = localtime (¤t);
strftime (stime, sizeof(stime), "%H%M %Z", timestruct);
XtVaSetValues (wids->TF1,
XmNvalue, stime,
NULL);
XmProcessTraversal (wids->next, XmTRAVERSE_CURRENT);
}
/*
* focusCB Callback
* This callback is called for any lose or gain of focus in any
* text field. The I beam cursor will only be visible if the
* textfield has focus.
*/
void focusCB (Widget w, XtPointer cdata, XtPointer cbs)
{
XmAnyCallbackStruct *cbstruct = (XmAnyCallbackStruct *) cbs;
switch (cbstruct->reason)
{
case XmCR_FOCUS:
XtVaSetValues (w,
XmNcursorPositionVisible, TRUE,
NULL);
break;
case XmCR_LOSING_FOCUS:
XtVaSetValues (w,
XmNcursorPositionVisible, FALSE,
NULL);
break;
default:
printf ("Oops\n");
break;
}
}
/*
* fileCB Callback
* All callbacks on the file pulldown come here. The button number
* is checked to see which option was selected.
*/
void fileCB (Widget w, XtPointer cdata, XtPointer cbs)
{
int btn = (int) cdata;
char tail[MAXNAME];
char *newname;
char *lprstr;
time_t current;
struct tm *timestruct = NULL;
Widget *col_2_wids;
switch (btn)
{
case APPEND:
XtVaGetValues (XtParent(w),
XmNuserData, &col_2_wids,
NULL);
appendlog (logpath, col_2_wids);
clearform (col_2_wids);
break;
case EDIT:
popupEdit (logpath);
break;
case PRINT:
if ((lprstr = malloc (sizeof (PRINT_CMD)
+ sizeof(logpath)
+ MAXNAME)) == NULL)
{
perror ("fileCB - print malloc failed");
exit (1);
}
strcpy (lprstr, PRINT_CMD);
strcat (lprstr, logpath);
system (lprstr);
free (lprstr);
break;
case NEW:
time (¤t);
timestruct = localtime (¤t);
strftime (tail, MAXNAME, "/log.%Y.%j.%H%M%S", timestruct);
if ((newname = malloc (strlen (dirpath) + MAXNAME)) == NULL)
{
perror ("newname malloc failed:");
exit (1);
}
strcpy (newname, dirpath);
strcat (newname, tail);
if (rename (logpath, newname) == 0)
creat (logpath, 0644);
else
{
perror ("Rename failed");
exit (1);
}
free (newname);
break;
case QRT:
exit (0);
}
}
/*
* appendlog Function
* Collects the data from the righthand column and writes it
* to the end of the log file. Two lines are written. The
* first line has all the data except for Notes, which are on
* the second line.
*/
#define MAXBOX 20
#define MAXNOTE 80
void appendlog (char logpath[], Widget *col_2_wids)
{
int i;
FILE *fp;
Widget btnwid;
XmString label_xs;
char *data;
char abox[9][MAXBOX+1];
char anote[MAXNOTE+1];
for (i=0; i<9; i++)
{
if (i<3 || i>5)
{
XtVaGetValues (col_2_wids[i], /* get text from a textfield */
XmNvalue, &data,
NULL);
strncpy (abox[i], data, MAXBOX);
}
else /* or get XmString from a menu */
{
XtVaGetValues (col_2_wids[i], /* get the menu button wid, then */
XmNmenuHistory, &btnwid,
NULL);
XtVaGetValues (btnwid, /* get label for selected button */
XmNlabelString, &label_xs,
NULL);
XmStringGetLtoR (label_xs, XmFONTLIST_DEFAULT_TAG, &data);
strncpy (abox[i], data, MAXBOX);
}
}
XtVaGetValues (col_2_wids[i], /* get the Note field */
XmNvalue, &data,
NULL);
strncpy (anote, data, MAXNOTE);
if ((fp = fopen (logpath, "a")) == NULL) /* open logfile */
{
perror ("appendlog - open failed");
exit (1);
}
fprintf (fp, "%-11s %-10s %-10s %-6s %-6s %-6s %-6s %-6s %-10s\n%-80s\n\n",
abox[0], abox[1], abox[2], abox[3], abox[4],
abox[5], abox[6], abox[7], abox[8], anote);
fclose (fp); /* and close logfile */
}
/*
* clearform Function
* Clears all text field widgets
*/
void clearform (Widget *col_2_wids)
{
int i;
for (i=0; i<10; i++)
{
if (i<3 || i >5)
XtVaSetValues (col_2_wids[i],
XmNvalue, "",
NULL);
}
}
/*
* helpCB Callback
* All callbacks on the help pulldown come here. The button number
* is checked to see which option was selected.
*/
void helpCB (Widget w, XtPointer cdata, XtPointer cbs)
{
int btn = (int) cdata;
switch (btn)
{
case ABOUT:
aboutDiag ();
break;
case HELP:
popupHelp (helppath);
break;
}
}
/*
* CRkey Function
* This action forces focus to the next widget when the Enter Key
* is pressed in any of the Option Menus
*/
void CRkey (Widget w, XEvent *event, String args[], Cardinal *nargs)
{
XmProcessTraversal (w, XmTRAVERSE_NEXT_TAB_GROUP);
}
|