Open With tool: show native dialong on Windows

This commit is contained in:
lupoDharkael
2018-01-13 17:21:40 +01:00
parent 46b6485db7
commit 0c7bd9ca0c
5 changed files with 90 additions and 6 deletions

View File

@@ -4,7 +4,7 @@
#
#-------------------------------------------------
win32:LIBS += -luser32 #-lshell32
win32:LIBS += -luser32 -lshell32
TAG_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)
DEFINES += APP_VERSION=\\\"$$TAG_VERSION\\\"
@@ -127,7 +127,8 @@ SOURCES += src/main.cpp \
src/capture/tools/blurtool.cpp \
src/capture/workers/launcher/terminallauncher.cpp \
src/config/visualseditor.cpp \
src/config/extendedslider.cpp
src/config/extendedslider.cpp \
src/capture/workers/launcher/openwithprogram.cpp
HEADERS += src/capture/widget/buttonhandler.h \
src/infowindow.h \
@@ -183,7 +184,8 @@ HEADERS += src/capture/widget/buttonhandler.h \
src/capture/tools/blurtool.h \
src/capture/workers/launcher/terminallauncher.h \
src/config/visualseditor.h \
src/config/extendedslider.h
src/config/extendedslider.h \
src/capture/workers/launcher/openwithprogram.h
unix:!macx {
SOURCES += src/core/flameshotdbusadapter.cpp \

View File

@@ -628,12 +628,14 @@ void CaptureWidget::updateCursor() {
void CaptureWidget::copyScreenshot() {
m_captureDone = true;
hide();
ResourceExporter().captureToClipboard(pixmap());
close();
}
void CaptureWidget::saveScreenshot() {
m_captureDone = true;
hide();
if (m_forcedSavePath.isEmpty()) {
ResourceExporter().captureToFileUi(pixmap());
} else {
@@ -644,12 +646,14 @@ void CaptureWidget::saveScreenshot() {
void CaptureWidget::uploadToImgur() {
m_captureDone = true;
hide();
ResourceExporter().captureToImgur(pixmap());
close();
}
void CaptureWidget::openWithProgram() {
m_captureDone = true;
hide();
ResourceExporter().captureToProgram(pixmap());
close();
}

View File

@@ -0,0 +1,54 @@
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
//
// This file is part of Flameshot.
//
// Flameshot 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 3 of the License, or
// (at your option) any later version.
//
// Flameshot 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 Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "openwithprogram.h"
#if defined(Q_OS_WIN)
#include "src/utils/filenamehandler.h"
#include <QDir>
#include <QMessageBox>
#include <windows.h>
#include <Shlobj.h>
#pragma comment(lib, "Shell32.lib")
#else
#include "src/capture/workers/launcher/applauncherwidget.h"
#endif
void showOpenWithMenu(const QPixmap &capture) {
#if defined(Q_OS_WIN)
QString tempFile =
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
bool ok = capture.save(tempFile);
if (!ok) {
QMessageBox::about(nullptr, QObject::tr("Error"),
QObject::tr("Unable to write in") + QDir::tempPath());
return;
}
OPENASINFO info;
auto wStringFile = tempFile.replace("/", "\\").toStdWString();
info.pcszFile = wStringFile.c_str();
info.pcszClass = nullptr;
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
SHOpenWithDialog(nullptr, &info);
#else
auto w = new AppLauncherWidget(capture);
w->show();
#endif
}

View File

@@ -0,0 +1,25 @@
// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
//
// This file is part of Flameshot.
//
// Flameshot 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 3 of the License, or
// (at your option) any later version.
//
// Flameshot 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 Flameshot. If not, see <http://www.gnu.org/licenses/>.
#ifndef OPENWITHPROGRAM_H
#define OPENWITHPROGRAM_H
#include <QPixmap>
void showOpenWithMenu(const QPixmap &capture);
#endif // OPENWITHPROGRAM_H

View File

@@ -19,7 +19,7 @@
#include "src/capture/workers/imgur/imguruploader.h"
#include "src/capture/workers/screenshotsaver.h"
#include "src/capture/workers/graphicalscreenshotsaver.h"
#include "src/capture/workers/launcher/applauncherwidget.h"
#include "src/capture/workers/launcher/openwithprogram.h"
ResourceExporter::ResourceExporter() {
@@ -44,6 +44,5 @@ void ResourceExporter::captureToImgur(const QPixmap &p) {
}
void ResourceExporter::captureToProgram(const QPixmap &p) {
auto w = new AppLauncherWidget(p);
w->show();
showOpenWithMenu(p);
}