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