[qo-modules-dev] [5]

[ Thread Index | Date Index | More lists.tuxfamily.org/qo-modules-dev Archives ]


Revision: 5
Author:   ytorres
Date:     2008-11-08 12:18:48 +0100 (Sat, 08 Nov 2008)

Log Message:
-----------
 

Added Paths:
-----------
    yannick/desktop/
    yannick/desktop/svn-commit.tmp
    yannick/img/
    yannick/img/.directory
    yannick/img/folder.png
    yannick/img/text.png
    yannick/index.html
    yannick/main.js
    yannick/php/
    yannick/php/get-desktop.php
    yannick/php/get-state.php
    yannick/php/set-state.php
    yannick/php/update-filename.php
    yannick/shortcuts.css
    yannick/shortcuts.js


Added: yannick/desktop/svn-commit.tmp
===================================================================
--- yannick/desktop/svn-commit.tmp	                        (rev 0)
+++ yannick/desktop/svn-commit.tmp	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,5 @@
+:X
+
+--Cette ligne, et les suivantes ci-dessous, seront ignorées--
+
+A    .

Added: yannick/img/.directory
===================================================================
--- yannick/img/.directory	                        (rev 0)
+++ yannick/img/.directory	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,3 @@
+[Dolphin]
+ShowPreview=true
+Timestamp=2008,11,7,21,2,18

Added: yannick/img/folder.png
===================================================================
(Binary files differ)


Property changes on: yannick/img/folder.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: yannick/img/text.png
===================================================================
(Binary files differ)


Property changes on: yannick/img/text.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: yannick/index.html
===================================================================
--- yannick/index.html	                        (rev 0)
+++ yannick/index.html	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>test</title>
+
+<!-- EXT -->
+<link rel="stylesheet" type="text/css" href="../ext-2.2/resources/css/ext-all.css" />
+<script src="../ext-2.2/adapter/ext/ext-base.js"></script>
+<script src="../ext-2.2/ext-all.js"></script>
+
+<!-- shortcuts -->
+<link rel="stylesheet" type="text/css" href="shortcuts.css" />
+<script src="shortcuts.js"></script>
+<script src="main.js"></script>
+</head>
+
+<body>
+
+</body>
+</html>
\ No newline at end of file

Added: yannick/main.js
===================================================================
--- yannick/main.js	                        (rev 0)
+++ yannick/main.js	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,20 @@
+Ext.onReady(function(){
+    var xd = Ext.data;
+
+    var store = new Ext.data.JsonStore({
+        url: 'php/get-desktop.php',
+        root: 'items',
+	id: 'id',
+        fields: ['id', 'name', 'originName', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}, 'type']
+    });
+    store.load();
+
+    var vport = new Ext.Viewport({
+		    layout: 'border',
+		    items: {
+			xtype: 'shortcutsView',
+			region: 'center',
+			store: store
+		    }
+	});
+});
\ No newline at end of file

Added: yannick/php/get-desktop.php
===================================================================
--- yannick/php/get-desktop.php	                        (rev 0)
+++ yannick/php/get-desktop.php	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,74 @@
+<?php
+$dir = "../desktop/";
+$dirP = "desktop/";
+$img = "img/";
+$items = array();
+$d = dir($dir);
+
+$i = 0;
+
+while($name = $d->read()){
+
+    // Skip this for Linux's users
+    if( $name == '..' || $name == '.' ) { continue; }
+
+    // Skip hidden files/folders
+    if( substr($name, 0, 1) == '.' ) { continue; }
+
+    // Files
+    if( is_file($dir.$name) ) {
+
+      // Images ?
+      if(preg_match('/\.(jpg|gif|png)$/', $name)) {
+
+	$size = filesize($dir.$name);
+	$lastmod = filemtime($dir.$name)*1000;
+	$items[] = array(
+		    'id'=>$i,
+		    'type'=>'file',
+		    'originName'=>$name,
+		    'name'=>$name,
+		    'size'=>$size,
+		    'lastmod'=>$lastmod,
+		    'url'=>$dirP.$name
+	);
+
+      } else {
+      // Common files
+	$size = filesize($dir.$name);
+	$lastmod = filemtime($dir.$name)*1000;
+	$items[] = array(
+		    'id'=>$i,
+		    'type'=>'file',
+		    'originName'=>$name,
+		    'name'=>$name,
+		    'size'=>$size,
+		    'lastmod'=>$lastmod,
+		    'url'=>$img.'text.png'
+	);
+
+      }
+    } else if( is_dir($dir.$name) ) {
+
+    // Folders
+      $size = disk_total_space($dir.$name);
+      $lastmod = filemtime($dir.$name)*1000;
+      $items[] = array(
+		  'id'=>$i,
+		  'type'=>'folder',
+		  'originName'=>$name,
+		  'name'=>$name,
+		  'size'=>$size,
+		  'lastmod'=>$lastmod,
+		  'url'=>$img.'folder'
+    );
+
+    }
+$i ++;
+}
+$d->close();
+
+
+$o = array('items'=>$items);
+echo json_encode($o);
+?>
\ No newline at end of file

Added: yannick/php/get-state.php
===================================================================
--- yannick/php/get-state.php	                        (rev 0)
+++ yannick/php/get-state.php	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,21 @@
+<?php
+$stateFile = "../desktop/.shortcutState";
+
+$state = Array("success" => true);
+
+if( !is_file($stateFile) ) { echo "{success:false}"; exit; }
+
+$content = file_get_contents($stateFile);
+
+$xml = new SimpleXMLElement($content);
+
+foreach ($xml->element as $item) {
+   $state[(string)$item->filename] = Array(
+	'name' => (string)$item->filename,
+	'posX' => (int)$item->posx,
+	'posY' => (int)$item->posy
+	);
+}
+
+echo json_encode($state);
+?>
\ No newline at end of file

Added: yannick/php/set-state.php
===================================================================
--- yannick/php/set-state.php	                        (rev 0)
+++ yannick/php/set-state.php	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,65 @@
+<?php
+$originName = $_POST['name'];
+$posX = $_POST['posX'];
+$posY = $_POST['posY'];
+
+$stateFile = "../desktop/.shortcutState";
+
+$currentState = Array();
+
+// This hidden file exist
+if( is_file($stateFile) ) {
+
+$content = file_get_contents($stateFile);
+
+$xml = new SimpleXMLElement($content);
+
+foreach ($xml->element as $item) {
+   $currentState[(string)$item->filename] = Array(
+	'posX' => (int)$item->posx,
+	'posY' => (int)$item->posy
+	);
+}
+
+} else {
+  // Create one
+  touch($stateFile);
+}
+
+//Is this setting exist ?
+if( isset($currentState[$originName]) ) {
+
+  $currentState[$originName]['posX'] = $posX;
+  $currentState[$originName]['posY'] = $posY;
+
+} else {
+
+  $currentState[$originName] = Array(
+	'posX' => (int)$posX,
+	'posY' => (int)$posY
+  );
+
+}
+
+// We rebuild the file
+$file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<items>
+";
+
+ while( list($key, $val) = each($currentState) ) {
+  $file .= "
+  <element>
+    <filename>".$key."</filename>
+    <posx>".$val['posX']."</posx>
+    <posy>".$val['posY']."</posy>
+  </element>
+  ";
+ }
+
+$file .= "
+</items>";
+
+$fp = fopen($stateFile, 'w');
+fwrite($fp, $file);
+fclose($fp);
+?>
\ No newline at end of file

Added: yannick/php/update-filename.php
===================================================================
--- yannick/php/update-filename.php	                        (rev 0)
+++ yannick/php/update-filename.php	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,15 @@
+<?php
+$dir = "../desktop/";
+
+$originName = $_POST['originName'];
+$NewValue = $_POST['NewValue'];
+
+$o->success = false;
+
+@rename($dir.$originName, $dir.$NewValue) or die(json_encode($o));
+
+$o->success = true;
+$o->newName = $NewValue;
+
+echo json_encode($o);
+?>
\ No newline at end of file

Added: yannick/shortcuts.css
===================================================================
--- yannick/shortcuts.css	                        (rev 0)
+++ yannick/shortcuts.css	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,55 @@
+/*
+ * Ext JS Library 2.2
+ * Copyright(c) 2006-2008, Ext JS, LLC.
+ * licensing@xxxxxxxxx
+ * 
+ * http://extjs.com/license
+ */
+
+body {
+	background: white;
+	font: 11px Arial, Helvetica, sans-serif;
+}
+
+.thumb {
+	background: transparent;
+	padding: 3px;
+}
+
+.thumb img {
+	height: 60px;
+	width: 80px;
+}
+
+.thumb-wrap{
+	float: left;
+	margin: 4px;
+	margin-right: 0;
+	padding: 5px;
+}
+.thumb-wrap span{
+	display: block;
+	overflow: hidden;
+	text-align: center;
+}
+
+.x-view-over{
+    border:1px solid #dddddd;
+    padding: 4px;
+}
+
+.x-view-selected{
+	border:1px solid #99bbe8;
+	padding: 4px;
+}
+.x-view-selected .thumb{
+	background:transparent;
+}
+
+.loading-indicator {
+	font-size:11px;
+	background-repeat: no-repeat;
+	background-position: left;
+	padding-left:20px;
+	margin:10px;
+}
\ No newline at end of file

Added: yannick/shortcuts.js
===================================================================
--- yannick/shortcuts.js	                        (rev 0)
+++ yannick/shortcuts.js	2008-11-08 11:18:48 UTC (rev 5)
@@ -0,0 +1,270 @@
+/*
+ * Ext JS Library 2.2
+ * Copyright(c) 2006-2008, Ext JS, LLC.
+ * licensing@xxxxxxxxx
+ * 
+ * http://extjs.com/license
+ */
+
+
+Ext.namespace('Ext.ux');
+
+Ext.ux.shortcutsView = Ext.extend(Ext.DataView, {
+    // Prototype Defaults, can be overridden by user's config object
+    //propA: 1,
+    style: 'border: 1px solid #FF0000',
+    height: this.height,
+    tpl: new Ext.XTemplate(
+	    '<tpl for=".">',
+	    '<div class="thumb-wrap" id="shortcuts_{id}">',
+		'<div class="thumb"><img src="{url}" title="{name}"></div>',
+		'<span class="x-editable">{shortName}</span></div>',
+	    '</tpl>',
+	    '<div class="x-clear"></div>'
+    ),
+    multiSelect: true,
+    overClass:'x-view-over',
+    itemSelector:'div.thumb-wrap',
+    labelEditor: new Ext.Editor(new Ext.form.TextField({
+            allowBlank: false,
+            growMin:90,
+            growMax:240,
+            grow:true,
+            selectOnFocus:true
+        }), {
+      alignment: "tl-tl",
+      hideEl : false,
+      cls: "x-small-editor",
+      shim: false,
+      completeOnEnter: true,
+      cancelOnEsc: true,
+      labelSelector: 'span.x-editable',
+      currentRecord: ''
+    }),
+
+    prepareData: function(data) {
+	data.shortName = Ext.util.Format.ellipsis(data.name, 15);
+	data.sizeString = Ext.util.Format.fileSize(data.size);
+	data.dateString = data.lastmod.format("m/d/Y g:i a");
+	return data;
+    },
+ 
+    initComponent: function(){
+        // Called during component initialization
+ 
+        // Config object has already been applied to 'this' so properties can 
+        // be overriden here or new properties (e.g. items, tools, buttons) 
+        // can be added, eg:
+        Ext.apply(this, {});
+ 
+        // Before parent code
+ 
+        // Call parent (required)
+        Ext.ux.shortcutsView.superclass.initComponent.apply(this, arguments);
+ 
+        // After parent code
+        // e.g. install event handlers on rendered component
+	this.store.on('load', this.onStoreLoad, this);
+    },
+ 
+    // Override other inherited methods 
+    onRender: function() {
+        // Call parent (required)
+        Ext.ux.shortcutsView.superclass.onRender.apply(this, arguments);
+    },
+    
+    onStoreLoad: function() {
+        // Init Drag ShortCuts
+	this.DDInit();
+	
+	// Init Editor for the label
+        this.getEl().on('dblclick', this.LabelEditorInit, this);
+	
+	// Init contextMenu for shortCut
+        this.getEl().on('contextmenu', this.ctxInit, this);
+	
+	// Move icon
+	this.DDmoveIcon();
+    },
+
+
+    // Drag & Drop
+    DDInit : function() {
+
+      var nodes = this.getNodes();
+      Ext.each(nodes, function(node) {
+
+	var dd = Ext.get(node.id).initDD('pp');
+	var record = this.store.getAt(this.indexOf(node));
+	var originName = record.data['originName'];
+
+	dd.endDrag = function(e) {
+	
+	  Ext.Ajax.request({
+	    scope: this,
+	    url: 'php/set-state.php',
+	    params: {
+	      posX: e.getPageX(),
+	      posY: e.getPageY(),
+	      name: originName
+	    },
+	    success: function(response, options) {
+	    }
+	  });
+	
+	};
+
+
+      }, this);
+    },
+    
+    // Move shortCut onRender
+    DDmoveIcon : function() {
+	Ext.Ajax.request({
+	  scope: this,
+	  url: 'php/get-state.php',
+	  success: function(response, options) {
+	  
+	    var o = Ext.util.JSON.decode(response.responseText);
+	    if( o.success ) {
+
+	      var nodes = this.getNodes();
+	      Ext.each(nodes, function(node) {
+	      
+		var record = this.store.getAt(this.indexOf(node));
+		
+		var originName = record.data['originName'];
+		
+		if( o[originName] ) {
+		  //Move
+		  Ext.get(node.id).moveTo(o[originName].posX, o[originName].posY, true);
+		}
+	    
+	      }, this);
+	    }
+	 }
+	});
+	
+	
+    },
+
+    // LabelEditor
+    LabelEditorInit : function(e, target) {
+
+        if(!e.ctrlKey && !e.shiftKey){
+            var item = this.findItemFromChild(target);
+	    if( item ) {
+	      e.stopEvent();
+	      var record = this.store.getAt(this.indexOf(item));
+	      this.currentRecord = record.data.id;
+	      this.labelEditor.startEdit(target, record.data['name']);
+	      this.labelEditor.on('complete', this.LabelEditorSave, this, {delegate: item});
+	    }
+        } else {
+            e.preventDefault();
+        }
+
+    },
+
+    LabelEditorSave: function(ed, NewValue, item) {
+     // Save into the store
+     this._LabelEditorUpdateStore(this.currentRecord, NewValue);
+     // Update LabelEl
+     this._LabelEditorUpdateEl(this.currentRecord, NewValue);
+     // Save to FileSystem
+     this._LabelEditorSaveToFileSystem(this.store.getById(this.currentRecord).data.originName, NewValue);
+    },
+
+    _LabelEditorUpdateStore : function(id, NewValue) {
+      this.store.getById(id).data.name = NewValue;
+      this.store.getById(id).data.shortName = Ext.util.Format.ellipsis(NewValue, 15);
+    },
+
+    _LabelEditorUpdateEl : function(id, NewValue) {
+      Ext.DomQuery.selectNode("div[@id='shortcuts_"+id+"'] > span[@class='x-editable']").innerHTML =  Ext.util.Format.ellipsis(NewValue, 15);
+    },
+    
+    _LabelEditorSaveToFileSystem: function(originName, NewValue, item) {
+     //console.log(originName);
+     //console.log(NewValue);
+        var item = item;
+	Ext.Ajax.request({
+	  scope: this,
+	  url: 'php/update-filename.php',
+	  params: {
+	      originName: originName,
+	      NewValue: NewValue
+	  },
+	  success: function(response, options) {
+	    var o = Ext.util.JSON.decode(response.responseText);
+	    //Update originName
+	    var record = this.store.getById(this.currentRecord);
+	    console.log(record);
+	    record.data['originName'] = o.newName;
+	    console.log(record);
+	  }
+	});
+
+    },
+
+    // ContextMenu
+    ctxInit: function(e, target) {
+
+        if(!e.ctrlKey && !e.shiftKey){
+            var item = this.findItemFromChild(target);
+	    if( item ) {
+	      this._ctxItems(e, item);
+	      e.stopEvent();
+	    } else {
+	      this._ctxView(e);
+	      e.stopEvent();
+	    }
+        } else {
+            e.preventDefault();
+        }
+    },
+
+    _ctxItems : function(e, item) {
+	      
+	var record = this.store.getAt(this.indexOf(item));
+	this.currentRecord = record.data.id;
+	
+	var menu = new Ext.menu.Menu();
+	menu.add({
+            text: 'Open',
+            //iconCls: '',
+            handler: function(){}
+        });
+	menu.add({
+            text: 'Remove',
+            //iconCls: '',
+            handler: function(){}
+        });
+        menu.showAt(e.getXY());
+	
+	      console.log(record.data.originName);
+    },
+
+    _ctxView : function(e) {
+	      console.log('contextMenu view');
+	
+	var menu = new Ext.menu.Menu();
+	menu.add({
+            text: 'Desktop options',
+            //iconCls: '',
+            handler: function(){}
+        });
+	menu.addSeparator();
+	menu.add({
+            text: 'About this desktop',
+            //iconCls: '',
+            handler: function(){}
+        });
+        menu.showAt(e.getXY());
+    
+    }
+    
+});
+
+// register xtype to allow for lazy initialization
+Ext.reg('shortcutsView', Ext.ux.shortcutsView);
\ No newline at end of file


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/