[1] | 1 | /* X-specific.h */
|
---|
| 2 |
|
---|
| 3 | #ifdef __cplusplus
|
---|
| 4 | extern "C" {
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
[59] | 7 | int ask_me_yes_or_no(char *prompt);
|
---|
| 8 | int ask_me_OK_or_cancel(char *prompt);
|
---|
| 9 | void close_evalcall_form(void);
|
---|
| 10 | void close_progress_form();
|
---|
| 11 | void fatal_error(char *error_string);
|
---|
| 12 | void fatal_error_sub(char *error_string);
|
---|
| 13 | void finish(int signal);
|
---|
| 14 | void mvaddstr_and_log_it(int y, int x, char *output);
|
---|
| 15 | void log_file_end_to_screen(char *filename, char *grep_for_me);
|
---|
| 16 | void log_to_screen(const char *op, ...);
|
---|
| 17 | void open_evalcall_form(char *title);
|
---|
| 18 | void open_progress_form(char *title, char *b1, char *b2, char *b3,
|
---|
| 19 | long max_val);
|
---|
| 20 | void popup_and_OK(char *prompt);
|
---|
| 21 | void popup_and_OK_sub(char *prompt);
|
---|
| 22 | int popup_and_get_string(char *title, char *b, char *output,
|
---|
| 23 | int maxsize);
|
---|
| 24 | int popup_and_get_string_sub(char *title, char *b, char *output,
|
---|
| 25 | int maxsize);
|
---|
| 26 | int popup_with_buttons(char *p, char *button1, char *button2);
|
---|
| 27 | int popup_with_buttons_sub(char *p, char *button1, char *button2);
|
---|
| 28 | void refresh_log_screen();
|
---|
| 29 | void setup_newt_stuff();
|
---|
| 30 | void update_evalcall_form_ratio(int num, int denom);
|
---|
| 31 | void update_evalcall_form(int curr);
|
---|
| 32 | void update_progress_form(char *blurb3);
|
---|
| 33 | void update_progress_form_full(char *blurb1, char *blurb2,
|
---|
| 34 | char *blurb3);
|
---|
[1] | 35 |
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
[59] | 41 | t_bkptype which_backup_media_type(bool);
|
---|
| 42 | int which_compression_level();
|
---|
[1] | 43 |
|
---|
[59] | 44 | void popup_chaneglist_from_file(char *source_file);
|
---|
[1] | 45 |
|
---|
| 46 | #if __cplusplus && WITH_X
|
---|
| 47 |
|
---|
[59] | 48 | extern int g_result_of_last_event;
|
---|
[1] | 49 |
|
---|
[59] | 50 | } /* extern "C" */
|
---|
[1] | 51 | #include <qvaluelist.h>
|
---|
| 52 | #include <qwidget.h>
|
---|
| 53 | #include <qprogressbar.h>
|
---|
| 54 | #include <qlabel.h>
|
---|
| 55 | #include <qstring.h>
|
---|
| 56 | #include <qmultilineedit.h>
|
---|
| 57 | /**
|
---|
| 58 | * A class for XMondo to hold events queued by the backup thread until the event thread is able to handle them.
|
---|
[59] | 59 | */ class XMEventHolder
|
---|
[1] | 60 | {
|
---|
[59] | 61 | public:
|
---|
| 62 | struct Event {
|
---|
| 63 | enum EventType { None, Show, Hide, New, SetProgress, SetTotal,
|
---|
[89] | 64 | SetText, InsLine, PopupWithButtons, InfoMsg, ErrorMsg,
|
---|
| 65 | GetInfo
|
---|
| 66 | } type;
|
---|
[59] | 67 | QWidget *data;
|
---|
[1] | 68 | // union {
|
---|
[59] | 69 | int iParam;
|
---|
| 70 | QString qsParam, title, text, b1, b2;
|
---|
| 71 | char *csParam;
|
---|
| 72 | int len;
|
---|
[1] | 73 | // };
|
---|
[59] | 74 |
|
---|
| 75 | Event():type(None), data(0) {
|
---|
| 76 | } Event(EventType thetype, QWidget * thedata) {
|
---|
| 77 | this->type = thetype;
|
---|
| 78 | this->data = thedata;
|
---|
| 79 | } Event(EventType thetype, QWidget * thedata, int ip) {
|
---|
| 80 | this->type = thetype;
|
---|
| 81 | this->data = thedata;
|
---|
| 82 | this->iParam = ip;
|
---|
| 83 | }
|
---|
| 84 | Event(EventType thetype, QWidget * thedata, QString qsp) {
|
---|
| 85 | this->type = thetype;
|
---|
| 86 | this->data = thedata;
|
---|
| 87 | this->qsParam = qsp;
|
---|
| 88 | }
|
---|
| 89 | Event(EventType thetype, QWidget * thedata, char *csp) {
|
---|
| 90 | this->type = thetype;
|
---|
| 91 | this->data = thedata;
|
---|
| 92 | this->csParam = csp;
|
---|
| 93 | }
|
---|
| 94 | Event(EventType thetype, QWidget * thedata, char *csp, int len) {
|
---|
| 95 | this->type = thetype;
|
---|
| 96 | this->data = thedata;
|
---|
| 97 | this->csParam = csp;
|
---|
| 98 | this->len = len;
|
---|
| 99 | }
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | XMEventHolder() {
|
---|
[1] | 103 | }
|
---|
| 104 |
|
---|
[59] | 105 | /* Backup thread functions */
|
---|
[1] | 106 |
|
---|
[59] | 107 | void event(Event::EventType type, QWidget * data) {
|
---|
| 108 | _events.push_back(Event(type, data));
|
---|
| 109 | }
|
---|
[1] | 110 |
|
---|
[59] | 111 | /**
|
---|
[1] | 112 | * Queue a "show" event for @p data.
|
---|
| 113 | * This is equivalent to a delayed call of @p data->show().
|
---|
| 114 | * @param data The widget to show when the event is processed.
|
---|
| 115 | */
|
---|
[59] | 116 | void show(QWidget * data) {
|
---|
| 117 | _events.push_back(Event(Event::Show, data));
|
---|
| 118 | }
|
---|
[1] | 119 |
|
---|
[59] | 120 | /**
|
---|
[1] | 121 | * Queue a "hide" event for @p data.
|
---|
| 122 | * This is equivalent to a delayed call of @p data->hide().
|
---|
| 123 | * @param data The widget to hide when the event is processed.
|
---|
| 124 | */
|
---|
[59] | 125 | void hide(QWidget * data) {
|
---|
| 126 | _events.push_back(Event(Event::Hide, data));
|
---|
| 127 | }
|
---|
[1] | 128 |
|
---|
[59] | 129 | /**
|
---|
[1] | 130 | * Queue a "setProgress" event for @p data.
|
---|
| 131 | * This is equivalent to a delayed call of <tt>data-\>setProgress(progress)</tt>.
|
---|
| 132 | * @param data The progress bar widget to set the progress of when the event is processed.
|
---|
| 133 | * @param progress The progress amount to set it to.
|
---|
| 134 | */
|
---|
[59] | 135 | void setProgress(QProgressBar * data, int progress) {
|
---|
| 136 | _events.push_back(Event(Event::SetProgress, data, progress));
|
---|
| 137 | }
|
---|
[1] | 138 |
|
---|
[59] | 139 | /**
|
---|
[1] | 140 | * Queue a "setTotalSteps" event for @p data.
|
---|
| 141 | * This is equivalent to a delayed call of <tt>data-\>setTotalSteps(totals)</tt>.
|
---|
| 142 | * @param data The progress bar widget to set the total steps of when the event is processed.
|
---|
| 143 | * @param totals The total number of steps to set.
|
---|
| 144 | */
|
---|
[59] | 145 | void setTotalSteps(QProgressBar * data, int totals) {
|
---|
| 146 | _events.push_back(Event(Event::SetTotal, data, totals));
|
---|
| 147 | }
|
---|
[1] | 148 |
|
---|
[59] | 149 | /**
|
---|
[1] | 150 | * Queue a "setText" event for @p data.
|
---|
| 151 | * This is equivalent to a delayed call of <tt>data-\>setText(text)</tt>.
|
---|
| 152 | * @param data The label widget to set the text of.
|
---|
| 153 | * @param text The text to set it to.
|
---|
| 154 | */
|
---|
[59] | 155 | void setText(QLabel * data, QString text) {
|
---|
| 156 | _events.push_back(Event(Event::SetText, data, text));
|
---|
| 157 | }
|
---|
[1] | 158 |
|
---|
[59] | 159 | /**
|
---|
[1] | 160 | * Queue an "insertLine" event for @p data.
|
---|
| 161 | * This is equivalent to a delayed call of <tt>data->insertLine(line)</tt>.
|
---|
| 162 | * @param data The edit box to add the line to.
|
---|
| 163 | * @param line The line to add.
|
---|
| 164 | */
|
---|
[59] | 165 | void insertLine(QMultiLineEdit * data, QString line) {
|
---|
| 166 | _events.push_back(Event(Event::InsLine, data, line));
|
---|
| 167 | }
|
---|
[1] | 168 |
|
---|
[59] | 169 | /**
|
---|
[1] | 170 | * Queue an alert box with two buttons to be displayed.
|
---|
| 171 | * The button pushed (the return value of popup_with_buttons()) will be stored
|
---|
| 172 | * in @p g_result_of_last_event.
|
---|
| 173 | * @param text The text of the popup dialog box.
|
---|
| 174 | * @param b1 The first button's text.
|
---|
| 175 | * @param b2 The second button's text.
|
---|
| 176 | */
|
---|
[59] | 177 | void popupWithButtons(QString text, QString b1, QString b2) {
|
---|
| 178 | Event e;
|
---|
| 179 | e.type = Event::PopupWithButtons;
|
---|
| 180 | e.text = text;
|
---|
| 181 | e.b1 = b1;
|
---|
| 182 | e.b2 = b2;
|
---|
| 183 | _events.push_back(e);
|
---|
| 184 | }
|
---|
[1] | 185 |
|
---|
[59] | 186 | /**
|
---|
[1] | 187 | * Queue an info box with one OK button to be displayed.
|
---|
| 188 | * @param text The text of the dialog box.
|
---|
| 189 | */
|
---|
[59] | 190 | void infoMsg(QString text) {
|
---|
| 191 | Event e;
|
---|
| 192 | e.type = Event::InfoMsg;
|
---|
| 193 | e.text = text;
|
---|
| 194 | _events.push_back(e);
|
---|
| 195 | }
|
---|
[1] | 196 |
|
---|
[59] | 197 | /**
|
---|
[1] | 198 | * Queue a "fatal error" message.
|
---|
| 199 | * @param text The fatal error.
|
---|
| 200 | */
|
---|
[59] | 201 | void errorMsg(QString text) {
|
---|
| 202 | Event e;
|
---|
| 203 | e.type = Event::ErrorMsg;
|
---|
| 204 | e.text = text;
|
---|
| 205 | _events.push_back(e);
|
---|
| 206 | }
|
---|
[1] | 207 |
|
---|
[59] | 208 | /**
|
---|
[1] | 209 | * Queue a request for some information from the user.
|
---|
| 210 | * If you want to wait until the text is stored, you can set @p g_result_of_last_event
|
---|
| 211 | * to -1 and busy-wait while it's equal to that. If the user pushes OK 1 will be stored,
|
---|
| 212 | * otherwise 0 will be stored.
|
---|
| 213 | * @param title The title of the dialog box.
|
---|
| 214 | * @param text The text of the dialog box.
|
---|
| 215 | * @param out Where to put the user's reply.
|
---|
| 216 | * @param len The size of the buffer allocated for @p out.
|
---|
| 217 | */
|
---|
[59] | 218 | void getInfo(QString title, QString text, char *out, int len) {
|
---|
| 219 | Event e;
|
---|
| 220 | e.type = Event::GetInfo;
|
---|
| 221 | e.title = title;
|
---|
| 222 | e.text = text;
|
---|
| 223 | e.csParam = out;
|
---|
| 224 | e.len = len;
|
---|
| 225 | _events.push_back(e);
|
---|
| 226 | }
|
---|
[1] | 227 |
|
---|
[59] | 228 | /* These are called in the GUI thread */
|
---|
| 229 |
|
---|
| 230 | /**
|
---|
[1] | 231 | * Clear all events stored in the queue without executing them.
|
---|
| 232 | */
|
---|
[59] | 233 | void clear() {
|
---|
| 234 | _events.erase(_events.begin(), _events.end());
|
---|
| 235 | }
|
---|
[1] | 236 |
|
---|
[59] | 237 | /**
|
---|
[1] | 238 | * Process all events stored in the queue and then clear them.
|
---|
| 239 | */
|
---|
[59] | 240 | void send() {
|
---|
| 241 | QProgressBar *pb;
|
---|
| 242 | QLabel *l;
|
---|
| 243 | QMultiLineEdit *mle;
|
---|
| 244 | for (QValueList < Event >::iterator it = _events.begin();
|
---|
| 245 | it != _events.end(); ++it) {
|
---|
| 246 | switch ((*it).type) {
|
---|
| 247 | case Event::Show:
|
---|
| 248 | ((*it).data)->show();
|
---|
| 249 | break;
|
---|
| 250 | case Event::Hide:
|
---|
| 251 | ((*it).data)->hide();
|
---|
| 252 | break;
|
---|
| 253 | case Event::SetProgress:
|
---|
| 254 | if ((pb = dynamic_cast < QProgressBar * >((*it).data))) {
|
---|
| 255 | pb->setProgress((*it).iParam);
|
---|
| 256 | }
|
---|
| 257 | break;
|
---|
| 258 | case Event::SetTotal:
|
---|
| 259 | if ((pb = dynamic_cast < QProgressBar * >((*it).data))) {
|
---|
| 260 | pb->setTotalSteps((*it).iParam);
|
---|
| 261 | }
|
---|
| 262 | break;
|
---|
| 263 | case Event::SetText:
|
---|
| 264 | if ((l = dynamic_cast < QLabel * >((*it).data))) {
|
---|
| 265 | l->setText((*it).qsParam);
|
---|
| 266 | }
|
---|
| 267 | break;
|
---|
| 268 | case Event::InsLine:
|
---|
| 269 | if ((mle = dynamic_cast < QMultiLineEdit * >((*it).data))) {
|
---|
| 270 | mle->insertLine((*it).qsParam);
|
---|
| 271 | }
|
---|
| 272 | break;
|
---|
| 273 | case Event::PopupWithButtons:
|
---|
| 274 | g_result_of_last_event =
|
---|
| 275 | popup_with_buttons_sub(const_cast <
|
---|
| 276 | char *>((*it).text.ascii()),
|
---|
| 277 | const_cast <
|
---|
| 278 | char *>((*it).b1.ascii()),
|
---|
| 279 | const_cast <
|
---|
| 280 | char *>((*it).b2.ascii()));
|
---|
| 281 | break;
|
---|
| 282 | case Event::InfoMsg:
|
---|
| 283 | popup_and_OK_sub(const_cast < char *>((*it).text.ascii()));
|
---|
| 284 | g_result_of_last_event = 0;
|
---|
| 285 | break;
|
---|
| 286 | case Event::ErrorMsg:
|
---|
| 287 | fatal_error_sub(const_cast < char *>((*it).text.ascii()));
|
---|
| 288 | break;
|
---|
| 289 | case Event::GetInfo:
|
---|
| 290 | g_result_of_last_event =
|
---|
| 291 | popup_and_get_string_sub(const_cast <
|
---|
| 292 | char *>((*it).title.ascii()),
|
---|
| 293 | const_cast <
|
---|
| 294 | char *>((*it).text.ascii()),
|
---|
| 295 | (*it).csParam, (*it).len);
|
---|
| 296 | break;
|
---|
| 297 | default:
|
---|
| 298 | qDebug("unknown event\n");
|
---|
| 299 | }
|
---|
[1] | 300 | }
|
---|
[59] | 301 | this->clear();
|
---|
[1] | 302 | }
|
---|
| 303 |
|
---|
[59] | 304 | /* Undocumented */
|
---|
| 305 | QValueList < Event > events() {
|
---|
| 306 | return _events;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | protected:
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | QValueList < Event > _events;
|
---|
[1] | 313 | };
|
---|
[59] | 314 |
|
---|
| 315 | #endif /* __cplusplus */
|
---|