* Bumped Standards to 3.9.8, no changes needed * Bumped compat to 10 * Removed --parallel from rules, standard compat 10 * Bumped minimum version debhelper (>= 10) * Bumped minimum version libfm-qt-dev (>= 0.11.1) * Added build dependency libkf5windowsystem-dev * Added build dependency liblxqt0-dev (>= 0.11.0) * Added build dependency libqt5svg5-dev * Added build dependency libqt5xdg-dev (>= 2.0.0) * Added Recommends lxqtimage-qt-l10n * Added Recommends qt5-image-formats-plugins * Fixed copyrights Format field to https * Dropped patches, applied upstream * Added translation control to rules * Set CMAKE_BUILD_TYPE=RelWithDebInfo * Exported LC_ALL=C.UTF-8, make builds reproducible
73 lines
2.4 KiB
C++
73 lines
2.4 KiB
C++
/*
|
|
<one line to give the program's name and a brief idea of what it does.>
|
|
Copyright (C) 2013 PCMan <email>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
|
|
#include "saveimagejob.h"
|
|
#include "mainwindow.h"
|
|
#include <QImageReader>
|
|
#include <QBuffer>
|
|
#include <qvarlengtharray.h>
|
|
|
|
using namespace LxImage;
|
|
|
|
SaveImageJob::SaveImageJob(MainWindow* window, FmPath* filePath):
|
|
Job(),
|
|
mainWindow_(window),
|
|
path_(fm_path_ref(filePath)),
|
|
image_(window->image()) {
|
|
}
|
|
|
|
SaveImageJob::~SaveImageJob() {
|
|
fm_path_unref(path_);
|
|
}
|
|
|
|
// This is called from the worker thread, not main thread
|
|
bool SaveImageJob::run() {
|
|
GFile* gfile = fm_path_to_gfile(path_);
|
|
GFileOutputStream* fileStream = g_file_replace(gfile, NULL, false, G_FILE_CREATE_NONE, cancellable_, &error_);
|
|
g_object_unref(gfile);
|
|
|
|
if(fileStream) { // if the file stream is successfually opened
|
|
const char* format = fm_path_get_basename(path_);
|
|
format = strrchr(format, '.');
|
|
if(format) // use filename extension as the image format
|
|
++format;
|
|
|
|
QBuffer imageBuffer;
|
|
image_.save(&imageBuffer, format); // save the image to buffer
|
|
GOutputStream* outputStream = G_OUTPUT_STREAM(fileStream);
|
|
g_output_stream_write_all(outputStream,
|
|
imageBuffer.data().constData(),
|
|
imageBuffer.size(),
|
|
NULL,
|
|
cancellable_,
|
|
&error_);
|
|
g_output_stream_close(outputStream, NULL, NULL);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// this function is called from main thread only
|
|
void SaveImageJob::finish() {
|
|
// only do processing if the job is not cancelled
|
|
if(!g_cancellable_is_cancelled(cancellable_)) {
|
|
mainWindow_->onImageSaved(this);
|
|
}
|
|
}
|