1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2001-2008, 2011, 2012 Peter Miller
4 // Copyright (C) 2007, 2008 Walter Franzini
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see
18 // <http://www.gnu.org/licenses/>.
19 //
20
21 #include <common/error.h>
22 #include <common/str_list.h>
23 #include <common/trace.h>
24 #include <libaegis/ael/change/inappropriat.h>
25 #include <libaegis/ael/change/user.h>
26 #include <libaegis/ael/column_width.h>
27 #include <libaegis/ael/project/inappropriat.h>
28 #include <libaegis/change.h>
29 #include <libaegis/change/identifier.h>
30 #include <libaegis/col.h>
31 #include <libaegis/output.h>
32 #include <libaegis/project.h>
33 #include <libaegis/sub.h>
34 #include <libaegis/user.h>
35
36
37 void
list_user_changes(change_identifier & cid,string_list_ty * args)38 list_user_changes(change_identifier &cid, string_list_ty *args)
39 {
40 string_ty *s;
41 string_list_ty name;
42
43 trace(("list_user_changes()\n{\n"));
44 if (cid.project_set())
45 list_project_inappropriate();
46 if (cid.set())
47 list_change_inappropriate();
48
49 //
50 // get the list of projects
51 //
52 project_list_get(&name);
53 if (!name.nstrings)
54 {
55 trace(("}\n"));
56 return;
57 }
58
59 user_ty::pointer up;
60 if (!args || !args->nstrings)
61 {
62 //
63 // No user name is provided, use the current user.
64 //
65 up = user_ty::create();
66 }
67 else
68 {
69 //
70 // Use the user name supplied by the caller.
71 //
72 up = user_ty::create(nstring(args->string[0]));
73 }
74
75 //
76 // open listing
77 //
78 col::pointer colp = col::open((string_ty *)0);
79 s =
80 str_format
81 (
82 "Owned by %s <%s>",
83 up->full_name().c_str(),
84 up->name().c_str()
85 );
86 colp->title("List of Changes", s->str_text);
87 str_free(s);
88
89 //
90 // create the columns
91 //
92 int left = 0;
93 output::pointer project_col =
94 colp->create(left, left + PROJECT_WIDTH, "Project\n----------");
95 left += PROJECT_WIDTH + 1;
96 output::pointer change_col =
97 colp->create(left, left + CHANGE_WIDTH, "Change\n------");
98 left += CHANGE_WIDTH + 1;
99 output::pointer state_col =
100 colp->create(left, left + STATE_WIDTH, "State\n----------");
101 left += STATE_WIDTH + 1;
102 output::pointer description_col =
103 colp->create(left, 0, "Description\n-------------");
104
105 //
106 // for each project, see if the current user
107 // is working on any of them.
108 //
109 for (size_t j = 0; j < name.nstrings; ++j)
110 {
111 //
112 // locate the project,
113 // and make sure we are allowed to look at it
114 //
115 project *pp = project_alloc(name.string[j]);
116 pp->bind_existing();
117 int err = project_is_readable(pp);
118 if (err != 0)
119 {
120 project_free(pp);
121 continue;
122 }
123
124 //
125 // for each change within this project the user
126 // is working on emit a line of information
127 //
128 for (long n = 0;; ++n)
129 {
130 long change_number = 0;
131 if (!up->own_nth(pp, n, change_number))
132 break;
133
134 //
135 // locate change data
136 //
137 change::pointer cp = change_alloc(pp, change_number);
138 change_bind_existing(cp);
139
140 //
141 // emit the info
142 //
143 project_col->fputs(project_name_get(pp).c_str());
144 change_col->fprintf("%4ld", magic_zero_decode(change_number));
145 cstate_ty *cstate_data = cp->cstate_get();
146 state_col->fputs(cstate_state_ename(cstate_data->state));
147 if (cstate_data->brief_description)
148 {
149 description_col->fputs
150 (
151 cstate_data->brief_description->str_text
152 );
153 }
154 colp->eoln();
155
156 //
157 // release change and project
158 //
159 change_free(cp);
160 }
161
162 //
163 // free project
164 //
165 project_free(pp);
166 }
167 trace(("}\n"));
168 }
169
170
171 // vim: set ts=8 sw=4 et :
172