~moovida-developers/moovida/example-plugin

« back to all changes in this revision

Viewing changes to elisa/plugins/skeleton/search_menu.py

  • Committer: Ugo Riboni
  • Date: 2009-09-14 14:41:18 UTC
  • Revision ID: uriboni@fluendo.com-20090914144118-liggkiunz8gl9doc
Add search example. Not documented for now as the entire search framework will be subject to major changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Moovida - Home multimedia server
 
3
# Copyright (C) 2006-2009 Fluendo Embedded S.L. (www.fluendo.com).
 
4
# All rights reserved.
 
5
#
 
6
# This file is available under one of two license agreements.
 
7
#
 
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.
 
11
#
 
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.
 
16
#
 
17
# Author: Your Name <you@example.com>
 
18
 
 
19
"""
 
20
WARNING: this example demonstrate some features of Moovida that are very likely
 
21
to be modified in the near future.
 
22
 
 
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.
 
27
 
 
28
This example demonstrates the following features of Moovida's framework:
 
29
 - Searching and displaying search results
 
30
"""
 
31
 
 
32
import os
 
33
 
 
34
from elisa.core.utils import defer
 
35
from elisa.core.utils.i18n import install_translation
 
36
from elisa.core.media_uri import MediaUri
 
37
 
 
38
from elisa.plugins.poblesec.base.list import GenericListViewMode
 
39
from elisa.plugins.poblesec.base.preview_list import MenuItemPreviewListController
 
40
 
 
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
 
46
 
 
47
from elisa.core.resource_manager import  ResourceProviderNotFound
 
48
from elisa.plugins.poblesec.search_controller import SearcherEntry
 
49
 
 
50
 
 
51
_ = install_translation('skeleton')
 
52
 
 
53
 
 
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)
 
60
 
 
61
 
 
62
class SkeletonFileSearcher(Searcher):
 
63
    paths = ['videos']
 
64
 
 
65
    def search(self, uri, model):
 
66
        home = os.path.expanduser("~")
 
67
        files = os.listdir(home)
 
68
        for file in files:
 
69
            # Skip files starting with dot as they are usually hidden files.
 
70
            if file.startswith("."):
 
71
                continue
 
72
            if not file.startswith(uri.filename):
 
73
                continue
 
74
 
 
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
 
77
            # framework.
 
78
            filepath = os.path.join(home, file)
 
79
            vid = VideoModel()
 
80
            vid.playable_uri = media_uri.MediaUri('file://' + filepath)
 
81
            model.videos.append(vid)
 
82
 
 
83
        return defer.succeed(model)
 
84
 
 
85
 
 
86
class SkeletonSearchResultsViewMode(GenericListViewMode):
 
87
    """
 
88
    Please see the file_menu.py and api_menu.py files for a detailed explanation
 
89
    of view mode classes.
 
90
    """
 
91
    def get_label(self, item):
 
92
        return defer.succeed(item.playable_uri.filename)
 
93
 
 
94
    def get_default_image(self, item):
 
95
        return 'elisa.plugins.poblesec.glyphs.small.video'
 
96
 
 
97
    def get_image(self, item, theme):
 
98
        return defer.succeed(None)
 
99
 
 
100
 
 
101
class SkeletonSearchResultsController(MenuItemPreviewListController):
 
102
    """
 
103
    Please see the file_menu.py and api_menu.py files for a detailed explanation
 
104
    of controller classes.
 
105
    """
 
106
    view_mode = SkeletonSearchResultsViewMode
 
107
 
 
108
    def initialize(self, videos=None, **kwargs):
 
109
        self._videos = videos
 
110
        return super(SkeletonSearchResultsController, self).initialize(**kwargs)
 
111
        
 
112
    def populate_model(self):
 
113
        return defer.succeed(self._videos)