~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to plasmarunner/clementinerunner.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2011, David Sansome <me@davidsansome.com>
 
3
 
 
4
   Clementine is free software: you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation, either version 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   Clementine is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef CLEMENTINERUNNER_H
 
19
#define CLEMENTINERUNNER_H
 
20
 
 
21
#include "src/globalsearch/common.h"
 
22
 
 
23
#include <QSemaphore>
 
24
 
 
25
#include <Plasma/AbstractRunner>
 
26
 
 
27
class OrgClementineplayerGlobalSearchInterface;
 
28
 
 
29
class ClementineRunner : public Plasma::AbstractRunner {
 
30
  Q_OBJECT
 
31
 
 
32
public:
 
33
  ClementineRunner(QObject* parent, const QVariantList& args);
 
34
 
 
35
  static const char* kDbusService;
 
36
  static const char* kDbusPath;
 
37
 
 
38
  void match(Plasma::RunnerContext& context);
 
39
  void run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match);
 
40
 
 
41
private slots:
 
42
  void ResultsAvailable(int id, GlobalSearchServiceResultList results);
 
43
  void SearchFinished(int id);
 
44
  void ArtLoaded(int result_id, const QByteArray& image_data);
 
45
 
 
46
private:
 
47
  struct PendingQuery {
 
48
    PendingQuery()
 
49
      : provider_order_(0),
 
50
        finished_signal_emitted_(false),
 
51
        finished_(false)
 
52
    {}
 
53
 
 
54
    // The main thread is the only one to access these variables.
 
55
    int provider_order_;
 
56
    GlobalSearchServiceResultList results_waiting_for_art_;
 
57
    bool finished_signal_emitted_;
 
58
 
 
59
    // This list contains results that are finished and waiting to be processed
 
60
    // by the match() thread.  results_mutex_ locks results_ and
 
61
    // results_semaphore_ is released once for each result.
 
62
    GlobalSearchServiceResultList results_;
 
63
    QMutex results_mutex_;
 
64
    QSemaphore results_semaphore_;
 
65
    bool finished_;
 
66
  };
 
67
  typedef QMap<int, PendingQuery*> PendingMap;
 
68
 
 
69
  qreal ResultRelevance(const GlobalSearchServiceResult& result) const;
 
70
  void FillMatch(const GlobalSearchServiceResult& result,
 
71
                 Plasma::QueryMatch* match) const;
 
72
 
 
73
private:
 
74
  OrgClementineplayerGlobalSearchInterface* interface_;
 
75
 
 
76
  QIcon nocover_;
 
77
 
 
78
  // pending_mutex_ locks any access to the PendingMap.
 
79
  QMutex pending_mutex_;
 
80
  PendingMap pending_queries_;
 
81
};
 
82
 
 
83
#endif // CLEMENTINERUNNER_H