Debian Codegraph @

src/gui/operations/LoadImageFromFileOperation.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "LoadImageFromFileOperation.h"
21
22 LoadImageFromFileOperation::LoadImageFromFileOperation(
23 const QString &path,
24 IImageProcessor *imageProcessor,
25 const QSharedPointer<INotificationService> &notificationService,
26 const QSharedPointer<IRecentImageService> &recentImageService,
27 const QSharedPointer<IFileService> &fileService,
28 const QSharedPointer<IConfig> &config) :
29 mImageProcessor(imageProcessor),
30 mPath(path),
31 mNotificationService(notificationService),
32 mRecentImageService(recentImageService),
33 mFileService(fileService),
34 mConfig(config)
35 {
36 }
37
38 bool LoadImageFromFileOperation::execute()
39 {
40 auto pixmap = mFileService->openPixmap(mPath);
41 if(pixmap.isNull()) {
42 notifyAboutInvalidPath();
43 return false;
44 } else {
45 mRecentImageService->storeImagePath(mPath);
46 CaptureFromFileDto captureDto(pixmap, mPath);
47 mImageProcessor->processImage(captureDto);
48 return true;
49 }
50 }
51
52 void LoadImageFromFileOperation::notifyAboutInvalidPath() const
53 {
54 auto title = tr("Unable to open image");
55 auto message = tr("Unable to open image from path %1").arg(mPath);
56 NotifyOperation operation(title, message, NotificationTypes::Warning, mNotificationService, mConfig);
57 operation.execute();
58 }
59