mime categories
This commit is contained in:
parent
071997c6bb
commit
50174005a1
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.39 2006-12-20 09:54:17 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.40 2006-12-20 13:12:49 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -318,15 +318,27 @@ string RclConfig::getSuffixFromMimeType(const string &mt)
|
||||
return "";
|
||||
}
|
||||
|
||||
void RclConfig::freeAll()
|
||||
/** Get list of file categories from mimeconf */
|
||||
bool RclConfig::getMimeCategories(list<string>& cats)
|
||||
{
|
||||
delete m_conf;
|
||||
delete mimemap;
|
||||
delete mimeconf;
|
||||
delete mimeview;
|
||||
delete STOPSUFFIXES;
|
||||
// just in case
|
||||
zeroMe();
|
||||
if (!mimeconf)
|
||||
return false;
|
||||
cats = mimeconf->getNames("categories");
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Get list of mime types for category from mimeconf */
|
||||
bool RclConfig::getMimeCatTypes(const string& cat, list<string>& tps)
|
||||
{
|
||||
tps.clear();
|
||||
if (!mimeconf)
|
||||
return false;
|
||||
string slist;
|
||||
if (!mimeconf->get(cat, slist, "categories"))
|
||||
return false;
|
||||
|
||||
stringToStrings(slist, tps);
|
||||
return true;
|
||||
}
|
||||
|
||||
string RclConfig::getMimeHandlerDef(const std::string &mtype)
|
||||
@ -374,7 +386,7 @@ bool RclConfig::setMimeViewerDef(const string& mt, const string& def)
|
||||
|
||||
delete mimeview;
|
||||
mimeview = new ConfStack<ConfTree>("mimeview", cdirs, true);
|
||||
if (mimeconf == 0 || !mimeconf->ok()) {
|
||||
if (mimeview == 0 || !mimeview->ok()) {
|
||||
m_reason = string("No/bad mimeview in: ") + m_confdir;
|
||||
return false;
|
||||
}
|
||||
@ -562,6 +574,17 @@ bool RclConfig::initUserConfig()
|
||||
return true;
|
||||
}
|
||||
|
||||
void RclConfig::freeAll()
|
||||
{
|
||||
delete m_conf;
|
||||
delete mimemap;
|
||||
delete mimeconf;
|
||||
delete mimeview;
|
||||
delete STOPSUFFIXES;
|
||||
// just in case
|
||||
zeroMe();
|
||||
}
|
||||
|
||||
void RclConfig::initFrom(const RclConfig& r)
|
||||
{
|
||||
zeroMe();
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _RCLCONFIG_H_INCLUDED_
|
||||
#define _RCLCONFIG_H_INCLUDED_
|
||||
/* @(#$Id: rclconfig.h,v 1.29 2006-12-20 09:54:17 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rclconfig.h,v 1.30 2006-12-20 13:12:49 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
@ -116,6 +116,11 @@ class RclConfig {
|
||||
/** Get icon name from mimeconf for mimetype */
|
||||
string getMimeIconName(const string &mtype, string *path = 0);
|
||||
|
||||
/** Get list of file categories from mimeconf */
|
||||
bool getMimeCategories(list<string>&);
|
||||
/** Get list of mime types for category from mimeconf */
|
||||
bool getMimeCatTypes(const string& cat, list<string>&);
|
||||
|
||||
/** Get a list of all indexable mime types defined in mimemap */
|
||||
list<string> getAllMimeTypes();
|
||||
|
||||
|
||||
@ -223,6 +223,25 @@
|
||||
<string>Restrict file types</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox">
|
||||
<property name="name">
|
||||
<cstring>restrictCtCB</cstring>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy>
|
||||
<hsizetype>1</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>By categories</string>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>saveFileTypesPB</cstring>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.15 2006-12-04 08:17:24 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.16 2006-12-20 13:12:49 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -42,10 +42,12 @@ static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.15 2006-12-04 08:17:24 dockes
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::list;
|
||||
using std::string;
|
||||
using std::map;
|
||||
#endif /* NO_NAMESPACES */
|
||||
|
||||
#include "recoll.h"
|
||||
@ -66,6 +68,8 @@ void AdvSearch::init()
|
||||
connect(searchPB, SIGNAL(clicked()), this, SLOT(searchPB_clicked()));
|
||||
connect(restrictFtCB, SIGNAL(toggled(bool)),
|
||||
this, SLOT(restrictFtCB_toggled(bool)));
|
||||
connect(restrictCtCB, SIGNAL(toggled(bool)),
|
||||
this, SLOT(restrictCtCB_toggled(bool)));
|
||||
connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(browsePB, SIGNAL(clicked()), this, SLOT(browsePB_clicked()));
|
||||
connect(addFiltypPB, SIGNAL(clicked()), this, SLOT(addFiltypPB_clicked()));
|
||||
@ -101,18 +105,12 @@ void AdvSearch::init()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize lists of accepted and ignored mime types from config
|
||||
// and settings
|
||||
list<string> types = rclconfig->getAllMimeTypes();
|
||||
noFiltypsLB->insertStringList(prefs.asearchIgnFilTyps);
|
||||
|
||||
QStringList ql;
|
||||
for (list<string>::iterator it = types.begin(); it != types.end(); it++) {
|
||||
if (prefs.asearchIgnFilTyps.findIndex(it->c_str())<0)
|
||||
ql.append(it->c_str());
|
||||
}
|
||||
yesFiltypsLB->insertStringList(ql);
|
||||
restrictCtCB->setChecked(prefs.fileTypesByCats);
|
||||
restrictCtCB->setEnabled(false);
|
||||
fillFileTypes();
|
||||
|
||||
subtreeCMB->insertStringList(prefs.asearchSubdirHist);
|
||||
subtreeCMB->setEditText("");
|
||||
@ -268,6 +266,7 @@ void AdvSearch::addAFiltypPB_clicked()
|
||||
// Activate file type selection
|
||||
void AdvSearch::restrictFtCB_toggled(bool on)
|
||||
{
|
||||
restrictCtCB->setEnabled(on);
|
||||
yesFiltypsLB->setEnabled(on);
|
||||
delFiltypPB->setEnabled(on);
|
||||
addFiltypPB->setEnabled(on);
|
||||
@ -277,6 +276,75 @@ void AdvSearch::restrictFtCB_toggled(bool on)
|
||||
saveFileTypesPB->setEnabled(on);
|
||||
}
|
||||
|
||||
void AdvSearch::restrictCtCB_toggled(bool on)
|
||||
{
|
||||
prefs.fileTypesByCats = on;
|
||||
fillFileTypes();
|
||||
}
|
||||
|
||||
static map<QString,QString> cat_translations;
|
||||
static map<QString,QString> cat_rtranslations;
|
||||
|
||||
void AdvSearch::fillFileTypes()
|
||||
{
|
||||
noFiltypsLB->clear();
|
||||
yesFiltypsLB->clear();
|
||||
|
||||
if (prefs.fileTypesByCats == false) {
|
||||
list<string> types = rclconfig->getAllMimeTypes();
|
||||
noFiltypsLB->insertStringList(prefs.asearchIgnFilTyps);
|
||||
|
||||
QStringList ql;
|
||||
for (list<string>::iterator it = types.begin();
|
||||
it != types.end(); it++) {
|
||||
if (prefs.asearchIgnFilTyps.findIndex(it->c_str())<0)
|
||||
ql.append(it->c_str());
|
||||
}
|
||||
yesFiltypsLB->insertStringList(ql);
|
||||
} else {
|
||||
cat_translations.clear();
|
||||
// Make sure we have entries for all defined categories
|
||||
// Translations for known cats
|
||||
cat_translations[QString::fromUtf8("texts")] = tr("texts");
|
||||
cat_rtranslations[tr("texts")] = QString::fromUtf8("texts");
|
||||
|
||||
cat_translations[QString::fromUtf8("spreadsheets")] =
|
||||
tr("spreadsheets");
|
||||
cat_rtranslations[tr("spreadsheets")] =
|
||||
QString::fromUtf8("spreadsheets");
|
||||
|
||||
cat_translations[QString::fromUtf8("presentations")] =
|
||||
tr("presentations");
|
||||
cat_rtranslations[tr("presentations")] =
|
||||
QString::fromUtf8("presentations");
|
||||
|
||||
cat_translations[QString::fromUtf8("media")] = tr("media");
|
||||
cat_rtranslations[tr("media")] = QString::fromUtf8("media");
|
||||
|
||||
cat_translations[QString::fromUtf8("messages")] = tr("messages");
|
||||
cat_rtranslations[tr("messages")] = QString::fromUtf8("messages");
|
||||
|
||||
cat_translations[QString::fromUtf8("other")] = tr("other");
|
||||
cat_rtranslations[tr("other")] = QString::fromUtf8("other");
|
||||
|
||||
list<string> cats;
|
||||
rclconfig->getMimeCategories(cats);
|
||||
QStringList ql;
|
||||
for (list<string>::const_iterator it = cats.begin();
|
||||
it != cats.end(); it++) {
|
||||
map<QString, QString>::const_iterator it1;
|
||||
if ((it1 =
|
||||
cat_translations.find(QString::fromUtf8((*it).c_str())))
|
||||
!= cat_translations.end()) {
|
||||
ql.append(it1->second);
|
||||
} else {
|
||||
ql.append(QString::fromUtf8((*it).c_str()));
|
||||
}
|
||||
}
|
||||
yesFiltypsLB->insertStringList(ql);
|
||||
}
|
||||
}
|
||||
|
||||
using namespace Rcl;
|
||||
void AdvSearch::searchPB_clicked()
|
||||
{
|
||||
@ -306,7 +374,26 @@ void AdvSearch::searchPB_clicked()
|
||||
}
|
||||
if (restrictFtCB->isOn() && noFiltypsLB->count() > 0) {
|
||||
for (unsigned int i = 0; i < yesFiltypsLB->count(); i++) {
|
||||
sdata->addFiletype((const char *)yesFiltypsLB->item(i)->text().utf8());
|
||||
if (restrictCtCB->isOn()) {
|
||||
QString qcat = yesFiltypsLB->item(i)->text();
|
||||
map<QString,QString>::const_iterator qit;
|
||||
string cat;
|
||||
if ((qit = cat_rtranslations.find(qcat)) !=
|
||||
cat_rtranslations.end()) {
|
||||
cat = (const char *)qit->second.utf8();
|
||||
} else {
|
||||
cat = (const char *)qcat.utf8();
|
||||
}
|
||||
list<string> types;
|
||||
rclconfig->getMimeCatTypes(cat, types);
|
||||
for (list<string>::const_iterator it = types.begin();
|
||||
it != types.end(); it++) {
|
||||
sdata->addFiletype(*it);
|
||||
}
|
||||
} else {
|
||||
sdata->addFiletype((const char *)
|
||||
yesFiltypsLB->item(i)->text().utf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _ADVSEARCH_W_H_INCLUDED_
|
||||
#define _ADVSEARCH_W_H_INCLUDED_
|
||||
/* @(#$Id: advsearch_w.h,v 1.10 2006-12-04 09:56:26 dockes Exp $ (C) 2005 J.F.Dockes */
|
||||
/* @(#$Id: advsearch_w.h,v 1.11 2006-12-20 13:12:49 dockes Exp $ (C) 2005 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
|
||||
@ -65,7 +65,8 @@ public slots:
|
||||
virtual void delAFiltypPB_clicked();
|
||||
virtual void addFiltypPB_clicked();
|
||||
virtual void addAFiltypPB_clicked();
|
||||
virtual void restrictFtCB_toggled(bool on);
|
||||
virtual void restrictFtCB_toggled(bool);
|
||||
virtual void restrictCtCB_toggled(bool);
|
||||
virtual void searchPB_clicked();
|
||||
virtual void browsePB_clicked();
|
||||
virtual void saveFileTypes();
|
||||
@ -84,6 +85,7 @@ private:
|
||||
virtual void init();
|
||||
std::list<SearchClauseW *> m_clauseWins;
|
||||
void saveCnf();
|
||||
void fillFileTypes();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.27 2006-12-04 06:19:11 dockes Exp $ (C) 2005 Jean-Francois Dockes";
|
||||
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.28 2006-12-20 13:12:49 dockes Exp $ (C) 2005 Jean-Francois Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -226,7 +226,7 @@ void rwSettings(bool writing)
|
||||
SETTING_RW(prefs.ssearchAutoPhrase,
|
||||
"/Recoll/prefs/query/ssearchAutoPhrase", Bool, false);
|
||||
|
||||
// Ssearch combobox history list
|
||||
// Ignored file types (advanced search)
|
||||
if (writing) {
|
||||
settings.writeEntry("/Recoll/prefs/query/asearchIgnFilTyps",
|
||||
prefs.asearchIgnFilTyps);
|
||||
@ -234,6 +234,8 @@ void rwSettings(bool writing)
|
||||
prefs.asearchIgnFilTyps =
|
||||
settings.readListEntry("/Recoll/prefs/query/asearchIgnFilTyps");
|
||||
}
|
||||
SETTING_RW(prefs.fileTypesByCats, "/Recoll/prefs/query/asearchFilTypByCat",
|
||||
Bool, false);
|
||||
|
||||
// The extra databases settings. These are stored as a list of
|
||||
// xapian directory names, encoded in base64 to avoid any
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#ifndef _GUIUTILS_H_INCLUDED_
|
||||
#define _GUIUTILS_H_INCLUDED_
|
||||
/*
|
||||
* @(#$Id: guiutils.h,v 1.18 2006-11-30 13:38:44 dockes Exp $ (C) 2005 Jean-Francois Dockes
|
||||
* @(#$Id: guiutils.h,v 1.19 2006-12-20 13:12:49 dockes Exp $ (C) 2005 Jean-Francois Dockes
|
||||
* jean-francois.dockes@wanadoo.fr
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -92,7 +92,8 @@ class PrefsPack {
|
||||
bool ssearchAutoPhrase;
|
||||
// Ignored file types in adv search (startup default)
|
||||
QStringList asearchIgnFilTyps;
|
||||
|
||||
bool fileTypesByCats;
|
||||
|
||||
// Synthetized abstract length and word context size
|
||||
int syntAbsLen;
|
||||
int syntAbsCtx;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# @(#$Id: mimeconf,v 1.20 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
# @(#$Id: mimeconf,v 1.21 2006-12-20 13:12:49 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
|
||||
# Recoll : associations of mime types to processing filters.
|
||||
# There are different sections for decompression, 'interning' for indexing
|
||||
@ -78,3 +78,40 @@ text/html = html
|
||||
text/plain = txt
|
||||
text/x-mail = message
|
||||
text/x-c = source
|
||||
|
||||
|
||||
[categories]
|
||||
|
||||
texts = application/msword \
|
||||
application/pdf \
|
||||
application/postscript \
|
||||
application/vnd.sun.xml.writer \
|
||||
application/vnd.sun.xml.writer.global \
|
||||
application/vnd.sun.xml.writer.template \
|
||||
application/x-dvi \
|
||||
image/vnd.djvu \
|
||||
text/html \
|
||||
text/plain \
|
||||
text/rtf
|
||||
|
||||
spreadsheets = application/vnd.ms-excel \
|
||||
application/vnd.sun.xml.calc \
|
||||
application/vnd.sun.xml.calc.template
|
||||
|
||||
presentations = application/vnd.ms-powerpoint \
|
||||
application/vnd.sun.xml.impress \
|
||||
application/vnd.sun.xml.impress.template
|
||||
|
||||
media = audio/mpeg \
|
||||
image/jpeg \
|
||||
image/png \
|
||||
|
||||
messages = message/rfc822 \
|
||||
text/x-gaim-log \
|
||||
text/x-mail \
|
||||
|
||||
other = application/vnd.sun.xml.draw \
|
||||
application/vnd.sun.xml.draw.template \
|
||||
application/vnd.sun.xml.math \
|
||||
application/x-fsdirectory
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user