Add auto saving.
This commit is contained in:
parent
b6943996ab
commit
24ee056485
2
.gitignore
vendored
2
.gitignore
vendored
@ -45,4 +45,6 @@ KShare
|
||||
|
||||
*.Debug
|
||||
|
||||
vgcore.*
|
||||
|
||||
*.Release
|
||||
|
@ -34,7 +34,8 @@ SOURCES += main.cpp\
|
||||
uploaders/default/imguruploader.cpp \
|
||||
io/ioutils.cpp \
|
||||
settings.cpp \
|
||||
uploaders/default/clipboarduploader.cpp
|
||||
uploaders/default/clipboarduploader.cpp \
|
||||
formatter.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -47,7 +48,8 @@ HEADERS += mainwindow.hpp \
|
||||
uploaders/default/imguruploader.hpp \
|
||||
io/ioutils.hpp \
|
||||
settings.hpp \
|
||||
uploaders/default/clipboarduploader.hpp
|
||||
uploaders/default/clipboarduploader.hpp \
|
||||
formatter.hpp
|
||||
|
||||
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 <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <cropeditor/cropeditor.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setApplicationName("KShare");
|
||||
a.setOrganizationName("ArsenArsen");
|
||||
a.setApplicationName("1.0");
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <settings.hpp>
|
||||
#include <uploaders/uploadersingleton.hpp>
|
||||
|
||||
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());
|
||||
item->setToolTip(u->description());
|
||||
// ui->uploaderList->setCurrentIndex(ui->uploaderList->model()->index(++i, 0))
|
||||
ui->uploaderList->addItem(item);
|
||||
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()
|
||||
@ -52,6 +58,11 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::setScheme(QString scheme)
|
||||
{
|
||||
ui->nameScheme->setText(scheme);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
@ -91,3 +102,8 @@ void MainWindow::on_uploaderList_clicked(const QModelIndex &)
|
||||
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_actionArea_triggered();
|
||||
void on_uploaderList_clicked(const QModelIndex &);
|
||||
void on_nameScheme_textEdited(const QString &arg1);
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
void setScheme(QString scheme);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QSystemTrayIcon *tray;
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<height>239</height>
|
||||
<width>256</width>
|
||||
<height>286</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -29,7 +29,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>241</width>
|
||||
<width>181</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -42,18 +42,47 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>20</y>
|
||||
<width>256</width>
|
||||
<width>251</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
</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 class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<width>256</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "default/imguruploader.hpp"
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <formatter.hpp>
|
||||
#include <settings.hpp>
|
||||
|
||||
UploaderSingleton::UploaderSingleton()
|
||||
@ -40,6 +41,15 @@ void UploaderSingleton::registerUploader(Uploader *uploader)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user