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 {
30  OpenWithDialog,
31  NoOpenWithDialog,
32  };
33  enum ErrorEditorWatcher {
34  Unknown = 0,
35  Canceled,
36  NoServiceFound,
37  CannotStart,
38  NoError,
39  };
40 
41  /**
42  * Constructs an EditorWatcher.
43  * @param url the given URL.
44  * @param mimeType the data MIME type.
45  * @param option the open option.
46  * @param parent the parent object of this EditorWatcher, which will take care of deleting
47  * this EditorWatcher if the parent is deleted.
48  * @param parentWidget the parent widget of this EditorWatcher, which will be used as the parent
49  * widget for message dialogs.
50  */
51  explicit EditorWatcher(const QUrl &url, const QString &mimeType, OpenWithOption option, QObject *parent, QWidget *parentWidget);
52 
53  ~EditorWatcher() override;
54  Q_REQUIRED_RESULT ErrorEditorWatcher start();
55  Q_REQUIRED_RESULT bool fileChanged() const;
56  Q_REQUIRED_RESULT QUrl url() const;
57 Q_SIGNALS:
58  void editDone(MessageViewer::EditorWatcher *watcher);
59 
60 private:
61  void editorExited();
62  void inotifyEvent();
63  void checkEditDone();
64  const QUrl mUrl;
65  const QString mMimeType;
66  QTimer mTimer;
67  QElapsedTimer mEditTime;
68 
69  KProcess *mEditor = nullptr;
70  QWidget *const mParentWidget;
71 
72  int mInotifyFd = -1;
73  int mInotifyWatch = -1;
74  const OpenWithOption mOpenWithOption;
75  bool mHaveInotify = false;
76  bool mFileOpen = false;
77  bool mEditorRunning = false;
78  bool mFileModified = true;
79  bool mDone = false;
80 };
81 }
Q_SCRIPTABLE Q_NOREPLY void start()
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-2023 The KDE developers.
Generated on Mon Mar 27 2023 04:08:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.