summaryrefslogtreecommitdiff
path: root/src/gtk/gui.h
blob: 450d752611afe814042e3d5878830946fcf36291 (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
// -*-c++-*-

// gui.h
//
//  Copyright 1999-2009 Daniel Burrows
//  Copyright 2008-2009 Obey Arthur Liu
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; see the file COPYING.  If not, write to
//  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
//  Boston, MA 02111-1307, USA.

#ifndef GUI_H_
#define GUI_H_

#undef OK
#include <gtkmm.h>
#include <libglademm/xml.h>

#include <set>

#include <sigc++/slot.h>

#include <boost/shared_ptr.hpp>

#include <apt-pkg/pkgcache.h>

#include <generic/util/safe_slot.h>

#include <gtk/errortab.h>
#include <gtk/notify.h>

#include "constants.h"

class download_manager;

namespace gui
{
  // Local forward declarations:
  class AptitudeWindow;
  class TabsManager;
  class Tab;

  //This is a list of global and unique base widgets and other related stuff
  extern AptitudeWindow * pMainWindow;
  extern Glib::RefPtr<Gnome::Glade::Xml> refXml;
  extern std::string glade_main_file;
  extern bool want_to_quit;

  /** \brief Used to control how the main download progress bar is
   *  displayed.
   *
   *  This lets us adapt to the vagaries of the various download
   *  processes.
   */
  enum download_progress_mode
    {
      /** \brief Only pulse the download bar. */
      download_progress_pulse,

      /** \brief Display the progress based only on the number of
       *  items downloaded.
       */
      download_progress_item_count,

      /** \brief Display progress based on the number of bytes
       *  downloaded.
       */
      download_progress_size
    };

  /** \brief Dispatch the given thunk to the main loop. */
  void post_event(const safe_slot0<void> &thunk);

  /** \brief Wrap the given thunk in a safe_slot and post it to the
   *  main loop.
   */
  void post_thunk(const sigc::slot<void> &thunk);

  void gtk_update();

  /** \brief Display a "Not implemented, yet." message. */
  void do_notimplemented_message();

  /** \brief Display a custom "Not implemented, yet." message. */
  void do_notimplemented_message_custom(Glib::ustring msg);

  /** \brief Invoke tab_add on pMainWindow. */
  void tab_add(Tab *tab);

  /** \brief Invoke tab_del on pMainWindow. */
  void tab_del(Tab *tab);

  /** \brief Insert the tags of the given package into a TextBuffer.
   *
   *  Each tag will be a link that pops up a new packages view.
   *
   *  \param buffer The buffer into which the tags should be inserted.
   *  \param pkg    The package whose tags should be displayed.
   *  \param headerTag  A text-tag used to display the header that
   *                    leads off the tag list.
   *
   *  \return an iterator pointing to the end of the newly inserted text.
   */
  Gtk::TextBuffer::iterator add_debtags(const Glib::RefPtr<Gtk::TextBuffer> &buffer,
					Gtk::TextBuffer::iterator where,
					const pkgCache::PkgIterator &pkg,
					const Glib::RefPtr<Gtk::TextBuffer::Tag> &headerTag);

  /**
   * This is the main Aptitude custom window widget.
   */
  class AptitudeWindow : public Gtk::Window
  {
    private:
      Gtk::ToolButton * pToolButtonDashboard;
      Gtk::ToolButton * pToolButtonUpdate;
      Gtk::ToolButton * pToolButtonPackages;
      Gtk::ToolButton * pToolButtonPreview;
      Gtk::ToolButton * pToolButtonResolver;
      Gtk::ToolButton * pToolButtonInstallRemove;

      Gtk::ImageMenuItem * pMenuFilePackageRun;
      Gtk::ImageMenuItem * pMenuFileUpdateLists;
      Gtk::ImageMenuItem * pMenuFileMarkUpgradable;
      Gtk::ImageMenuItem * pMenuFileForgetNew;
      Gtk::ImageMenuItem * pMenuFileKeepAll;
      Gtk::ImageMenuItem * pMenuFileClean;
      Gtk::ImageMenuItem * pMenuFileAutoclean;
      Gtk::ImageMenuItem * pMenuFileReloadCache;
      Gtk::ImageMenuItem * pMenuFileSuToRoot;
      Gtk::ImageMenuItem * pMenuFileExit;

      Gtk::ImageMenuItem * pMenuTabPrevious;
      Gtk::ImageMenuItem * pMenuTabNext;
      Gtk::ImageMenuItem * pMenuTabClose;

      Gtk::Menu * pMenuPackage;
      Gtk::MenuItem *menu_undo_undo;
      Gtk::MenuItem *menu_view_edit_columns;

      Gtk::ProgressBar * pProgressBar;
      Gtk::Statusbar * pStatusBar;
      NotifyView * pNotifyView;
      TabsManager * pNotebook;

      // The "global" singleton for storing apt errors.
      ErrorStore errorStore;

      // If this is not NULL, it points at the currently active
      // errors-view.
      ErrorTab *activeErrorTab;

      // Nulls out the error tab when it's closed.
      void apt_error_tab_closed();

      void show_dependency_chains_tab();

      // Register the resolver-sensitivity callback.
      void update_resolver_sensitivity_callback();
      // Update the resolver sensistivity.
      void update_resolver_sensitivity();

      /** \brief Update the Package menu by querying the currently
       *  visible tab.
       *
       *  \param notebook  The notebook whose tabs should be examined.
       *
       *  \param packageMenu  The menu to update.
       *
       *  The parameters are passed mostly to ensure that the signal
       *  auto-disconnects when the menu and/or notebook are
       *  destroyed.
       */
      static void update_package_menu(TabsManager &notebook, Gtk::Menu &package_menu);

      /** \brief Update whether the Undo menu item is sensitive. */
      static void update_undo_sensitivity(TabsManager &notebook, Gtk::Widget &menu_undo_undo);

      /** \brief Update whether the "Edit Columns..." menu item is sensitive. */
      static void update_edit_columns_sensitivity(TabsManager &notebook, Gtk::Widget &menu_view_edit_columns);

    public:
      /**
       * Glade::Xml derived widget constructor.
       */
      AptitudeWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)/* : Gtk::Window(cobject)*/;

    /** \brief Show the apt errors tab.
     *
     *  \todo This manually handles finding the active tab if there is
     *  one; perhaps this logic should be part of the tab manager?
     */
    void show_apt_errors();

    Gtk::Menu * get_menu_package() const { return pMenuPackage; }
    Gtk::ProgressBar * get_progress_bar() const { return pProgressBar; }
    Gtk::Statusbar * get_status_bar() const { return pStatusBar; }
    NotifyView *get_notifyview() const { return pNotifyView; }
    TabsManager * get_notebook() const { return pNotebook; }

    /** \brief Add a tab to the main notebook of this window. */
    void tab_add(Tab *tab);

    /** \brief Remove a tab from the main notebook of this window. */
    void tab_del(Tab *tab);

    /** \brief Undo the last action in the visible tab, as if Undo had
     *  been triggered from the Edit menu.
     */
    void do_undo();

    /** \brief Edit the visible columns of the main package list in
     *  the current tab, as if "Edit Columns..." had been triggered
     *  from the View menu.
     */
    void do_edit_columns();

    /** \brief Open a resolver tab, as if it had been triggered from the menu.
     */
    void do_resolver();

    /** \brief Open a dashboard tab, as if it had been triggered by
     *  pushing the toolbar button.
     */
    void do_dashboard();

    /** \brief Open a preview tab, as if it had been triggered from the menu. */
    void do_preview();

    /** \brief Open a list of currently broken packages. */
    void do_show_broken();

    /** \brief Open a new Packages tab to search for the given pattern. */
    void add_packages_tab(const std::string &pattern);
  };


  /** \brief Start a new download, creating the appropriate GUI
   *  elements.
   *
   *  \param manager The download manager defining the download
   *                 process to run.
   *
   *  \param title   A string describing the download.
   *
   *  \param image   An image to show in the download notification,
   *                 or NULL for none.
   *
   *  \param download_progress  How to display the download progress.
   *
   *  \param view    The notification view in which to place the
   *                 notification corresponding to this download.
   *
   *  \param download_starts_slot   A slot to be invoked in the
   *                                foreground thread when the
   *                                download is about to start.
   *
   *  \param download_stops_slot    A slot to be invoked in the
   *                                background thread after the
   *                                download and post-download
   *                                actions complete.
   */
  void start_download(const boost::shared_ptr<download_manager> &manager,
		      const std::string &title,
		      Gtk::Widget *image,
		      download_progress_mode download_progress,
		      NotifyView *view,
		      const sigc::slot0<void> &download_starts_slot = sigc::slot0<void>(),
		      const sigc::slot0<void> &download_stops_slot = sigc::slot0<void>());


  /** \brief Add package actions to a menu.
   *
   *  \param actions    The actions to include in the menu.
   *  \param callback   The callback to invoke when the actions are selected.
   *  \param menu       The menu in which to place the actions.
   *
   *  The actions are added to the end of the menu in a standard
   *  order.
   */
  void fill_package_menu(const std::set<PackagesAction> &actions,
			 const sigc::slot1<void, PackagesAction> &callback,
			 Gtk::Menu * menu);

  /** \brief Try to start up the user interface.
   *
   *  \return \b true if the interface was successfully started.
   */
  bool main(int argc, char *argv[]);

  /** \brief Start an install/remove run, as if it had been triggered
   *  from the menu.
   */
  void do_installremove();

  /** \return \b true if an install/remove run can be started. */
  void do_installremove_allowed();

  /** \brief Start a list update, as if it had been triggered from the menu.
   */
  void do_update();

  /** \brief Schedule all possible upgrades, as if "Mark Upgradable"
   *  had been selected from the menu or toolbar.
   */
  void do_mark_upgradable();

  /** @{
   *  Constants giving the textual and iconic representation of the
   *  current and selected states of packages.
   */

  /** \brief Represents information about a state that the packag can be in. */
  class entity_state_info
  {
    std::string flag;
    std::string description;
    Gtk::StockID icon;

    // Hidden.
    entity_state_info();
  public:
    entity_state_info(const std::string &_flag,
		      const std::string &_description,
		      const Gtk::StockID &_icon)
      : flag(_flag), description(_description), icon(_icon)
    {
    }

    const std::string &get_flag() const { return flag; }
    /** \brief Retrieve the translated description of this state.
     */
    std::string get_description_i18n() const;
    const Gtk::StockID &get_icon() const { return icon; }
  };

  extern const entity_state_info virtual_columns;
  extern const entity_state_info not_installed_columns;
  extern const entity_state_info unpacked_columns;
  extern const entity_state_info half_configured_columns;
  extern const entity_state_info half_installed_columns;
  extern const entity_state_info config_files_columns;
  extern const entity_state_info triggers_awaited_columns;
  extern const entity_state_info triggers_pending_columns;
  extern const entity_state_info installed_columns;
  extern const entity_state_info error_columns;

  extern const entity_state_info install_columns;
  extern const entity_state_info reinstall_columns;
  extern const entity_state_info upgrade_columns;
  extern const entity_state_info downgrade_columns;
  extern const entity_state_info remove_columns;
  extern const entity_state_info purge_columns;
  extern const entity_state_info hold_columns;
  extern const entity_state_info forbid_columns;
  extern const entity_state_info broken_columns;
  extern const entity_state_info no_action_columns;

  extern const char *lightred_background_color;
  extern const char *lightgreen_background_color;

  /** @} */
}

#endif /*GUI_H_*/