1st version for recoll as proxy for lens open of embedded documents

This commit is contained in:
Jean-Francois Dockes
2012-03-27 11:39:17 +02:00
parent 9f3abe0466
commit f144edfb83
6 changed files with 270 additions and 151 deletions
+20 -2
View File
@@ -203,7 +203,7 @@ static int op_flags;
static const char usage [] =
"\n"
"recoll [-h] [-c <configdir>] [-q options]\n"
"recoll [-h] [-c <configdir>] [-q query]\n"
" -h : Print help and exit\n"
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
" [-o|l|f|a] [-t] -q 'query' : search query to be executed as if entered\n"
@@ -219,6 +219,9 @@ static const char usage [] =
" explicitly as -t (not ie, -at), and -q <query> MUST\n"
" be last on the command line if this is used.\n"
" Use -t -h to see the additional non-gui options\n"
"recoll <url>\n"
" This is used to open a recoll url (including an ipath), and called\n"
" typically from another search interface like the Unity Dash\n"
;
static void
Usage(void)
@@ -245,6 +248,7 @@ int main(int argc, char **argv)
string a_config;
string question;
string urltoview;
thisprog = argv[0];
argc--; argv++;
@@ -276,11 +280,22 @@ int main(int argc, char **argv)
// to the query. This is for the common case recoll -q x y z to
// avoid needing quoting "x y z"
if (op_flags & OPT_q)
while (argc--) {
while (argc > 0) {
question += " ";
question += *argv++;
argc--;
}
// Else the remaining argument should be an URL to be opened
if (argc == 1) {
urltoview = *argv++;argc--;
if (urltoview.compare(0, 7, cstr_fileu)) {
Usage();
}
} else if (argc > 0)
Usage();
// Translation file for Qt
QString slang = QLocale::system().name().left(2);
QTranslator qt(0);
@@ -375,6 +390,9 @@ int main(int argc, char **argv)
mainWindow->sSearch->searchTypCMB->setCurrentIndex(int(stype));
mainWindow->
sSearch->setSearchString(QString::fromLocal8Bit(question.c_str()));
} else if (!urltoview.empty()) {
LOGDEB(("MAIN: got urltoview [%s]\n", urltoview.c_str()));
mainWindow->setUrlToView(QString::fromLocal8Bit(urltoview.c_str()));
}
return app.exec();
}
+55
View File
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <regex.h>
@@ -78,6 +79,7 @@ using std::pair;
#include "rtitool.h"
#include "indexer.h"
#include "rclzg.h"
#include "fileudi.h"
using namespace confgui;
@@ -389,6 +391,59 @@ void RclMain::initDbOpen()
// command line argument
if (!nodb && sSearch->hasSearchString())
QTimer::singleShot(0, sSearch, SLOT(startSimpleSearch()));
if (!m_urltoview.isEmpty())
viewUrl();
}
// Start native viewer or preview for input Doc. This is used allow
// the using Recoll result docs with an ipath in another app. We act
// as a proxy to extract the data and start a viewer.
// The Url are encoded as file://path#ipath
void RclMain::viewUrl()
{
if (m_urltoview.isEmpty() || !rcldb)
return;
QUrl qurl(m_urltoview);
LOGDEB(("RclMain::viewUrl: Path [%s] fragment [%s]\n",
(const char *)qurl.path().toLocal8Bit(),
(const char *)qurl.fragment().toLocal8Bit()));
/* In theory, the url might not be for a file managed by the fs
indexer so that the make_udi() call here would be
wrong(). When/if this happens we'll have to hide this part
inside internfile and have some url magic to indicate the
appropriate indexer/identification scheme */
string udi;
make_udi((const char *)qurl.path().toLocal8Bit(),
(const char *)qurl.fragment().toLocal8Bit(), udi);
Rcl::Doc doc;
if (!rcldb->getDoc(udi, doc) || doc.pc == -1)
return;
// Start a native viewer if the mimetype has one defined, else a
// preview.
string apptag;
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
string viewer = theconfig->getMimeViewerDef(doc.mimetype, apptag);
if (viewer.empty()) {
startPreview(doc);
} else {
startNativeViewer(doc);
// We have a problem here because xdg-open will exit
// immediately after starting the command instead of waiting
// for it, so we can't wait either and we don't know when we
// can exit (deleting the temp file). As a bad workaround we
// sleep some time then exit. The alternative would be to just
// prevent the temp file deletion completely, leaving it
// around forever. Better to let the user save a copy if he
// wants I think.
hide();
sleep(10);
fileExit();
}
}
void RclMain::focusToSearch()
+10
View File
@@ -79,6 +79,12 @@ public:
virtual bool eventFilter(QObject *target, QEvent *event);
QString getQueryDescription();
/** This is only called from main() to set an URL to be displayed (using
recoll as a doc extracter for embedded docs */
virtual void setUrlToView(const QString& u) {m_urltoview = u;}
/** Same usage: actually display the current urltoview */
virtual void viewUrl();
public slots:
virtual bool close();
virtual void fileExit();
@@ -169,6 +175,10 @@ private:
RefCntr<DocSequence> m_source;
IndexerState m_indexerState;
// If set on init, will be displayed either through ext app, or
// preview (if no ext app set)
QString m_urltoview;
virtual void init();
virtual void previewPrevOrNextInTab(Preview *, int sid, int docnum,
bool next);