/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2011, Tomasz Sowa * All rights reserved. * */ #include "templates/templates.h" #include "core/plugin.h" #include "groupinfo.h" #include "core/misc.h" namespace GroupItem { using namespace TemplatesFunctions; using TemplatesFunctions::system; extern GroupInfo group_info; static bool group_tab_found = false; static Groups * pgroups; static size_t req_id = 0; static size_t set_index; static size_t group_index; static size_t value_index; static std::wstring last_set, last_value; static std::wstring path; void group_tab_init(const std::wstring & set, const std::wstring & value) { if( req_id != cur->request->id || last_set != set || last_value != value ) { req_id = cur->request->id; pgroups = group_info.FindGroups(cur->mount->dir_id); last_set = set; last_value = value; group_tab_found = false; if( pgroups && pgroups->Find(set, value, set_index, group_index) ) group_tab_found = true; } } void group_tab(Info & i) { if( i.params.size() == 2 ) { group_tab_init(i.params[0], i.params[1]); value_index = i.iter; if( group_tab_found ) i.res = value_index < pgroups->Size(set_index, group_index); } else { group_tab_found = false; } } void build_current_path() { system->dirs.MakePath(cur->request->dir_tab, path); if( cur->request->is_item ) { path += cur->request->item.url; } else { // we assume that directories are without the last trailing slash NoLastSlash(path); } } void group_link_tab(Info & i) { if( i.params.size() == 1 ) { build_current_path(); group_tab_init(i.params[0], path); value_index = i.iter; if( group_tab_found ) i.res = value_index < pgroups->Size(set_index, group_index); } else { group_tab_found = false; } } void group_tab_value(Info & i) { if( group_tab_found ) { if( !i.par.empty() ) i.out << pgroups->GetOption(set_index, group_index, value_index, i.par); else i.out << pgroups->GetOption(set_index, group_index, value_index, L"value"); } } void group_tab_is_current_link(Info & i) { if( group_tab_found ) { build_current_path(); if( !i.par.empty() ) i.res = (pgroups->GetOption(set_index, group_index, value_index, i.par) == path); else i.res = (pgroups->GetOption(set_index, group_index, value_index, L"value") == path); } } void AddEzcFunctions(PluginInfo & info) { using TemplatesFunctions::EzcFun; EzcFun * fun = reinterpret_cast(info.p1); /* */ fun->Insert("group_tab", group_tab); fun->Insert("group_link_tab", group_link_tab); fun->Insert("group_tab_value", group_tab_value); fun->Insert("group_tab_is_current_link", group_tab_is_current_link); } } // namespace