Add local history for last screenshots
This commit is contained in:
committed by
Yuriy Puchkov
parent
c84db1fa03
commit
5861b21fcf
78
src/tools/historywidget.cpp
Normal file
78
src/tools/historywidget.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "historywidget.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/configenterprise.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPixmap>
|
||||
#include <QLabel>
|
||||
#include <QScrollArea>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QClipboard>
|
||||
|
||||
|
||||
HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setWindowTitle(tr("Screenshots history"));
|
||||
setFixedSize(this->size());
|
||||
|
||||
m_pVBox = new QVBoxLayout(this);
|
||||
|
||||
QScrollArea *scrollArea = new QScrollArea( this );
|
||||
scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
|
||||
scrollArea->setWidgetResizable( true );
|
||||
scrollArea->setGeometry( this->frameGeometry() );
|
||||
|
||||
QWidget *widget = new QWidget();
|
||||
scrollArea->setWidget( widget );
|
||||
widget->setLayout( m_pVBox );
|
||||
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
void HistoryWidget::loadHistory() {
|
||||
History history = History();
|
||||
QList<QString> historyFiles = history.history();
|
||||
|
||||
foreach(QString fileName, historyFiles) {
|
||||
QString fullFileName = history.path() + fileName;
|
||||
|
||||
QPixmap pixmap;
|
||||
pixmap.load( fullFileName, "png" );
|
||||
pixmap = pixmap.scaledToWidth(120);
|
||||
|
||||
QPushButton *button = new QPushButton;
|
||||
button->setStyleSheet("Text-align:left");
|
||||
QIcon buttonIcon(fullFileName);
|
||||
button->setIcon(buttonIcon);
|
||||
button->setIconSize(pixmap.rect().size());
|
||||
|
||||
QFileInfo *pFileInfo = new QFileInfo(fullFileName);
|
||||
QString lastModified = pFileInfo->lastModified().toString("yyyy-MM-dd hh:mm:ss");
|
||||
button->setText(lastModified);
|
||||
|
||||
connect(button, &QPushButton::clicked, this, [=](){
|
||||
// TODO - optimize it
|
||||
this->close();
|
||||
ConfigEnterprise configEnterprise;
|
||||
QSettings *settings = configEnterprise.settings();
|
||||
settings->beginGroup("S3");
|
||||
QString url = settings->value("S3_URL").toString() + fileName;
|
||||
settings->endGroup();
|
||||
QApplication::clipboard()->setText(url);
|
||||
// qDebug() << "URL copied to clipboard:" << url;
|
||||
|
||||
// NotificationWidget *notification = new NotificationWidget();
|
||||
// notification->showMessage(tr("URL copied to clipboard."));
|
||||
});
|
||||
|
||||
|
||||
m_pVBox->addWidget(button);
|
||||
}
|
||||
}
|
||||
24
src/tools/historywidget.h
Normal file
24
src/tools/historywidget.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef HISTORYWIDGET_H
|
||||
#define HISTORYWIDGET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
class HistoryWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HistoryWidget(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
void loadHistory();
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_pVBox;
|
||||
};
|
||||
|
||||
#endif // HISTORYWIDGET_H
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "src/widgets/imagelabel.h"
|
||||
#include "src/widgets/notificationwidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/configenterprise.h"
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
@@ -48,19 +50,6 @@
|
||||
ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) :
|
||||
QWidget(parent), m_pixmap(capture)
|
||||
{
|
||||
QSettings *pSettings = nullptr;
|
||||
QString configIniPath = QDir(QDir::currentPath()).filePath("config.ini");
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if(!(QFileInfo::exists(configIniPath) && QFileInfo(configIniPath).isFile())) {
|
||||
configIniPath = "/etc/flameshot/config.ini";
|
||||
}
|
||||
#endif
|
||||
pSettings = new QSettings(configIniPath, QSettings::IniFormat);
|
||||
pSettings->beginGroup("S3");
|
||||
m_s3CredsUrl = pSettings->value("S3_CREDS_URL").toString();
|
||||
m_s3XApiKey = pSettings->value("S3_X_API_KEY").toString();
|
||||
pSettings->endGroup();
|
||||
|
||||
setWindowTitle(tr("Upload to ImgS3"));
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
|
||||
@@ -83,13 +72,24 @@ ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) :
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
QString httpProxyHost = pSettings->value("HTTP_PROXY_HOST").toString();
|
||||
// get enterprise settings
|
||||
m_configEnterprise = new ConfigEnterprise();
|
||||
QSettings *settings = m_configEnterprise->settings();
|
||||
|
||||
// get s3 credentials
|
||||
settings->beginGroup("S3");
|
||||
m_s3CredsUrl = settings->value("S3_CREDS_URL").toString();
|
||||
m_s3XApiKey = settings->value("S3_X_API_KEY").toString();
|
||||
settings->endGroup();
|
||||
|
||||
// set proxy server parameters
|
||||
QString httpProxyHost = settings->value("HTTP_PROXY_HOST").toString();
|
||||
if(httpProxyHost.length() > 0) {
|
||||
qDebug() << "Using proxy server";
|
||||
m_proxy = new QNetworkProxy();
|
||||
|
||||
if(pSettings->contains("HTTP_PROXY_TYPE")) {
|
||||
switch (pSettings->value("HTTP_PROXY_TYPE").toInt()) {
|
||||
if(settings->contains("HTTP_PROXY_TYPE")) {
|
||||
switch (settings->value("HTTP_PROXY_TYPE").toInt()) {
|
||||
case 0:
|
||||
m_proxy->setType(QNetworkProxy::DefaultProxy);
|
||||
break;
|
||||
@@ -111,22 +111,26 @@ ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) :
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set proxy server parameters
|
||||
if(httpProxyHost.length() > 0) {
|
||||
m_proxy->setHostName(httpProxyHost);
|
||||
if(pSettings->contains("HTTP_PROXY_PORT")) {
|
||||
m_proxy->setPort(pSettings->value("HTTP_PROXY_PORT").toInt());
|
||||
if(settings->contains("HTTP_PROXY_PORT")) {
|
||||
m_proxy->setPort(settings->value("HTTP_PROXY_PORT").toInt());
|
||||
} else {
|
||||
m_proxy->setPort(3128);
|
||||
}
|
||||
|
||||
if(pSettings->contains("HTTP_PROXY_USER")) {
|
||||
m_proxy->setUser(pSettings->value("HTTP_PROXY_USER").toString());
|
||||
if(settings->contains("HTTP_PROXY_USER")) {
|
||||
m_proxy->setUser(settings->value("HTTP_PROXY_USER").toString());
|
||||
}
|
||||
if(pSettings->contains("HTTP_PROXY_PASSWORD")) {
|
||||
m_proxy->setPassword(pSettings->value("HTTP_PROXY_PASSWORD").toString());
|
||||
if(settings->contains("HTTP_PROXY_PASSWORD")) {
|
||||
m_proxy->setPassword(settings->value("HTTP_PROXY_PASSWORD").toString());
|
||||
}
|
||||
QNetworkProxy::setApplicationProxy(*m_proxy);
|
||||
m_NetworkAM->setProxy(*m_proxy);
|
||||
m_NetworkAMCreds->setProxy(*m_proxy);
|
||||
}
|
||||
|
||||
upload();
|
||||
@@ -135,6 +139,16 @@ ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) :
|
||||
void ImgS3Uploader::handleReply(QNetworkReply *reply) {
|
||||
m_spinner->deleteLater();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
// save history
|
||||
QString imageName = m_imageURL.toString();
|
||||
int lastSlash = imageName.lastIndexOf("/");
|
||||
if (lastSlash >= 0) {
|
||||
imageName = imageName.mid(lastSlash);
|
||||
}
|
||||
History history;
|
||||
history.save(m_pixmap, imageName);
|
||||
|
||||
// Copy url to clipboard if required
|
||||
if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
|
||||
QApplication::clipboard()->setText(m_imageURL.toString());
|
||||
SystemNotification().sendMessage(QObject::tr("URL copied to clipboard."));
|
||||
|
||||
@@ -30,6 +30,7 @@ class LoadSpinner;
|
||||
class QPushButton;
|
||||
class QUrl;
|
||||
class NotificationWidget;
|
||||
class ConfigEnterprise;
|
||||
|
||||
class ImgS3Uploader : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -49,6 +50,7 @@ private:
|
||||
void uploadToS3(QJsonDocument &response);
|
||||
|
||||
private:
|
||||
ConfigEnterprise *m_configEnterprise;
|
||||
QString m_s3CredsUrl;
|
||||
QString m_s3XApiKey;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user