From: <nan...@us...> - 2010-03-24 02:29:07
|
Revision: 2080 http://nghost.svn.sourceforge.net/nghost/?rev=2080&view=rev Author: nanonymous Date: 2010-03-24 02:29:01 +0000 (Wed, 24 Mar 2010) Log Message: ----------- applied IonIdea-dev's patch for filesystem based listbox Modified Paths: -------------- libnghost/README libnghost/src/dao/populate.cpp libnghost/src/dao/populate.h libnghost/src/gui2/screen.cpp libnghost/src/gui2/screen.h Modified: libnghost/README =================================================================== --- libnghost/README 2010-03-24 02:24:59 UTC (rev 2079) +++ libnghost/README 2010-03-24 02:29:01 UTC (rev 2080) @@ -0,0 +1,56 @@ +Copyright (C)2010 IonIdea Ukraine +Email ic...@io... +http://ionidea.ua/nghost + +Table of contents: +1. Features +2. Applying the patch +3. Usage + +1. Features. +This patch implements new listbox with ability to display filesystem contents without using nScan-populated database, history stack and support for "back" and "home" actions. + +2. Applying the patch. +Instruction assumes the patch is being applied to the following SVN revisions of sources: + -libnghost: revision 2049 + -nghost: revision 2049 +Check out libnghost and nghost sources, ending up with two directories: 'libnghost' and 'trunk' +Place the .diff files extracted from the patch archive to the source root directory +Run the apply_patch script like 'sh < apply_patch.sh' +In case of successfull patching, continue build process as usual, following nghost build instructions (running autogen.sh scripts, configure, make all install etc ) + +3. Usage +New filesystem listboxes can be added to the skin XML screens as in following example: + + <item> + <name>list_box_name</name> + <type>fslistbox</type> + <xcords>100</xcords> + <ycords>200</ycords> + <area_x>3</area_x> + <area_y>3</area_y> + <area_width>-3</area_width> + <area_height>-3</area_height> + <dir>$music</dir> + <file_type>$audioextensions</file_type> + <path>images/media_list_background.png</path> + <action type="media">null playList "%this%" "%pos%"</action> + </item> + +FS listbox supports following options: + <dir> - root directory to search for files, regular filesystem path of config variables can be used ( i.e. /home/foo/music or $music ) + <file_type> - extensions of files to search for, standart syntax or config variable should be used ( i.e. mp3|flac|ogg or $audioextensions ) + +New actions: + +populateWithDir - populates the listbox with contents of given directory +lastDir - populates the listbox with previous path in history stack, removes current path from history stack +resetDir - populates the listbox with path from the <dir> option, flushes the history stack + +examples: + +<action type="listbox">media_list_box populateWithDir "/tmp"</action> + +<action type="listbox">media_list_box resetDir</action> + +<action type="listbox">media_list_box lastDir</action> Modified: libnghost/src/dao/populate.cpp =================================================================== --- libnghost/src/dao/populate.cpp 2010-03-24 02:24:59 UTC (rev 2079) +++ libnghost/src/dao/populate.cpp 2010-03-24 02:29:01 UTC (rev 2080) @@ -166,6 +166,85 @@ return icount; } +int +nghost::SearchDir::listDir(std::string dir, std::vector<std::string> &list) +{ + if(dir2old.size()==0) + { + dir2=dir; + currentdir=get_current_dir_name(); + } + ndebug::out(ndebug::LOG_INFO, "SearchDir: searching '%s'", dir.c_str()); + DIR *dp; + if((dp=opendir(dir.c_str()))==NULL) + { + ndebug::out(ndebug::LOG_WARNING, "SearchDir: couldn't open: %s (%d) - %s", dir.c_str(), errno, strerror(errno)); + return -1; + } + struct dirent *entry; + struct stat statbuf; + std::vector<std::string> dirlist; + string tempdir="",temptitle,next=""; + + chdir(dir.c_str()); + while((entry=readdir(dp)) != NULL) + { + if(stat(entry->d_name,&statbuf)<0) + { + ndebug::out(ndebug::LOG_ERR,"SearchDir: failed to get stats on '%s': (%d) - %s",entry->d_name, errno, strerror(errno)); + continue; + } + + tempdir=""; + next=""; + + if(S_ISDIR(statbuf.st_mode)) + { + //skip unneeded curdir and parent + if(strcmp(".",entry->d_name)==0 || strcmp("..",entry->d_name)==0) + continue; + ndebug::out(ndebug::LOG_DEBUG, "SearchDir: entering %s", entry->d_name); + dir2+="/"; + dir2+=entry->d_name; + dirlist.push_back(dir2); + dir2=dir; + } + else + { + next=entry->d_name; + size_t n=0; + for(size_t i=0;i<typelist.size();i++) + { + string tempext=next, temptype=typelist[i]; + ndebug::out(ndebug::LOG_DEBUG,"SearchDir: checking %s against %s",tempext.c_str(),temptype.c_str()); + if(tempext.length() >= temptype.length() && + (n=tempext.find(temptype)) != string::npos && + tempext.substr(n) == temptype) + { + temptitle=entry->d_name; + tempdir=dir; + tempdir+="/"+temptitle; + icount++; + list.push_back(tempdir); + ndebug::out(ndebug::LOG_DEBUG,"SearchDir: found match %s",tempdir.c_str()); + } + } + } + } + closedir(dp); + if(dir2old.size()==0) chdir(currentdir.c_str()); + list.insert(list.begin(),dirlist.begin(),dirlist.end()); + return icount; +} + +bool +nghost::SearchDir::isDir(string path) +{ + struct stat statbuf; + return ( stat( path.c_str(), &statbuf ) != -1 ) && ( S_ISDIR(statbuf.st_mode )); +} + + void nghost::SearchDir::loadExtensions(std::string f) { Modified: libnghost/src/dao/populate.h =================================================================== --- libnghost/src/dao/populate.h 2010-03-24 02:24:59 UTC (rev 2079) +++ libnghost/src/dao/populate.h 2010-03-24 02:29:01 UTC (rev 2080) @@ -46,6 +46,8 @@ SearchDir(); virtual ~SearchDir(); int searchDirFor(std::string dir,std::vector<std::string> &list, bool=true, std::vector<std::string> * = NULL); + int listDir(std::string dir,std::vector<std::string> &list); + bool isDir(std::string path); void loadExtensions(std::string strtoparse); MediaObj getMetaData(std::string filename); static bool getMetaData(std::string filename, MediaObj *obj); Modified: libnghost/src/gui2/screen.cpp =================================================================== --- libnghost/src/gui2/screen.cpp 2010-03-24 02:24:59 UTC (rev 2079) +++ libnghost/src/gui2/screen.cpp 2010-03-24 02:29:01 UTC (rev 2080) @@ -1,7 +1,8 @@ /*************************************************************************** * Copyright (C) 2007 by Kevron "tripzero" Rees,,, * * tri...@ne... * - * * + * Copyright (C) 2010 IonIdea Ukraine * + * ic...@io... * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -285,6 +286,20 @@ DictionaryList<string> listboxOptions = createOptionsList(optionsList); addListbox(path, i_name, action_type, i_action, i_socket, listatt, listboxOptions, i_area, x, y); } + else if(i_type=="fslistbox") + { + ndebug::out(ndebug::LOG_DEBUG, "FS listbox found"); + //cout<<"first x="<<i_area.x<<" y="<<i_area.y<<" w= "<<i_area.w<<" h="<<i_area.h<<endl; + listattributes listatt; + listatt.filetype=isVariable(myscreen->get_screen(screen_num).get_item(i).get_file_type()); + listatt.dirtosearch=isVariable(myscreen->get_screen(screen_num).get_item(i).get_dir()); + listatt.numvisible = myscreen->get_screen(screen_num).get_item(i).get_size(); + string options = myscreen->get_screen(screen_num).get_item(i).get_options(); + vector<string> optionsList; + parseItems(options,optionsList); + DictionaryList<string> listboxOptions = createOptionsList(optionsList); + addFsListbox(path, i_name, action_type, i_action, i_socket, listatt, listboxOptions, i_area, x, y); + } else if(i_type=="alpha_selector") { addListboxAlpha(path,i_name,i_action,i_socket); @@ -638,6 +653,26 @@ } int +nghost::ScreenClass::addFsListbox(string path, string i_name, string action_type, string i_action,string s, nghost::listattributes listatt, nghost::DictionaryList<string> options, nghost::nRect a, int x, int y) +{ + Events::ListboxEvents::init(outqueue); + ListBox *l = new fsListBox(); + //Populate *p = new Populate(); + IListboxDao * dao = GetListboxDao(getOption("DataAccessObject",options),listatt.table); + l->init(gfx,listatt, dao); + l->setActionClass((action_type != "" ? action_type+":" : "") +i_action); + l->loadImage(path,i_name,x,y); + l->setArea(a); + l->setAction(action_type,i_action); + l->setInActive(); + if(s.length()>0) l->setSocket(s); + //l->loadExtentions(listatt.filetype); + l->update(); + listboxes.push_back(l); + return 1; +} + +int nghost::ScreenClass::addListboxAlpha(std::string path, std::string i_name, std::string i_action, std::string i_socket) { string ac=i_action; Modified: libnghost/src/gui2/screen.h =================================================================== --- libnghost/src/gui2/screen.h 2010-03-24 02:24:59 UTC (rev 2079) +++ libnghost/src/gui2/screen.h 2010-03-24 02:29:01 UTC (rev 2080) @@ -38,6 +38,7 @@ #include "progress.h" #include "slider.h" #include "listbox.h" +#include "fslistbox.h" #include "desktop.h" //#define OPENGL @@ -104,6 +105,7 @@ bool isInUpdateRect(SDL_Rect pos); public: int addListbox(std::string path, std::string i_name, std::string action_type, std::string i_action, std::string s,listattributes, DictionaryList<std::string> options, nRect a, int x, int y); + int addFsListbox(std::string path, std::string i_name, std::string action_type, std::string i_action, std::string s,listattributes, DictionaryList<std::string> options, nRect a, int x, int y); int addListboxAlpha(std::string path, std::string i_name, std::string i_action, std::string i_socket); int addButton(std::string path, std::string i_name, std::string action_type, std::string i_action, bool, std::string s, int x, int y, int p, DictionaryList<std::string> options, nRect a); int addImage(std::string path, std::string i_name, std::string s, int x, int y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |