ExportManager.h 3.5 KB
Newer Older
1
2
/* This file is part of Spectacle, the KDE screenshot utility
 * Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org>
Boudhayan Gupta's avatar
Boudhayan Gupta committed
3
 *
4
5
6
7
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
Boudhayan Gupta's avatar
Boudhayan Gupta committed
8
 *
9
10
11
12
 * 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.
Boudhayan Gupta's avatar
Boudhayan Gupta committed
13
 *
14
15
16
17
18
19
 * You should have received a copy of the GNU Lesser 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.
 *
 * SPDX-License-Identifier: LGPL-2.0-or-later
Boudhayan Gupta's avatar
Boudhayan Gupta committed
20
21
 */

22
23
24
#pragma once

#include <SpectacleCommon.h>
Boudhayan Gupta's avatar
Boudhayan Gupta committed
25
26
27

#include <QObject>
#include <QIODevice>
28
#include <QMap>
Boudhayan Gupta's avatar
Boudhayan Gupta committed
29
#include <QPrinter>
Boudhayan Gupta's avatar
Boudhayan Gupta committed
30
#include <QPixmap>
31
#include <QDateTime>
Boudhayan Gupta's avatar
Boudhayan Gupta committed
32
#include <QUrl>
33
34
#include <KLocalizedString>

35
36
class QTemporaryDir;

37
class ExportManager: public QObject
Boudhayan Gupta's avatar
Boudhayan Gupta committed
38
39
40
41
42
43
44
45
46
47
48
{
    Q_OBJECT

    // singleton-ize the class

    public:

    static ExportManager* instance();

    private:

Laurent Montel's avatar
Laurent Montel committed
49
    explicit ExportManager(QObject *parent = nullptr);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
50
51
52
53
54
55
56
57
58
    virtual ~ExportManager();

    ExportManager(ExportManager const&) = delete;
    void operator= (ExportManager const&) = delete;

    // now the usual stuff

    public:

59
    QString defaultSaveLocation() const;
60
    bool isFileExists(const QUrl &url) const;
Boudhayan Gupta's avatar
Boudhayan Gupta committed
61
62
    void setPixmap(const QPixmap &pixmap);
    QPixmap pixmap() const;
63
    void updatePixmapTimestamp();
64
    void setTimestamp(const QDateTime &timestamp);
65
    QString windowTitle() const;
66
    Spectacle::CaptureMode captureMode() const;
Laurent Montel's avatar
Laurent Montel committed
67
    void setCaptureMode(Spectacle::CaptureMode theCaptureMode);
68
    QString formatFilename(const QString &nameTemplate);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
69

70
    static const QMap<QString, KLocalizedString> filenamePlaceholders;
71

72
    Q_SIGNALS:
Boudhayan Gupta's avatar
Boudhayan Gupta committed
73
74

    void errorMessage(const QString &str);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
75
    void imageSaved(const QUrl &savedAt);
76
    void imageCopied();
Antonio Prcela's avatar
Antonio Prcela committed
77
    void imageSavedAndCopied(const QUrl &savedAt);
78
    void forceNotify(const QUrl &savedAt);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
79

80
    public Q_SLOTS:
Boudhayan Gupta's avatar
Boudhayan Gupta committed
81
82

    QUrl getAutosaveFilename();
83
    QUrl tempSave();
Boudhayan Gupta's avatar
Boudhayan Gupta committed
84

85
    void setWindowTitle(const QString &windowTitle);
86
    void doSave(const QUrl &url = QUrl(), bool notify = false);
Laurent Montel's avatar
Laurent Montel committed
87
    bool doSaveAs(QWidget *parentWindow = nullptr, bool notify = false);
Antonio Prcela's avatar
Antonio Prcela committed
88
    void doSaveAndCopy(const QUrl &url = QUrl());
89
    void doCopyToClipboard(bool notify = false);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
90
    void doPrint(QPrinter *printer);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
91
92
93

    private:

94
    QString truncatedFilename(const QString &filename);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
95
    QString makeAutosaveFilename();
96
97
98
    using FileNameAlreadyUsedCheck = bool (ExportManager::*)(const QUrl&) const;
    QString autoIncrementFilename(const QString &baseName, const QString &extension,
                                  FileNameAlreadyUsedCheck isFileNameUsed);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
99
100
    QString makeSaveMimetype(const QUrl &url);
    bool writeImage(QIODevice *device, const QByteArray &format);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
101
    bool save(const QUrl &url);
Boudhayan Gupta's avatar
Boudhayan Gupta committed
102
103
    bool localSave(const QUrl &url, const QString &mimetype);
    bool remoteSave(const QUrl &url, const QString &mimetype);
104
    bool isTempFileAlreadyUsed(const QUrl &url) const;
Boudhayan Gupta's avatar
Boudhayan Gupta committed
105
106

    QPixmap mSavePixmap;
107
    QDateTime mPixmapTimestamp;
Boudhayan Gupta's avatar
Boudhayan Gupta committed
108
    QUrl mTempFile;
109
110
    QTemporaryDir *mTempDir;
    QList<QUrl> mUsedTempFileNames;
111
    QString mWindowTitle;
112
    Spectacle::CaptureMode mCaptureMode { Spectacle::CaptureMode::AllScreens };
Boudhayan Gupta's avatar
Boudhayan Gupta committed
113
};