Messagelib

editorwatcher.h
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QUrl>
10
11#include <QElapsedTimer>
12#include <QObject>
13#include <QTimer>
14class KProcess;
15
16namespace MessageComposer
17{
18/**
19 Starts an editor for the given URL and emits an signal when
20 editing has been finished. Both, the editor process as well
21 as the edited file are watched to work with as many as possible
22 editors.
23*/
24class EditorWatcher : public QObject
25{
27public:
28 enum OpenWithOption {
30 NoOpenWithDialog,
31 };
32 enum ErrorEditorWatcher {
33 Unknown = 0,
34 Canceled,
35 NoServiceFound,
36 CannotStart,
37 NoError,
38 };
39
40 /**
41 * Constructs an EditorWatcher.
42 * @param url the given URL.
43 * @param mimeType the data MIME type.
44 * @param option the open option.
45 * @param parent the parent object of this EditorWatcher, which will take care of deleting
46 * this EditorWatcher if the parent is deleted.
47 * @param parentWidget the parent widget of this EditorWatcher, which will be used as the parent
48 * widget for message dialogs.
49 */
50 explicit EditorWatcher(const QUrl &url, const QString &mimeType, OpenWithOption option, QObject *parent, QWidget *parentWidget);
51
52 ~EditorWatcher() override;
53 [[nodiscard]] ErrorEditorWatcher start();
54 [[nodiscard]] bool fileChanged() const;
55 [[nodiscard]] QUrl url() const;
57 void editDone(MessageComposer::EditorWatcher *watcher);
58
59private:
60 void editorExited();
61 void inotifyEvent();
62 void checkEditDone();
63 const QUrl mUrl;
64 const QString mMimeType;
65 QTimer mTimer;
66 QElapsedTimer mEditTime;
67
68 KProcess *mEditor = nullptr;
69 QWidget *const mParentWidget;
70
71 int mInotifyFd = -1;
72 int mInotifyWatch = -1;
73 const OpenWithOption mOpenWithOption;
74 bool mHaveInotify = false;
75 bool mFileOpen = false;
76 bool mEditorRunning = false;
77 bool mFileModified = true;
78 bool mDone = false;
79};
80}
Starts an editor for the given URL and emits an signal when editing has been finished.
EditorWatcher(const QUrl &url, const QString &mimeType, OpenWithOption option, QObject *parent, QWidget *parentWidget)
Constructs an EditorWatcher.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.