1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2004-2009, 2011, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18
19 #include <common/ac/assert.h>
20 #include <common/ac/string.h>
21
22 #include <common/uuidentifier.h>
23 #include <libaegis/ael/column_width.h>
24 #include <libaegis/attribute.h>
25 #include <libaegis/change/branch.h>
26 #include <libaegis/change/functor/invento_list.h>
27 #include <libaegis/col.h>
28 #include <libaegis/option.h>
29 #include <libaegis/output.h>
30 #include <libaegis/project.h>
31
32
~change_functor_inventory_list()33 change_functor_inventory_list::~change_functor_inventory_list()
34 {
35 }
36
37
change_functor_inventory_list(bool arg1,project * pp)38 change_functor_inventory_list::change_functor_inventory_list(bool arg1,
39 project *pp) :
40 change_functor(arg1)
41 {
42 colp = col::open((string_ty *)0);
43 string_ty *line1 =
44 str_format("Project \"%s\"", project_name_get(pp).c_str());
45 colp->title(line1->str_text, "Change Set Inventory");
46 str_free(line1);
47 line1 = 0;
48
49 int left = 0;
50 vers_col = colp->create(left, left + VERSION_WIDTH, "Change\n-------");
51 left += VERSION_WIDTH + 1;
52 uuid_col = colp->create(left, left + UUID_WIDTH, "UUID\n------");
53 left += UUID_WIDTH + 1;
54 if (option_verbose_get())
55 when_col = colp->create(left, 0, "Date and Time\n---------------");
56 }
57
58
59 void
print_one_line(change::pointer cp,string_ty * uuid)60 change_functor_inventory_list::print_one_line(change::pointer cp,
61 string_ty *uuid)
62 {
63 vers_col->fputs(cp->version_get());
64 uuid_col->fputs(uuid);
65 if (when_col)
66 {
67 //
68 // Change UUIDs were introduces in 4.16 (public release
69 // 4.17), so for backwards compatibility reasons, do not
70 // expect all completed changes have UUIDs.
71 //
72 time_t when = cp->completion_timestamp();
73 struct tm *theTm = localtime(&when);
74 char buffer[30];
75 strftime(buffer, sizeof(buffer), "%Y-%b-%d %H:%M:%S", theTm);
76 when_col->fputs(buffer);
77 }
78 colp->eoln();
79 }
80
81
82 void
operator ()(change::pointer cp)83 change_functor_inventory_list::operator()(change::pointer cp)
84 {
85 cstate_ty *cstate_data = cp->cstate_get();
86 if (cstate_data->uuid)
87 print_one_line(cp, cstate_data->uuid);
88 if (!cstate_data->attribute)
89 return;
90 for (size_t j = 0; j < cstate_data->attribute->length; ++j)
91 {
92 attributes_ty *ap = cstate_data->attribute->list[j];
93 assert(ap->name);
94 assert(ap->value);
95 if
96 (
97 ap->value
98 &&
99 // users can edit, we will check
100 universal_unique_identifier_valid(ap->value)
101 )
102 {
103 print_one_line(cp, ap->value);
104 }
105 }
106 }
107
108
109 // vim: set ts=8 sw=4 et :
110