]>
Commit | Line | Data |
---|---|---|
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" | |
18 | #include "package_db.h" | |
19 | ||
20 | const std::wstring | |
21 | PickPackageLine::get_text(int col_num) const | |
22 | { | |
23 | if (col_num == pkgname_col) | |
24 | { | |
25 | return string_to_wstring(pkg.name); | |
26 | } | |
27 | else if (col_num == current_col) | |
28 | { | |
29 | return string_to_wstring(pkg.installed.Canonical_version()); | |
30 | } | |
31 | else if (col_num == new_col) | |
32 | { | |
33 | return pkg.action_caption (); | |
34 | } | |
35 | else if (col_num == srctick_col) | |
36 | { | |
37 | const char *srctick = "?"; | |
38 | if ( /* uninstall */ !pkg.desired || | |
39 | /* when no source mirror available */ | |
40 | !pkg.desired.sourcePackage().accessible()) | |
41 | srctick = "n/a"; | |
42 | else if (pkg.srcpicked()) | |
43 | srctick = "yes"; | |
44 | else | |
45 | srctick = "no"; | |
46 | ||
47 | return string_to_wstring(srctick); | |
48 | } | |
49 | else if (col_num == cat_col) | |
50 | { | |
51 | return string_to_wstring(pkg.getReadableCategoryList()); | |
52 | } | |
53 | else if (col_num == size_col) | |
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 | |
67 | picked = pkg.trustp (false, theView.deftrust); | |
68 | ||
69 | /* Include the size of the binary package, and if selected, the source | |
70 | package as well. */ | |
71 | sz += picked.source()->size; | |
72 | if (pkg.srcpicked()) | |
73 | sz += picked.sourcePackage().source()->size; | |
74 | ||
75 | /* If size still 0, size must be unknown. */ | |
76 | std::string size = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k"; | |
77 | ||
78 | return string_to_wstring(size); | |
79 | } | |
80 | else if (col_num == pkg_col) | |
81 | { | |
82 | return string_to_wstring(pkg.SDesc()); | |
83 | } | |
84 | ||
85 | return L"unknown"; | |
86 | } | |
87 | ||
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 | ||
99 | int | |
100 | PickPackageLine::do_action(int col_num, int action_id) | |
101 | { | |
102 | if (col_num == new_col) | |
103 | { | |
104 | pkg.select_action(action_id, theView.deftrust); | |
105 | return 1; | |
106 | } | |
107 | ||
108 | if (col_num == srctick_col) | |
109 | { | |
110 | if (pkg.desired.sourcePackage ().accessible ()) | |
111 | pkg.srcpick (!pkg.srcpicked ()); | |
112 | ||
113 | return 1; | |
114 | } | |
115 | ||
116 | return 0; | |
117 | } | |
118 | ||
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 | ||
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 | } | |
140 | ||
141 | int | |
142 | PickPackageLine::get_indent() const | |
143 | { | |
144 | return indent; | |
145 | } | |
146 | ||
147 | int | |
148 | PickPackageLine::map_key_to_action(WORD vkey, int modkeys, int & col_num, | |
149 | int & action_id) const | |
150 | { | |
151 | switch (vkey) | |
152 | { | |
153 | case VK_SPACE: // install/reinstall/uninstall context menu for package | |
154 | case VK_APPS: | |
155 | col_num = new_col; | |
156 | return Action::PopUp; | |
157 | case 'I': // Ctrl+I: select install default version and move to next row | |
158 | case 'K': // Ctrl+K: select keep or skip package and move to next row | |
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; | |
167 | default: action_id = packagemeta::NoChange_action; break; | |
168 | case 'R': action_id = packagemeta::Reinstall_action; break; | |
169 | case 'U': action_id = packagemeta::Uninstall_action; break; | |
170 | } | |
171 | return Action::Direct | Action::NextRow; | |
172 | } | |
173 | ||
174 | return Action::None; | |
175 | } |