Пример #1
0
void Controller::requestCapture(const CaptureRequest &request) {
    uint id = request.id();
    m_requestMap.insert(id, request);

    switch (request.captureMode()) {
    case CaptureRequest::FULLSCREEN_MODE:
        doLater(request.delay(), this, [this, id](){
            this->startFullscreenCapture(id);
        });
        break;
    case CaptureRequest::SCREEN_MODE: {
        int &&number = request.data().toInt();
        doLater(request.delay(), this, [this, id, number](){
            this->startScreenGrab(id, number);
        });
        break;
    } case CaptureRequest::GRAPHICAL_MODE: {
        QString &&path = request.path();
        doLater(request.delay(), this, [this, id, path](){
            this->startVisualCapture(id, path);
        });
        break;
    } default:
        emit captureFailed(id);
        break;
    }
}
Пример #2
0
void FlameshotDBusAdapter::fullScreen(
        QString path, bool toClipboard, int delay, uint id)
{
    auto f = [id, path, toClipboard, this]() {
        bool ok = true;
        QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
        if (!ok) {
            SystemNotification().sendMessage(tr("Unable to capture screen"));
            Q_EMIT captureFailed(id);
            return;
        }
        if(toClipboard) {
            ResourceExporter().captureToClipboard(p);
        }
        if(!path.isEmpty()) {
            ResourceExporter().captureToFile(p, path);
        }
        QByteArray byteArray;
        QBuffer buffer(&byteArray);
        p.save(&buffer, "PNG");
        Q_EMIT captureTaken(id, byteArray);
    };
    //QTimer::singleShot(delay, this, f); // // requires Qt 5.4
    doLater(delay, this, f);
}
Пример #3
0
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id) {
    auto controller =  Controller::getInstance();

    auto f = [controller, id, path, this]() {
       controller->createVisualCapture(id, path);
    };
    // QTimer::singleShot(delay, controller, f); // requires Qt 5.4
    doLater(delay, controller, f);
}
Пример #4
0
void Controller::enableTrayIcon() {
    if (m_trayIcon) {
        return;
    }
    ConfigHandler().setDisabledTrayIcon(false);
    QAction *captureAction = new QAction(tr("&Take Screenshot"), this);
    connect(captureAction, &QAction::triggered, this, [this](){
        // Wait 400 ms to hide the QMenu
        doLater(400, this, [this](){ this->startVisualCapture(); });
    });
    QAction *configAction = new QAction(tr("&Configuration"), this);
    connect(configAction, &QAction::triggered, this,
            &Controller::openConfigWindow);
    QAction *infoAction = new QAction(tr("&Information"), this);
    connect(infoAction, &QAction::triggered, this,
            &Controller::openInfoWindow);
    QAction *quitAction = new QAction(tr("&Quit"), this);
    connect(quitAction, &QAction::triggered, qApp,
            &QCoreApplication::quit);

    QMenu *trayIconMenu = new QMenu();
    trayIconMenu->addAction(captureAction);
    trayIconMenu->addAction(configAction);
    trayIconMenu->addAction(infoAction);
    trayIconMenu->addSeparator();
    trayIconMenu->addAction(quitAction);

    m_trayIcon = new QSystemTrayIcon();
    m_trayIcon->setToolTip("Flameshot");
    m_trayIcon->setContextMenu(trayIconMenu);
    QIcon trayicon = QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
    m_trayIcon->setIcon(trayicon);

    auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r){
        if (r == QSystemTrayIcon::Trigger) {
            startVisualCapture();
        }
    };
    connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
    m_trayIcon->show();
}