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 "messageviewer_export.h"
10 #include <QUrl>
11 
12 #include <QElapsedTimer>
13 #include <QObject>
14 #include <QTimer>
15 class KProcess;
16 
17 namespace MessageViewer
18 {
19 /**
20  Starts an editor for the given URL and emits an signal when
21  editing has been finished. Both, the editor process as well
22  as the edited file are watched to work with as many as possible
23  editors.
24 */
25 class MESSAGEVIEWER_EXPORT EditorWatcher : public QObject
26 {
27  Q_OBJECT
28 public:
29  enum OpenWithOption { OpenWithDialog, NoOpenWithDialog };
30  enum ErrorEditorWatcher { Unknown = 0, Canceled, NoServiceFound, CannotStart, NoError };
31 
32  /**
33  * Constructs an EditorWatcher.
34  * @param url the given URL.
35  * @param mimeType the data MIME type.
36  * @param option the open option.
37  * @param parent the parent object of this EditorWatcher, which will take care of deleting
38  * this EditorWatcher if the parent is deleted.
39  * @param parentWidget the parent widget of this EditorWatcher, which will be used as the parent
40  * widget for message dialogs.
41  */
42  explicit EditorWatcher(const QUrl &url, const QString &mimeType, OpenWithOption option, QObject *parent, QWidget *parentWidget);
43 
44  ~EditorWatcher() override;
45  Q_REQUIRED_RESULT ErrorEditorWatcher start();
46  Q_REQUIRED_RESULT bool fileChanged() const;
47  Q_REQUIRED_RESULT QUrl url() const;
48 Q_SIGNALS:
49  void editDone(MessageViewer::EditorWatcher *watcher);
50 
51 private:
52  void editorExited();
53  void inotifyEvent();
54  void checkEditDone();
55  const QUrl mUrl;
56  const QString mMimeType;
57  QTimer mTimer;
58  QElapsedTimer mEditTime;
59 
60  KProcess *mEditor = nullptr;
61  QWidget *const mParentWidget;
62 
63  int mInotifyFd = -1;
64  int mInotifyWatch = -1;
65  const OpenWithOption mOpenWithOption;
66  bool mHaveInotify = false;
67  bool mFileOpen = false;
68  bool mEditorRunning = false;
69  bool mFileModified = true;
70  bool mDone = false;
71 };
72 }
73 
Starts an editor for the given URL and emits an signal when editing has been finished.
Definition: editorwatcher.h:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.