2 * Copyright (c) 2002 Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <robertc@hotmail.com>
16 #include "PickPackageLine.h"
18 #include "package_db.h"
21 PickPackageLine::get_text(int col_num
) const
23 if (col_num
== pkgname_col
)
25 return string_to_wstring(pkg
.name
);
27 else if (col_num
== current_col
)
29 return string_to_wstring(pkg
.installed
.Canonical_version());
31 else if (col_num
== new_col
)
33 return pkg
.action_caption ();
35 else if (col_num
== srctick_col
)
37 const char *srctick
= "?";
38 if ( /* uninstall */ !pkg
.desired
||
39 /* when no source mirror available */
40 !pkg
.desired
.sourcePackage().accessible())
42 else if (pkg
.srcpicked())
47 return string_to_wstring(srctick
);
49 else if (col_num
== cat_col
)
51 return string_to_wstring(pkg
.getReadableCategoryList());
53 else if (col_num
== size_col
)
56 packageversion picked
;
58 /* Find the size of the package. If user has chosen to upgrade/downgrade
59 the package, use that version. Otherwise use the currently installed
60 version, or if not installed then use the version that would be chosen
61 based on the current trust level (curr/prev/test). */
64 else if (pkg
.installed
)
65 picked
= pkg
.installed
;
67 picked
= pkg
.trustp (false, theView
.deftrust
);
69 /* Include the size of the binary package, and if selected, the source
71 sz
+= picked
.source()->size
;
73 sz
+= picked
.sourcePackage().source()->size
;
75 /* If size still 0, size must be unknown. */
76 std::string size
= (sz
== 0) ? "?" : format_1000s((sz
+1023)/1024) + "k";
78 return string_to_wstring(size
);
80 else if (col_num
== pkg_col
)
82 return string_to_wstring(pkg
.SDesc());
89 PickPackageLine::get_tooltip(int col_num
) const
91 if (col_num
== pkg_col
)
100 PickPackageLine::do_action(int col_num
, int action_id
)
102 if (col_num
== new_col
)
104 pkg
.select_action(action_id
, theView
.deftrust
);
108 if (col_num
== srctick_col
)
110 if (pkg
.desired
.sourcePackage ().accessible ())
111 pkg
.srcpick (!pkg
.srcpicked ());
120 PickPackageLine::do_default_action(int col_num
)
122 if (col_num
== new_col
)
131 PickPackageLine::get_actions(int col_num
) const
133 if (col_num
== new_col
)
135 return pkg
.list_actions (theView
.deftrust
);
142 PickPackageLine::get_indent() const
148 PickPackageLine::map_key_to_action(WORD vkey
, int modkeys
, int & col_num
,
149 int & action_id
) const
153 case VK_SPACE
: // install/reinstall/uninstall context menu for package
156 return Action::PopUp
;
157 case 'I': // Ctrl+I: select install default version and move to next row
158 case 'R': // Ctrl+R: select reinstall and move to next row
159 case 'U': // Ctrl+U: select uninstall and move to next row
160 if (modkeys
!= ModifierKeys::Control
)
165 case 'I': action_id
= packagemeta::Install_action
; break;
166 case 'R': action_id
= packagemeta::Reinstall_action
; break;
167 default: action_id
= packagemeta::Uninstall_action
; break;
169 return Action::Direct
| Action::NextRow
;