source: MondoRescue/trunk/mondo/mondo/common/X-specific.h@ 89

Last change on this file since 89 was 89, checked in by bcornec, 18 years ago

merge r87:88 of the 2.04_berlios branch
indent some files

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