Windows: GUI "Open" works

This commit is contained in:
Jean-Francois Dockes 2015-10-09 11:03:27 +02:00
parent 6eb2fd3622
commit 0dea7a849d
10 changed files with 135 additions and 15 deletions

View file

@ -399,7 +399,9 @@ void RclMain::execViewer(const map<string, string>& subs, bool istempfile,
// Also substitute inside the unsplitted command line and display
// in status bar
pcSubst(cmd, ncmd, subs);
#ifndef _WIN32
ncmd += " &";
#endif
QStatusBar *stb = statusBar();
if (stb) {
string fcharset = theconfig->getDefCharset(true);
@ -417,7 +419,7 @@ void RclMain::execViewer(const map<string, string>& subs, bool istempfile,
zg_send_event(ZGSEND_OPEN, doc);
// We keep pushing back and never deleting. This can't be good...
ExecCmd *ecmd = new ExecCmd;
ExecCmd *ecmd = new ExecCmd(ExecCmd::EXF_SHOWWINDOW);
m_viewers.push_back(ecmd);
ecmd->startExec(execpath, lcmd, false, false);
}

View file

@ -6,8 +6,11 @@ LANGUAGE = C++
QT += webkit
# QT += dbus
# QMAKE_CXXFLAGS += -DUSE_ZEITGEIST
DEFINES += BUILDING_RECOLL
DEFINES -= UNICODE
DEFINES -= _UNICODE
DEFINES += _MBCS
DEFINES += PSAPI_VERSION=1
QT += xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webkitwidgets printsupport
@ -106,7 +109,7 @@ windows {
contains(QMAKE_CC, cl){
# Visual Studio
}
LIBS += C:/recoll/src/build-librecoll-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/librecoll.dll
LIBS += C:/recoll/src/windows/build-librecoll-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/librecoll.dll
}
TRANSLATIONS = \

View file

@ -153,7 +153,7 @@ public:
};
bool ExecCmd::Internal::o_useVfork = false;
ExecCmd::ExecCmd()
ExecCmd::ExecCmd(int)
{
m = new Internal();
if (m)

View file

@ -176,7 +176,14 @@ class ExecCmd {
*/
bool requestChildExit();
ExecCmd();
enum ExFlags {EXF_NONE,
// Only does anything on windows. Used when starting
// a viewer. The default is to hide the window,
// because it avoids windows appearing and
// disappearing when executing stuff for previewing
EXF_SHOWWINDOW = 1,
};
ExecCmd(int flags = 0);
~ExecCmd();
/**

View file

@ -361,6 +361,10 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
case EPERM:
case EACCES:
case ENOENT:
#ifdef _WIN32
// We get this quite a lot, don't know why. To be checked.
case EINVAL:
#endif
goto out;
default:
status = FtwError;

View file

@ -255,8 +255,9 @@ static int getVMMBytes(HANDLE hProcess)
class ExecCmd::Internal {
public:
Internal()
: m_advise(0), m_provide(0), m_timeoutMs(1000), m_rlimit_as_mbytes(0) {
Internal(int flags)
: m_advise(0), m_provide(0), m_timeoutMs(1000), m_rlimit_as_mbytes(0),
m_flags(flags) {
reset();
}
@ -265,6 +266,7 @@ public:
ExecCmdProvide *m_provide;
int m_timeoutMs;
int m_rlimit_as_mbytes;
int m_flags;
// We need buffered I/O for getline. The Unix version uses netcon's
string m_buf; // Buffer. Only used when doing getline()s
@ -360,9 +362,9 @@ private:
bool m_active;
};
ExecCmd::ExecCmd()
ExecCmd::ExecCmd(int flags)
{
m = new Internal();
m = new Internal(flags);
if (m) {
m->reset();
}
@ -703,7 +705,11 @@ int ExecCmd::startExec(const string &cmd, const vector<string>& args,
// This structure specifies the STDIN and STDOUT handles for redirection.
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
if (m->m_flags & EXF_SHOWWINDOW) {
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
} else {
siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
}
siStartInfo.hStdOutput = hOutputWrite;
siStartInfo.hStdInput = hInputRead;
siStartInfo.hStdError = hErrorWrite;

View file

@ -22,7 +22,10 @@ xallexcepts = \
[view]
# Pseudo entry used if the 'use desktop' preference is set in the GUI
application/x-all = cmd /c start %u
# Could not get the cmd-based ones to work (tried quoting "start %u" too)
#application/x-all = c:/Windows/System32/cmd /c start %u
#application/x-all = cmd /c start %u
application/x-all = rclstartw %f
####### Special ones
# Open the parent epub document for epub parts instead of opening them as
@ -53,7 +56,10 @@ application/x-dvi = evince --page-index=%p --find=%s %f
application/x-lyx = lyx %f
application/x-scribus = scribus %f
application/msword = libreoffice %f
#application/msword = libreoffice %f
application/msword = \
"C:/Program Files (x86)/LibreOffice 5/program/soffice.exe" %f
application/vnd.ms-excel = libreoffice %f
application/vnd.ms-powerpoint = libreoffice %f

View file

@ -22,7 +22,7 @@ LIBR=C:/recoll/src/windows/build-librecoll-Desktop_Qt_5_5_0_MinGW_32bit-Debug/de
GUIBIN=C:/Users/Bill/recoll/src/build-recoll-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/recoll.exe
RCLIDX=C:/recoll/src/windows/build-recollindex-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/recollindex.exe
RCLQ=C:/recoll/src/windows/build-recollq-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/recollq.exe
RCLS=C:/recoll/src/windows/build-rclstartw-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/rclstartw.exe
################
# Script:
@ -56,6 +56,7 @@ copyrecoll()
cc $GUIBIN $DESTDIR
cc $RCLIDX $DESTDIR
cc $RCLQ $DESTDIR
cc $RCLS $DESTDIR
cc $RECOLL/sampleconf/fields $DESTDIR/Share/examples
cc $RECOLL/sampleconf/fragbuts.xml $DESTDIR/Share/examples

View file

@ -0,0 +1,33 @@
QT -= core gui
TARGET = rclstartw
TEMPLATE = app
DEFINES += BUILDING_RECOLL
DEFINES -= UNICODE
DEFINES -= _UNICODE
DEFINES += _MBCS
DEFINES += PSAPI_VERSION=1
SOURCES += \
../rclstartw.cpp
INCLUDEPATH += ../../common ../../index ../../internfile ../../query \
../../unac ../../utils ../../aspell ../../rcldb ../../qtgui \
../../xaposix ../../confgui ../../bincimapmime
windows {
contains(QMAKE_CC, gcc){
# MingW
QMAKE_CXXFLAGS += -std=c++11 -Wno-unused-parameter
}
contains(QMAKE_CC, cl){
# Visual Studio
}
LIBS += \
-liconv -lshlwapi -lpsapi -lkernel32
INCLUDEPATH += ../../windows
}

58
src/windows/rclstartw.cpp Normal file
View file

@ -0,0 +1,58 @@
/* Copyright (C) 2015 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 "autoconfig.h"
#include <shellapi.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
// This exists only because I could not find any way to get "cmd /c
// start fn" to work when executed from the recoll GUI. Otoh,
// cygstart, which uses ShellExecute() did work... So this is just a
// simpler cygstart
static char *thisprog;
static char usage [] ="rclstartw <fn>\n"
" Will use ShellExecute to open the arg with the default app\n";
static void Usage(FILE *fp = stderr)
{
fprintf(fp, "%s: usage:\n%s", thisprog, usage);
exit(1);
}
int main(int argc, char *argv[])
{
thisprog = argv[0];
argc--; argv++;
if (argc != 1) {
Usage();
}
char *fn = strdup(argv[0]);
// Do we need this ?
//https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx
//CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
int ret = (int)ShellExecute(NULL, "open", fn, NULL, NULL, SW_SHOWNORMAL);
if (ret) {
fprintf(stderr, "ShellExecute returned %d\n", ret);
}
return ret;
}