summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2011-07-21 16:19:39 (GMT)
committer Edwin Eefting <edwin@datux.nl>2011-07-21 16:19:39 (GMT)
commit651796be75a2023283225440eb60c3d45bbb86e2 (patch)
tree78ed28927af1c090955b389f9389bdab1a841e0c
parent8813d2d35a31d3b454d9d259985f5bad2926989c (diff)
parent3750727cca3486a5b754ca56f55860b855cc621f (diff)
Merge branch 'master' of code.dyne.org:synapse
-rw-r--r--modules/http_json.module/module.cpp3
-rw-r--r--modules/paper.module/module.cpp22
-rw-r--r--modules/pl.module/module.cpp212
-rw-r--r--wwwdir/paper/auth_admin.pngbin0 -> 3163 bytes
-rw-r--r--wwwdir/paper/auth_none.pngbin0 -> 670 bytes
-rw-r--r--wwwdir/paper/auth_read.pngbin0 -> 3157 bytes
-rw-r--r--wwwdir/paper/auth_write.pngbin0 -> 3156 bytes
-rw-r--r--wwwdir/paper/edit.html4
-rw-r--r--wwwdir/paper/index.html6
-rw-r--r--wwwdir/paper/paper.js8
-rw-r--r--wwwdir/synapse/synapse-core.js2
-rw-r--r--wwwdir/test.html9
12 files changed, 215 insertions, 51 deletions
diff --git a/modules/http_json.module/module.cpp b/modules/http_json.module/module.cpp
index 50fffc6..3518dce 100644
--- a/modules/http_json.module/module.cpp
+++ b/modules/http_json.module/module.cpp
@@ -15,6 +15,8 @@
You should have received a copy of the GNU General Public License
along with Synapse. If not, see <http://www.gnu.org/licenses/>. */
+//remove this to enable debugging in this module:
+#define NDEBUG
#include "cnetman.h"
#include "synapse.h"
@@ -47,6 +49,7 @@
#include <time.h>
+
/**
Sessions are identified with a authCookie. This cookie is NOT a regular browser cookie, its generated by the server for every java-script instance.
diff --git a/modules/paper.module/module.cpp b/modules/paper.module/module.cpp
index 994c8fa..f19d21f 100644
--- a/modules/paper.module/module.cpp
+++ b/modules/paper.module/module.cpp
@@ -231,6 +231,7 @@ namespace paper
mAuthCursor=false;
mAuthChat=false;
+
}
@@ -601,13 +602,20 @@ namespace paper
if (!getClient(clientId).mAuthOwner)
throw(synapse::runtime_error("Only the owner can change the security settings of this drawing."));
- mDrawing["auth"][key]["view"]=rights["view"];
- mDrawing["auth"][key]["change"]=rights["change"];
- mDrawing["auth"][key]["owner"]=rights["owner"];
- mDrawing["auth"][key]["cursor"]=rights["cursor"];
- mDrawing["auth"][key]["chat"]=rights["chat"];
- if (rights.isSet("description"))
- mDrawing["auth"][key]["description"]=rights["description"];
+ if (rights.map().size()!=0)
+ {
+ mDrawing["auth"][key]["view"]=rights["view"];
+ mDrawing["auth"][key]["change"]=rights["change"];
+ mDrawing["auth"][key]["owner"]=rights["owner"];
+ mDrawing["auth"][key]["cursor"]=rights["cursor"];
+ mDrawing["auth"][key]["chat"]=rights["chat"];
+ if (rights.isSet("description"))
+ mDrawing["auth"][key]["description"]=rights["description"];
+ }
+ else
+ {
+ mDrawing["auth"].map().erase(key);
+ }
mDrawing.changed();
diff --git a/modules/pl.module/module.cpp b/modules/pl.module/module.cpp
index fc4745c..166b20e 100644
--- a/modules/pl.module/module.cpp
+++ b/modules/pl.module/module.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2008,2009,2010 Edwin Eefting (edwin@datux.nl)
+/* Copyright 2008,2009,2010 Edwin Eefting (edwin@datux.nl)
This file is part of Synapse.
@@ -35,6 +35,7 @@ This module can dynamicly generate playlists from directory's. It also can cache
#include "exception/cexception.h"
+#define BOOST_FILESYSTEM_VERSION 3
#include "boost/filesystem.hpp"
@@ -93,12 +94,13 @@ namespace pl
public:
- Cpath()
- :path()
+ Cpath(const path & p)
+ :path(p)
{
mWriteDate=0;
}
+
//get/cache modification date
int getDate()
{
@@ -114,6 +116,8 @@ namespace pl
return(filename());
}
+
+
//get/cache metadata field (from the path database)
std::string getMeta(std::string key)
{
@@ -128,14 +132,16 @@ namespace pl
}
};
- class CsortedDir
+ class CsortedDir: public list<Cpath>
{
private:
path mBasePath;
string mSortField;
public:
- list<Cpath> mPaths;
+ enum Efiletype { FILE, DIR, ALL };
+// list<Cpath> mPaths;
+// list<Cpath>::iterator iterator;
static bool compareFilename (Cpath first, Cpath second)
{
@@ -148,39 +154,44 @@ namespace pl
}
- CsortedDir(path basePath, string sortField)
+ CsortedDir(path basePath, string sortField, Efiletype filetype)
{
mBasePath=basePath;
mSortField=sortField;
- DEB("Reading directory " << basePath);
+ DEB("Reading directory " << basePath.string());
directory_iterator end_itr;
for ( directory_iterator itr( basePath );
itr != end_itr;
++itr )
{
- Cpath p;
- //p=*itr;
- mPaths.push_back(p);
+ path p;
+ p=itr->filename();
+ if (
+ (filetype==ALL) ||
+ (filetype==DIR && is_directory(*itr)) ||
+ (filetype==FILE && is_regular(*itr))
+ )
+ {
+ push_back(p);
+ }
}
if (sortField=="filename")
- mPaths.sort(compareFilename);
+ sort(compareFilename);
else if (sortField=="date")
- mPaths.sort(compareDate);
+ sort(compareDate);
else
throw(synapse::runtime_error("sort mode not implemented yet!"));
-
-
- mPaths.sort(compareFilename);
}
+
};
class Citer
{
private:
- path mBasePath;
+ path mRootPath;
path mCurrentPath;
path mCurrentFile;
@@ -193,18 +204,104 @@ namespace pl
//to make stuff more readable and less error prone
enum Edirection { NEXT, PREVIOUS };
enum Erecursion { RECURSE, DONT_RECURSE };
- enum Efiletype { DIRECTORY, FILE };
+ /*
+ /a/b
+ /a/b/c/d
+ */
//traverses directories/files
- path movePath(path currentPath, string sortField, Edirection direction, Erecursion recursion, Efiletype filetype)
+ //currentPath contains the 'selected' path. direction tells if you want to move up or down.
+ //returns resulting path after this movement. when first or last path is reached it loops.
+ //recursion means, recurse until we're at a file
+ //rootPath is the highest path, it can never be escaped.
+ path movePath(path rootPath, path currentPath, string sortField, Edirection direction, Erecursion recursion, CsortedDir::Efiletype filetype)
{
- //get directory listing of the path
- CsortedDir sortedDir(currentPath,sortField);
+ //determine the path we should get the initial listing of:
+ path listPath;
+ if (currentPath==rootPath)
+ listPath=currentPath;
+ else
+ listPath=currentPath.parent_path();
+
+ CsortedDir::iterator dirI;
+ do
+ {
+ //get sorted directory listing
+ CsortedDir sortedDir(listPath, sortField, filetype);
+
+ //try to find the current path:
+ if (!currentPath.empty())
+ dirI=find(sortedDir.begin(), sortedDir.end(), currentPath.filename());
+ else
+ dirI=sortedDir.end();
+
+ //currentPath not found?
+ if (dirI==sortedDir.end())
+ {
+ //start at the first or last entry depending on direction
+ if (direction==NEXT)
+ dirI=sortedDir.begin();
+ else
+ {
+ dirI=sortedDir.end();
+ dirI--;
+ }
+ }
+ else
+ {
+ //move one step in the correct direction
+ if (direction==NEXT)
+ {
+ dirI++;
+ }
+ //PREVIOUS:
+ else
+ {
+ if (dirI==sortedDir.begin())
+ dirI=sortedDir.end();
+ else
+ dirI--;
+ }
+ }
+
+ //top or bottom was reached
+ if (dirI==sortedDir.end())
+ {
+ //can we one dir higher?
+ if (recursion==RECURSE && listPath!=rootPath)
+ {
+ //yes, so go one dir higher and continue the loop
+ currentPath=listPath;
+ listPath=currentPath.parent_path();
+ }
+ else
+ {
+ //no, cant go higher.
+ //clear the current path, so it just gets the first or last entry
+ currentPath.clear();
+ }
+ }
+ //we found something
+ else
+ {
+ //should we recurse?
+ if (recursion==RECURSE && is_directory(listPath/(*dirI)))
+ {
+ //enter it
+ listPath=listPath/(*dirI);
+ currentPath.clear();
+ }
+ else
+ {
+ return (listPath/(*dirI));
+ }
+ }
+ }
+ while(listPath!=currentPath);
- //find the path
- path p;
- return p;
+ //not found, return currentpath
+ return(currentPath);
}
public:
@@ -212,22 +309,59 @@ namespace pl
//next file
void next()
{
- mCurrentFile=movePath(mCurrentFile,"filename",NEXT,RECURSE,FILE);
+ mCurrentFile=movePath(mCurrentPath, mCurrentFile, "filename", NEXT, RECURSE, CsortedDir::FILE);
}
//prev file
- void prev()
+ void previous()
{
+ mCurrentFile=movePath(mCurrentPath, mCurrentFile,"filename", PREVIOUS, RECURSE, CsortedDir::FILE);
}
- void create(string id, string basePath)
+ void nextDir()
{
- mId=id;
- mBasePath=basePath;
- mCurrentPath=basePath;
- mCurrentFile=basePath;
+ mCurrentPath=movePath(mRootPath, mCurrentPath, "filename", NEXT, DONT_RECURSE, CsortedDir::DIR);
+ mCurrentFile=mCurrentPath;
+ next();
+ }
+
+ void previousDir()
+ {
+ mCurrentPath=movePath(mRootPath, mCurrentPath, "filename", PREVIOUS, DONT_RECURSE, CsortedDir::DIR);
+ mCurrentFile=mCurrentPath;
+ previous();
+ }
+
+ void exitDir()
+ {
+ if (mCurrentPath!=mRootPath)
+ {
+ mCurrentPath=mCurrentPath.parent_path();
+ mCurrentFile=mCurrentPath;
+ next();
+ }
+ }
+
+ void enterDir()
+ {
+// mCurrentPath=movePath(mRootPath, mCurrentPath,"filename",NEXT,DONT_RECURSE);
+ mCurrentFile=mCurrentPath;
next();
-// reset();
+ }
+
+ void reset()
+ {
+ mCurrentPath=mRootPath;
+ mCurrentFile=mRootPath;
+ next();
+ }
+
+ void create(string id, string rootPath)
+ {
+ mId=id;
+ mRootPath=rootPath;
+ DEB("Created iterator " << id << " for path " << rootPath);
+ reset();
}
@@ -237,8 +371,9 @@ namespace pl
out.event="pl_Entry";
out.dst=dst;
out["id"]=mId;
- out["basePath"]=mBasePath.directory_string();
+ out["rootPath"]=mRootPath.directory_string();
out["currentPath"]=mCurrentPath.directory_string();
+ out["currentFile"]=mCurrentFile.directory_string();
// if (*mIterDir!= directory_iterator())
// out["selectedDir"]=(*mIterDir)->path().directory_string();
@@ -350,6 +485,8 @@ namespace pl
*/
SYNAPSE_REGISTER(pl_NextDir)
{
+ iterMan.get(msg["id"]).nextDir();
+ iterMan.get(msg["id"]).send(msg.src);
}
@@ -361,7 +498,8 @@ namespace pl
*/
SYNAPSE_REGISTER(pl_PreviousDir)
{
-
+ iterMan.get(msg["id"]).previousDir();
+ iterMan.get(msg["id"]).send(msg.src);
}
/** Enters selected directory
@@ -371,7 +509,8 @@ namespace pl
*/
SYNAPSE_REGISTER(pl_EnterDir)
{
-
+ iterMan.get(msg["id"]).enterDir();
+ iterMan.get(msg["id"]).send(msg.src);
}
/** Exits directory, selecting directory on higher up the hierarchy
@@ -381,6 +520,8 @@ namespace pl
*/
SYNAPSE_REGISTER(pl_ExitDir)
{
+ iterMan.get(msg["id"]).exitDir();
+ iterMan.get(msg["id"]).send(msg.src);
}
@@ -403,7 +544,8 @@ namespace pl
*/
SYNAPSE_REGISTER(pl_Previous)
{
-
+ iterMan.get(msg["id"]).previous();
+ iterMan.get(msg["id"]).send(msg.src);
}
diff --git a/wwwdir/paper/auth_admin.png b/wwwdir/paper/auth_admin.png
new file mode 100644
index 0000000..db08a09
--- /dev/null
+++ b/wwwdir/paper/auth_admin.png
Binary files differ
diff --git a/wwwdir/paper/auth_none.png b/wwwdir/paper/auth_none.png
new file mode 100644
index 0000000..81f91f7
--- /dev/null
+++ b/wwwdir/paper/auth_none.png
Binary files differ
diff --git a/wwwdir/paper/auth_read.png b/wwwdir/paper/auth_read.png
new file mode 100644
index 0000000..918d226
--- /dev/null
+++ b/wwwdir/paper/auth_read.png
Binary files differ
diff --git a/wwwdir/paper/auth_write.png b/wwwdir/paper/auth_write.png
new file mode 100644
index 0000000..b0dc8e3
--- /dev/null
+++ b/wwwdir/paper/auth_write.png
Binary files differ
diff --git a/wwwdir/paper/edit.html b/wwwdir/paper/edit.html
index 08055cf..9502cf1 100644
--- a/wwwdir/paper/edit.html
+++ b/wwwdir/paper/edit.html
@@ -14,7 +14,7 @@
<script type="text/javascript" src="/synapse/common.js"></script>
<script type="text/javascript" src="/paper/svg.js"></script>
- <script type="text/javascript" src="/paper/jquery.url.js"></script>
+ <script type="text/javascript" src="/lib/jquery.url.js"></script>
<script type="text/javascript" src="/paper/paper.js?1"></script>
<style>
@@ -470,7 +470,7 @@
</div>
- <div class='toolHeader' style='background-image:url("paper.png");'>
+ <div class='toolHeader' style='background-image:url("/paper/paper.png");'>
Kleuren
</div>
diff --git a/wwwdir/paper/index.html b/wwwdir/paper/index.html
index 69f3df8..c951b71 100644
--- a/wwwdir/paper/index.html
+++ b/wwwdir/paper/index.html
@@ -68,10 +68,10 @@
synapse_register("object_Joined",function(msg_src, msg_dst, msg_event, msg)
{
//up on creating we get temporary owner rights.
- //now create our own permanent key with full rights:
+ //now set permanent global rights to "allow all"
send(msg_src,"paper_ChangeAuth",
{
- "key":getClientId(),
+ "key":"",
"rights":
{
"owner":1,
@@ -84,7 +84,7 @@
});
//now go to the paper
- document.location=msg["htmlPath"]+"#"+getClientId();
+ document.location=msg["htmlPath"];//+"#"+getClientId();
});
diff --git a/wwwdir/paper/paper.js b/wwwdir/paper/paper.js
index 1e5dc51..21a4eef 100644
--- a/wwwdir/paper/paper.js
+++ b/wwwdir/paper/paper.js
@@ -131,7 +131,8 @@ function chatPrintOnline()
//determine the id of the paper the user wants to edit
function getUrlId()
{
- var file=jQuery.url.segment(1);
+
+ var file=$.url(document.location).segment(1);
if (file==parseInt(file))
return(file);
else
@@ -795,6 +796,11 @@ synapse_register("module_SessionStart",function(msg_src, msg_dst, msg_event, msg
}
});
+ //delete the session just before unloading
+ window.onbeforeunload=function()
+ {
+ send(0,"core_DelSession");
+ }
/// JAVA SCRIPT EVENT HANDLERS
diff --git a/wwwdir/synapse/synapse-core.js b/wwwdir/synapse/synapse-core.js
index 79f2e0b..5d4c8b5 100644
--- a/wwwdir/synapse/synapse-core.js
+++ b/wwwdir/synapse/synapse-core.js
@@ -238,7 +238,7 @@ $(document).ready(function(){
//(if it fails its no problem: the session will eventually timeout in http_json)
//inoffical propiertary way, but earlier so message sending still works
- //DONT, doesnt allow refresh while auto-loggin in again?
+ //DONT, doesnt allow refresh while auto-loggin in again!
// window.onbeforeunload=function()
// {
// send(0,"core_DelSession");
diff --git a/wwwdir/test.html b/wwwdir/test.html
index 2ed84a4..25a37cc 100644
--- a/wwwdir/test.html
+++ b/wwwdir/test.html
@@ -35,9 +35,14 @@
$(document).ready(function(){
var messages=[
'[0,"core_Login",{"username":"admin", "password":"as"}]',
- '[0,"pl_Create",{"id":"test","path":"/home/psy/mp3"}]',
+ '[0,"pl_Create",{"id":"test","path":"/home/psy/pl"}]',
'[0,"pl_Current",{"id":"test"}]',
- '[0,"pl_Next",{"id":"test"}]'
+ '[0,"pl_Next",{"id":"test"}]',
+ '[0,"pl_Previous",{"id":"test"}]',
+ '[0,"pl_NextDir",{"id":"test"}]',
+ '[0,"pl_PreviousDir",{"id":"test"}]',
+ '[0,"pl_EnterDir",{"id":"test"}]',
+ '[0,"pl_ExitDir",{"id":"test"}]'
]
for (var messageI in messages)