Add --clipboard to gui subcommand (#1829)

* Add --clipboard to gui subcommand

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Prevent duplicate notification

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
Haris Gušić
2021-08-20 20:09:06 +02:00
committed by GitHub
parent 39afd66650
commit 584bcd7f6c
7 changed files with 34 additions and 10 deletions

View File

@@ -5,6 +5,7 @@
<!--
graphicCapture:
@path: the path where the screenshot will be saved. When the argument is empty the program will ask for a path graphically.
@toClipboard: Whether to copy the screenshot to clipboard or not.
@delay: delay time in milliseconds.
@id: identificator of the call.
@@ -13,6 +14,7 @@
-->
<method name="graphicCapture">
<arg name="path" type="s" direction="in"/>
<arg name="toClipboard" type="b" direction="in"/>
<arg name="delay" type="i" direction="in"/>
<arg name="id" type="u" direction="in"/>
</method>

View File

@@ -140,6 +140,11 @@ void Controller::setCheckForUpdatesEnabled(const bool enabled)
}
}
QMap<uint, CaptureRequest>& Controller::requests()
{
return m_requestMap;
}
void Controller::getLatestAvailableVersion()
{
// This features is required for MacOS and Windows user and for Linux users

View File

@@ -42,6 +42,8 @@ public:
void setCheckForUpdatesEnabled(const bool enabled);
QMap<uint, CaptureRequest>& requests();
signals:
void captureTaken(uint id, QPixmap p, QRect selection);
void captureFailed(uint id);

View File

@@ -28,12 +28,15 @@ FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent)
FlameshotDBusAdapter::~FlameshotDBusAdapter() {}
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
void FlameshotDBusAdapter::graphicCapture(QString path,
bool toClipboard,
int delay,
uint id)
{
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path);
// if (toClipboard) {
// req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
// }
if (toClipboard) {
req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
}
req.setStaticID(id);
Controller::getInstance()->requestCapture(req);
}

View File

@@ -21,7 +21,10 @@ signals:
void captureSaved(uint id, QString savePath);
public slots:
Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
Q_NOREPLY void graphicCapture(QString path,
bool toClipboard,
int delay,
uint id);
Q_NOREPLY void fullScreen(QString path,
bool toClipboard,
int delay,

View File

@@ -247,9 +247,12 @@ int main(int argc, char* argv[])
parser.AddArgument(configArgument);
auto helpOption = parser.addHelpOption();
auto versionOption = parser.addVersionOption();
parser.AddOptions(
{ pathOption, delayOption, rawImageOption, selectionOption },
guiArgument);
parser.AddOptions({ pathOption,
clipboardOption,
delayOption,
rawImageOption,
selectionOption },
guiArgument);
parser.AddOptions({ screenNumberOption,
clipboardOption,
pathOption,
@@ -289,10 +292,14 @@ int main(int argc, char* argv[])
} else if (parser.isSet(guiArgument)) { // GUI
QString pathValue = parser.value(pathOption);
int delay = parser.value(delayOption).toInt();
bool toClipboard = parser.isSet(clipboardOption);
bool isRaw = parser.isSet(rawImageOption);
bool isSelection = parser.isSet(selectionOption);
DBusUtils dbusUtils;
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, pathValue);
if (toClipboard) {
req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
}
uint id = req.id();
// Send message
@@ -301,7 +308,7 @@ int main(int argc, char* argv[])
QStringLiteral("/"),
QLatin1String(""),
QStringLiteral("graphicCapture"));
m << pathValue << delay << id;
m << pathValue << toClipboard << delay << id;
QDBusConnection sessionBus = QDBusConnection::sessionBus();
dbusUtils.checkDBusConnection(sessionBus);
sessionBus.call(m);

View File

@@ -1574,7 +1574,9 @@ void CaptureWidget::copyScreenshot()
processPixmapWithTool(&m_context.screenshot, m_activeTool);
}
ScreenshotSaver().saveToClipboard(pixmap());
auto req = Controller::getInstance()->requests().find(m_id);
req->addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
close();
}