Add auto saving.
This commit is contained in:
parent
b6943996ab
commit
24ee056485
2
.gitignore
vendored
2
.gitignore
vendored
@ -45,4 +45,6 @@ KShare
|
|||||||
|
|
||||||
*.Debug
|
*.Debug
|
||||||
|
|
||||||
|
vgcore.*
|
||||||
|
|
||||||
*.Release
|
*.Release
|
||||||
|
@ -34,7 +34,8 @@ SOURCES += main.cpp\
|
|||||||
uploaders/default/imguruploader.cpp \
|
uploaders/default/imguruploader.cpp \
|
||||||
io/ioutils.cpp \
|
io/ioutils.cpp \
|
||||||
settings.cpp \
|
settings.cpp \
|
||||||
uploaders/default/clipboarduploader.cpp
|
uploaders/default/clipboarduploader.cpp \
|
||||||
|
formatter.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -47,7 +48,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
uploaders/default/imguruploader.hpp \
|
uploaders/default/imguruploader.hpp \
|
||||||
io/ioutils.hpp \
|
io/ioutils.hpp \
|
||||||
settings.hpp \
|
settings.hpp \
|
||||||
uploaders/default/clipboarduploader.hpp
|
uploaders/default/clipboarduploader.hpp \
|
||||||
|
formatter.hpp
|
||||||
|
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
|
|
||||||
|
18
formatter.cpp
Normal file
18
formatter.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "formatter.hpp"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
QString formatter::format(QString toFormat)
|
||||||
|
{
|
||||||
|
QRegExp dateRegex("%\\((.+)\\)date");
|
||||||
|
dateRegex.indexIn(toFormat);
|
||||||
|
QStringList capturedTexts(dateRegex.capturedTexts());
|
||||||
|
QString formatted(toFormat);
|
||||||
|
QDateTime date = QDateTime::currentDateTime();
|
||||||
|
for (int i = 0; i < capturedTexts.length(); i += 2)
|
||||||
|
{
|
||||||
|
formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
|
||||||
|
}
|
||||||
|
return formatted;
|
||||||
|
}
|
12
formatter.hpp
Normal file
12
formatter.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef FORMATTER_HPP
|
||||||
|
#define FORMATTER_HPP
|
||||||
|
|
||||||
|
#include <QRegExp>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace formatter
|
||||||
|
{
|
||||||
|
QString format(QString toFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FORMATTER_HPP
|
7
main.cpp
7
main.cpp
@ -1,13 +1,12 @@
|
|||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <cropeditor/cropeditor.hpp>
|
|
||||||
#include <screenshotutil.hpp>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
a.setApplicationName("KShare");
|
||||||
|
a.setOrganizationName("ArsenArsen");
|
||||||
|
a.setApplicationName("1.0");
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <settings.hpp>
|
||||||
#include <uploaders/uploadersingleton.hpp>
|
#include <uploaders/uploadersingleton.hpp>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
@ -41,10 +42,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
{
|
{
|
||||||
QListWidgetItem *item = new QListWidgetItem(u->name());
|
QListWidgetItem *item = new QListWidgetItem(u->name());
|
||||||
item->setToolTip(u->description());
|
item->setToolTip(u->description());
|
||||||
// ui->uploaderList->setCurrentIndex(ui->uploaderList->model()->index(++i, 0))
|
|
||||||
ui->uploaderList->addItem(item);
|
ui->uploaderList->addItem(item);
|
||||||
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
|
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set filename scheme
|
||||||
|
if ((settings::settings().contains("fileFormat")))
|
||||||
|
setScheme(settings::settings().value("fileFormat").toString());
|
||||||
|
else
|
||||||
|
setScheme("Screenshot %(yyyy-MM-dd HH:mm:ss)date");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -52,6 +58,11 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setScheme(QString scheme)
|
||||||
|
{
|
||||||
|
ui->nameScheme->setText(scheme);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
@ -91,3 +102,8 @@ void MainWindow::on_uploaderList_clicked(const QModelIndex &)
|
|||||||
UploaderSingleton::inst().set(index.at(0)->text());
|
UploaderSingleton::inst().set(index.at(0)->text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_nameScheme_textEdited(const QString &arg1)
|
||||||
|
{
|
||||||
|
settings::settings().setValue("fileFormat", arg1);
|
||||||
|
}
|
||||||
|
@ -20,11 +20,14 @@ class MainWindow : public QMainWindow
|
|||||||
void on_actionFullscreen_triggered();
|
void on_actionFullscreen_triggered();
|
||||||
void on_actionArea_triggered();
|
void on_actionArea_triggered();
|
||||||
void on_uploaderList_clicked(const QModelIndex &);
|
void on_uploaderList_clicked(const QModelIndex &);
|
||||||
|
void on_nameScheme_textEdited(const QString &arg1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
void setScheme(QString scheme);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QSystemTrayIcon *tray;
|
QSystemTrayIcon *tray;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>262</width>
|
<width>256</width>
|
||||||
<height>239</height>
|
<height>286</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -29,7 +29,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>241</width>
|
<width>181</width>
|
||||||
<height>19</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -42,18 +42,47 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>256</width>
|
<width>251</width>
|
||||||
<height>192</height>
|
<height>192</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="nameScheme">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>230</y>
|
||||||
|
<width>251</width>
|
||||||
|
<height>27</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>http://doc.qt.io/qt-5/qdatetime.html#toString</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Screenshot %(yyyy-MM-dd HH:mm:ss)date</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>210</y>
|
||||||
|
<width>141</width>
|
||||||
|
<height>19</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>File name scheme:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menuBar">
|
<widget class="QMenuBar" name="menuBar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>262</width>
|
<width>256</width>
|
||||||
<height>24</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "default/imguruploader.hpp"
|
#include "default/imguruploader.hpp"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <formatter.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
|
||||||
UploaderSingleton::UploaderSingleton()
|
UploaderSingleton::UploaderSingleton()
|
||||||
@ -40,6 +41,15 @@ void UploaderSingleton::registerUploader(Uploader *uploader)
|
|||||||
|
|
||||||
void UploaderSingleton::upload(QPixmap *pixmap)
|
void UploaderSingleton::upload(QPixmap *pixmap)
|
||||||
{
|
{
|
||||||
|
if (settings::settings().contains("fileFormat"))
|
||||||
|
{
|
||||||
|
QString format = settings::settings().value("fileFormat").toString();
|
||||||
|
if (!format.isEmpty())
|
||||||
|
{
|
||||||
|
pixmap->save(QDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).absoluteFilePath(formatter::format(format) + ".png"),
|
||||||
|
"PNG");
|
||||||
|
}
|
||||||
|
}
|
||||||
uploaders.value(uploader)->doUpload(pixmap);
|
uploaders.value(uploader)->doUpload(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user