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