Parent: [b0b372] (diff)

Child: [083584] (diff)

Download this file

appformime.h    63 lines (55 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _APPFORMIME_H_INCLUDED_
#define _APPFORMIME_H_INCLUDED_
#include <string>
/**
* Rather strangely, I could not find a reasonably simple piece of
* code which would parse /usr/share/applications to return a list of
* apps for a given mime type. So here goes. Note that the implementation
* is very primitive for now (no use of cache file, no updating once built).
* Also, this is not thread-safe, but could be made so quite easily.
*/
class DesktopDb {
public:
class AppDef {
public:
AppDef(const std::string& nm, const std::string& cmd)
: name(nm), command(cmd)
{}
std::string name;
std::string command;
};
static DesktopDb* getDb();
static const string& getReason();
~DesktopDb();
/**
* Get a list of applications able to process a given MIME type.
* @param mime MIME type we want the apps for
* @param[output] apps appropriate applications
* @param[output] reason if we fail, an explanation ?
* @return true for no error (apps may still be empty). false if a serious
* problem was detected.
*/
bool appForMime(const std::string& mime, vector<AppDef> *apps,
std::string *reason = 0);
private:
DesktopDb();
DesktopDb(const DesktopDb &);
DesktopDb& operator=(const DesktopDb &);
};
#endif /* _APPFORMIME_H_INCLUDED_ */