~timo-jyrinki/unity-scope-mediascanner/manual_import_rtm_0.2+14.10.20141009-0ubuntu1

« back to all changes in this revision

Viewing changes to src/videoaggregator/videoaggregatorscope.cpp

  • Committer: Timo Jyrinki
  • Date: 2014-10-29 14:28:38 UTC
  • Revision ID: timo.jyrinki@canonical.com-20141029142838-uveiptpvvs5yz0pe
Manual import of 0.2+14.10.20141009-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2014 Canonical Ltd
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by Jussi Pakkanen <jussi.pakkanen@canonical.com>
17
 
 *
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
#include "videoaggregatorscope.h"
22
 
#include "videoaggregatorquery.h"
23
 
#include <unity/scopes/Registry.h>
24
 
#include <unity/scopes/Category.h>
25
 
#include <unity/scopes/CategoryRenderer.h>
26
 
#include <iostream>
27
 
#include "../utils/i18n.h"
28
 
 
29
 
using namespace unity::scopes;
30
 
 
31
 
const std::vector<const char*> SUBSCOPE_NAMES{
32
 
#ifdef CLICK_MODE
33
 
    "com.ubuntu.scopes.myvideos_myvideos",
34
 
#else
35
 
    "mediascanner-video",
36
 
#endif
37
 
    "com.ubuntu.scopes.youtube_youtube",
38
 
};
39
 
 
40
 
void VideoAggregatorScope::start(std::string const&) {
41
 
    init_gettext(*this);
42
 
    find_subscopes(true);
43
 
}
44
 
 
45
 
void VideoAggregatorScope::find_subscopes(bool warn_missing) {
46
 
    subscopes.clear();
47
 
    for (const auto &scope_name : SUBSCOPE_NAMES) {
48
 
        try {
49
 
            subscopes.emplace_back(registry()->get_metadata(scope_name));
50
 
        } catch (const std::exception &e) {
51
 
            if (warn_missing) {
52
 
                std::cerr << "Could not find scope '" << scope_name << "': " << e.what() << std::endl;
53
 
            }
54
 
        }
55
 
    }
56
 
}
57
 
 
58
 
void VideoAggregatorScope::stop() {
59
 
}
60
 
 
61
 
SearchQueryBase::UPtr VideoAggregatorScope::search(CannedQuery const& q,
62
 
                                                   SearchMetadata const& hints) {
63
 
    // FIXME: workaround for problem with no remote scopes on first run
64
 
    // until network becomes available
65
 
    if (subscopes.size() != SUBSCOPE_NAMES.size()) {
66
 
        find_subscopes(false);
67
 
    }
68
 
    SearchQueryBase::UPtr query(new VideoAggregatorQuery(q, hints, subscopes));
69
 
    return query;
70
 
}
71
 
 
72
 
PreviewQueryBase::UPtr VideoAggregatorScope::preview(Result const& /*result*/, ActionMetadata const& /*hints*/) {
73
 
    return nullptr;
74
 
}
75
 
 
76
 
#define EXPORT __attribute__ ((visibility ("default")))
77
 
 
78
 
extern "C"
79
 
{
80
 
 
81
 
    EXPORT
82
 
    unity::scopes::ScopeBase*
83
 
    // cppcheck-suppress unusedFunction
84
 
    UNITY_SCOPE_CREATE_FUNCTION()
85
 
    {
86
 
        return new VideoAggregatorScope();
87
 
    }
88
 
 
89
 
    EXPORT
90
 
    void
91
 
    // cppcheck-suppress unusedFunction
92
 
    UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
93
 
    {
94
 
        delete scope_base;
95
 
    }
96
 
 
97
 
}