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
|
// $Id: xxRareModeSavePrompts.cc,v 1.2 2003/01/17 17:31:00 flaterco Exp $
/* xxRareModeSavePrompts Get a file name and two timestamps from the user.
Copyright (C) 1998 David Flater.
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 received 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.
*/
#include "xtide.hh"
void
xxRareModeSavePromptsCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxRareModeSavePrompts *e = (xxRareModeSavePrompts *)client_data;
Dstr filename (e->filenamediag->val());
if (filename.strchr ('\n') != -1 ||
filename.strchr ('\r') != -1 ||
filename.strchr (' ') != -1 ||
filename[0] == '-') {
Dstr details ("Well, it's not that I can't do it, it's that you probably\n\
don't want me to. The filename that you entered is '");
details += filename;
details += "'.\n";
if (filename[0] == '-')
details += "Filenames that begin with a dash are considered harmful.";
else
details += "Whitespace in filenames is considered harmful.";
barf (CANT_OPEN_FILE, details, 0);
} else {
Dstr start_tm_string, end_tm_string;
e->btimediag->val (start_tm_string);
Timestamp start_tm (start_tm_string, e->timezone, e->xtidecontext->settings);
e->etimediag->val (end_tm_string);
Timestamp end_tm (end_tm_string, e->timezone, e->xtidecontext->settings);
if (start_tm.isNull()) {
Dstr details ("Bad start time. The offending input was ");
details += start_tm_string;
details += "\nin the time zone ";
if (e->xtidecontext->settings->z == "n")
details += e->timezone;
else
details += "UTC0";
barf (MKTIME_FAILED, details, 0);
} else if (end_tm.isNull()) {
Dstr details ("Bad end time. The offending input was ");
details += end_tm_string;
details += "\nin the time zone ";
if (e->xtidecontext->settings->z == "n")
details += e->timezone;
else
details += "UTC0";
barf (MKTIME_FAILED, details, 0);
} else {
if (start_tm <= end_tm)
(*(e->callback)) (filename, start_tm, end_tm, e->ptr);
else
(*(e->callback)) (filename, end_tm, start_tm, e->ptr);
}
}
delete e;
}
static void
xxRareModeSavePromptsCancelCallback (Widget w, XtPointer client_data, XtPointer
call_data) {
xxRareModeSavePrompts *e = (xxRareModeSavePrompts *)client_data;
e->dismiss();
}
void
xxRareModeSavePrompts::dismiss() {
delete this;
}
xxRareModeSavePrompts::~xxRareModeSavePrompts() {
mypopup->unrealize();
delete filenamediag;
delete helplabel1;
delete gobutton;
delete cancelbutton;
delete btimediag;
delete etimediag;
delete spacelabel1;
}
xxRareModeSavePrompts::xxRareModeSavePrompts (xxTideContext *in_xtidecontext,
xxContext *context, void (*in_callback) (Dstr &filename, Timestamp start_tm,
Timestamp end_tm, void *in_ptr), void *in_ptr, char *initname,
Timestamp in_start_tm, Timestamp in_end_tm, const Dstr &in_timezone):
xxWindow (in_xtidecontext, context, 1, XtGrabExclusive) {
ptr = in_ptr;
callback = in_callback;
timezone = in_timezone;
mypopup->setTitle ("Save prompts");
Arg labelargs[3] = {
{XtNbackground, (XtArgVal)mypopup->pixels[Colors::background]},
{XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]},
{XtNborderWidth, (XtArgVal)0}
};
Arg buttonargs[4] = {
{XtNvisual, (XtArgVal)mypopup->visual},
{XtNcolormap, (XtArgVal)mypopup->colormap},
{XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
{XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]}
};
{
Dstr helptext ("\
Please enter the name of the file in which to save output.\n\
You can also change the begin and end times for the listing.\n\
The active time zone is ");
if (in_xtidecontext->settings->z == "n")
helptext += timezone;
else
helptext += "UTC0";
helptext += ".";
Widget labelwidget = XtCreateManagedWidget (helptext.aschar(),
labelWidgetClass, container->manager, labelargs, 3);
helplabel1 = new xxContext (mypopup, labelwidget);
}
filenamediag = new xxHorizDialog (container, "Filename:", initname);
btimediag = new xxTimestampDialog (xtidecontext, container, "Start at:",
in_start_tm, timezone);
etimediag = new xxTimestampDialog (xtidecontext, container, "End at:",
in_end_tm, timezone);
{
Widget labelwidget = XtCreateManagedWidget (" ", labelWidgetClass,
container->manager, labelargs, 3);
spacelabel1 = new xxContext (mypopup, labelwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("Go", commandWidgetClass,
container->manager, buttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxRareModeSavePromptsCallback,
(XtPointer)this);
gobutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("Cancel", commandWidgetClass,
container->manager, buttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxRareModeSavePromptsCancelCallback,
(XtPointer)this);
cancelbutton = new xxContext (mypopup, buttonwidget);
}
mypopup->realize();
}
|