]>
Commit | Line | Data |
---|---|---|
97647369 RC |
1 | /* |
2 | * Copyright (c) 2002 Robert Collins. | |
3 | * | |
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. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <robertc@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "PickPackageLine.h" | |
17 | #include "PickView.h" | |
0d053c58 | 18 | #include "package_db.h" |
97647369 | 19 | |
f34a20e7 | 20 | const std::wstring |
ce9f6dd0 | 21 | PickPackageLine::get_text(int col_num) const |
97647369 | 22 | { |
ce9f6dd0 JT |
23 | if (col_num == pkgname_col) |
24 | { | |
f34a20e7 | 25 | return string_to_wstring(pkg.name); |
ce9f6dd0 JT |
26 | } |
27 | else if (col_num == current_col) | |
82306ac2 | 28 | { |
f34a20e7 | 29 | return string_to_wstring(pkg.installed.Canonical_version()); |
51fc56a1 | 30 | } |
ce9f6dd0 | 31 | else if (col_num == new_col) |
97647369 | 32 | { |
ce9f6dd0 | 33 | return pkg.action_caption (); |
97647369 | 34 | } |
ce9f6dd0 | 35 | else if (col_num == srctick_col) |
82306ac2 | 36 | { |
ce9f6dd0 | 37 | const char *srctick = "?"; |
82306ac2 | 38 | if ( /* uninstall */ !pkg.desired || |
ce9f6dd0 JT |
39 | /* when no source mirror available */ |
40 | !pkg.desired.sourcePackage().accessible()) | |
41 | srctick = "n/a"; | |
4209699d | 42 | else if (pkg.srcpicked()) |
ce9f6dd0 | 43 | srctick = "yes"; |
82306ac2 | 44 | else |
ce9f6dd0 JT |
45 | srctick = "no"; |
46 | ||
f34a20e7 | 47 | return string_to_wstring(srctick); |
82306ac2 | 48 | } |
ce9f6dd0 | 49 | else if (col_num == cat_col) |
97647369 | 50 | { |
f34a20e7 | 51 | return string_to_wstring(pkg.getReadableCategoryList()); |
97647369 | 52 | } |
ce9f6dd0 | 53 | else if (col_num == size_col) |
0ac305ec BD |
54 | { |
55 | int sz = 0; | |
56 | packageversion picked; | |
57 | ||
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). */ | |
62 | if (pkg.desired) | |
63 | picked = pkg.desired; | |
64 | else if (pkg.installed) | |
65 | picked = pkg.installed; | |
66 | else | |
ced3a1ae | 67 | picked = pkg.trustp (false, theView.deftrust); |
0ac305ec BD |
68 | |
69 | /* Include the size of the binary package, and if selected, the source | |
70 | package as well. */ | |
71 | sz += picked.source()->size; | |
4209699d | 72 | if (pkg.srcpicked()) |
0ac305ec BD |
73 | sz += picked.sourcePackage().source()->size; |
74 | ||
75 | /* If size still 0, size must be unknown. */ | |
ce9f6dd0 JT |
76 | std::string size = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k"; |
77 | ||
f34a20e7 | 78 | return string_to_wstring(size); |
0ac305ec | 79 | } |
ce9f6dd0 | 80 | else if (col_num == pkg_col) |
97647369 | 81 | { |
f34a20e7 | 82 | return string_to_wstring(pkg.SDesc()); |
97647369 | 83 | } |
ce9f6dd0 | 84 | |
f34a20e7 | 85 | return L"unknown"; |
97647369 RC |
86 | } |
87 | ||
800274fd JT |
88 | const std::string |
89 | PickPackageLine::get_tooltip(int col_num) const | |
90 | { | |
91 | if (col_num == pkg_col) | |
92 | { | |
93 | return pkg.LDesc(); | |
94 | } | |
95 | ||
96 | return ""; | |
97 | } | |
98 | ||
97647369 | 99 | int |
4018914c | 100 | PickPackageLine::do_action(int col_num, int action_id) |
97647369 | 101 | { |
ce9f6dd0 | 102 | if (col_num == new_col) |
2f6d93ed | 103 | { |
4018914c | 104 | pkg.select_action(action_id, theView.deftrust); |
ce9f6dd0 | 105 | return 1; |
2f6d93ed | 106 | } |
beb453d3 JT |
107 | |
108 | if (col_num == srctick_col) | |
2f6d93ed CV |
109 | { |
110 | if (pkg.desired.sourcePackage ().accessible ()) | |
ce9f6dd0 | 111 | pkg.srcpick (!pkg.srcpicked ()); |
ce9f6dd0 JT |
112 | |
113 | return 1; | |
cd2e3f50 JT |
114 | } |
115 | ||
2c4487b3 | 116 | return 0; |
97647369 | 117 | } |
4018914c | 118 | |
76dc99c1 JT |
119 | int |
120 | PickPackageLine::do_default_action(int col_num) | |
121 | { | |
122 | if (col_num == new_col) | |
123 | { | |
124 | pkg.toggle_action(); | |
125 | return 1; | |
126 | } | |
127 | return 0; | |
128 | } | |
129 | ||
4018914c JT |
130 | ActionList * |
131 | PickPackageLine::get_actions(int col_num) const | |
132 | { | |
133 | if (col_num == new_col) | |
134 | { | |
135 | return pkg.list_actions (theView.deftrust); | |
136 | } | |
137 | ||
138 | return NULL; | |
139 | } | |
68487c7c JT |
140 | |
141 | int | |
142 | PickPackageLine::get_indent() const | |
143 | { | |
144 | return indent; | |
145 | } | |
22e01f51 | 146 | |
c99e4c14 CF |
147 | int |
148 | PickPackageLine::map_key_to_action(WORD vkey, int modkeys, int & col_num, | |
149 | int & action_id) const | |
22e01f51 JT |
150 | { |
151 | switch (vkey) | |
152 | { | |
c99e4c14 | 153 | case VK_SPACE: // install/reinstall/uninstall context menu for package |
22e01f51 | 154 | case VK_APPS: |
c99e4c14 CF |
155 | col_num = new_col; |
156 | return Action::PopUp; | |
157 | case 'I': // Ctrl+I: select install default version and move to next row | |
8eb2882d | 158 | case 'K': // Ctrl+K: select keep or skip package and move to next row |
c99e4c14 CF |
159 | case 'R': // Ctrl+R: select reinstall and move to next row |
160 | case 'U': // Ctrl+U: select uninstall and move to next row | |
161 | if (modkeys != ModifierKeys::Control) | |
162 | break; | |
163 | col_num = new_col; | |
164 | switch (vkey) | |
165 | { | |
166 | case 'I': action_id = packagemeta::Install_action; break; | |
8eb2882d | 167 | default: action_id = packagemeta::NoChange_action; break; |
c99e4c14 | 168 | case 'R': action_id = packagemeta::Reinstall_action; break; |
8eb2882d | 169 | case 'U': action_id = packagemeta::Uninstall_action; break; |
c99e4c14 CF |
170 | } |
171 | return Action::Direct | Action::NextRow; | |
22e01f51 JT |
172 | } |
173 | ||
c99e4c14 | 174 | return Action::None; |
22e01f51 | 175 | } |