rewritten: plugin 'menu'

now we have a cache for the plugin
           (this limits the number of database requests)
added:     to plugin 'menu'
           menu_dir_tab can have a 'current' parameter (first argument)
           (it uses the last path from the previous menu_dir_tab) 
changed:   updated to the new EZC api
added:     new message to plugins: WINIX_DIR_ADDED


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@808 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-02-24 12:09:38 +00:00
parent 97c7edafd6
commit a45fb30e0a
11 changed files with 632 additions and 304 deletions

View File

@ -119,6 +119,10 @@
// in p1 you have a pointer to the Item struct
#define WINIX_FILE_CHANGED 30160
// a new directory has been added
// in p1 you have a pointer to the Item struct
#define WINIX_DIR_ADDED 30155
// a file (page) has been copied
// in p1 you have a pointer to the Item struct
// not every fields of Item struct are filled

View File

@ -633,7 +633,12 @@ mkdir.o: ../core/lastcontainer.h ../templates/misc.h
mkdir.o: ../templates/htmltextstream.h ../core/mounts.h ../core/mountparser.h
mkdir.o: ../core/crypt.h ../core/users.h ../core/groups.h ../core/group.h
mkdir.o: ../core/loadavg.h ../core/image.h ../core/basethread.h
mkdir.o: ../core/threadmanager.h ../core/synchro.h
mkdir.o: ../core/threadmanager.h ../core/synchro.h ../core/plugin.h
mkdir.o: ../core/pluginmsg.h ../core/system.h ../core/sessionmanager.h
mkdir.o: ../core/sessioncontainer.h ../functions/functions.h
mkdir.o: ../templates/templates.h ../templates/patterncacher.h
mkdir.o: ../templates/indexpatterns.h ../templates/patterns.h
mkdir.o: ../templates/changepatterns.h ../core/sessionmanager.h
mount.o: mount.h functionbase.h ../core/item.h ../db/db.h ../db/dbbase.h
mount.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h
mount.o: ../core/misc.h ../core/item.h ../core/requesttypes.h ../core/error.h

View File

@ -9,6 +9,7 @@
#include "mkdir.h"
#include "functions.h"
#include "core/plugin.h"
@ -63,11 +64,15 @@ void Mkdir::PostFunMkdir(bool add_to_dir_tab, int privileges)
functions->ReadItem(cur->request->item, Item::dir);
functions->SetUser(cur->request->item);
cur->request->item.privileges = privileges;
Item * pdir;
cur->request->status = system->dirs.AddDirectory(cur->request->item, add_to_dir_tab);
cur->request->status = system->dirs.AddDirectory(cur->request->item, add_to_dir_tab, &pdir);
if( cur->request->status == WINIX_ERR_OK )
{
if( pdir )
plugin.Call(WINIX_DIR_ADDED, pdir);
system->RedirectTo(cur->request->item);
}
else

View File

@ -1,46 +1,126 @@
# DO NOT DELETE
init.o: ../../core/log.h ../../core/textstream.h ../../core/misc.h
init.o: ../../core/item.h ../../core/requesttypes.h
init.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
init.o: ../../core/request.h ../../core/error.h ../../core/config.h
init.o: ../../core/htmlfilter.h ../../templates/htmltextstream.h
init.o: ../../core/textstream.h ../../core/session.h ../../core/user.h
init.o: ../../core/plugindata.h ../../core/rebus.h ../../core/mount.h
init.o: ../../templates/locale.h ../../core/plugin.h ../../core/pluginmsg.h
init.o: ../../core/log.h ../../core/system.h ../../core/dirs.h
init.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
init.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
init.o: ../../db/dbitemquery.h ../../core/item.h ../../db/dbitemcolumns.h
init.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
init.o: ../../core/ugcontainer.h ../../notify/notify.h
init.o: ../../notify/notifypool.h ../../templates/patterns.h
init.o: ../../templates/locale.h ../../templates/localefilter.h
init.o: ../../../ezc/src/ezc.h ../../../ezc/src/generator.h
init.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
init.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
init.o: ../../notify/notifythread.h ../../core/basethread.h
init.o: ../../core/synchro.h ../../notify/templatesnotify.h
init.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
init.o: ../../core/lastcontainer.h ../../templates/misc.h
init.o: ../../templates/htmltextstream.h ../../core/mounts.h
init.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
init.o: ../../core/users.h ../../core/groups.h ../../core/group.h
init.o: ../../core/loadavg.h ../../core/image.h ../../core/basethread.h
init.o: ../../core/threadmanager.h ../../core/sessionmanager.h
init.o: ../../core/sessioncontainer.h ../../functions/functions.h
init.o: ../../functions/functionbase.h ../../core/request.h
init.o: ../../core/system.h ../../core/synchro.h
init.o: ../../functions/functionparser.h ../../core/cur.h
init.o: ../../functions/adduser.h ../../functions/cat.h
init.o: ../../functions/chmod.h ../../functions/privchanger.h
init.o: ../../functions/chown.h ../../functions/ckeditor.h
init.o: ../../functions/cp.h ../../functions/default.h
init.o: ../../functions/download.h ../../functions/emacs.h
init.o: ../../functions/env.h ../../functions/last.h ../../functions/login.h
init.o: ../../functions/logout.h ../../functions/ln.h ../../functions/ls.h
init.o: ../../functions/man.h ../../functions/meta.h ../../functions/mkdir.h
init.o: ../../functions/mv.h ../../functions/nicedit.h ../../functions/node.h
Kopia templates.o: ../../templates/templates.h ../../../ezc/src/ezc.h
Kopia templates.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
Kopia templates.o: ../../../ezc/src/item.h ../../../ezc/src/funinfo.h
Kopia templates.o: ../../../ezc/src/functions.h ../../../ezc/src/stringconv.h
Kopia templates.o: ../../templates/misc.h ../../templates/localefilter.h
Kopia templates.o: ../../templates/locale.h ../../templates/htmltextstream.h
Kopia templates.o: ../../core/textstream.h ../../templates/patterncacher.h
Kopia templates.o: ../../core/item.h ../../templates/indexpatterns.h
Kopia templates.o: ../../templates/patterns.h
Kopia templates.o: ../../templates/changepatterns.h ../../core/config.h
Kopia templates.o: ../../core/htmlfilter.h ../../core/cur.h
Kopia templates.o: ../../core/request.h ../../core/requesttypes.h
Kopia templates.o: ../../core/error.h ../../core/config.h
Kopia templates.o: ../../core/textstream.h ../../templates/htmltextstream.h
Kopia templates.o: ../../core/session.h ../../core/user.h
Kopia templates.o: ../../core/plugindata.h ../../core/rebus.h
Kopia templates.o: ../../core/mount.h ../../core/system.h ../../core/dirs.h
Kopia templates.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
Kopia templates.o: ../../db/dbconn.h ../../db/dbtextstream.h
Kopia templates.o: ../../core/error.h ../../db/dbitemquery.h
Kopia templates.o: ../../db/dbitemcolumns.h ../../core/user.h
Kopia templates.o: ../../core/group.h ../../core/dircontainer.h
Kopia templates.o: ../../core/ugcontainer.h ../../core/log.h
Kopia templates.o: ../../core/logmanipulators.h ../../core/slog.h
Kopia templates.o: ../../core/cur.h ../../templates/locale.h
Kopia templates.o: ../../notify/notify.h ../../notify/notifypool.h
Kopia templates.o: ../../templates/patterns.h ../../notify/notifythread.h
Kopia templates.o: ../../core/basethread.h ../../core/synchro.h
Kopia templates.o: ../../notify/templatesnotify.h ../../core/users.h
Kopia templates.o: ../../core/ugcontainer.h ../../core/lastcontainer.h
Kopia templates.o: ../../templates/misc.h ../../core/mounts.h
Kopia templates.o: ../../core/mountparser.h ../../core/crypt.h
Kopia templates.o: ../../core/run.h ../../core/users.h ../../core/groups.h
Kopia templates.o: ../../core/group.h ../../core/loadavg.h ../../core/image.h
Kopia templates.o: ../../core/basethread.h ../../core/threadmanager.h
Kopia templates.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
Kopia templates.o: ../../core/system.h ../../core/htmlfilter.h
Kopia templates.o: ../../core/plugin.h ../../core/pluginmsg.h
Kopia templates.o: ../../core/sessionmanager.h ../../functions/functions.h
Kopia templates.o: ../../functions/functionbase.h ../../core/request.h
Kopia templates.o: ../../core/synchro.h ../../functions/functionparser.h
Kopia templates.o: ../../functions/adduser.h ../../functions/cat.h
Kopia templates.o: ../../functions/chmod.h ../../functions/privchanger.h
Kopia templates.o: ../../functions/chown.h ../../functions/ckeditor.h
Kopia templates.o: ../../functions/cp.h ../../functions/default.h
Kopia templates.o: ../../functions/download.h ../../functions/emacs.h
Kopia templates.o: ../../functions/env.h ../../functions/last.h
Kopia templates.o: ../../functions/login.h ../../functions/logout.h
Kopia templates.o: ../../functions/ln.h ../../functions/ls.h
Kopia templates.o: ../../functions/man.h ../../functions/meta.h
Kopia templates.o: ../../functions/mkdir.h ../../functions/mv.h
Kopia templates.o: ../../functions/nicedit.h ../../functions/node.h
Kopia templates.o: ../../functions/passwd.h ../../functions/priv.h
Kopia templates.o: ../../functions/reload.h ../../functions/rm.h
Kopia templates.o: ../../functions/sort.h ../../functions/specialdefault.h
Kopia templates.o: ../../functions/stat.h ../../functions/subject.h
Kopia templates.o: ../../functions/template.h ../../functions/tinymce.h
Kopia templates.o: ../../functions/uname.h ../../functions/upload.h
Kopia templates.o: ../../functions/uptime.h ../../functions/who.h
Kopia templates.o: ../../functions/vim.h ../../core/log.h ../../core/misc.h
cache.o: cache.h ../../core/item.h ../../core/dirs.h ../../../ezc/src/item.h
cache.o: ../../../ezc/src/funinfo.h ../../core/dircontainer.h ../../db/db.h
cache.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
cache.o: ../../core/textstream.h ../../templates/misc.h
cache.o: ../../templates/localefilter.h ../../templates/locale.h
cache.o: ../../../ezc/src/ezc.h ../../../ezc/src/generator.h
cache.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
cache.o: ../../../ezc/src/stringconv.h ../../templates/htmltextstream.h
cache.o: ../../core/error.h ../../db/dbitemquery.h ../../db/dbitemcolumns.h
cache.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
cache.o: ../../core/ugcontainer.h ../../core/log.h ../../core/textstream.h
cache.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
cache.o: ../../templates/locale.h ../../core/request.h
cache.o: ../../core/requesttypes.h ../../core/error.h ../../core/config.h
cache.o: ../../templates/htmltextstream.h ../../notify/notify.h
cache.o: ../../notify/notifypool.h ../../templates/patterns.h
cache.o: ../../notify/notifythread.h ../../core/basethread.h
cache.o: ../../core/synchro.h ../../notify/templatesnotify.h
cache.o: ../../core/config.h ../../core/htmlfilter.h ../../core/users.h
cache.o: ../../core/user.h ../../core/ugcontainer.h
cache.o: ../../core/lastcontainer.h ../../templates/misc.h ../../core/misc.h
init.o: ../../core/log.h ../../core/plugin.h ../../core/pluginmsg.h
init.o: ../../core/log.h ../../core/textstream.h ../../core/logmanipulators.h
init.o: ../../core/slog.h ../../core/cur.h ../../templates/locale.h
init.o: ../../core/plugindata.h ../../core/config.h ../../core/request.h
init.o: ../../core/requesttypes.h ../../../ezc/src/item.h
init.o: ../../../ezc/src/funinfo.h ../../core/error.h
init.o: ../../templates/htmltextstream.h ../../core/system.h
init.o: ../../core/sessionmanager.h ../../core/synchro.h
init.o: ../../functions/functions.h ../../functions/functionbase.h
init.o: ../../core/item.h ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h
init.o: ../../db/dbtextstream.h ../../core/textstream.h
init.o: ../../templates/misc.h ../../templates/localefilter.h
init.o: ../../templates/locale.h ../../../ezc/src/ezc.h
init.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
init.o: ../../../ezc/src/functions.h ../../../ezc/src/stringconv.h
init.o: ../../templates/htmltextstream.h ../../core/error.h
init.o: ../../db/dbitemquery.h ../../db/dbitemcolumns.h ../../core/user.h
init.o: ../../core/group.h ../../core/dircontainer.h ../../core/ugcontainer.h
init.o: ../../core/request.h ../../core/config.h ../../core/htmlfilter.h
init.o: ../../core/system.h ../../core/dirs.h ../../core/dircontainer.h
init.o: ../../notify/notify.h ../../notify/notifypool.h
init.o: ../../templates/patterns.h ../../notify/notifythread.h
init.o: ../../core/basethread.h ../../notify/templatesnotify.h
init.o: ../../core/users.h ../../core/user.h ../../core/ugcontainer.h
init.o: ../../core/lastcontainer.h ../../templates/misc.h ../../core/mounts.h
init.o: ../../core/mount.h ../../core/mountparser.h ../../core/crypt.h
init.o: ../../core/run.h ../../core/users.h ../../core/groups.h
init.o: ../../core/group.h ../../core/rebus.h ../../core/loadavg.h
init.o: ../../core/image.h ../../core/basethread.h ../../core/threadmanager.h
init.o: ../../core/synchro.h ../../functions/functionparser.h
init.o: ../../core/cur.h ../../core/session.h ../../functions/adduser.h
init.o: ../../functions/cat.h ../../functions/chmod.h
init.o: ../../functions/privchanger.h ../../functions/chown.h
init.o: ../../functions/ckeditor.h ../../functions/cp.h
init.o: ../../functions/default.h ../../functions/download.h
init.o: ../../functions/emacs.h ../../functions/env.h ../../functions/last.h
init.o: ../../functions/login.h ../../functions/logout.h ../../functions/ln.h
init.o: ../../functions/ls.h ../../functions/man.h ../../functions/meta.h
init.o: ../../functions/mkdir.h ../../functions/mv.h
init.o: ../../functions/nicedit.h ../../functions/node.h
init.o: ../../functions/passwd.h ../../functions/priv.h
init.o: ../../functions/reload.h ../../functions/rm.h ../../functions/sort.h
init.o: ../../functions/specialdefault.h ../../functions/stat.h
@ -51,39 +131,41 @@ init.o: ../../functions/who.h ../../functions/vim.h ../../core/htmlfilter.h
init.o: ../../templates/templates.h ../../templates/patterncacher.h
init.o: ../../templates/indexpatterns.h ../../templates/patterns.h
init.o: ../../templates/changepatterns.h ../../core/sessionmanager.h
init.o: ../../core/sessioncontainer.h cache.h ../../core/dirs.h
templates.o: ../../templates/templates.h ../../../ezc/src/ezc.h
templates.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
templates.o: ../../core/item.h ../../../ezc/src/functions.h
templates.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
templates.o: ../../core/misc.h ../../core/requesttypes.h
templates.o: ../../templates/patterncacher.h ../../core/item.h
templates.o: ../../templates/indexpatterns.h ../../templates/patterns.h
templates.o: ../../templates/locale.h ../../templates/changepatterns.h
templates.o: ../../templates/htmltextstream.h ../../templates/localefilter.h
templates.o: ../../core/config.h ../../core/cur.h ../../core/system.h
templates.o: ../../core/sessionmanager.h ../../core/htmlfilter.h
templates.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h
templates.o: ../../db/dbtextstream.h ../../core/textstream.h
templates.o: ../../core/error.h ../../db/dbitemquery.h
templates.o: ../../db/dbitemcolumns.h ../../core/user.h ../../core/group.h
templates.o: ../../core/dircontainer.h ../../core/ugcontainer.h
templates.o: ../../core/log.h ../../core/plugin.h ../../core/pluginmsg.h
templates.o: ../../core/plugindata.h ../../core/config.h
templates.o: ../../core/htmlfilter.h ../../core/request.h ../../core/error.h
templates.o: ../../core/textstream.h ../../templates/htmltextstream.h
templates.o: ../../core/system.h ../../core/dirs.h ../../core/dircontainer.h
templates.o: ../../notify/notify.h ../../notify/notifypool.h
templates.o: ../../templates/locale.h ../../templates/patterns.h
templates.o: ../../../ezc/src/item.h ../../../ezc/src/funinfo.h
templates.o: ../../../ezc/src/functions.h ../../../ezc/src/stringconv.h
templates.o: ../../templates/misc.h ../../templates/localefilter.h
templates.o: ../../templates/locale.h ../../templates/htmltextstream.h
templates.o: ../../core/textstream.h ../../templates/patterncacher.h
templates.o: ../../core/item.h ../../templates/indexpatterns.h
templates.o: ../../templates/patterns.h ../../templates/changepatterns.h
templates.o: ../../core/config.h ../../core/htmlfilter.h ../../core/cur.h
templates.o: ../../core/request.h ../../core/requesttypes.h
templates.o: ../../core/error.h ../../core/config.h ../../core/textstream.h
templates.o: ../../templates/htmltextstream.h ../../core/session.h
templates.o: ../../core/user.h ../../core/plugindata.h ../../core/rebus.h
templates.o: ../../core/mount.h ../../core/system.h ../../core/dirs.h
templates.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
templates.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
templates.o: ../../db/dbitemquery.h ../../db/dbitemcolumns.h
templates.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
templates.o: ../../core/ugcontainer.h ../../core/log.h
templates.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
templates.o: ../../templates/locale.h ../../notify/notify.h
templates.o: ../../notify/notifypool.h ../../templates/patterns.h
templates.o: ../../notify/notifythread.h ../../core/basethread.h
templates.o: ../../core/synchro.h ../../notify/templatesnotify.h
templates.o: ../../core/users.h ../../core/user.h ../../core/ugcontainer.h
templates.o: ../../core/lastcontainer.h ../../core/cur.h ../../core/session.h
templates.o: ../../core/rebus.h ../../core/mount.h ../../templates/misc.h
templates.o: ../../core/users.h ../../core/ugcontainer.h
templates.o: ../../core/lastcontainer.h ../../templates/misc.h
templates.o: ../../core/mounts.h ../../core/mountparser.h ../../core/crypt.h
templates.o: ../../core/run.h ../../core/users.h ../../core/groups.h
templates.o: ../../core/group.h ../../core/loadavg.h ../../core/image.h
templates.o: ../../core/basethread.h ../../core/threadmanager.h
templates.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
templates.o: ../../core/system.h ../../core/htmlfilter.h ../../core/plugin.h
templates.o: ../../core/pluginmsg.h ../../core/sessionmanager.h
templates.o: ../../functions/functions.h ../../functions/functionbase.h
templates.o: ../../core/request.h ../../core/synchro.h
templates.o: ../../functions/functionparser.h ../../functions/adduser.h
@ -105,4 +187,4 @@ templates.o: ../../functions/subject.h ../../functions/template.h
templates.o: ../../functions/tinymce.h ../../functions/uname.h
templates.o: ../../functions/upload.h ../../functions/uptime.h
templates.o: ../../functions/who.h ../../functions/vim.h ../../core/log.h
templates.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/misc.h
templates.o: ../../core/misc.h cache.h ../../core/dirs.h

View File

@ -1 +1 @@
o = init.o templates.o
o = Kopia templates.o cache.o init.o templates.o

96
plugins/menu/cache.cpp Executable file
View File

@ -0,0 +1,96 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "cache.h"
#include "core/misc.h"
namespace Menu
{
void Cache::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
CacheItem * Cache::Get(long dir_id, int param)
{
Tab::iterator i;
for(i=tab.begin() ; i!=tab.end() ; ++i)
{
if( i->dir_id == dir_id && i->param == param )
{
return &(*i);
}
}
return 0;
}
CacheItem * Cache::Insert(long dir_id, int param)
{
empty_cache_item.dir_id = dir_id;
empty_cache_item.param = param;
empty_cache_item.menu_items.clear();
if( !dirs->MakePath(dir_id, empty_cache_item.dir) )
empty_cache_item.dir.clear();
NoLastSlash(empty_cache_item.dir);
tab.push_back(empty_cache_item);
return &tab.back();
}
void Cache::Remove(long dir_id)
{
Tab::iterator i;
for(i=tab.begin() ; i!=tab.end() ; )
{
if( i->dir_id == dir_id )
{
tab.erase(i++);
}
else
{
++i;
}
}
}
void Cache::Clear()
{
tab.clear();
}
} // namespace

75
plugins/menu/cache.h Executable file
View File

@ -0,0 +1,75 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_menu_cache
#define headerfile_winix_plugins_menu_cache
#include <string>
#include <vector>
#include <list>
#include "core/item.h"
#include "core/dirs.h"
namespace Menu
{
struct MenuItem
{
long id; // item id
std::wstring url;
std::wstring subject;
Item::Type type;
int file_type;
};
struct CacheItem
{
long dir_id;
int param;
std::vector<MenuItem> menu_items;
std::wstring dir; // without the last slash
CacheItem()
{
dir_id = -1;
param = -1;
}
};
class Cache
{
public:
void SetDirs(Dirs * pdirs);
CacheItem * Get(long dir_id, int param);
CacheItem * Insert(long dir_id, int param);
void Remove(long dir_id);
void Clear();
private:
Dirs * dirs;
typedef std::list<CacheItem> Tab;
Tab tab;
CacheItem empty_cache_item;
};
} // namespace
#endif

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* Copyright (c) 2011-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -10,7 +10,7 @@
#include "core/log.h"
#include "core/plugin.h"
#include "cache.h"
extern "C" void Init(PluginInfo &);
@ -24,7 +24,7 @@ namespace Menu
const wchar_t plugin_name[] = L"menu";
int mount_par_menu_skip = -1;
Cache cache;
void AddMountParams(PluginInfo & info)
@ -53,6 +53,36 @@ void FstabChanged(PluginInfo & info)
*/
}
void InvalidateCache(long dir_id)
{
log << log4 << "Menu: removing cache for dir id: " << dir_id << logend;
cache.Remove(dir_id);
}
void InvalidateCacheByPointerParent(PluginInfo & info)
{
Item * pitem = reinterpret_cast<Item*>(info.p1);
if( pitem )
InvalidateCache(pitem->parent_id);
}
void InvalidateCacheByPointer(PluginInfo & info)
{
Item * pitem = reinterpret_cast<Item*>(info.p1);
if( pitem )
InvalidateCache(pitem->id);
}
void InvalidateCacheById(PluginInfo & info)
{
InvalidateCache(info.l1);
}
void AddEzcFunctions(PluginInfo & info);
@ -67,10 +97,26 @@ void Init(PluginInfo & info)
{
using namespace Menu;
cache.SetDirs(&info.system->dirs);
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
plugin.Assign(WINIX_ADD_MOUNTS, AddMountParams);
plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
// !! IMPROVE ME
// use modify parameter from a directory
// (not implemented yet)
plugin.Assign(WINIX_FILE_REMOVED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_DIR_ADDED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_DIR_PREPARE_TO_REMOVE, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_DIR_REMOVED, InvalidateCacheById);
plugin.Assign(WINIX_FILE_ADDED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_FILE_CHANGED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_FILE_COPIED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_FILE_PREPARE_TO_MOVE, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_FILE_MOVED, InvalidateCacheByPointerParent);
plugin.Assign(WINIX_DIR_CONTENT_SORTED, InvalidateCacheByPointer);
info.p1 = (void*)(plugin_name);
}

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* Copyright (c) 2011-2012, Tomasz Sowa
* All rights reserved.
*
*/
@ -12,113 +12,107 @@
#include "core/item.h"
#include "core/log.h"
#include "core/misc.h"
#include "cache.h"
// !! temporarily
template<class Key1, class Key2, class Value>
class Stack
{
public:
typedef Key1 StackKey1;
typedef Key2 StackKey2;
typedef Value StackValue;
struct Item
{
StackKey1 key1;
StackKey2 key2;
StackValue value;
};
Stack()
{
added_new = false;
}
StackValue * Get(const StackKey1 & key1, const StackKey2 & key2)
{
for(size_t i=0 ; i<tab.size() ; ++i)
{
if( tab[i].key1 == key1 && tab[i].key2 == key2 )
{
added_new = false;
return &tab[i].value;
}
}
// there is no such an element in our table
// so we add a new item
tab.push_back(Item());
tab.back().key1 = key1;
tab.back().key2 = key2;
added_new = true;
return &tab.back().value;
}
/*
returning true if Get() method has inserted a new Item
*/
bool AddedNew()
{
return added_new;
}
void Clear()
{
tab.clear();
}
private:
std::vector<Item> tab;
bool added_new;
};
#define WINIX_PL_MENU_PARAM_NONE 0
#define WINIX_PL_MENU_PARAM_IMAGES 1
#define WINIX_PL_MENU_PARAM_DIRS 2
#define WINIX_PL_MENU_PARAM_FILES 3
namespace Menu
{
using namespace TemplatesFunctions;
using TemplatesFunctions::system;
extern int mount_par_menu_skip;
extern Cache cache;
static DbItemQuery iq;
static std::vector<Item> item_tab;
static MenuItem menu_item;
struct MenuDir
struct StackItem : public Ezc::FunData
{
std::vector<Item> items;
size_t index;
std::wstring dir;
CacheItem * citem;
MenuDir()
StackItem(CacheItem * ci)
{
index = 0;
citem = ci;
}
};
static MenuDir * menu_dir = 0;
static DbItemQuery iq;
static Stack<std::wstring, std::wstring, MenuDir> menu_dir_stack;
static size_t req_id = 0;
static std::wstring strempty;
// warning: O(n^2) complexity
void menu_dir_skip_items(long parent_id)
int string_to_param(const std::wstring & param, bool use_log = true)
{
Mount * m = system->mounts.CalcMount(parent_id);
if( param == L"images" )
return WINIX_PL_MENU_PARAM_IMAGES;
else
if( param == L"dirs" )
return WINIX_PL_MENU_PARAM_DIRS;
else
if( param == L"files" )
return WINIX_PL_MENU_PARAM_FILES;
else
if( !param.empty() )
{
if( use_log )
log << log1 << "Menu: unknown parameter: " << param << logend;
}
return WINIX_PL_MENU_PARAM_NONE;
}
void read_from_db(long dir_id, int param)
{
iq.SetAll(false, false);
iq.sel_subject = true;
iq.sel_url = true;
iq.sel_sort_index = true;
iq.sel_type = true;
iq.sel_file = true;
iq.WhereParentId(dir_id);
if( param == WINIX_PL_MENU_PARAM_IMAGES )
{
iq.WhereType(Item::file);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
}
else
if( param == WINIX_PL_MENU_PARAM_DIRS )
{
iq.WhereType(Item::dir);
}
else
if( param == WINIX_PL_MENU_PARAM_FILES )
{
iq.WhereType(Item::file);
}
db->GetItems(item_tab, iq);
log << log4 << "Menu: loaded directories/files from the database for parent_id: "
<< dir_id << logend;
}
// !! IMPROVE ME
// O(n^2) complexity
void skip_mount_items(CacheItem & citem)
{
Mount * m = system->mounts.CalcMount(citem.dir_id);
if( !m || mount_par_menu_skip==-1 || !m->param[mount_par_menu_skip].defined )
return;
@ -127,10 +121,10 @@ void menu_dir_skip_items(long parent_id)
for(size_t i=0 ; i<arg.size() ; ++i)
{
for(size_t x=0 ; x<menu_dir->items.size() ; )
for(size_t x=0 ; x<citem.menu_items.size() ; )
{
if( menu_dir->items[x].url == arg[i] )
menu_dir->items.erase(menu_dir->items.begin() + x);
if( citem.menu_items[x].url == arg[i] )
citem.menu_items.erase(citem.menu_items.begin() + x);
else
x += 1;
}
@ -138,141 +132,154 @@ void menu_dir_skip_items(long parent_id)
}
void menu_dir_skip_static_files()
void skip_static_files(CacheItem & citem)
{
for(size_t x=0 ; x<menu_dir->items.size() ; )
for(size_t x=0 ; x<citem.menu_items.size() ; )
{
if( menu_dir->items[x].type == Item::file && menu_dir->items[x].file_type != WINIX_ITEM_FILETYPE_NONE )
menu_dir->items.erase(menu_dir->items.begin() + x);
if( citem.menu_items[x].type == Item::file && citem.menu_items[x].file_type != WINIX_ITEM_FILETYPE_NONE )
citem.menu_items.erase(citem.menu_items.begin() + x);
else
x += 1;
}
}
void menu_dir_load_menu(long parent_id, const std::wstring & arg)
void copy_items(CacheItem & citem)
{
iq.SetAll(false, false);
iq.sel_subject = true;
iq.sel_url = true;
iq.sel_sort_index = true;
iq.sel_type = true;
iq.sel_file = true;
iq.WhereParentId(parent_id);
size_t new_size = citem.menu_items.size() + item_tab.size();
if( arg == L"images" )
{
iq.WhereType(Item::file);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
}
else
if( arg == L"dirs" )
{
iq.WhereType(Item::dir);
}
else
if( arg == L"files" )
{
iq.WhereType(Item::file);
}
else
if( arg == L"" )
{
}
else
{
log << log1 << "Menu: unknown parameter: " << arg << logend;
}
if( new_size > citem.menu_items.capacity() )
citem.menu_items.reserve(new_size);
for(size_t i=0 ; i < item_tab.size() ; ++i)
{
menu_item.id = item_tab[i].id;
menu_item.subject = item_tab[i].subject;
menu_item.url = item_tab[i].url;
menu_item.type = item_tab[i].type;
menu_item.file_type = item_tab[i].file_type;
db->GetItems(menu_dir->items, iq);
menu_dir_skip_items(parent_id);
// !! FIXME: in the future is better to have DbItemQuery with a special option
// that skips static files
if( arg == L"" )
menu_dir_skip_static_files();
// !! temporarily for debug purposes
log << log1 << "Menu: db used" << logend;
citem.menu_items.push_back(menu_item);
}
}
void menu_dir_init(const std::wstring & path, const std::wstring & arg)
{
menu_dir = menu_dir_stack.Get(path, arg);
if( menu_dir_stack.AddedNew() )
void menu_dir_init(Info & i, long dir_id, int param)
{
CacheItem * citem = cache.Get(dir_id, param);
if( !citem )
{
if( path.empty() )
read_from_db(dir_id, param);
citem = cache.Insert(dir_id, param);
copy_items(*citem);
skip_mount_items(*citem);
if( param == WINIX_PL_MENU_PARAM_NONE )
skip_static_files(*citem);
}
i.fun_data = new StackItem(citem);
}
void menu_dir_init(Info & i, const std::wstring & dir, int param)
{
Item * pdir = system->dirs.GetDir(dir);
if( pdir )
{
menu_dir_init(i, pdir->id, param);
}
else
{
log << log1 << "Menu: there is not such a directory: " << dir << logend;
}
}
void menu_dir_init(Info & i)
{
int param = WINIX_PL_MENU_PARAM_NONE;
if( i.params.size() >= 2 )
param = string_to_param(i.params[1]);
if( !i.params.empty() )
{
if( i.params[0] == L"current" )
{
// current directory
menu_dir_load_menu(cur->request->dir_tab.back()->id, arg);
system->dirs.MakePath(cur->request->dir_tab, menu_dir->dir);
if( i.last_fun_data )
{
StackItem * previous_sitem = reinterpret_cast<StackItem*>(i.last_fun_data);
if( i.last_iter < previous_sitem->citem->menu_items.size() )
menu_dir_init(i, previous_sitem->citem->menu_items[i.last_iter].id, param);
}
}
else
if( !i.params[0].empty() && i.params[0][0] != '/' )
{
log << log1 << "Menu: path for a menu should not be relative" << logend;
return;
}
else
{
menu_dir->dir = path;
Item * pdir = system->dirs.GetDir(path);
if( pdir )
menu_dir_load_menu(pdir->id, arg);
else
log << log1 << "Menu: I cannot find a directory: " << path << logend;
menu_dir_init(i, i.params[0], param);
}
}
else
{
menu_dir_init(i, cur->request->dir_tab.back()->id, param);
}
}
void menu_dir_init(const std::vector<std::wstring> & params)
{
if( cur->request->id != req_id )
{
menu_dir_stack.Clear();
menu_dir = 0;
req_id = cur->request->id;
}
if( !params.empty() && !params[0].empty() && params[0][0] != '/' )
{
log << log1 << "Menu: path for a menu should not be relative" << logend;
return;
}
strempty.clear(); // for safety
if( params.empty() )
menu_dir_init(strempty, strempty);
else
if( params.size() == 1 )
menu_dir_init(params[0], strempty);
else
menu_dir_init(params[0], params[1]);
}
void menu_dir_tab(Info & i)
{
menu_dir_init(i.params);
if( !i.fun_data )
menu_dir_init(i);
menu_dir->index = i.iter;
i.res = menu_dir->index < menu_dir->items.size();
if( i.fun_data )
{
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
i.res = (i.iter < sitem->citem->menu_items.size());
}
}
void menu_dir_tab_subject(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.out << menu_dir->items[menu_dir->index].subject;
if( i.fun_data )
{
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.out << sitem->citem->menu_items[i.last_iter].subject;
}
}
void menu_dir_tab_url(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.out << menu_dir->items[menu_dir->index].url;
if( i.fun_data )
{
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.out << sitem->citem->menu_items[i.last_iter].url;
}
}
@ -281,14 +288,25 @@ void menu_dir_tab_url(Info & i)
void menu_dir_tab_link(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
if( i.fun_data )
{
i.out << menu_dir->dir;
if( !IsLastSlash(menu_dir->dir) )
i.out << '/';
i.out << menu_dir->items[menu_dir->index].url;
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.out << sitem->citem->dir << '/'
<< sitem->citem->menu_items[i.last_iter].url;
}
}
void menu_dir_tab_is_dir(Info & i)
{
if( i.fun_data )
{
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.res = (sitem->citem->menu_items[i.last_iter].type == Item::dir);
}
}
@ -296,9 +314,12 @@ void menu_dir_tab_link(Info & i)
void menu_dir_tab_is_current(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
if( i.fun_data )
{
i.res = (menu_dir->items[menu_dir->index].id == cur->request->last_item->id);
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.res = (sitem->citem->menu_items[i.last_iter].id == cur->request->last_item->id);
}
}
@ -308,8 +329,13 @@ void menu_dir_tab_is_current(Info & i)
// returning true if the dir tab element is a first parent for current item
void menu_dir_tab_is_first_parent_for_current_item(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.res = (menu_dir->items[menu_dir->index].id == cur->request->last_item->parent_id);
if( i.fun_data )
{
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( i.last_iter < sitem->citem->menu_items.size() )
i.res = (sitem->citem->menu_items[i.last_iter].id == cur->request->last_item->parent_id);
}
}
@ -317,22 +343,27 @@ void menu_dir_tab_is_first_parent_for_current_item(Info & i)
// (it don't have to be the first parent - it can be a descendant)
void menu_dir_tab_is_parent_for_current_item(Info & i)
{
if( menu_dir && menu_dir->index < menu_dir->items.size() )
if( i.fun_data )
{
size_t len = cur->request->dir_tab.size(); // at least one
StackItem * sitem = reinterpret_cast<StackItem*>(i.fun_data);
if( !cur->request->is_item )
if( i.last_iter < sitem->citem->menu_items.size() )
{
// the last item is a directory so we don't get it into account
len -= 1;
}
size_t len = cur->request->dir_tab.size(); // at least one
for(size_t a=0 ; a<len ; ++a)
{
if( menu_dir->items[menu_dir->index].id == cur->request->dir_tab[a]->id )
if( !cur->request->is_item )
{
i.res = true;
break;
// the last item is a directory so we don't get it into account
len -= 1;
}
for(size_t a=0 ; a<len ; ++a)
{
if( sitem->citem->menu_items[i.last_iter].id == cur->request->dir_tab[a]->id )
{
i.res = true;
break;
}
}
}
}
@ -346,11 +377,12 @@ void AddEzcFunctions(PluginInfo & info)
using TemplatesFunctions::EzcFun;
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
fun->Insert("menu_dir_tab", menu_dir_tab);
fun->Insert("menu_dir_tab_subject", menu_dir_tab_subject);
fun->Insert("menu_dir_tab_url", menu_dir_tab_url);
fun->Insert("menu_dir_tab_link", menu_dir_tab_link);
fun->Insert("menu_dir_tab_is_current", menu_dir_tab_is_current);
fun->Insert("menu_dir_tab", menu_dir_tab);
fun->Insert("menu_dir_tab_subject", menu_dir_tab_subject);
fun->Insert("menu_dir_tab_url", menu_dir_tab_url);
fun->Insert("menu_dir_tab_link", menu_dir_tab_link);
fun->Insert("menu_dir_tab_is_dir", menu_dir_tab_is_dir);
fun->Insert("menu_dir_tab_is_current", menu_dir_tab_is_current);
fun->Insert("menu_dir_tab_is_first_parent_for_current_item", menu_dir_tab_is_first_parent_for_current_item);
fun->Insert("menu_dir_tab_is_parent_for_current_item", menu_dir_tab_is_parent_for_current_item);
}

View File

@ -429,11 +429,7 @@ void tickets_tab_conf_tab(Info & i)
if( tickets_value.is_ticket )
{
if( !i.is_for || i.is_for_first_iter )
conf_index = 0;
else
conf_index += 1;
conf_index = i.iter;
PT::Space & space = *ticket_info.cur_conf;
while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" )
@ -522,11 +518,7 @@ void ticket_tab(Info & i)
ticket_tab_check_reqid();
value.Clear();
if( !i.is_for || i.is_for_first_iter )
conf_index = 0;
else
conf_index += 1;
conf_index = i.iter;
PT::Space & space = *ticket_info.cur_conf;
while( conf_index < space.spaces.size() && space.spaces[conf_index]->name != L"param" )
@ -622,11 +614,7 @@ void ticket_tab_select_tab(Info & i)
if( value.is_param )
{
if( !i.is_for || i.is_for_first_iter )
select_index = 0;
else
select_index += 1;
select_index = i.iter;
PT::Space & sp = *value.config_par;
while( select_index < sp.spaces.size() && sp.spaces[select_index]->name != L"option" )
@ -711,16 +699,11 @@ void ticket_tab_file_tab(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
if( !i.is_for || i.is_for_first_iter )
{
ticket_file_index = 0;
ticket_file_number = 0;
}
else
{
ticket_file_index += 1;
}
ticket_file_index = i.iter;
if( i.iter == 0 )
ticket_file_number = 0;
PT::Space & mt = *value.value_meta;
while( ticket_file_index < mt.spaces.size() && mt.spaces[ticket_file_index]->name != L"file" )
@ -728,7 +711,7 @@ void ticket_tab_file_tab(Info & i)
i.res = (ticket_file_index < mt.spaces.size());
if( i.res && i.is_for && i.iter > 0 )
if( i.res && i.iter > 0 )
ticket_file_number += 1;
}
}

View File

@ -49,7 +49,7 @@ void man_winixfun_tab(Info & i)
void man_winixfun_tab_index(Info & i)
{
i.out << (i.iter+1);
i.out << (i.last_iter+1);
}
@ -95,7 +95,7 @@ void man_ezcfun_tab(Info & i)
void man_ezcfun_tab_index(Info & i)
{
i.out << (i.iter+1);
i.out << (i.last_iter+1);
}