/********************************************************************** * * vlistbrowserclass.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *********************************************************************/ #include "vlistbrowserclass.h" #include #include "OIDtools.h" #include "browsetools.h" vlistbrowserclass::vlistbrowserclass () { } vlistbrowserclass::~vlistbrowserclass () { } // returns the name that specifies the browserclass type text_t vlistbrowserclass::get_browser_name () { return "VList"; } browserclass* vlistbrowserclass::clone() { vlistbrowserclass* browser = new vlistbrowserclass(); if (browser != NULL) { #ifdef GSDL_USE_BY_BOOK_MACROS browser->m_oByBookMacros.Copy(m_oByBookMacros); #endif } return browser; } void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) { metadata.insert ("haschildren"); metadata.insert ("doctype"); } text_t vlistbrowserclass::get_default_formatstring () { return "[link][icon][/link]" "[srclink][srcicon][/srclink]" "[highlight]{Or}{[Title],Untitled}[/highlight]" "{If}{[Source],
([Source])}"; } int vlistbrowserclass::output_section_group (ResultDocInfo_t §ion, cgiargsclass &args, const text_t &collection, int colnumber, format_t *formatlistptr, bool use_table, text_tset &/*metadata*/, bool &/*getParents*/, recptproto * collectproto, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream& logout) { text_t link, icon; text_t collink = collection; if (!collink.empty()) collink = "&c=" + collink; get_link_icon (section, args, collink, link, icon); bool highlight = false; if (!args["d"].empty()) { if (args["d"] == section.OID) highlight = true; } else if (args["cl"] == section.OID) highlight = true; if (use_table || colnumber > 0) { textout << outconvert << ""; // get tab size text_t tab; int itab; disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab); itab = tab.getint(); if (colnumber > 0) textout << outconvert << disp << ""; } text_tmap options; options["link"] = link; options["icon"] = icon; if (highlight) options["highlight"] = "1"; else options["highlight"] = "0"; options["DocImage"] = get_cover_image(); textout << outconvert << disp << get_formatted_string (collection, collectproto, section, disp, formatlistptr, options, logout); if (use_table || colnumber > 0) textout << outconvert << "
\n"; return 1; } int vlistbrowserclass::output_section_group (FilterResponse_t §ions, cgiargsclass &args, const text_t &collection, int colnumber, format_t *formatlistptr, bool use_table, text_tset &/*metadata*/, bool &/*getParents*/, recptproto * collectproto, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream& logout) { text_t link, icon; text_t &arg_d = args["d"]; text_t &arg_cl = args["cl"]; text_t collink = collection; if (!collink.empty()) collink = "&c=" + collink; if (colnumber > 0) { textout << outconvert << ""; // get tab size text_t tab; int itab; disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab); itab = tab.getint(); if (colnumber > 0) textout << outconvert << disp << ""; textout << outconvert << "
"; } if (use_table) textout << outconvert << "\n"; ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin(); ResultDocInfo_tarray::iterator endsection = sections.docInfo.end(); // ** here lies Alan's hack to get 4 results per table row int item = 0, perline;; // set perline to 1 normally text_t fstring; text_tmap options; options["link"] = link; options["icon"] = icon; options["highlight"] = "0"; options["DocImage"] = get_cover_image(); if ( thissection != endsection ) { // only if there are results (else corrupts display) fstring = get_formatted_string (collection, collectproto, *thissection, disp, formatlistptr, options, logout); // if format string // has
) then // we assume it is an image and put it in 4 columns if (fstring[5] == 't') perline = 4; else perline = 1; } while (thissection != endsection) { ++item; get_link_icon (*thissection, args, collink, link, icon); bool highlight = false; if (!arg_d.empty()) { if (arg_d == (*thissection).OID) highlight = true; } else if (arg_cl == (*thissection).OID) highlight = true; if ((item == 1 && use_table) || colnumber > 0 ) textout << outconvert << "\n"; options["link"] = link; options["icon"] = icon; if (highlight) options["highlight"] = "1"; else options["highlight"] = "0"; options["DocImage"] = get_cover_image(); textout << outconvert << disp << " " << get_formatted_string (collection, collectproto, *thissection, disp, formatlistptr, options, logout); if ((item >= perline && use_table) || colnumber > 0) { textout << outconvert << "\n"; item = 0; } textout << outconvert << "\n"; ++thissection; } if (use_table) textout << outconvert << "
\n"; if (colnumber > 0) textout << outconvert << "
\n"; return 1; } // get_link_icon attempts to work out what type of icon should be displayed for // the given section and what it should link to. // [modification to allow default document detach settings -- kjdon] void vlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args, const text_t &collink, text_t &link, text_t &icon) { link = ""; text_t detach_link_end = "&x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page icon = "_document:icontext_"; text_t doctype; int haschildren = 0; if (section.metadata.count("haschildren")>0) haschildren = section.metadata["haschildren"].values[0].getint(); if (section.metadata.count("doctype")>0) doctype = section.metadata["doctype"].values[0]; text_t &arg_d = args["d"]; text_t &arg_cl = args["cl"]; if (args["a"] == "q") { // query results list link += "&cl=search&d=" + section.OID; if (args["xx"] == "1") { link += detach_link_end; } else { link += link_end; } if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_"; else if (haschildren == 1) icon = "_document:iconclosedfolder_"; } else if (!arg_d.empty()) { // we are in a document - none of the links should be detach links if (is_top(section.OID)) { // we link back to the originating page eg search page or classifier page icon = "_document:iconopenbook_"; if (arg_cl == "search") { link = ""; } else link += "&cl=" + arg_cl + "\">"; } else if (haschildren == 1) { if ((args["gc"] == "1") || (is_child_of (section.OID, arg_d)) || (section.OID == arg_d)) { icon = "_document:iconopenfolder_"; link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">"; } else { icon = "_document:iconclosedfolder_"; link += "&cl=" + arg_cl + "&d=" + section.OID + "\">"; } } else { if (args["gt"] == "0") { link += "&cl=" + arg_cl + "&d=" + section.OID + "\">"; } else { link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">"; } } } else { // classification level - links to docs may be detaching if (haschildren == 1) { if (doctype == "classify") { if ((args["gc"] == "1") || (is_child_of (section.OID, arg_cl)) || (section.OID == arg_cl)) { icon = "_document:iconopenbookshelf_"; link += "&cl=" + section.OID + ".pr\">"; } else { icon = "_document:iconclosedbookshelf_"; link += "&cl=" + section.OID + "\">"; } } else { icon = "_document:iconclosedbook_"; link += "&cl=" + arg_cl + "&d=" + section.OID; if (args["xx"] == "1") { link += detach_link_end; } else { link += link_end; } } } else { if (doctype == "classify") link = ""; else { link += "&cl=" + arg_cl + "&d=" + section.OID; if (args["xx"] == "1") { link += detach_link_end; } else { link += link_end; } } } } }