00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include "autoconfig.h"
00034 #endif
00035
00036 #include "pages.h"
00037 #include "common.h"
00038 #include "storage.h"
00039 #include "cds_objects.h"
00040 #include "cds_resource_manager.h"
00041
00042 using namespace zmm;
00043 using namespace mxml;
00044
00045 web::items::items() : WebRequestHandler()
00046 {
00047 }
00048
00049 void web::items::process()
00050 {
00051 check_request();
00052
00053 int parentID = intParam(_("parent_id"));
00054 int start = intParam(_("start"));
00055 int count = intParam(_("count"));
00056 if (start < 0)
00057 throw _Exception(_("illegal start parameter"));
00058 if (count < 0)
00059 throw _Exception(_("illegal count parameter"));
00060
00061 Ref<Storage> storage = Storage::getInstance();
00062 Ref<Element> items (new Element(_("items")));
00063 items->setArrayName(_("item"));
00064 items->setAttribute(_("parent_id"), String::from(parentID), mxml_int_type);
00065 root->appendElementChild(items);
00066 Ref<CdsObject> obj;
00067 obj = storage->loadObject(parentID);
00068 Ref<BrowseParam> param(new BrowseParam(parentID, BROWSE_DIRECT_CHILDREN | BROWSE_ITEMS));
00069 param->setRange(start, count);
00070
00071 if ((obj->getClass() == UPNP_DEFAULT_CLASS_MUSIC_ALBUM) ||
00072 (obj->getClass() == UPNP_DEFAULT_CLASS_PLAYLIST_CONTAINER))
00073 param->setFlag(BROWSE_TRACK_SORT);
00074
00075 Ref<Array<CdsObject> > arr;
00076 arr = storage->browse(param);
00077
00078 String location = obj->getVirtualPath();
00079 if (string_ok(location))
00080 items->setAttribute(_("location"), location);
00081 items->setAttribute(_("virtual"), (obj->isVirtual() ? _("1") : _("0")), mxml_bool_type);
00082
00083 items->setAttribute(_("start"), String::from(start), mxml_int_type);
00084
00085 items->setAttribute(_("total_matches"), String::from(param->getTotalMatches()), mxml_int_type);
00086
00087 int protectContainer = 0;
00088 int protectItems = 0;
00089 String autoscanMode = _("none");
00090
00091 int autoscanType = storage->getAutoscanDirectoryType(parentID);
00092 if (autoscanType > 0)
00093 autoscanMode = _("timed");
00094
00095 #ifdef HAVE_INOTIFY
00096 if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
00097 {
00098 int startpoint_id = INVALID_OBJECT_ID;
00099 if (autoscanType == 0)
00100 {
00101 startpoint_id = storage->isAutoscanChild(parentID);
00102 }
00103 else
00104 {
00105 startpoint_id = parentID;
00106 }
00107
00108 if (startpoint_id != INVALID_OBJECT_ID)
00109 {
00110 Ref<AutoscanDirectory> adir = storage->getAutoscanDirectory(startpoint_id);
00111 if ((adir != nil) && (adir->getScanMode() == InotifyScanMode))
00112 {
00113 protectItems = 1;
00114 if (autoscanType == 0 || adir->persistent())
00115 protectContainer = 1;
00116
00117 autoscanMode = _("inotify");
00118 }
00119 }
00120 }
00121 #endif
00122 items->setAttribute(_("autoscan_mode"), autoscanMode);
00123 items->setAttribute(_("autoscan_type"), mapAutoscanType(autoscanType));
00124 items->setAttribute(_("protect_container"), String::from(protectContainer), mxml_bool_type);
00125 items->setAttribute(_("protect_items"), String::from(protectItems), mxml_bool_type);
00126
00127 for (int i = 0; i < arr->size(); i++)
00128 {
00129 Ref<CdsObject> obj = arr->get(i);
00130
00131
00132 Ref<Element> item (new Element(_("item")));
00133 item->setAttribute(_("id"), String::from(obj->getID()), mxml_int_type);
00134 item->appendTextChild(_("title"), obj->getTitle());
00137 #ifdef YOUTUBE
00138 if (IS_CDS_ITEM_EXTERNAL_URL(obj->getObjectType()) &&
00139 obj->getFlag(OBJECT_FLAG_ONLINE_SERVICE))
00140 {
00141 item->appendTextChild(_("res"), RefCast(obj, CdsItemExternalURL)->getURL());
00142 }
00143 else
00144 #endif
00145 item->appendTextChild(_("res"), CdsResourceManager::getFirstResource(RefCast(obj, CdsItem)));
00146
00147 items->appendElementChild(item);
00148
00149 }
00150
00151 }