summaryrefslogtreecommitdiff
path: root/src/ui.h
blob: cea44f5fc152d7cf23c4d692d38feb70b6e4e23b (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// ui.h    -*-c++-*-
//
//  Copyright 2000,2001 Daniel Burrows
//

#ifndef UI_H
#define UI_H

#include <apt-pkg/pkgcache.h>

#include <sigc++/signal.h>

#include <string>

#include <cwidget/generic/util/bool_accumulate.h>
#include <cwidget/generic/util/slotarg.h>

#include <cwidget/widgets/editline.h> // Included for history support.

/** \brief Global UI definitions and routines
 *
 * 
 *  Global UI definitions and routines.  A lot of things here just provide a
 *  single point for common actions so those actions can be customized later.
 *  (eg, the progress-bar can appear in various forms)
 * 
 *  \file ui.h
 */

class OpProgress;

class download_signal_log;
namespace cwidget
{
  class fragment;
}

class download_list;
typedef cwidget::util::ref_ptr<download_list> download_list_ref;

class progress;
typedef cwidget::util::ref_ptr<progress> progress_ref;
/******************************************************************************
 * Global signals:
 *****************************************************************************/

// File menu
extern sigc::signal0<void> file_quit;

/* A signal that widgets watching package states should update themselves.
 *
 * This should be triggered at the end of any keystroke (or mouse-stroke)
 * handler that alters the package states.  At a minimum, it will
 * call vscreen_update().
 *
 * \todo this seems to be at least partly redundant with the similar
 * signal on the apt cache file.  Should one of them be removed or
 * scaled back?
 */
extern sigc::signal0<void> package_states_changed;

/** Tests whether Undo -> Undo is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> undo_undo_enabled;

/** Emitted for Undo -> Undo. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> undo_undo;

/** Used to determine whether a target is available for the "package actions".
 */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_menu_enabled;

/** Emitted for Package -> Install. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_install;

/** Emitted for Package -> Reinstall. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_reinstall;

/** Emitted for Package -> Remove. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_remove;

/** Emitted for Package -> Purge. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_purge;

/** Emitted for Package -> Hold. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_hold;

/** Emitted for Package -> Keep. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_keep;

/** Emitted for Package -> Mark Auto */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_mark_auto;

/** Emitted for Package -> Mark Manual */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_unmark_auto;

/** Tests whether Package -> Forbid Version is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_forbid_enabled;

/** Emitted for Package -> Forbid. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_forbid;

/** Tests whether Package -> Package Information is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_information_enabled;

/** Emitted for Package -> Package Information. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_information;

/** Tests whether Package -> Cycle Information is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_cycle_information_enabled;

/** Emitted for Package -> Cycle Information. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_cycle_information;

/** Tests whether Package -> Changelog is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_changelog_enabled;

/** Emitted for Package -> Changelog. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> package_changelog;


/** Emitted for Resolver -> Toggle Rejected. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_toggle_rejected;

/** Tests whether Resolver -> Reject/Unreject Action is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_toggle_rejected_enabled;

/** Emitted for Resolver -> Toggle Approved. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_toggle_approved;

/** Tests whether Resolver -> Toggle Approved is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_toggle_approved_enabled;
/** Emitted for Resolver -> View Target */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_view_target;

/** Tests whether Resolver -> View Target is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> resolver_view_target_enabled;


/** Tests whether Search -> Find is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_search_enabled;

/** Tests whether Search -> Find Backwards is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_search_back_enabled;

/** Tests whether Search -> Find Again is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_research_enabled;

/** Tests whether Search -> Find Again Reverse is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_repeat_search_back_enabled;

/** Tests whether Search -> Limit is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_limit_enabled;

/** Tests whether Search -> Cancel Limit is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_cancel_limit_enabled;

/** Tests whether Searc -> Find Broken is enabled. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_broken_enabled;

/** Emitted for Search -> Find. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_search;

/** Emitted for Search -> Find Backwards. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_search_back;

/** Emitted for Search -> Find Again. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_research;

/** Emitted for Search -> Find Again Reverse. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_repeat_search_back;

/** Emitted for Search -> Limit. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_limit;

/** Emitted for Search -> Cancel Limit. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_cancel_limit;

/** Emitted for Search -> Find Broken. */
extern sigc::signal0<bool, cwidget::util::accumulate_or> find_broken;

/*****************************************************************************/

/** \brief Emitted when an install completes.  The parameter is \b
 *  true if the install succeeded and \b false otherwise.
 */
extern sigc::signal1<void, bool> install_finished;

/** \brief Emitted when a list update completes.  The parameter is \b
 *  true if the update succeeded and \b false otherwise.
 */
extern sigc::signal1<void, bool> update_finished;

void ui_init();
void ui_main();

// Displays a "popup" widget.  If the second argument is false, show_all
// will not be called on the widget.
void popup_widget(const cwidget::widgets::widget_ref &w, bool do_show_all=true);

// Displays a widget on the "main" program level, inserting the given string
// into the menu listing available "main" screens to reference it.
//
// The "insert" form adds the new widget directly after the currently visible
// widget.

/** Add a new widget to the main interaction area.
 *
 *  \param w the widget to add
 *  \param menuref the text to add in the corresponding menu
 *  \param menudesc the description of the generated menu item
 *  \param tablabel the label of the corresponding tab
 */
void add_main_widget(const cwidget::widgets::widget_ref &w,
		     const std::string &menuref,
		     const std::string &menudesc,
		     const std::string &tablabel);
void insert_main_widget(const cwidget::widgets::widget_ref &w,
			const std::string &menuref,
			const std::string &menudesc,
			const std::string &tablabel);

/** Returns the currently active main widget. */
cwidget::widgets::widget_ref active_main_widget();

// Generates a progress bar.
progress_ref gen_progress_bar();

// Generates an appropriate box to wrap text.
cwidget::fragment *wrapbox(cwidget::fragment *contents);

/** Generates a download progress object based on the user's current
 *  settings.
 *
 *  \param force_noninvasive if \b true, the generated UI object will
 *            always be "noninvasive" (typically a bar at the bottom of
 *            the screen).
 *  \param list_update       if \b true, this bar is for a list update
 *                           (meaning that we have to deal with apt's
 *                           utterly useless progress indication in this
 *                           case)
 *  \param title             if a new view is generated, this string is
 *                           used as its title; it will be cwidget::util::transcoded.
 *  \param longtitle         if a new view is generated, this string is
 *                           used as its long title; it will be cwidget::util::transcoded.
 *
 *  \return the new download manager and the download status widget.
 */
std::pair<download_signal_log *,
	  download_list_ref>
gen_download_progress(bool force_noninvasive,
		      bool list_update,
		      const std::string &title,
		      const std::string &longtitle,
		      const std::string &tablabel);

// Asks the user for simple input (the question will appear in a "minibuffer"
// or in a dialog according to preferences)

void prompt_string(const std::string &prompt,
		   const std::string &text,
		   cwidget::util::slotarg<sigc::slot1<void, std::wstring> > slot,
		   cwidget::util::slotarg<sigc::slot0<void> > cancel_slot,
		   cwidget::util::slotarg<sigc::slot1<void, std::wstring> > changed_slot,
		   cwidget::widgets::editline::history_list *history);

void prompt_string(const std::wstring &prompt,
		   const std::wstring &text,
		   cwidget::util::slotarg<sigc::slot1<void, std::wstring> > slot,
		   cwidget::util::slotarg<sigc::slot0<void> > cancel_slot,
		   cwidget::util::slotarg<sigc::slot1<void, std::wstring> > changed_slot,
		   cwidget::widgets::editline::history_list *history);

void prompt_yesno(const std::string &prompt,
		  bool deflt,
		  cwidget::util::slot0arg yesslot,
		  cwidget::util::slot0arg noslot);

/** Display a popup dialog for a yes-no prompt.  Meant for prompts
 *  with large quantities of text.
 */
void prompt_yesno_popup(cwidget::fragment *f,
			bool deflt,
			cwidget::util::slot0arg yesslot,
			cwidget::util::slot0arg noslot);

/** Display the given message, either in a popup dialog box or as a
 *  "transient" message at the bottom of the screen.  The message
 *  should be expected to be relatively short (ie, short enough to not
 *  need a scrollbar on a 'reasonable' terminal).  For convenience, a
 *  wrapbox is implicitly placed around the message.
 *
 *  \param msg the message to display
 *  \param okslot an optional slot to be called when the message is dismissed
 */
void show_message(cwidget::fragment *msg,
		  cwidget::util::slot0arg okslot,
		  const cwidget::style &st = cwidget::style_attrs_flip(A_REVERSE));

/** Display the given message, either in a popup dialog box or as a
 *  "transient" message at the bottom of the screen.  The message
 *  should be expected to be relatively short (ie, short enough to not
 *  need a scrollbar on a 'reasonable' terminal); it will be
 *  paragraph-wrapped as necessary.
 *
 *  \param msg the message to display
 *  \param okslot an optional slot to be called when the message is dismissed
 */
void show_message(const std::wstring &msg,
		  cwidget::util::slot0arg okslot=NULL,
		  const cwidget::style &st = cwidget::style_attrs_flip(A_REVERSE));

/** Display the given message, either in a popup dialog box or as a
 *  "transient" message at the bottom of the screen.  The message
 *  should be expected to be relatively short (ie, short enough to not
 *  need a scrollbar on a 'reasonable' terminal); it will be
 *  paragraph-wrapped as necessary.
 *
 *  \param msg the message to display; will be cwidget::util::transcoded
 *  \param okslot an optional slot to be called when the message is dismissed
 */
void show_message(const std::string &msg,
		  cwidget::util::slot0arg okslot=NULL,
		  const cwidget::style &st = cwidget::style_attrs_flip(A_REVERSE));

/** Call this when a download starts; it sets the flag associated with
 *  the existence of a download, destroys the active preview (if any),
 *  and maeks the apt cache read-only.
 *
 *  \param hide_preview if \b true, the preview screen will be hidden
 *  prior to starting the download.
 */
void ui_start_download(bool hide_preview = true);

/** Call this when a download finishes; it clears the flag associated
 *  with the existence of a download and puts the cache back into
 *  read-write mode.
 */
void ui_stop_download();

// Can be used to manually pop up an error dialog, if necessary.
void check_apt_errors();

/** Display the solution editor screen if it isn't visible. */
void do_examine_solution();

void do_new_package_view(OpProgress &progress);
// Displays a new package-view.

void do_new_flat_view(OpProgress &progress);
// Displays a new flat-view.

void do_package_run_or_show_preview();
// Shows a preview if previews are enabled (and why would you disable them?),
// otherwise does the same thing as install_or_remove_packages.

void install_or_remove_packages();
// Installs or removes packages.  (the thing that happens after you press
// "g" twice)

void do_update_lists();
// Updates the package lists.

/** \brief Delete obsolete downloaded files. */
void do_autoclean();

/** \brief Clean the package cache. */
void do_clean();

void do_forget_new();
// Forgets which packages are "new".

/** Advances to the next solution, if one exists. */
void do_next_solution();

/** Returns to the previous solution, if one exists. */
void do_previous_solution();

/** Applies the current solution, if it exists. */
void do_apply_solution();

// These generate particular screens of the UI:

// Info screen
cwidget::widgets::widget_ref make_info_screen(const pkgCache::PkgIterator &pkg,
			       const pkgCache::VerIterator &ver);
void show_info_screen(const pkgCache::PkgIterator &pkg,
		      const pkgCache::VerIterator &ver);
// Dependency screen
cwidget::widgets::widget_ref make_dep_screen(const pkgCache::PkgIterator &pkg,
			      const pkgCache::VerIterator &ver,
			      bool reverse=false);
void show_dep_screen(const pkgCache::PkgIterator &pkg,
		     const pkgCache::VerIterator &ver,
		     bool reverse=false);
// List of versions
cwidget::widgets::widget_ref make_ver_screen(const pkgCache::PkgIterator &pkg);
void show_ver_screen(const pkgCache::PkgIterator &pkg);

// Various defaults:
extern const char *default_pkgstatusdisplay;
extern const char *default_pkgheaderdisplay;
extern const char *default_grpstr;
extern const char *confirm_delete_essential_str;

#endif