File indexing completed on 2024-04-21 09:42:24

0001 /*
0002     SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com>
0003     SPDX-FileCopyrightText: 2009 Thomas Dreibholz <dreibh@iem.uni-due.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SAVEHISTORYTASK_H
0009 #define SAVEHISTORYTASK_H
0010 
0011 #include "konsoleprivate_export.h"
0012 #include "session/SessionTask.h"
0013 
0014 #include <kio/job.h>
0015 
0016 namespace Konsole
0017 {
0018 class TerminalCharacterDecoder;
0019 
0020 /**
0021  * A task which prompts for a URL for each session and saves that session's output
0022  * to the given URL
0023  */
0024 class KONSOLEPRIVATE_EXPORT SaveHistoryTask : public SessionTask
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /** Constructs a new task to save session output to URLs */
0030     explicit SaveHistoryTask(QObject *parent = nullptr);
0031     ~SaveHistoryTask() override;
0032 
0033     /**
0034      * Opens a save file dialog for each session in the group and begins saving
0035      * each session's history to the given URL.
0036      *
0037      * The data transfer is performed asynchronously and will continue after execute() returns.
0038      */
0039     void execute() override;
0040 
0041 private Q_SLOTS:
0042     void jobDataRequested(KIO::Job *job, QByteArray &data);
0043     void jobResult(KJob *job);
0044 
0045 private:
0046     class SaveJob // structure to keep information needed to process
0047                   // incoming data requests from jobs
0048     {
0049     public:
0050         QPointer<Session> session; // the session associated with a history save job
0051         int lastLineFetched; // the last line processed in the previous data request
0052         // set this to -1 at the start of the save job
0053 
0054         TerminalCharacterDecoder *decoder; // decoder used to convert terminal characters
0055         // into output
0056     };
0057 
0058     QHash<KJob *, SaveJob> _jobSession;
0059 
0060     static QString _saveDialogRecentURL;
0061 };
0062 
0063 }
0064 
0065 #endif