Messagelib

editorwatcher.h
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
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>
14 class KProcess;
15 
16 namespace 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 */
24 class EditorWatcher : public QObject
25 {
26  Q_OBJECT
27 public:
28  enum OpenWithOption {
29  OpenWithDialog,
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  Q_REQUIRED_RESULT ErrorEditorWatcher start();
54  Q_REQUIRED_RESULT bool fileChanged() const;
55  Q_REQUIRED_RESULT QUrl url() const;
56 Q_SIGNALS:
57  void editDone(MessageComposer::EditorWatcher *watcher);
58 
59 private:
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 }
Q_OBJECTQ_OBJECT
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
Starts an editor for the given URL and emits an signal when editing has been finished.
Definition: editorwatcher.h:24
EditorWatcher(const QUrl &url, const QString &mimeType, OpenWithOption option, QObject *parent, QWidget *parentWidget)
Constructs an EditorWatcher.
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 30 2023 03:53:39 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.