Просмотр исходного кода

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>
Haris Gušić 3 лет назад
Родитель
Сommit
584bcd7f6c

+ 2 - 0
data/dbus/org.flameshot.Flameshot.xml

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

+ 5 - 0
src/core/controller.cpp

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

+ 2 - 0
src/core/controller.h

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

+ 7 - 4
src/core/flameshotdbusadapter.cpp

@@ -28,12 +28,15 @@ FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent)
 
 
 FlameshotDBusAdapter::~FlameshotDBusAdapter() {}
 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);
     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);
     req.setStaticID(id);
     Controller::getInstance()->requestCapture(req);
     Controller::getInstance()->requestCapture(req);
 }
 }

+ 4 - 1
src/core/flameshotdbusadapter.h

@@ -21,7 +21,10 @@ signals:
     void captureSaved(uint id, QString savePath);
     void captureSaved(uint id, QString savePath);
 
 
 public slots:
 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,
     Q_NOREPLY void fullScreen(QString path,
                               bool toClipboard,
                               bool toClipboard,
                               int delay,
                               int delay,

+ 11 - 4
src/main.cpp

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

+ 3 - 1
src/widgets/capture/capturewidget.cpp

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