created mimeview and the viewer conf edit dialog

This commit is contained in:
dockes 2006-12-14 13:53:43 +00:00
parent 4141db6d50
commit d7f0562f3a
26 changed files with 1424 additions and 924 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.35 2006-12-13 09:13:18 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.36 2006-12-14 13:53:42 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -19,6 +19,7 @@ static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.35 2006-12-13 09:13:18 dockes E
*/
#ifndef TEST_RCLCONFIG
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <langinfo.h>
@ -70,50 +71,30 @@ RclConfig::RclConfig(const string *argcnf)
return;
}
list<string>cfns;
string cpath;
list<string> cdirs;
cdirs.push_back(m_confdir);
cdirs.push_back(path_cat(m_datadir, "examples"));
cpath = path_cat(m_confdir, "recoll.conf");
cfns.push_back(cpath);
cpath = path_cat(m_datadir, "examples/recoll.conf");
cfns.push_back(cpath);
m_conf = new ConfStack<ConfTree>(cfns, true);
m_conf = new ConfStack<ConfTree>("recoll.conf", cdirs, true);
if (m_conf == 0 || !m_conf->ok()) {
m_reason = string("No main configuration file: ");
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
it++)
m_reason += "[" + *it + "] ";
m_reason += " do not exist or cannot be parsed";
m_reason = string("No/bad main configuration file in: ") + m_confdir;
return;
}
cfns.clear();
cpath = path_cat(m_confdir, "mimemap");
cfns.push_back(cpath);
cpath = path_cat(m_datadir, "examples/mimemap");
cfns.push_back(cpath);
mimemap = new ConfStack<ConfTree>(cfns, true);
mimemap = new ConfStack<ConfTree>("mimemap", cdirs, true);
if (mimemap == 0 || !mimemap->ok()) {
m_reason = string("No mime map configuration file: ");
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
it++)
m_reason += "[" + *it + "] ";
m_reason += " do not exist or cannot be parsed";
m_reason = string("No or bad mimemap file in: ") + m_confdir;
return;
}
cfns.clear();
cpath = path_cat(m_confdir, "mimeconf");
cfns.push_back(cpath);
cpath = path_cat(m_datadir, "examples/mimeconf");
cfns.push_back(cpath);
mimeconf = new ConfStack<ConfTree>(cfns, true);
mimeconf = new ConfStack<ConfTree>("mimeconf", cdirs, true);
if (mimeconf == 0 || !mimeconf->ok()) {
m_reason = string("No mime configuration file: ");
for (list<string>::const_iterator it = cfns.begin(); it != cfns.end();
it++)
m_reason += "[" + *it + "] ";
m_reason += " do not exist or cannot be parsed";
m_reason = string("No/bad mimeconf in: ") + m_confdir;
return;
}
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true);
if (mimeconf == 0 || !mimeconf->ok()) {
m_reason = string("No/bad mimeview in: ") + m_confdir;
return;
}
@ -200,7 +181,7 @@ const string& RclConfig::getDefCharset(bool filename)
// iso-8859. Some won't take iso8859
localecharset = string("ISO-8859-1");
}
LOGDEB(("RclConfig::getDefCharset: localecharset [%s]\n",
LOGDEB1(("RclConfig::getDefCharset: localecharset [%s]\n",
localecharset.c_str()));
}
@ -215,9 +196,9 @@ const string& RclConfig::getDefCharset(bool filename)
}
}
// Get all known document mime values. We get them from the mimeconf
// 'index' submap: values not in there (ie from mimemap or idfile) can't
// possibly belong to documents in the database.
// Get all known document mime values (for indexing). We get them from
// the mimeconf 'index' submap: values not in there (ie from mimemap
// or idfile) can't possibly belong to documents in the database.
std::list<string> RclConfig::getAllMimeTypes()
{
std::list<string> lst;
@ -261,10 +242,46 @@ string RclConfig::getMimeHandlerDef(const std::string &mtype)
string RclConfig::getMimeViewerDef(const string &mtype)
{
string hs;
mimeconf->get(mtype, hs, "view");
mimeview->get(mtype, hs, "view");
return hs;
}
bool RclConfig::getMimeViewerDefs(vector<pair<string, string> >& defs)
{
if (mimeview == 0)
return false;
list<string>tps = mimeview->getNames("view");
for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
defs.push_back(pair<string, string>(*it, getMimeViewerDef(*it)));
}
return true;
}
bool RclConfig::setMimeViewerDef(const string& mt, const string& def)
{
string pconfname = path_cat(m_confdir, "mimeview");
// Make sure this exists
close(open(pconfname.c_str(), O_CREAT|O_WRONLY, 0600));
ConfTree tree(pconfname.c_str());
if (!tree.set(mt, def, "view")) {
m_reason = string("RclConfig::setMimeViewerDef: cant set value in ")
+ pconfname;
return false;
}
list<string> cdirs;
cdirs.push_back(m_confdir);
cdirs.push_back(path_cat(m_datadir, "examples"));
delete mimeview;
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true);
if (mimeconf == 0 || !mimeconf->ok()) {
m_reason = string("No/bad mimeview in: ") + m_confdir;
return false;
}
return true;
}
/**
* Return icon name and path
*/
@ -412,7 +429,8 @@ static const char blurb0[] =
;
// Create initial user config by creating commented empty files
static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf"};
static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf",
"mimeview"};
static int ncffiles = sizeof(configfiles) / sizeof(char *);
bool RclConfig::initUserConfig()
{
@ -461,6 +479,8 @@ void RclConfig::initFrom(const RclConfig& r)
mimemap = new ConfStack<ConfTree>(*(r.mimemap));
if (r.mimeconf)
mimeconf = new ConfStack<ConfTree>(*(r.mimeconf));
if (r.mimeview)
mimeview = new ConfStack<ConfTree>(*(r.mimeview));
if (r.stopsuffixes)
stopsuffixes = new std::list<std::string>(*(r.stopsuffixes));
defcharset = r.defcharset;

View File

@ -16,13 +16,17 @@
*/
#ifndef _RCLCONFIG_H_INCLUDED_
#define _RCLCONFIG_H_INCLUDED_
/* @(#$Id: rclconfig.h,v 1.26 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rclconfig.h,v 1.27 2006-12-14 13:53:42 dockes Exp $ (C) 2004 J.F.Dockes */
#include <list>
#include <string>
#include <vector>
#include <utility>
#ifndef NO_NAMESPACES
using std::list;
using std::string;
using std::vector;
using std::pair;
#endif
#include "conftree.h"
@ -103,6 +107,8 @@ class RclConfig {
/** Get external viewer exec string from mimeconf for mimetype */
string getMimeViewerDef(const string &mimetype);
bool getMimeViewerDefs(vector<pair<string, string> >&);
bool setMimeViewerDef(const string& mimetype, const string& cmd);
/** Get icon name from mimeconf for mimetype */
string getMimeIconName(const string &mtype, string *path = 0);
@ -140,8 +146,9 @@ class RclConfig {
string m_keydir; // Current directory used for parameter fetches.
ConfStack<ConfTree> *m_conf; // Parsed configuration files
ConfStack<ConfTree> *mimemap; // The files don't change with keydir, but their
ConfStack<ConfTree> *mimeconf; // content may depend on it.
ConfStack<ConfTree> *mimemap; // The files don't change with keydir,
ConfStack<ConfTree> *mimeconf; // but their content may depend on it.
ConfStack<ConfTree> *mimeview; //
list<string> *stopsuffixes;
@ -160,6 +167,7 @@ class RclConfig {
m_conf = 0;
mimemap = 0;
mimeconf = 0;
mimeview = 0;
stopsuffixes = 0;
}
/** Free data then zero pointers */
@ -167,6 +175,7 @@ class RclConfig {
delete m_conf;
delete mimemap;
delete mimeconf;
delete mimeview;
delete stopsuffixes;
// just in case
zeroMe();

View File

@ -24,7 +24,7 @@
Dockes</holder>
</copyright>
<releaseinfo>$Id: usermanual.sgml,v 1.28 2006-11-30 13:38:43 dockes Exp $</releaseinfo>
<releaseinfo>$Id: usermanual.sgml,v 1.29 2006-12-14 13:53:42 dockes Exp $</releaseinfo>
<abstract>
<para>This document introduces full text search notions
@ -575,9 +575,9 @@ RECOLL_CONFDIR=$recollconf $recolldata/examples/rclmon.sh stop
by side.</para>
<para>Clicking the <literal>Edit</literal> link will attempt to
start an external viewer (have a look at the
<filename>mimeconf</filename> configuration file to see how
these are configured).</para>
start an external viewer. The viewers can be configured through the
user preferences dialog, or by editing the
<filename>mimeview</filename> configuration file.</para>
<para>The <literal>Preview</literal> and <literal>Edit</literal>
edit links may not be present for all entries, meaning that
@ -586,8 +586,9 @@ RECOLL_CONFDIR=$recollconf $recolldata/examples/rclmon.sh stop
the file type. This can sometimes be adjusted simply by tweaking
the <link linkend="rclinstall.config.mimemap">
<filename>mimemap</filename></link> and
<link linkend="rclinstall.config.mimeconf">
<filename>mimeconf</filename></link> configuration files.</para>
<link linkend="rclinstall.config.mimeview">
<filename>mimeview</filename></link> configuration files (the latter
can be modified with the user preferences dialog).</para>
<para>You can click on the <literal>Query details</literal> link
at the top of the results page to see the query actually
@ -1664,28 +1665,44 @@ RECOLL_CONFDIR=$recollconf $recolldata/examples/rclmon.sh stop
<title>The mimeconf file</title>
<para><filename>mimeconf</filename> specifies how the
different mime types are handled for indexing, and for
display.</para>
different mime types are handled for indexing, and which icons
are displayed in the <command>recoll</command> result lists.</para>
<para>Changing the indexing parameters is probably not a
good idea except if you are a &RCL; developers.</para>
<para>You may want to adjust the external viewers defined in
(ie: HTML is either previewed internally or displayed using
<application>firefox</application>, but you may prefer
<application>mozilla</application>, your
<application>openoffice.org</application>
program might be named <command>oofice</command> instead of
<command>openoffice</command> ...). Look
for the <literal>[view]</literal> section.</para>
<para>You can also change the icons which are displayed by
<para>You can change the icons which are displayed by
<command>recoll</command> in the result lists (the values are
the basenames of the png images inside the
<filename>iconsdir</filename> directory (specified in
<filename>recoll.conf</filename>).</para>
</sect2>
<sect2 id="rclinstall.config.mimeview">
<title>The mimeview file</title>
<para><filename>mimeview</filename> specifies which programs
are started when you click on an <guilabel>Edit</guilabel>
link in a result list. Ie: HTML is normally displayed using
<application>firefox</application>, but you may prefer
<application>Konqueror</application>, your
<application>openoffice.org</application>
program might be named <command>oofice</command> instead of
<command>openoffice</command> etc.
</para>
<para>Changes to this file can be done by direct editing, or
through the <command>recoll</command> user preferences dialog.</para>
<para>As for the other configuration files, the normal usage
is to have a <filename>mimeview</filename> inside your own
configuration directory, with just the non-default entries,
which will override those from the central configuration
file.</para>
<para>Please note that these entries must be placed under a
<literal>[view]</literal> section.</para>
</sect2>
</sect1>
</chapter>

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.45 2006-11-30 13:38:44 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.46 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -163,11 +163,14 @@ bool DbIndexer::createStemmingDatabases()
bool DbIndexer::init(bool resetbefore, bool rdonly)
{
if (m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0)
if (!maketmpdir(m_tmpdir)) {
LOGERR(("DbIndexer: cannot create temporary directory\n"));
if (m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0) {
string reason;
if (!maketmpdir(m_tmpdir, reason)) {
LOGERR(("DbIndexer: cannot create temporary directory: %s\n",
reason.c_str()));
return false;
}
}
Rcl::Db::OpenMode mode = rdonly ? Rcl::Db::DbRO :
resetbefore ? Rcl::Db::DbTrunc : Rcl::Db::DbUpd;
if (!m_db.open(m_dbdir, mode)) {

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.9 2006-12-04 08:17:24 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.10 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -452,9 +452,11 @@ class LoadThread : public QThread {
}
virtual void run() {
DebugLog::getdbl()->setloglevel(loglevel);
if (!maketmpdir(tmpdir)) {
string reason;
if (!maketmpdir(tmpdir, reason)) {
QMessageBox::critical(0, "Recoll",
Preview::tr("Cannot create temporary directory"));
LOGERR(("Preview: %s\n", reason.c_str()));
*statusp = -1;
return;
}
@ -639,7 +641,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
l = MIN(CHUNKL, richTxt.length() - pos);
// Avoid breaking inside a tag. Our tags are short (ie: <br>)
if (pos + l != richTxt.length()) {
if (pos + l != (int)richTxt.length()) {
for (int i = -15; i < 0; i++) {
if (richTxt[pos+l+i] == '<') {
l = l+i;

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.13 2006-12-07 07:07:35 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.14 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -65,6 +65,7 @@ using std::pair;
#include "transcode.h"
#include "refcntr.h"
#include "ssearch_w.h"
#include "execmd.h"
#include "rclmain_w.h"
#include "moc_rclmain_w.cpp"
@ -659,6 +660,31 @@ void RclMain::startNativeViewer(int docnum)
+ doc.mimetype.c_str());
return;
}
list<string> lcmd;
if (!stringToStrings(cmd, lcmd)) {
QMessageBox::warning(0, "Recoll",
tr("Bad viewer command line for %1: [%2]\n"
"Please check the mimeconf file")
.arg(QString::fromAscii(doc.mimetype.c_str()))
.arg(QString::fromLocal8Bit(cmd.c_str())));
return;
}
string cmdpath;
if (!ExecCmd::which(lcmd.front(), cmdpath)) {
QString message = tr("The viewer specified in mimeconf for %1: %2"
" is not found.\nDo you want to start the "
" preferences dialog ?")
.arg(QString::fromAscii(doc.mimetype.c_str()))
.arg(QString::fromLocal8Bit(lcmd.front().c_str()));
switch(QMessageBox::warning(0, "Recoll", message,
"Yes", "No", 0, 0, 1)) {
case 0: showUIPrefs();break;
case 1:
return;
}
}
string fn = urltolocalpath(doc.url);
string url = url_encode(doc.url, 7);

View File

@ -12,7 +12,8 @@ HEADERS += \
sort_w.h \
searchclause_w.h \
ssearch_w.h \
uiprefs_w.h
uiprefs_w.h \
viewaction_w.h
SOURCES += \
@ -28,7 +29,8 @@ SOURCES += \
sort_w.cpp \
searchclause_w.cpp \
ssearch_w.cpp \
uiprefs_w.cpp
uiprefs_w.cpp \
viewaction_w.cpp
FORMS = \
advsearch.ui \
@ -37,7 +39,8 @@ FORMS = \
rclmain.ui \
sort.ui \
ssearchb.ui \
uiprefs.ui
uiprefs.ui \
viewaction.ui
IMAGES = images/asearch.png \
images/history.png \

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.15 2006-12-08 07:11:17 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.16 2006-12-14 13:53:43 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -65,9 +65,6 @@ void SSearch::searchTextChanged( const QString & text )
} else {
searchPB->setEnabled(true);
clearqPB->setEnabled(true);
string u8 = (const char *)queryText->currentText().utf8();
if (prefs.autoSearchOnWS && !u8.empty() && u8[u8.length()-1] == ' ')
startSimpleSearch();
}
}
@ -227,11 +224,11 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
completion();
m_escape = false;
return true;
} else {
m_escape = false;
} else if (ke->key() == Qt::Key_Space) {
if (prefs.autoSearchOnWS)
startSimpleSearch();
}
m_escape = false;
}
return QWidget::eventFilter(target, event);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.12 2006-12-04 08:17:24 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.13 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -55,10 +55,13 @@ static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.12 2006-12-04 08:17:24 dockes E
#include "rcldb.h"
#include "pathut.h"
#include "uiprefs_w.h"
#include "viewaction_w.h"
void UIPrefsDialog::init()
{
m_viewAction = 0;
connect(viewActionPB, SIGNAL(clicked()), this, SLOT(showViewAction()));
connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
connect(helpBrowserPB, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
@ -253,6 +256,18 @@ void UIPrefsDialog::showBrowserDialog()
helpBrowserLE->setText(s);
}
void UIPrefsDialog::showViewAction()
{
if (m_viewAction== 0) {
m_viewAction = new ViewAction(0);
m_viewAction->show();
} else {
// Close and reopen, in hope that makes us visible...
m_viewAction->close();
m_viewAction->show();
}
}
////////////////////////////////////////////
// External / extra search indexes setup
// TBD: a way to remove entry from 'all' list (del button?)

View File

@ -1,4 +1,4 @@
/* @(#$Id: uiprefs_w.h,v 1.5 2006-12-04 09:56:27 dockes Exp $ (C) 2006 J.F.Dockes */
/* @(#$Id: uiprefs_w.h,v 1.6 2006-12-14 13:53:43 dockes Exp $ (C) 2006 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
@ -17,7 +17,7 @@
*/
#ifndef _UIPREFS_W_H_INCLUDED_
#define _UIPREFS_W_H_INCLUDED_
/* @(#$Id: uiprefs_w.h,v 1.5 2006-12-04 09:56:27 dockes Exp $ (C) 2005 J.F.Dockes */
/* @(#$Id: uiprefs_w.h,v 1.6 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes */
#include <qvariant.h>
#include <qdialog.h>
@ -44,6 +44,8 @@ class DummyUIPrefsDialogBase : public QDialog, protected Ui::UIPrefsDialogBase
#endif
//MOC_SKIP_END
class ViewAction;
class UIPrefsDialog : public DummyUIPrefsDialogBase
{
Q_OBJECT
@ -63,6 +65,7 @@ public:
public slots:
virtual void showFontDialog();
virtual void showViewAction();
virtual void resetReslistFont();
virtual void showBrowserDialog();
virtual void extraDbTextChanged( const QString & text );
@ -79,8 +82,10 @@ signals:
protected slots:
virtual void accept();
virtual void reject();
private:
private:
void setFromPrefs();
ViewAction *m_viewAction;
};

106
src/qtgui/viewaction.ui Normal file
View File

@ -0,0 +1,106 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>ViewActionBase</class>
<widget class="QDialog">
<property name="name">
<cstring>ViewActionBase</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>224</width>
<height>132</height>
</rect>
</property>
<property name="caption">
<string>Form1</string>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QListView">
<column>
<property name="text">
<string>File type</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Action</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>actionsLV</cstring>
</property>
<property name="frameShape">
<enum>StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="selectionMode">
<enum>Extended</enum>
</property>
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>AllColumns</enum>
</property>
<property name="toolTip" stdset="0">
<string>Select one or several file types, then click Change Action to modify the program used to open them</string>
</property>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout1</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>chgActPB</cstring>
</property>
<property name="text">
<string>Change Action</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>closePB</cstring>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
</hbox>
</widget>
<layoutdefaults spacing="6" margin="11"/>
</UI>

113
src/qtgui/viewaction_w.cpp Normal file
View File

@ -0,0 +1,113 @@
#ifndef lint
static char rcsid[] = "@(#$Id: viewaction_w.cpp,v 1.1 2006-12-14 13:53:43 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* 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.
*/
#include <vector>
#include <utility>
#include <string>
using namespace std;
#include <qcombobox.h>
#include <qspinbox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qlistview.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qinputdialog.h>
#include "recoll.h"
#include "debuglog.h"
#include "guiutils.h"
#include "viewaction_w.h"
void ViewAction::init()
{
connect(closePB, SIGNAL(clicked()), this, SLOT(close()));
connect(chgActPB, SIGNAL(clicked()), this, SLOT(editAction()));
fillLists();
actionsLV->setColumnWidth(0, 150);
actionsLV->setColumnWidth(1, 150);
resize(550,350);
}
void ViewAction::fillLists()
{
actionsLV->clear();
vector<pair<string, string> > defs;
rclconfig->getMimeViewerDefs(defs);
for (vector<pair<string, string> >::const_iterator it = defs.begin();
it != defs.end(); it++) {
new QListViewItem(actionsLV,
QString::fromAscii(it->first.c_str()),
QString::fromAscii(it->second.c_str()));
}
}
void ViewAction::editAction()
{
QString action0;
list<string> mtypes;
bool dowarnmultiple = true;
QListViewItemIterator it(actionsLV);
while (it.current()) {
QListViewItem *item = it.current();
if (!item->isSelected()) {
++it;
continue;
}
mtypes.push_back((const char *)item->text(0).utf8());
QString action = (const char *)item->text(1).utf8();
if (action0.isEmpty()) {
action0 = action;
} else {
if (action != action0 && dowarnmultiple) {
switch (QMessageBox::warning(0, "Recoll",
tr("Changing actions with different"
"current values"),
"Continue",
"Cancel",
0, 0, 1)) {
case 0: dowarnmultiple = false;break;
case 1: return;
}
}
}
++it;
}
if (action0.isEmpty())
return;
bool ok;
QString text = QInputDialog::getText(
"Recoll", "Edit action:",
QLineEdit::Normal,
action0, &ok, this);
if (!ok || text.isEmpty() )
return;
string sact = (const char *)text.utf8();
for (list<string>::const_iterator it = mtypes.begin();
it != mtypes.end(); it++) {
rclconfig->setMimeViewerDef(*it, sact);
}
fillLists();
}

73
src/qtgui/viewaction_w.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef _VIEWACTION_W_H_INCLUDED_
#define _VIEWACTION_W_H_INCLUDED_
/* @(#$Id: viewaction_w.h,v 1.1 2006-12-14 13:53:43 dockes Exp $ (C) 2006 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.
*/
#include <qvariant.h>
#include <qdialog.h>
#if (QT_VERSION < 0x040000)
#include "viewaction.h"
#else
#include "ui_viewaction.h"
#endif
class QDialog;
//MOC_SKIP_BEGIN
#if QT_VERSION < 0x040000
class DummyViewActionBase : public ViewActionBase
{
public: DummyViewActionBase(QWidget* parent = 0) : ViewActionBase(parent) {}
};
#else
class DummyViewActionBase : public QDialog, public Ui::ViewActionBase
{
public:
DummyViewActionBase(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
}
};
#endif
//MOC_SKIP_END
class ViewAction : public DummyViewActionBase
{
Q_OBJECT
public:
ViewAction(QDialog* parent = 0)
: DummyViewActionBase(parent)
{
init();
}
~ViewAction() {}
public slots:
virtual void editAction();
private:
virtual void init();
virtual void fillLists();
};
#endif /* _VIEWACTION_W_H_INCLUDED_ */

View File

@ -78,8 +78,12 @@ ${INSTALL} -m 0755 filters/rcl* ${datadir}/recoll/filters/ || exit 1
# Clean up possible old filters in examples
rm -f ${datadir}/recoll/examples/rcl*
${INSTALL} -m 0444 sampleconf/recoll.conf sampleconf/mimeconf \
sampleconf/mimemap ${datadir}/recoll/examples/ || exit 1
${INSTALL} -m 0444 \
sampleconf/mimeconf \
sampleconf/mimeview \
sampleconf/recoll.conf \
sampleconf/mimemap \
${datadir}/recoll/examples/ || exit 1
${INSTALL} -m 0755 index/rclmon.sh ${datadir}/recoll/examples/ || exit 1

View File

@ -1,4 +1,4 @@
# @(#$Id: mimeconf,v 1.18 2006-10-02 08:26:20 dockes Exp $ (C) 2004 J.F.Dockes
# @(#$Id: mimeconf,v 1.19 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes
# Recoll : associations of mime types to processing filters.
# There are different sections for decompression, 'interning' for indexing
@ -50,34 +50,6 @@ text/rtf = exec rclrtf
text/x-gaim-log = exec rclgaim
text/x-mail = internal
## ##########################################
# External viewers, launched when you on a result entry 'edit' link
[view]
application/msword = openoffice %f
application/pdf = xpdf %f
application/postscript = gv %f
application/vnd.ms-excel = openoffice %f
application/vnd.ms-powerpoint = openoffice %f
application/vnd.sun.xml.calc = openoffice %f
application/vnd.sun.xml.calc.template = openoffice %f
application/vnd.sun.xml.draw = openoffice %f
application/vnd.sun.xml.draw.template = openoffice %f
application/vnd.sun.xml.impress = openoffice %f
application/vnd.sun.xml.impress.template = openoffice %f
application/vnd.sun.xml.math = openoffice %f
application/vnd.sun.xml.writer = openoffice %f
application/vnd.sun.xml.writer.global = openoffice %f
application/vnd.sun.xml.writer.template = openoffice %f
application/x-dvi = xdvi %f
audio/mpeg = xmms %f
image/jpeg = xv %f
image/png = xv %f
image/vnd.djvu = djview %f
# Or firefox -remote "openFile(%u)"
text/html = firefox %u
text/plain = gnuclient -q %f
text/x-c = gnuclient -q %f
## #############################################
# Icons to be used in the result list if required by gui config
[icons]

31
src/sampleconf/mimeview Normal file
View File

@ -0,0 +1,31 @@
# @(#$Id: mimeview,v 1.1 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes
## ##########################################
# External viewers, launched by the recoll GUI when you click on a result
# 'edit' link
[view]
application/msword = openoffice %f
application/pdf = xpdf %f
application/postscript = gv %f
application/vnd.ms-excel = openoffice %f
application/vnd.ms-powerpoint = openoffice %f
application/vnd.sun.xml.calc = openoffice %f
application/vnd.sun.xml.calc.template = openoffice %f
application/vnd.sun.xml.draw = openoffice %f
application/vnd.sun.xml.draw.template = openoffice %f
application/vnd.sun.xml.impress = openoffice %f
application/vnd.sun.xml.impress.template = openoffice %f
application/vnd.sun.xml.math = openoffice %f
application/vnd.sun.xml.writer = openoffice %f
application/vnd.sun.xml.writer.global = openoffice %f
application/vnd.sun.xml.writer.template = openoffice %f
application/x-dvi = xdvi %f
audio/mpeg = xmms %f
image/jpeg = xv %f
image/png = xv %f
image/vnd.djvu = djview %f
# Or firefox -remote "openFile(%u)"
text/html = firefox %u
text/plain = gnuclient -q %f
text/x-c = gnuclient -q %f

View File

@ -73,7 +73,7 @@ trutf8iter.o : utf8iter.cpp utf8iter.h
utf8iter.cpp
CONFTREE_OBJS= trconftree.o $(BIGLIB)
CONFTREE_OBJS= trconftree.o ../lib/pathut.o ../lib/smallut.o ../lib/conftree.o
trconftree : $(CONFTREE_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o trconftree $(CONFTREE_OBJS)
trconftree.o : conftree.cpp

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.7 2006-11-08 06:56:41 dockes Exp $ (C) 2003 J.F.Dockes";
static char rcsid [] = "@(#$Id: conftree.cpp,v 1.8 2006-12-14 13:53:43 dockes Exp $ (C) 2003 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -28,6 +28,7 @@ static char rcsid [] = "@(#$Id: conftree.cpp,v 1.7 2006-11-08 06:56:41 dockes Ex
#include <fstream>
#include <sstream>
#include <algorithm>
#include "conftree.h"
#include "pathut.h"
@ -342,7 +343,7 @@ ConfSimple::sortwalk(WalkerCode (*walker)(void *,const string&,const string&),
}
#include <iostream>
void ConfSimple::list()
void ConfSimple::listall()
{
if (!ok())
return;
@ -362,6 +363,8 @@ list<string> ConfSimple::getNames(const string &sk)
for (it = ss->second.begin();it != ss->second.end();it++) {
mylist.push_back(it->first);
}
mylist.sort();
mylist.unique();
return mylist;
}
@ -431,7 +434,7 @@ const char *longvalue =
void memtest(ConfSimple &c)
{
cout << "Initial:" << endl;
c.list();
c.listall();
if (c.set("nom", "avec nl \n 2eme ligne", "")) {
fprintf(stderr, "set with embedded nl succeeded !\n");
exit(1);
@ -450,7 +453,7 @@ void memtest(ConfSimple &c)
}
cout << "Final:" << endl;
c.list();
c.listall();
}
static char usage [] =
@ -616,7 +619,7 @@ int main(int argc, char **argv)
exit(1);
}
printf("LIST\n");
parms.list();
parms.listall();
//printf("WALK\n");parms.sortwalk(mywalker, 0);
printf("\nNAMES in global space:\n");
list<string> names = parms.getNames("");

View File

@ -42,6 +42,7 @@
#include <string>
#include <map>
#include <list>
// rh7.3 likes iostream better...
#if defined(__GNUC__) && __GNUC__ < 3
#include <iostream>
@ -53,13 +54,16 @@
using std::string;
using std::list;
using std::map;
using std::istream;
#endif // NO_NAMESPACES
#include "pathut.h"
/**
* Manages a simple configuration file with subsections.
*/
class ConfSimple {
public:
public:
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
/**
@ -92,7 +96,7 @@ class ConfSimple {
* global space if sk is empty).
* @return 0 if name not found, 1 else
*/
virtual int get(const std::string &name, string &value,
virtual int get(const string &name, string &value,
const string &sk = string(""));
/* Note: the version returning char* was buggy and has been removed */
@ -100,14 +104,14 @@ class ConfSimple {
* Set value for named parameter in specified subsection (or global)
* @return 0 for error, 1 else
*/
virtual int set(const std::string &nm, const std::string &val,
const std::string &sk);
virtual int set(const string &nm, const string &val,
const string &sk);
virtual int set(const char *name, const char *value, const char *sk = 0);
/**
* Remove name and value from config
*/
virtual int erase(const std::string &name, const std::string &sk);
virtual int erase(const string &name, const string &sk);
virtual StatusCode getStatus();
virtual bool ok() {return getStatus() != STATUS_ERROR;}
@ -121,17 +125,17 @@ class ConfSimple {
*/
enum WalkerCode {WALK_STOP, WALK_CONTINUE};
virtual WalkerCode sortwalk(WalkerCode
(*wlkr)(void *cldata, const std::string &nm,
const std::string &val),
(*wlkr)(void *cldata, const string &nm,
const string &val),
void *clidata);
virtual void list();
virtual void listall();
/**
* Return all names in given submap
*/
virtual std::list<string> getNames(const string &sk);
virtual list<string> getNames(const string &sk);
virtual std::string getFilename() {return filename;}
virtual string getFilename() {return filename;}
/**
* Copy constructor. Expensive but less so than a full rebuild
@ -158,15 +162,15 @@ class ConfSimple {
return *this;
}
protected:
protected:
bool dotildexpand;
StatusCode status;
private:
private:
string filename; // set if we're working with a file
string *data; // set if we're working with an in-memory string
map<string, map<string, string> > submaps;
void parseinput(std::istream &input);
void parseinput(istream &input);
};
/**
@ -185,7 +189,7 @@ class ConfSimple {
*/
class ConfTree : public ConfSimple {
public:
public:
/**
* Build the object by reading content from file.
*/
@ -203,7 +207,7 @@ class ConfTree : public ConfSimple {
* parents.
* @return 0 if name not found, 1 else
*/
virtual int get(const std::string &name, string &value, const string &sk);
virtual int get(const string &name, string &value, const string &sk);
virtual int get(const char *name, string &value, const char *sk) {
return get(string(name), value, sk ? string(sk) : string(""));
@ -219,15 +223,20 @@ class ConfTree : public ConfSimple {
* one must or we generate an error. We open all trees readonly.
*/
template <class T> class ConfStack {
public:
ConfStack(const std::list<string> &fns, bool ro = true) {
public:
/// Construct from list of configuration file names
ConfStack(const list<string> &fns, bool ro = true) {
construct(fns, ro);
}
ConfStack(const char *nm, bool ro = true) {
std::list<string> fns;
fns.push_back(string(nm));
construct(fns, ro);
// Construct out of one name
// Construct out of name and list of directories
ConfStack(const string& nm, const list<string>& dirs, bool ro = true) {
list<string> fns;
for (list<string>::const_iterator it = dirs.begin();
it != dirs.end(); it++){
fns.push_back(path_cat(*it, nm));
}
ConfStack::construct(fns, ro);
}
~ConfStack() {
@ -249,8 +258,8 @@ template <class T> class ConfStack {
return *this;
}
int get(const std::string &name, string &value, const string &sk) {
typename std::list<T*>::iterator it;
int get(const string &name, string &value, const string &sk) {
typename list<T*>::iterator it;
for (it = m_confs.begin();it != m_confs.end();it++) {
if ((*it)->get(name, value, sk))
return true;
@ -262,25 +271,27 @@ template <class T> class ConfStack {
return get(string(name), value, sk ? string(sk) : string(""));
}
std::list<string> getNames(const string &sk) {
std::list<string> nms;
typename std::list<T*>::iterator it;
for (it = m_confs.begin();it != m_confs.end();it++) {
std::list<string> lst;
list<string> getNames(const string &sk) {
list<string> nms;
typename list<T*>::iterator it;
for (it = m_confs.begin();it != m_confs.end(); it++) {
list<string> lst;
lst = (*it)->getNames(sk);
nms.splice(nms.end(), lst);
}
nms.sort();
nms.unique();
return nms;
}
bool ok() {return m_ok;}
private:
private:
bool m_ok;
std::list<T*> m_confs;
list<T*> m_confs;
void erase() {
typename std::list<T*>::iterator it;
typename list<T*>::iterator it;
for (it = m_confs.begin();it != m_confs.end();it++) {
delete (*it);
}
@ -290,7 +301,7 @@ template <class T> class ConfStack {
/// Common code to initialize from existing object
void init_from(const ConfStack &rhs) {
if ((m_ok = rhs.m_ok)) {
typename std::list<T*>::const_iterator it;
typename list<T*>::const_iterator it;
for (it = rhs.m_confs.begin();it != rhs.m_confs.end();it++) {
m_confs.push_back(new T(**it));
}
@ -298,12 +309,12 @@ template <class T> class ConfStack {
}
/// Common constructor code
void construct(const std::list<string> &fns, bool ro) {
void construct(const list<string> &fns, bool ro) {
if (!ro) {
m_ok = false;
return;
}
std::list<std::string>::const_iterator it;
list<string>::const_iterator it;
bool lastok = false;
for (it = fns.begin();it != fns.end();it++) {
T* p = new T(it->c_str(), true);

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.20 2006-11-30 13:38:44 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.21 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -19,6 +19,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.20 2006-11-30 13:38:44 dockes Exp
*/
#ifndef TEST_EXECMD
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/select.h>
@ -30,6 +31,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.20 2006-11-30 13:38:44 dockes Exp
#endif
#include <list>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
@ -37,13 +39,60 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.20 2006-11-30 13:38:44 dockes Exp
#include "execmd.h"
#include "pathut.h"
#include "debuglog.h"
#include "smallut.h"
#ifndef NO_NAMESPACES
using namespace std;
#endif /* NO_NAMESPACES */
#define MAX(A,B) ((A) > (B) ? (A) : (B))
/* From FreeBSD's which command */
static bool
exec_is_there(const char *candidate)
{
struct stat fin;
/* XXX work around access(2) false positives for superuser */
if (access(candidate, X_OK) == 0 &&
stat(candidate, &fin) == 0 &&
S_ISREG(fin.st_mode) &&
(getuid() != 0 ||
(fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0)) {
return true;
}
return false;
}
bool ExecCmd::which(const string& cmd, string& path)
{
if (cmd.empty())
return false;
if (cmd[0] == '/') {
if (exec_is_there(cmd.c_str())) {
path = cmd;
return true;
} else {
return false;
}
}
const char *pp = getenv("PATH");
if (pp == 0)
return false;
list<string> pels;
stringToTokens(pp, pels, ":");
for (list<string>::iterator it = pels.begin(); it != pels.end(); it++) {
if (it->empty())
*it = ".";
string candidate = (it->empty() ? string(".") : *it) + "/" + cmd;
if (exec_is_there(candidate.c_str())) {
path = candidate;
return true;
}
}
return false;
}
void ExecCmd::putenv(const string &ea)
{
m_env.push_back(ea);
@ -299,7 +348,8 @@ int ExecCmd::doexec(const string &cmd, const list<string>& args,
while (argv[i]) cerr << argv[i++] << endl;}
#endif
for (it = m_env.begin(); it != m_env.end(); it++) {
for (vector<string>::const_iterator it = m_env.begin();
it != m_env.end(); it++) {
#ifdef PUTENV_ARG_NOT_CONST
::putenv(strdup(it->c_str()));
#else
@ -382,11 +432,10 @@ static int op_flags;
#define OPT_MOINS 0x1
#define OPT_s 0x2
#define OPT_b 0x4
#define OPT_w 0x8
int main(int argc, char **argv)
{
int count = 10;
thisprog = argv[0];
argc--; argv++;
@ -397,12 +446,13 @@ int main(int argc, char **argv)
Usage();
while (**argv)
switch (*(*argv)++) {
case 's': op_flags |= OPT_s; break;
case 'b': op_flags |= OPT_b; if (argc < 2) Usage();
if ((sscanf(*(++argv), "%d", &count)) != 1)
Usage();
argc--;
goto b1;
case 's': op_flags |= OPT_s; break;
case 'w': op_flags |= OPT_w; break;
default: Usage(); break;
}
b1: argc--; argv++;
@ -420,6 +470,14 @@ int main(int argc, char **argv)
DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr");
if (op_flags & OPT_w) {
string path;
if (ExecCmd::which(cmd, path)) {
cout << path << endl;
exit(0);
}
exit(1);
}
ExecCmd mexec;
MEAdv adv;
adv.cmd = &mexec;

View File

@ -16,13 +16,15 @@
*/
#ifndef _EXECMD_H_INCLUDED_
#define _EXECMD_H_INCLUDED_
/* @(#$Id: execmd.h,v 1.10 2006-10-11 16:09:45 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: execmd.h,v 1.11 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#include <vector>
#ifndef NO_NAMESPACES
using std::list;
using std::string;
using std::vector;
#endif
/** Callback function object to advise of new data arrival (or just heartbeat) * if cnt is 0 */
@ -117,13 +119,19 @@ class ExecCmd {
: m_advise(0), m_provide(0), m_cancelRequest(false), m_timeoutMs(1000)
{}
/**
* Utility routine: check if/where a command is found according to the
* current PATH
*/
static bool which(const string& cmd, string& path);
private:
list<string> m_env;
ExecCmdAdvise *m_advise;
ExecCmdProvide *m_provide;
bool m_cancelRequest;
int m_timeoutMs;
string m_stderrFile;
vector<string> m_env;
ExecCmdAdvise *m_advise;
ExecCmdProvide *m_provide;
bool m_cancelRequest;
int m_timeoutMs;
string m_stderrFile;
};

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.11 2006-10-23 15:00:31 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.12 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -26,14 +26,53 @@ static char rcsid[] = "@(#$Id: pathut.cpp,v 1.11 2006-10-23 15:00:31 dockes Exp
#include <iostream>
#include <list>
#include <stack>
#include "pathut.h"
#ifndef NO_NAMESPACES
using std::string;
using std::list;
using std::stack;
#endif /* NO_NAMESPACES */
#include "pathut.h"
bool maketmpdir(string& tdir, string& reason)
{
const char *tmpdir = getenv("RECOLL_TMPDIR");
if (!tmpdir)
tmpdir = getenv("TMPDIR");
if (!tmpdir)
tmpdir = "/tmp";
tdir = path_cat(tmpdir, "rcltmpXXXXXX");
{
char *cp = strdup(tdir.c_str());
if (!cp) {
reason = "maketmpdir: out of memory (for file name !)\n";
tdir.erase();
return false;
}
#ifdef HAVE_MKDTEMP
if (!mkdtemp(cp)) {
#else
if (!mktemp(cp)) {
#endif // HAVE_MKDTEMP
free(cp);
reason = "maketmpdir: mktemp failed\n";
tdir.erase();
return false;
}
tdir = cp;
free(cp);
}
#ifndef HAVE_MKDTEMP
if (mkdir(tdir.c_str(), 0700) < 0) {
reason = string("maketmpdir: mkdir ) + tdir : " failed";
tdir.erase();
return false;
}
#endif
return true;
}
void path_catslash(std::string &s) {
if (s.empty() || s[s.length() - 1] != '/')
s += '/';

View File

@ -16,7 +16,7 @@
*/
#ifndef _PATHUT_H_INCLUDED_
#define _PATHUT_H_INCLUDED_
/* @(#$Id: pathut.h,v 1.9 2006-10-23 15:00:31 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: pathut.h,v 1.10 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@ -51,4 +51,7 @@ extern string url_encode(const string url,
/// Stat parameter and check if it's a directory
extern bool path_isdir(const string& path);
/// Create temporary directory
extern bool maketmpdir(string& tdir, string& reason);
#endif /* _PATHUT_H_INCLUDED_ */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.21 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.22 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -31,8 +31,6 @@ static char rcsid[] = "@(#$Id: smallut.cpp,v 1.21 2006-12-11 14:50:53 dockes Exp
#include <string>
#include "smallut.h"
#include "debuglog.h"
#include "pathut.h"
#ifndef NO_NAMESPACES
using namespace std;
@ -40,45 +38,6 @@ using namespace std;
#define MIN(A,B) ((A)<(B)?(A):(B))
bool maketmpdir(string& tdir)
{
const char *tmpdir = getenv("RECOLL_TMPDIR");
if (!tmpdir)
tmpdir = getenv("TMPDIR");
if (!tmpdir)
tmpdir = "/tmp";
tdir = path_cat(tmpdir, "rcltmpXXXXXX");
{
char *cp = strdup(tdir.c_str());
if (!cp) {
LOGERR(("maketmpdir: out of memory (for file name !)\n"));
tdir.erase();
return false;
}
#ifdef HAVE_MKDTEMP
if (!mkdtemp(cp)) {
#else
if (!mktemp(cp)) {
#endif // HAVE_MKDTEMP
free(cp);
LOGERR(("maketmpdir: mktemp failed\n"));
tdir.erase();
return false;
}
tdir = cp;
free(cp);
}
#ifndef HAVE_MKDTEMP
if (mkdir(tdir.c_str(), 0700) < 0) {
LOGERR(("maketmpdir: mkdir %s failed\n", tdir.c_str()));
tdir.erase();
return false;
}
#endif
return true;
}
string stringlistdisp(const list<string>& sl)
{
string s;
@ -88,7 +47,6 @@ string stringlistdisp(const list<string>& sl)
s.erase(s.length()-1);
return s;
}
int stringicmp(const string & s1, const string& s2)
{

View File

@ -16,7 +16,7 @@
*/
#ifndef _SMALLUT_H_INCLUDED_
#define _SMALLUT_H_INCLUDED_
/* @(#$Id: smallut.h,v 1.21 2006-12-11 14:50:53 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: smallut.h,v 1.22 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#include <map>
@ -37,7 +37,6 @@ extern int stringisuffcmp(const string& s1, const string& s2);
// Compare charset names, removing the more common spelling variations
extern bool samecharset(const string &cs1, const string &cs2);
extern bool maketmpdir(string& tdir);
extern string stringlistdisp(const list<string>& strs);
/**