258 lines
4.8 KiB
C++
Executable File
258 lines
4.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
|
|
#include "core/log.h"
|
|
#include "core/plugin.h"
|
|
#include "exportthread.h"
|
|
#include "exportinfo.h"
|
|
#include "edb.h"
|
|
|
|
|
|
|
|
extern "C" void Init(PluginInfo &);
|
|
|
|
|
|
|
|
|
|
namespace Export
|
|
{
|
|
|
|
|
|
const wchar_t plugin_name[] = L"export";
|
|
int mount_par_export_conf = -1;
|
|
ExportThread export_thread;
|
|
EDb edb;
|
|
ExportInfo export_info;
|
|
|
|
|
|
|
|
void AddMountParams(PluginInfo & info)
|
|
{
|
|
using TemplatesFunctions::system;
|
|
|
|
mount_par_export_conf = system->mounts.AddMountPar(L"export_conf");
|
|
}
|
|
|
|
|
|
|
|
void FstabChanged(PluginInfo & info)
|
|
{
|
|
}
|
|
|
|
|
|
|
|
void InitPlugin(PluginInfo & info)
|
|
{
|
|
export_thread.SetUTF8(info.config->utf8);
|
|
export_thread.SetBaseUrl(info.config->base_url);
|
|
|
|
info.system->thread_manager.Add(&export_thread, L"export");
|
|
|
|
export_info.ReadExportDirs();
|
|
}
|
|
|
|
|
|
void SendDir(PluginInfo & info)
|
|
{
|
|
const Item * dir = reinterpret_cast<Item*>(info.p1);
|
|
|
|
if( dir )
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
export_info.SendDir(*dir);
|
|
export_info.SendAllFilesFromDir(dir->id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SendFileAdded(PluginInfo & info)
|
|
{
|
|
const Item * item = reinterpret_cast<Item*>(info.p1);
|
|
|
|
if( item )
|
|
{
|
|
if( item->file_type == WINIX_ITEM_FILETYPE_IMAGE && info.config->image_resize )
|
|
{
|
|
// there'll be a next message WINIX_IMAGE_RESIZED
|
|
log << log4 << "Export: image will be resized, waiting..." << logend;
|
|
}
|
|
else
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
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.ResetRecurrenceCheck();
|
|
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.ResetRecurrenceCheck();
|
|
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);
|
|
|
|
if( item )
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
export_info.SendFile(*item);
|
|
export_info.SendDir(item->parent_id);
|
|
}
|
|
}
|
|
|
|
|
|
void SendFileThumb(PluginInfo & info)
|
|
{
|
|
const Item * item = reinterpret_cast<Item*>(info.p1);
|
|
|
|
if( item )
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
export_info.SendFile(*item, true);
|
|
export_info.SendDir(item->parent_id);
|
|
}
|
|
}
|
|
|
|
|
|
void SendFilePrepareMove(PluginInfo & info)
|
|
{
|
|
const Item * item = reinterpret_cast<Item*>(info.p1);
|
|
|
|
if( item )
|
|
{
|
|
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
export_info.SendAllFilesFromDir(item->parent_id);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void FileRemoved(PluginInfo & info)
|
|
{
|
|
const Item * item = reinterpret_cast<Item*>(info.p1);
|
|
|
|
if( item )
|
|
{
|
|
export_info.ResetRecurrenceCheck();
|
|
export_info.SendDir(item->parent_id);
|
|
|
|
if( item->file_type == WINIX_ITEM_FILETYPE_NONE )
|
|
export_info.SendAllFilesFromDir(item->parent_id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProcessRequest(PluginInfo & info)
|
|
{
|
|
if( info.cur->request->function == &info.functions->fun_reload )
|
|
{
|
|
if( info.cur->request->IsParam(L"export") )
|
|
export_info.ReadExportDirs();
|
|
}
|
|
}
|
|
|
|
|
|
void AddEzcFunctions(PluginInfo & info);
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
void Init(PluginInfo & info)
|
|
{
|
|
using namespace Export;
|
|
|
|
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.SetEDb(&edb);
|
|
export_info.SetDb(info.db);
|
|
export_info.SetExportThread(&export_thread);
|
|
|
|
|
|
// plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
|
|
plugin.Assign(WINIX_ADD_MOUNTS, AddMountParams);
|
|
// plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
|
|
|
|
|
|
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(WINIX_FILE_REMOVED, FileRemoved);
|
|
|
|
plugin.Assign(WINIX_PROCESS_REQUEST, ProcessRequest);
|
|
|
|
plugin.Assign(WINIX_PLUGIN_INIT, InitPlugin);
|
|
|
|
|
|
|
|
|
|
info.p1 = (void*)(plugin_name);
|
|
}
|
|
|
|
|