changed: plugin messages:

WINIX_FILE_REMOVED and WINIX_DIR_PREPARE_TO_REMOVE
         now as a parameter we have a pointer to the Item struct
changed: export plugin now exports all files from a directory
         (in the future there'll be an option how the plugin should behave)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@772 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-09-30 01:33:42 +00:00
parent 9dae2de2fa
commit c7b6ca67a2
13 changed files with 172 additions and 85 deletions

View File

@ -57,8 +57,7 @@
#define WINIX_CLOSE 3004
// a file or symlink was removed (rm function)
// PluginInfo::l1 is the file (item) id
// !! moze zmienic nazwe i dodac symlink w nazwie?
// in p1 you have a pointer to the Item struct (old file)
#define WINIX_FILE_REMOVED 3005
// directory was removed (rm function)
@ -66,7 +65,7 @@
#define WINIX_DIR_REMOVED 3006
// preparing to remove a directory (rm function)
// PluginInfo::l1 is the dir id
// in p1 you have a pointer to the Item struct (directory)
#define WINIX_DIR_PREPARE_TO_REMOVE 3007
// winix is initialized,
@ -121,26 +120,24 @@
// not every fields of Item struct are filled
#define WINIX_FILE_MOVED 3019
// a thumbnail was created
// this message is called from another thread
// the thread is called Lock() before sending this message
// in p1 you have a pointer to the Item struct
#define WINIX_CREATED_THUMB 3020
#define WINIX_CREATED_THUMB 3050
// an image has been resized
// this message is called from another thread
// the thread is called Lock() before sending this message
// in p1 you have a pointer to the Item struct
#define WINIX_IMAGE_RESIZED 3022
#define WINIX_IMAGE_RESIZED 3052
// content of a directory was sorted
// (winix 'sort' function was used)
// in p1 you have a pointer to the Item struct (of the directory)
// this is from system->dirs so you should not change the item
#define WINIX_DIR_CONTENT_SORTED 3030
#define WINIX_DIR_CONTENT_SORTED 3050
// here you add your own html templates

View File

@ -121,14 +121,10 @@ void Rm::RemoveStaticFile(Item & item)
if( RemoveStaticFile(path) )
{
if( item.has_thumb && system->MakeFilePath(item, path, true) )
{
RemoveStaticFile(path);
item.has_thumb = false;
}
// we don't store it to db (it will be removed or is removed already)
item.file_path.clear();
item.file_type = WINIX_ITEM_FILETYPE_NONE;
// we don't change item.file_path and others file_* variables
// they can be used by a plugin
}
}
else
@ -141,8 +137,6 @@ void Rm::RemoveStaticFile(Item & item)
void Rm::RemoveFileOrSymlink(Item & item)
{
plugin.Call(5000, &item); // !! dodac do pluginmsg.h
if( db->DelItem(item) == WINIX_ERR_OK )
{
if( item.type == Item::file )
@ -153,10 +147,11 @@ void Rm::RemoveFileOrSymlink(Item & item)
log << item.url << logend;
TemplatesFunctions::pattern_cacher.DeletePattern(item);
plugin.Call(WINIX_FILE_REMOVED, item.id);
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
RemoveStaticFile(item);
plugin.Call(WINIX_FILE_REMOVED, &item);
}
}
@ -189,14 +184,14 @@ void Rm::RemoveDirTree(long dir_id)
for( ; p != system->dirs.ParentEnd() ; p = pnext )
{
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, &(*p->second));
// this iterator p will be deleted by the next DeleteDir(p->second->id)
// (the next iterator we must calculate beforehand)
pnext = system->dirs.NextChild(p);
RemoveDirTree(p->second->id);
}
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, dir_id);
content_dir_iq.WhereParentId(dir_id);
db->GetItems(content_item_tab, content_dir_iq);
@ -214,9 +209,13 @@ void Rm::RemoveDirTree(long dir_id)
void Rm::RemoveDir(const Item & dir)
{
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, const_cast<Item*>(&dir));
old_url = dir.url;
RemoveDirTree(dir.id);
// warning: 'dir' has been deleted so don't use the 'dir' reference
if( cur->request->status == WINIX_ERR_OK )
log << log3 << "Rm: removed directory " << old_url << logend;
}

View File

@ -1,29 +1,29 @@
# DO NOT DELETE
db.o: db.h ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
db.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h
db.o: ../../core/requesttypes.h ../../core/error.h export.h ../../core/dirs.h
db.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
db.o: ../../db/dbitemquery.h ../../core/item.h ../../db/dbitemcolumns.h
db.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
db.o: ../../core/ugcontainer.h ../../core/log.h ../../core/textstream.h
db.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
db.o: ../../core/request.h ../../core/error.h ../../core/config.h
db.o: ../../core/confparser.h ../../core/htmlfilter.h
db.o: ../../templates/htmltextstream.h ../../core/session.h ../../core/user.h
db.o: ../../core/plugindata.h ../../core/rebus.h ../../core/mount.h
db.o: ../../templates/locale.h ../../core/confparser.h ../../notify/notify.h
db.o: ../../notify/notifypool.h ../../templates/patterns.h
db.o: ../../templates/locale.h ../../templates/localefilter.h
db.o: ../../../ezc/src/ezc.h ../../../ezc/src/utf8.h
db.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
db.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
db.o: ../../../ezc/src/stringconv.h ../../notify/notifythread.h
db.o: ../../core/basethread.h ../../core/synchro.h
db.o: ../../notify/templatesnotify.h ../../core/config.h ../../core/users.h
db.o: ../../core/ugcontainer.h ../../core/lastcontainer.h
db.o: ../../templates/misc.h ../../templates/htmltextstream.h
db.o: ../../core/log.h
edb.o: edb.h ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
edb.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h
edb.o: ../../core/requesttypes.h ../../core/error.h export.h
edb.o: ../../core/dirs.h ../../core/dircontainer.h ../../db/db.h
edb.o: ../../db/dbbase.h ../../db/dbitemquery.h ../../core/item.h
edb.o: ../../db/dbitemcolumns.h ../../core/user.h ../../core/group.h
edb.o: ../../core/dircontainer.h ../../core/ugcontainer.h ../../core/log.h
edb.o: ../../core/textstream.h ../../core/logmanipulators.h ../../core/slog.h
edb.o: ../../core/cur.h ../../core/request.h ../../core/error.h
edb.o: ../../core/config.h ../../core/confparser.h ../../core/htmlfilter.h
edb.o: ../../templates/htmltextstream.h ../../core/session.h
edb.o: ../../core/user.h ../../core/plugindata.h ../../core/rebus.h
edb.o: ../../core/mount.h ../../templates/locale.h ../../core/confparser.h
edb.o: ../../notify/notify.h ../../notify/notifypool.h
edb.o: ../../templates/patterns.h ../../templates/locale.h
edb.o: ../../templates/localefilter.h ../../../ezc/src/ezc.h
edb.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
edb.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
edb.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
edb.o: ../../notify/notifythread.h ../../core/basethread.h
edb.o: ../../core/synchro.h ../../notify/templatesnotify.h
edb.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
edb.o: ../../core/lastcontainer.h ../../templates/misc.h
edb.o: ../../templates/htmltextstream.h ../../core/log.h
exportinfo.o: ../../core/log.h exportinfo.h ../../core/system.h
exportinfo.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h
exportinfo.o: ../../db/db.h ../../db/dbbase.h ../../db/dbitemquery.h
@ -53,7 +53,7 @@ exportinfo.o: ../../templates/htmltextstream.h ../../core/mounts.h
exportinfo.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
exportinfo.o: ../../core/users.h ../../core/groups.h ../../core/group.h
exportinfo.o: ../../core/loadavg.h ../../core/image.h ../../core/basethread.h
exportinfo.o: ../../core/threadmanager.h export.h db.h ../../db/dbbase.h
exportinfo.o: ../../core/threadmanager.h export.h edb.h ../../db/dbbase.h
exportinfo.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
exportinfo.o: ../../core/dirs.h message.h exportthread.h
exportthread.o: exportthread.h ../../core/basethread.h ../../core/synchro.h
@ -111,6 +111,6 @@ 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: exportthread.h message.h exportinfo.h export.h db.h ../../db/dbbase.h
init.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
init.o: ../../core/dirs.h
init.o: exportthread.h message.h exportinfo.h export.h edb.h
init.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
init.o: ../../core/error.h ../../core/dirs.h

View File

@ -1 +1 @@
o = db.o exportinfo.o exportthread.o init.o
o = edb.o exportinfo.o exportthread.o init.o

View File

@ -7,21 +7,21 @@
*
*/
#include "db.h"
#include "edb.h"
#include "core/log.h"
namespace Export
{
void Db::SetDirs(Dirs * pdirs)
void EDb::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
void Db::SetExportCols(PGresult * r)
void EDb::SetExportCols(PGresult * r)
{
cid = AssertColumn(r, "id");
cuser_id = AssertColumn(r, "user_id");
@ -40,7 +40,7 @@ void Db::SetExportCols(PGresult * r)
}
void Db::SetExportValues(PGresult * r, int row, Export & exp)
void EDb::SetExportValues(PGresult * r, int row, Export & exp)
{
exp.Clear();
@ -65,7 +65,7 @@ void Db::SetExportValues(PGresult * r, int row, Export & exp)
bool Db::GetExport(long user_id, std::vector<Export> & export_tab, bool clear_tab)
bool EDb::GetExport(long user_id, std::vector<Export> & export_tab, bool clear_tab)
{
if( clear_tab )
export_tab.clear();
@ -106,7 +106,7 @@ return result;
bool Db::GetExport(long id, Export & exp)
bool EDb::GetExport(long id, Export & exp)
{
exp.Clear();
PGresult * r = 0;
@ -142,7 +142,7 @@ return result;
bool Db::GetExportDirs(std::vector<ExportDir> & export_tab, bool clear_tab)
bool EDb::GetExportDirs(std::vector<ExportDir> & export_tab, bool clear_tab)
{
if( clear_tab )
export_tab.clear();

View File

@ -7,8 +7,8 @@
*
*/
#ifndef headerfile_winix_plugins_export_db
#define headerfile_winix_plugins_export_db
#ifndef headerfile_winix_plugins_export_edb
#define headerfile_winix_plugins_export_edb
#include <vector>
#include "db/dbbase.h"
@ -22,7 +22,7 @@ namespace Export
class Db : public DbBase
class EDb : public DbBase
{
public:

View File

@ -35,6 +35,12 @@ void ExportInfo::SetConfig(Config * pconfig)
}
void ExportInfo::SetEDb(EDb * pdb)
{
edb = pdb;
}
void ExportInfo::SetDb(Db * pdb)
{
db = pdb;
@ -50,7 +56,7 @@ void ExportInfo::SetExportThread(ExportThread * pexport_thread)
void ExportInfo::ReadExportDirs()
{
db->GetExportDirs(export_dirs);
edb->GetExportDirs(export_dirs);
}
@ -151,7 +157,7 @@ void ExportInfo::SendFile(const Item & item, bool thumb)
msg.errors = 0;
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
if( SkipDir(exp_dir->dir_id, msg.path) && edb->GetExport(exp_dir->id, exp) )
{
if( DecodePass(exp) )
{
@ -195,7 +201,7 @@ void ExportInfo::SendDir(const Item & item)
msg.errors = 0;
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
if( SkipDir(exp_dir->dir_id, msg.path) && edb->GetExport(exp_dir->id, exp) )
{
if( DecodePass(exp) )
{
@ -228,6 +234,25 @@ void ExportInfo::SendDir(long dir_id)
}
// send all non-static files from a directory
void ExportInfo::SendAllFilesFromDir(long dir_id)
{
iq_dir.SetAll(false, false);
iq_dir.sel_parent_id = true;
iq_dir.sel_url = true;
iq_dir.sel_file = true;
iq_dir.WhereParentId(dir_id);
iq_dir.WhereType(Item::file);
iq_dir.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(dir_items, iq_dir);
for(size_t i=0 ; i<dir_items.size() ; ++i)
{
SendFile(dir_items[i]);
}
}
} // namespace

View File

@ -11,8 +11,9 @@
#define headerfile_winix_plugins_export_exportinfo
#include "core/system.h"
#include "db/db.h"
#include "export.h"
#include "db.h"
#include "edb.h"
#include "message.h"
#include "exportthread.h"
@ -30,6 +31,7 @@ public:
void SetSystem(System * psystem);
void SetConfig(Config * pconfig);
void SetEDb(EDb * pdb);
void SetDb(Db * pdb);
void SetExportThread(ExportThread * pexport_thread);
@ -43,11 +45,13 @@ public:
void SendFile(const Item & item, bool thumb = false);
void SendDir(const Item & item);
void SendDir(long dir_id);
void SendAllFilesFromDir(long dir_id);
private:
System * system;
Config * config;
EDb * edb;
Db * db;
ExportThread * export_thread;
@ -58,6 +62,8 @@ private:
Export exp;
std::wstring tmp_dir;
std::vector<ExportDir> export_dirs;
DbItemQuery iq_dir;
std::vector<Item> dir_items;
bool SkipDir(long dir_id, std::wstring & dir);

View File

@ -112,7 +112,7 @@ bool end;
end = true;
}
WaitForSignalSleep(5);
WaitForSignalSleep(1);
Unlock();
}
while( !end && !IsExitSignal() );

View File

@ -12,7 +12,7 @@
#include "core/plugin.h"
#include "exportthread.h"
#include "exportinfo.h"
#include "db.h"
#include "edb.h"
@ -28,7 +28,7 @@ namespace Export
const wchar_t plugin_name[] = L"export";
int mount_par_export_conf = -1;
ExportThread export_thread;
Db db;
EDb edb;
ExportInfo export_info;
@ -64,12 +64,15 @@ void SendDir(PluginInfo & info)
const Item * dir = reinterpret_cast<Item*>(info.p1);
if( dir )
{
export_info.SendDir(*dir);
export_info.SendAllFilesFromDir(dir->id);
}
}
void SendFile(PluginInfo & info)
void SendFileAdded(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
@ -84,27 +87,52 @@ void SendFile(PluginInfo & info)
{
export_info.SendFile(*item);
export_info.SendDir(item->parent_id);
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
export_info.SendAllFilesFromDir(item->parent_id);
}
}
}
void SendFileChanged(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
{
export_info.SendFile(*item);
export_info.SendDir(item->parent_id);
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
export_info.SendAllFilesFromDir(item->parent_id);
}
}
void SendFileCopied(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
{
export_info.SendFile(*item);
if( item->file_type != WINIX_ITEM_FILETYPE_NONE )
export_info.SendFile(*item, true);
export_info.SendDir(item->parent_id);
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
{
export_info.SendAllFilesFromDir(item->parent_id);
}
else
{
export_info.SendFile(*item);
export_info.SendFile(*item, true);
}
}
}
void SendFileResized(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
@ -129,6 +157,18 @@ void SendFileThumb(PluginInfo & info)
}
void SendFilePrepareMove(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
{
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
export_info.SendAllFilesFromDir(item->parent_id);
}
}
void FileRemoved(PluginInfo & info)
{
const Item * item = reinterpret_cast<Item*>(info.p1);
@ -136,6 +176,9 @@ void FileRemoved(PluginInfo & info)
if( item )
{
export_info.SendDir(item->parent_id);
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
export_info.SendAllFilesFromDir(item->parent_id);
}
}
@ -164,12 +207,13 @@ void Init(PluginInfo & info)
{
using namespace Export;
db.SetConn(info.db->GetConn());
db.LogQueries(info.config->log_db_query);
db.SetDirs(&info.system->dirs);
edb.SetConn(info.db->GetConn());
edb.LogQueries(info.config->log_db_query);
edb.SetDirs(&info.system->dirs);
export_info.SetSystem(info.system);
export_info.SetConfig(info.config);
export_info.SetDb(&db);
export_info.SetEDb(&edb);
export_info.SetDb(info.db);
export_info.SetExportThread(&export_thread);
@ -178,15 +222,17 @@ using namespace Export;
// plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
plugin.Assign(WINIX_FILE_ADDED, SendFile);
plugin.Assign(WINIX_FILE_CHANGED, SendFileResized);
plugin.Assign(WINIX_FILE_ADDED, SendFileAdded);
plugin.Assign(WINIX_FILE_CHANGED, SendFileChanged);
plugin.Assign(WINIX_CREATED_THUMB, SendFileThumb);
plugin.Assign(WINIX_IMAGE_RESIZED, SendFileResized);
plugin.Assign(WINIX_FILE_PREPARE_TO_MOVE, SendFilePrepareMove);
plugin.Assign(WINIX_FILE_MOVED, SendFileCopied);
plugin.Assign(WINIX_FILE_COPIED, SendFileCopied);
plugin.Assign(WINIX_DIR_CONTENT_SORTED, SendDir);
plugin.Assign(5000, FileRemoved);
plugin.Assign(WINIX_FILE_REMOVED, FileRemoved);
plugin.Assign(WINIX_PROCESS_REQUEST, ProcessRequest);

View File

@ -172,13 +172,19 @@ void Close(PluginInfo & info)
void RemoveFile(PluginInfo & info)
{
stats.RemoveItem(info.l1);
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
stats.RemoveItem(item->id);
}
void RemoveDir(PluginInfo & info)
{
stats.RemoveItem(info.l1);
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
stats.RemoveItem(item->id);
}

View File

@ -72,10 +72,15 @@ void AddMounts(PluginInfo & info)
void RemoveThread(PluginInfo & i)
void RemoveThread(PluginInfo & info)
{
thread_info.RemoveThread(i.l1);
thread_info.RemoveThreadAnswer(i.l1);
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
{
thread_info.RemoveThread(item->id);
thread_info.RemoveThreadAnswer(item->id);
}
}

View File

@ -86,9 +86,12 @@ void ProcessRequest(PluginInfo & info)
void RemoveTicket(PluginInfo & i)
void RemoveTicket(PluginInfo & info)
{
ticket_info.RemoveTicket(i.l1);
const Item * item = reinterpret_cast<Item*>(info.p1);
if( item )
ticket_info.RemoveTicket(item->id);
}