source: trunk/gsdl/src/recpt/vlistbrowserclass.cpp@ 1048

Last change on this file since 1048 was 1048, checked in by nzdl, 24 years ago

tidied up some of the browsing code - replaced DocumentImages,
DocumentTitles and DocumentHeading with DocumentIcon

  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/**********************************************************************
2 *
3 * vlistbrowserclass.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: vlistbrowserclass.cpp 1048 2000-03-31 03:04:32Z nzdl $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.8 2000/03/31 03:04:32 nzdl
31 tidied up some of the browsing code - replaced DocumentImages,
32 DocumentTitles and DocumentHeading with DocumentIcon
33
34 Revision 1.7 2000/02/17 02:33:09 sjboddie
35 minor tidy up - made some function definitions virtual
36
37 Revision 1.6 1999/12/13 02:44:23 davidb
38 Better protection when accessing "haschildren"
39
40 Revision 1.5 1999/10/30 23:01:24 sjboddie
41 tidied things up slightly
42
43 Revision 1.4 1999/10/30 22:14:44 sjboddie
44 added a collection argument
45
46 Revision 1.3 1999/10/19 08:40:13 sjboddie
47 fixed some stupid compiler warnings on windows
48
49 Revision 1.2 1999/10/14 22:59:34 sjboddie
50 finished off browser classes
51
52 Revision 1.1 1999/10/10 08:14:11 sjboddie
53 - metadata now returns mp rather than array
54 - redesigned browsing support (although it's not finished so
55 won't currently work ;-)
56
57 */
58
59
60#include "vlistbrowserclass.h"
61#include <assert.h>
62#include "OIDtools.h"
63
64vlistbrowserclass::vlistbrowserclass () {
65}
66
67vlistbrowserclass::~vlistbrowserclass () {
68}
69
70// returns the name that specifies the browserclass type
71text_t vlistbrowserclass::get_browser_name () {
72 return "VList";
73}
74
75void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
76 metadata.insert ("haschildren");
77 metadata.insert ("doctype");
78}
79
80text_t vlistbrowserclass::get_default_formatstring () {
81 return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td>";
82}
83
84int vlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
85 const text_t &collection, int colnumber,
86 format_t *formatlistptr, bool use_table,
87 text_tset &/*metadata*/, bool &/*getParents*/,
88 recptproto * /*collectproto*/, displayclass &disp,
89 outconvertclass &outconvert, ostream &textout,
90 ostream &/*logout*/) {
91
92 text_t link, icon;
93
94 text_t collink = collection;
95 if (!collink.empty()) collink = "&c=" + collink;
96
97 get_link_icon (section, args, collink, link, icon);
98 bool highlight = false;
99 if (!args["d"].empty()) {
100 if (args["d"] == section.OID) highlight = true;
101 } else
102 if (args["cl"] == section.OID) highlight = true;
103
104
105 if (use_table || colnumber > 0) {
106 textout << "<table><tr valign=top>";
107 // get tab size
108 text_t tab; int itab;
109 disp.expandstring ("Global", "_tabwidth_", tab);
110 itab = tab.getint();
111 if (colnumber > 0) textout << outconvert << disp
112 << "<td><img src=\"_httpimg_/space.gif\" width="
113 << (itab*colnumber) << "></td>";
114 }
115
116 textout << outconvert << disp << get_formatted_string (section, formatlistptr,
117 link, icon, highlight);
118
119 if (use_table || colnumber > 0) textout << "</tr></table>\n";
120
121 return 1;
122}
123
124int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
125 const text_t &collection, int colnumber,
126 format_t *formatlistptr, bool use_table,
127 text_tset &/*metadata*/, bool &/*getParents*/,
128 recptproto * /*collectproto*/, displayclass &disp,
129 outconvertclass &outconvert, ostream &textout,
130 ostream &/*logout*/) {
131
132 text_t link, icon;
133 text_t &arg_d = args["d"];
134 text_t &arg_cl = args["cl"];
135
136 text_t collink = collection;
137 if (!collink.empty()) collink = "&c=" + collink;
138
139 if (colnumber > 0) {
140 textout << "<table><tr valign=top>";
141 // get tab size
142 text_t tab; int itab;
143 disp.expandstring ("Global", "_tabwidth_", tab);
144 itab = tab.getint();
145 if (colnumber > 0) textout << outconvert << disp
146 << "<td><img src=\"_httpimg_/space.gif\" width="
147 << (itab*colnumber) << "></td>";
148 textout << "<td>";
149 }
150 if (use_table) textout << "<table>\n";
151
152 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
153 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
154
155 while (thissection != endsection) {
156
157 get_link_icon (*thissection, args, collink, link, icon);
158 bool highlight = false;
159 if (!arg_d.empty()) {
160 if (arg_d == (*thissection).OID) highlight = true;
161 } else
162 if (arg_cl == (*thissection).OID) highlight = true;
163
164 if (use_table || colnumber > 0) textout << "<tr valign=top>";
165 textout << outconvert << disp << get_formatted_string (*thissection, formatlistptr,
166 link, icon, highlight);
167 if (use_table || colnumber > 0) textout << "</tr>";
168 textout << "\n";
169 thissection ++;
170 }
171
172 if (use_table) textout << "</table>\n";
173 if (colnumber > 0) textout << "</table></td></tr></table>\n";
174
175 return 1;
176}
177
178
179// get_link_icon attempts to work out what type of icon should be displayed for
180// the given section and what it should link to.
181void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
182 const text_t &collink, text_t &link, text_t &icon) {
183
184 link = "<a href=\"_httpdocument_" + collink;
185 icon = "_document:icontext_";
186 int haschildren = 0;
187
188 if (section.metadata.count("haschildren")>0)
189 haschildren = section.metadata["haschildren"].values[0].getint();
190
191 text_t doctype;
192 if (section.metadata.count("doctype")>0)
193 doctype = section.metadata["doctype"].values[0];
194
195 text_t &arg_d = args["d"];
196 text_t &arg_cl = args["cl"];
197
198 if (args["a"] == "q") {
199 // query results
200 if (is_top (section.OID)) icon = "_document:iconclosedbook_";
201 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
202 link += "&cl=search&d=" + section.OID + "\">";
203
204 } else if (!arg_d.empty()) {
205 // document level
206 if (is_top(section.OID)) {
207 icon = "_document:iconopenbook_";
208 if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
209 else link += "&cl=" + arg_cl + "\">";
210
211 } else if (haschildren == 1) {
212 if ((args["gc"] == "1") ||
213 (is_child_of (section.OID, arg_d)) ||
214 (section.OID == arg_d)) {
215 icon = "_document:iconopenfolder_";
216 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
217 } else {
218 icon = "_document:iconclosedfolder_";
219 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
220 }
221 } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
222
223 } else {
224 // classification level
225 if (haschildren == 1) {
226 if (doctype == "classify") {
227 if ((args["gc"] == "1") ||
228 (is_child_of (section.OID, arg_cl)) ||
229 (section.OID == arg_cl)) {
230 icon = "_document:iconopenbookshelf_";
231 link += "&cl=" + section.OID + ".pr\">";
232 } else {
233 icon = "_document:iconclosedbookshelf_";
234 link += "&cl=" + section.OID + "\">";
235 }
236 } else {
237 icon = "_document:iconclosedbook_";
238 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
239 }
240 } else {
241 if (doctype == "classify") link = "";
242 else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
243 }
244 }
245}
Note: See TracBrowser for help on using the repository browser.