trial version of "run script" popup menu entry for the GUI
This commit is contained in:
parent
e5dfb800f7
commit
7373f5e58d
3 changed files with 85 additions and 20 deletions
|
@ -77,6 +77,27 @@ QMenu *create(QWidget *me, int opts, RefCntr<DocSequence> source, Rcl::Doc& doc)
|
||||||
SLOT(menuOpenWith(QAction *)));
|
SLOT(menuOpenWith(QAction *)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See if there are any desktop files in $RECOLL_CONFDIR/scripts
|
||||||
|
// and possibly create a "run script" menu.
|
||||||
|
aps.clear();
|
||||||
|
ddb = new DesktopDb(path_cat(theconfig->getConfDir(), "scripts"));
|
||||||
|
if (ddb && ddb->allApps(&aps) && !aps.empty()) {
|
||||||
|
QMenu *sub = popup->addMenu(me->tr("Run Script"));
|
||||||
|
if (sub) {
|
||||||
|
for (vector<DesktopDb::AppDef>::const_iterator it = aps.begin();
|
||||||
|
it != aps.end(); it++) {
|
||||||
|
QAction *act = new
|
||||||
|
QAction(QString::fromUtf8(it->name.c_str()), me);
|
||||||
|
QVariant v(QString::fromUtf8(it->command.c_str()));
|
||||||
|
act->setData(v);
|
||||||
|
sub->addAction(act);
|
||||||
|
}
|
||||||
|
sub->connect(sub, SIGNAL(triggered(QAction *)), me,
|
||||||
|
SLOT(menuOpenWith(QAction *)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete ddb;
|
||||||
}
|
}
|
||||||
|
|
||||||
popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN()));
|
popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN()));
|
||||||
|
|
|
@ -30,21 +30,15 @@ static const string desktopext("desktop");
|
||||||
|
|
||||||
static DesktopDb *theDb;
|
static DesktopDb *theDb;
|
||||||
|
|
||||||
typedef map<string, vector<DesktopDb::AppDef> > AppMap;
|
|
||||||
static AppMap theAppMap;
|
|
||||||
|
|
||||||
static std::string o_reason;
|
|
||||||
static bool o_ok;
|
|
||||||
|
|
||||||
class FstCb : public FsTreeWalkerCB {
|
class FstCb : public FsTreeWalkerCB {
|
||||||
public:
|
public:
|
||||||
FstCb(AppMap *appdefs)
|
FstCb(DesktopDb::AppMap *appdefs)
|
||||||
: m_appdefs(appdefs)
|
: m_appdefs(appdefs)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual FsTreeWalker::Status
|
virtual FsTreeWalker::Status
|
||||||
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
|
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
|
||||||
AppMap *m_appdefs;
|
DesktopDb::AppMap *m_appdefs;
|
||||||
};
|
};
|
||||||
|
|
||||||
FsTreeWalker::Status FstCb::processone(const string& fn, const struct stat *,
|
FsTreeWalker::Status FstCb::processone(const string& fn, const struct stat *,
|
||||||
|
@ -100,27 +94,37 @@ DesktopDb* DesktopDb::getDb()
|
||||||
if (theDb == 0) {
|
if (theDb == 0) {
|
||||||
theDb = new DesktopDb();
|
theDb = new DesktopDb();
|
||||||
}
|
}
|
||||||
if (o_ok)
|
if (theDb && theDb->m_ok)
|
||||||
return theDb;
|
return theDb;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesktopDb::build(const string& dir)
|
||||||
|
{
|
||||||
|
FstCb procapp(&m_appMap);
|
||||||
|
FsTreeWalker walker;
|
||||||
|
if (walker.walk(dir, procapp) != FsTreeWalker::FtwOk) {
|
||||||
|
m_ok = false;
|
||||||
|
m_reason = walker.getReason();
|
||||||
|
}
|
||||||
|
m_ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
DesktopDb::DesktopDb()
|
DesktopDb::DesktopDb()
|
||||||
{
|
{
|
||||||
FstCb procapp(&theAppMap);
|
build(topappsdir);
|
||||||
FsTreeWalker walker;
|
}
|
||||||
if (walker.walk(topappsdir, procapp) != FsTreeWalker::FtwOk) {
|
|
||||||
o_ok = false;
|
DesktopDb::DesktopDb(const string& dir)
|
||||||
o_reason = walker.getReason();
|
{
|
||||||
}
|
build(dir);
|
||||||
o_ok = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesktopDb::appForMime(const string& mime, vector<AppDef> *apps,
|
bool DesktopDb::appForMime(const string& mime, vector<AppDef> *apps,
|
||||||
string *reason)
|
string *reason)
|
||||||
{
|
{
|
||||||
AppMap::const_iterator it = theAppMap.find(mime);
|
AppMap::const_iterator it = m_appMap.find(mime);
|
||||||
if (it == theAppMap.end()) {
|
if (it == m_appMap.end()) {
|
||||||
if (reason)
|
if (reason)
|
||||||
*reason = string("No application found for ") + mime;
|
*reason = string("No application found for ") + mime;
|
||||||
return false;
|
return false;
|
||||||
|
@ -129,9 +133,27 @@ bool DesktopDb::appForMime(const string& mime, vector<AppDef> *apps,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DesktopDb::allApps(vector<AppDef> *apps)
|
||||||
|
{
|
||||||
|
map<string, AppDef> allaps;
|
||||||
|
for (AppMap::const_iterator it = m_appMap.begin();
|
||||||
|
it != m_appMap.end(); it++) {
|
||||||
|
for (vector<AppDef>::const_iterator it1 = it->second.begin();
|
||||||
|
it1 != it->second.end(); it1++) {
|
||||||
|
allaps.insert(pair<string, AppDef>
|
||||||
|
(it1->name, AppDef(it1->name, it1->command)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (map<string, AppDef>::const_iterator it = allaps.begin();
|
||||||
|
it != allaps.end(); it++) {
|
||||||
|
apps->push_back(it->second);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const string& DesktopDb::getReason()
|
const string& DesktopDb::getReason()
|
||||||
{
|
{
|
||||||
return o_reason;
|
return m_reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // TEST_APPFORMIME
|
#else // TEST_APPFORMIME
|
||||||
|
|
|
@ -37,10 +37,17 @@ public:
|
||||||
std::string command;
|
std::string command;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Build/Get the db for the standard fdo directory */
|
||||||
static DesktopDb* getDb();
|
static DesktopDb* getDb();
|
||||||
static const string& getReason();
|
|
||||||
|
/** Constructor for a db based on a non-standard location */
|
||||||
|
DesktopDb(const string& dir);
|
||||||
|
|
||||||
~DesktopDb();
|
~DesktopDb();
|
||||||
|
|
||||||
|
/** In case of error: what happened ? */
|
||||||
|
const string& getReason();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of applications able to process a given MIME type.
|
* Get a list of applications able to process a given MIME type.
|
||||||
* @param mime MIME type we want the apps for
|
* @param mime MIME type we want the apps for
|
||||||
|
@ -52,10 +59,25 @@ public:
|
||||||
bool appForMime(const std::string& mime, vector<AppDef> *apps,
|
bool appForMime(const std::string& mime, vector<AppDef> *apps,
|
||||||
std::string *reason = 0);
|
std::string *reason = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all applications defs:
|
||||||
|
* @param[output] apps applications
|
||||||
|
* @return true
|
||||||
|
*/
|
||||||
|
bool allApps(vector<AppDef> *apps);
|
||||||
|
|
||||||
|
typedef map<string, vector<DesktopDb::AppDef> > AppMap;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** This is used by getDb() and builds a db for the standard location */
|
||||||
DesktopDb();
|
DesktopDb();
|
||||||
|
void build(const string& dir);
|
||||||
DesktopDb(const DesktopDb &);
|
DesktopDb(const DesktopDb &);
|
||||||
DesktopDb& operator=(const DesktopDb &);
|
DesktopDb& operator=(const DesktopDb &);
|
||||||
|
|
||||||
|
AppMap m_appMap;
|
||||||
|
std::string m_reason;
|
||||||
|
bool m_ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue