1
# -*- coding: utf-8 -*-
2
# Moovida - Home multimedia server
3
# Copyright (C) 2006-2009 Fluendo Embedded S.L. (www.fluendo.com).
6
# This file is available under one of two license agreements.
8
# This file is licensed under the GPL version 3.
9
# See "LICENSE.GPL" in the root of this distribution including a special
10
# exception to use Moovida with Fluendo's plugins.
12
# The GPL part of Moovida is also available under a commercial licensing
13
# agreement from Fluendo.
14
# See "LICENSE.Moovida" in the root directory of this distribution package
15
# for details on that license.
17
# Author: Your Name <you@example.com>
20
WARNING: this example demonstrate some features of Moovida that are very likely
21
to be modified in the near future.
23
This example shows how to use the facilities that Moovida provide to enable
24
users to perform searches and display search results.
25
It implements the ability to search for files that start with a certain name
26
inside the user's home directory.
28
This example demonstrates the following features of Moovida's framework:
29
- Searching and displaying search results
34
from elisa.core.utils import defer
35
from elisa.core.utils.i18n import install_translation
36
from elisa.core.media_uri import MediaUri
38
from elisa.plugins.poblesec.base.list import GenericListViewMode
39
from elisa.plugins.poblesec.base.preview_list import MenuItemPreviewListController
41
from elisa.plugins.search.models import VideosSearchResultModel
42
from elisa.plugins.search.searcher import Searcher
43
from elisa.core import media_uri
44
from elisa.core.utils import defer
45
from elisa.plugins.base.models.video import VideoModel
47
from elisa.core.resource_manager import ResourceProviderNotFound
48
from elisa.plugins.poblesec.search_controller import SearcherEntry
51
_ = install_translation('skeleton')
54
def video_search_result_decorator(controller):
55
searcher = 'SkeletonFileSearcher'
56
title = 'Skeleton File Search Results'
57
searcher_entry = SearcherEntry(searcher, title, None)
58
controller.searchers.append(searcher_entry)
59
return defer.succeed(None)
62
class SkeletonFileSearcher(Searcher):
65
def search(self, uri, model):
66
home = os.path.expanduser("~")
67
files = os.listdir(home)
69
# Skip files starting with dot as they are usually hidden files.
70
if file.startswith("."):
72
if not file.startswith(uri.filename):
75
# For each file create a VideoModel and append it to the videos list
76
# in the specialized model that got passed to us by the search
78
filepath = os.path.join(home, file)
80
vid.playable_uri = media_uri.MediaUri('file://' + filepath)
81
model.videos.append(vid)
83
return defer.succeed(model)
86
class SkeletonSearchResultsViewMode(GenericListViewMode):
88
Please see the file_menu.py and api_menu.py files for a detailed explanation
91
def get_label(self, item):
92
return defer.succeed(item.playable_uri.filename)
94
def get_default_image(self, item):
95
return 'elisa.plugins.poblesec.glyphs.small.video'
97
def get_image(self, item, theme):
98
return defer.succeed(None)
101
class SkeletonSearchResultsController(MenuItemPreviewListController):
103
Please see the file_menu.py and api_menu.py files for a detailed explanation
104
of controller classes.
106
view_mode = SkeletonSearchResultsViewMode
108
def initialize(self, videos=None, **kwargs):
109
self._videos = videos
110
return super(SkeletonSearchResultsController, self).initialize(**kwargs)
112
def populate_model(self):
113
return defer.succeed(self._videos)