Import sample fragbuts.xml if user file does not exist
This commit is contained in:
parent
5c067685f0
commit
895f7c1ab1
4 changed files with 58 additions and 13 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include "recoll.h"
|
#include "recoll.h"
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "readfile.h"
|
#include "readfile.h"
|
||||||
|
#include "copyfile.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -147,6 +148,12 @@ FragButs::FragButs(QWidget* parent)
|
||||||
m_fn = path_cat(theconfig->getConfDir(), "fragbuts.xml");
|
m_fn = path_cat(theconfig->getConfDir(), "fragbuts.xml");
|
||||||
|
|
||||||
string data, reason;
|
string data, reason;
|
||||||
|
if (access(m_fn.c_str(), 0) != 0) {
|
||||||
|
// config does not exist: try to create it from sample
|
||||||
|
string src = path_cat(theconfig->getDatadir(), "examples");
|
||||||
|
src = path_cat(src, "fragbuts.xml");
|
||||||
|
copyfile(src.c_str(), m_fn.c_str(), reason);
|
||||||
|
}
|
||||||
if (!file_to_string(m_fn, data, &reason)) {
|
if (!file_to_string(m_fn, data, &reason)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("%1 not found.").arg(
|
tr("%1 not found.").arg(
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Example file for configuring the "Query fragments" window.
|
||||||
|
Each <buttons> or <radiobuttons> element defines a lines of buttons
|
||||||
|
Each active button adds a query language fragment to the current query
|
||||||
|
before execution.
|
||||||
|
-->
|
||||||
|
|
||||||
<fragbuts version="1.0">
|
<fragbuts version="1.0">
|
||||||
|
|
||||||
<radiobuttons>
|
<radiobuttons>
|
||||||
|
<!-- Actually useful: toggle WEB queue results inclusion -->
|
||||||
<fragbut>
|
<fragbut>
|
||||||
<label>Include Web Results</label>
|
<label>Include Web Results</label>
|
||||||
<frag></frag>
|
<frag></frag>
|
||||||
|
@ -23,20 +29,29 @@
|
||||||
<buttons>
|
<buttons>
|
||||||
|
|
||||||
<fragbut>
|
<fragbut>
|
||||||
<label>Year 2010</label>
|
<label>Example: Year 2010</label>
|
||||||
<frag>date:2010-01-01/2010-12-31</frag>
|
<frag>date:2010-01-01/2010-12-31</frag>
|
||||||
</fragbut>
|
</fragbut>
|
||||||
|
|
||||||
<fragbut>
|
<fragbut>
|
||||||
<label>c++ files</label>
|
<label>Example: c++ files</label>
|
||||||
<frag>ext:cpp OR ext:cxx</frag>
|
<frag>ext:cpp OR ext:cxx</frag>
|
||||||
</fragbut>
|
</fragbut>
|
||||||
|
|
||||||
<fragbut>
|
<fragbut>
|
||||||
<label>My Great Directory</label>
|
<label>Example: My Great Directory</label>
|
||||||
<frag>dir:/my/great/directory</frag>
|
<frag>dir:/my/great/directory</frag>
|
||||||
</fragbut>
|
</fragbut>
|
||||||
|
|
||||||
</buttons>
|
</buttons>
|
||||||
|
|
||||||
|
<buttons>
|
||||||
|
|
||||||
|
<fragbut>
|
||||||
|
<label>Check the manual (Query Fragments Window section) for explanations</label>
|
||||||
|
<frag></frag>
|
||||||
|
</fragbut>
|
||||||
|
|
||||||
|
</buttons>
|
||||||
|
|
||||||
</fragbuts>
|
</fragbuts>
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
#include "copyfile.h"
|
#include "copyfile.h"
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#define CPBSIZ 8192
|
#define CPBSIZ 8192
|
||||||
#define COPYFILE_NOERRUNLINK 1
|
|
||||||
|
|
||||||
bool copyfile(const char *src, const char *dst, string &reason, int flags)
|
bool copyfile(const char *src, const char *dst, string &reason, int flags)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +39,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
|
||||||
int dfd = -1;
|
int dfd = -1;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
char buf[CPBSIZ];
|
char buf[CPBSIZ];
|
||||||
|
int oflags = O_WRONLY|O_CREAT|O_TRUNC;
|
||||||
|
|
||||||
LOGDEB(("copyfile: %s to %s\n", src, dst));
|
LOGDEB(("copyfile: %s to %s\n", src, dst));
|
||||||
|
|
||||||
|
@ -46,7 +48,11 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dfd = open(dst, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
|
if (flags & COPYFILE_EXCL) {
|
||||||
|
oflags |= O_EXCL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dfd = open(dst, oflags, 0644)) < 0) {
|
||||||
reason += string("open/creat ") + dst + ": " + strerror(errno);
|
reason += string("open/creat ") + dst + ": " + strerror(errno);
|
||||||
// If we fail because of an open/truncate error, we do not want to unlink
|
// If we fail because of an open/truncate error, we do not want to unlink
|
||||||
// the file, we might succeed...
|
// the file, we might succeed...
|
||||||
|
@ -143,18 +149,21 @@ bool renameormove(const char *src, const char *dst, string &reason)
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#include "copyfile.h"
|
#include "copyfile.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
static int op_flags;
|
static int op_flags;
|
||||||
#define OPT_MOINS 0x1
|
#define OPT_MOINS 0x1
|
||||||
#define OPT_m 0x2
|
#define OPT_m 0x2
|
||||||
|
#define OPT_e 0x4
|
||||||
|
|
||||||
static const char *thisprog;
|
static const char *thisprog;
|
||||||
static char usage [] =
|
static char usage [] =
|
||||||
"trcopyfile [-m] src dst\n"
|
"trcopyfile [-m] src dst\n"
|
||||||
" -m : move instead of copying\n"
|
" -m : move instead of copying\n"
|
||||||
|
" -e : fail if dest exists (only for copy)\n"
|
||||||
"\n"
|
"\n"
|
||||||
;
|
;
|
||||||
static void
|
static void
|
||||||
|
@ -177,6 +186,7 @@ int main(int argc, const char **argv)
|
||||||
while (**argv)
|
while (**argv)
|
||||||
switch (*(*argv)++) {
|
switch (*(*argv)++) {
|
||||||
case 'm': op_flags |= OPT_m; break;
|
case 'm': op_flags |= OPT_m; break;
|
||||||
|
case 'e': op_flags |= OPT_e; break;
|
||||||
default: Usage(); break;
|
default: Usage(); break;
|
||||||
}
|
}
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
@ -191,7 +201,11 @@ int main(int argc, const char **argv)
|
||||||
if (op_flags & OPT_m) {
|
if (op_flags & OPT_m) {
|
||||||
ret = renameormove(src.c_str(), dst.c_str(), reason);
|
ret = renameormove(src.c_str(), dst.c_str(), reason);
|
||||||
} else {
|
} else {
|
||||||
ret = copyfile(src.c_str(), dst.c_str(), reason);
|
int flags = 0;
|
||||||
|
if (op_flags & OPT_e) {
|
||||||
|
flags |= COPYFILE_EXCL;
|
||||||
|
}
|
||||||
|
ret = copyfile(src.c_str(), dst.c_str(), reason, flags);
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
cerr << reason << endl;
|
cerr << reason << endl;
|
||||||
|
|
|
@ -18,14 +18,23 @@
|
||||||
#define _COPYFILE_H_INCLUDED_
|
#define _COPYFILE_H_INCLUDED_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
using std::string;
|
|
||||||
|
|
||||||
enum CopyfileFlags {COPYFILE_NONE = 0, COPYFILE_NOERRUNLINK = 1};
|
enum CopyfileFlags {COPYFILE_NONE = 0,
|
||||||
|
COPYFILE_NOERRUNLINK = 1,
|
||||||
|
COPYFILE_EXCL = 2,
|
||||||
|
};
|
||||||
|
|
||||||
extern bool copyfile(const char *src, const char *dst, string &reason,
|
/** Copy src to dst.
|
||||||
|
*
|
||||||
|
* We destroy an existing dst except if COPYFILE_EXCL is set (or we if
|
||||||
|
* have no permission...).
|
||||||
|
* A partially copied dst is normally removed, except if COPYFILE_NOERRUNLINK
|
||||||
|
* is set.
|
||||||
|
*/
|
||||||
|
extern bool copyfile(const char *src, const char *dst, std::string &reason,
|
||||||
int flags = 0);
|
int flags = 0);
|
||||||
|
|
||||||
// Try to rename, copy/unlink source if this fails (different devs)
|
/** Try to rename src. If this fails (different devices) copy then unlink src */
|
||||||
extern bool renameormove(const char *src, const char *dst, string &reason);
|
extern bool renameormove(const char *src, const char *dst, std::string &reason);
|
||||||
|
|
||||||
#endif /* _COPYFILE_H_INCLUDED_ */
|
#endif /* _COPYFILE_H_INCLUDED_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue