"Fossies" - the Fresh Open Source Software Archive

Member "recoll-1.26.3/utils/appformime.h" (4 Sep 2019, 2912 Bytes) of package /linux/privat/recoll-1.26.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "appformime.h" see the Fossies "Dox" file reference documentation.

    1 /* Copyright (C) 2014 J.F.Dockes
    2  *   This program is free software; you can redistribute it and/or modify
    3  *   it under the terms of the GNU General Public License as published by
    4  *   the Free Software Foundation; either version 2 of the License, or
    5  *   (at your option) any later version.
    6  *
    7  *   This program is distributed in the hope that it will be useful,
    8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  *   GNU General Public License for more details.
   11  *
   12  *   You should have received a copy of the GNU General Public License
   13  *   along with this program; if not, write to the
   14  *   Free Software Foundation, Inc.,
   15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   16  */
   17 #ifndef _APPFORMIME_H_INCLUDED_
   18 #define _APPFORMIME_H_INCLUDED_
   19 
   20 #include <string>
   21 #include <map>
   22 #include <vector>
   23 
   24 /**
   25  * Rather strangely, I could not find a reasonably simple piece of
   26  * code which would parse /usr/share/applications to return a list of
   27  * apps for a given mime type. So here goes. Note that the implementation
   28  * is very primitive for now (no use of cache file, no updating once built).
   29  * Also, this is not thread-safe, but could be made so quite easily.
   30  */
   31 class DesktopDb {
   32 public:
   33     class AppDef {
   34     public:
   35         AppDef(const std::string& nm, const std::string& cmd)
   36             : name(nm), command(cmd)
   37             {}
   38         AppDef() {}
   39 
   40         std::string name;
   41         std::string command;
   42     };
   43 
   44     /** Build/Get the db for the standard fdo directory */
   45     static DesktopDb* getDb();
   46 
   47     /** Constructor for a db based on a non-standard location */
   48     DesktopDb(const string& dir);
   49 
   50     /** In case of error: what happened ? */
   51     const string& getReason();
   52 
   53     /**
   54      * Get a list of applications able to process a given MIME type.
   55      * @param mime MIME type we want the apps for
   56      * @param[output] apps appropriate applications 
   57      * @param[output] reason if we fail, an explanation ?
   58      * @return true for no error (apps may still be empty). false if a serious
   59      *   problem was detected.
   60      */
   61     bool appForMime(const std::string& mime, vector<AppDef> *apps, 
   62                     std::string *reason = 0);
   63 
   64     /**
   65      * Get all applications defs:
   66      * @param[output] apps applications 
   67      * @return true 
   68      */
   69     bool allApps(vector<AppDef> *apps);
   70 
   71     /** 
   72      * Get app with given name 
   73      */
   74     bool appByName(const string& nm, AppDef& app);
   75 
   76     typedef std::map<std::string, std::vector<DesktopDb::AppDef> > AppMap;
   77 
   78 private:
   79     /** This is used by getDb() and builds a db for the standard location */
   80     DesktopDb();
   81     void build(const std::string& dir);
   82     DesktopDb(const DesktopDb &);
   83     DesktopDb& operator=(const DesktopDb &);
   84 
   85     AppMap m_appMap;
   86     std::string m_reason;
   87     bool m_ok;
   88 };
   89 
   90 
   91 #endif /* _APPFORMIME_H_INCLUDED_ */