Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
KDE Pim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Unmaintained
KDE Pim
Commits
606ebaa8
Commit
606ebaa8
authored
Dec 05, 2014
by
Laurent Montel
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make editorwatcher works. Fix attachmentedit work too
parent
58747988
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
19 deletions
+43
-19
messageviewer/job/attachmenteditjob.cpp
messageviewer/job/attachmenteditjob.cpp
+1
-1
messageviewer/viewer/editorwatcher.cpp
messageviewer/viewer/editorwatcher.cpp
+41
-17
messageviewer/viewer/editorwatcher.h
messageviewer/viewer/editorwatcher.h
+1
-1
No files found.
messageviewer/job/attachmenteditjob.cpp
View file @
606ebaa8
...
...
@@ -78,7 +78,7 @@ void AttachmentEditJob::setMainWindow(QWidget *mainWindow)
void
AttachmentEditJob
::
slotAttachmentEditDone
(
MessageViewer
::
EditorWatcher
*
editorWatcher
)
{
const
QString
name
=
editorWatcher
->
url
().
fileName
();
const
QString
name
=
editorWatcher
->
url
().
path
();
if
(
editorWatcher
->
fileChanged
()
)
{
QFile
file
(
name
);
if
(
file
.
open
(
QIODevice
::
ReadOnly
)
)
{
...
...
messageviewer/viewer/editorwatcher.cpp
View file @
606ebaa8
...
...
@@ -62,6 +62,13 @@ EditorWatcher::EditorWatcher( const KUrl & url, const QString &mimeType, OpenWit
connect
(
&
mTimer
,
SIGNAL
(
timeout
()),
SLOT
(
checkEditDone
())
);
}
EditorWatcher
::~
EditorWatcher
()
{
#ifdef HAVE_SYS_INOTIFY_H
::
close
(
mInotifyFd
);
#endif
}
bool
EditorWatcher
::
start
()
{
// find an editor
...
...
@@ -83,7 +90,9 @@ bool EditorWatcher::start()
// monitor file
mInotifyFd
=
inotify_init
();
if
(
mInotifyFd
>
0
)
{
mInotifyWatch
=
inotify_add_watch
(
mInotifyFd
,
mUrl
.
path
().
toLatin1
(),
IN_CLOSE
|
IN_OPEN
|
IN_MODIFY
);
(
void
)
fcntl
(
mInotifyFd
,
F_SETFD
,
FD_CLOEXEC
);
qDebug
()
<<
" mUrl.path().toLatin1()"
<<
mUrl
.
path
().
toLatin1
();
mInotifyWatch
=
inotify_add_watch
(
mInotifyFd
,
mUrl
.
path
().
toLatin1
(),
IN_CLOSE
|
IN_OPEN
|
IN_MODIFY
|
IN_ATTRIB
);
if
(
mInotifyWatch
>=
0
)
{
QSocketNotifier
*
sn
=
new
QSocketNotifier
(
mInotifyFd
,
QSocketNotifier
::
Read
,
this
);
connect
(
sn
,
SIGNAL
(
activated
(
int
)),
SLOT
(
inotifyEvent
())
);
...
...
@@ -122,38 +131,53 @@ KUrl EditorWatcher::url() const
void
EditorWatcher
::
inotifyEvent
()
{
qDebug
()
<<
" void EditorWatcher::inotifyEvent()"
;
assert
(
mHaveInotify
);
#ifdef HAVE_SYS_INOTIFY_H
int
pending
=
-
1
;
char
buffer
[
4096
];
int
offsetStartRead
=
0
;
// where we read into buffer
char
buf
[
8192
];
assert
(
mInotifyFd
>
-
1
);
ioctl
(
mInotifyFd
,
FIONREAD
,
&
pending
);
while
(
pending
>
0
)
{
int
size
=
read
(
mInotifyFd
,
buffer
,
qMin
(
pending
,
(
int
)
sizeof
(
buffer
)
)
);
pending
-=
size
;
if
(
size
<
0
)
break
;
// error
int
offset
=
0
;
while
(
size
>
0
)
{
struct
inotify_event
*
event
=
(
struct
inotify_event
*
)
&
buffer
[
offset
];
qDebug
()
<<
" size > 0"
<<
event
->
mask
;
size
-=
sizeof
(
struct
inotify_event
)
+
event
->
len
;
offset
+=
sizeof
(
struct
inotify_event
)
+
event
->
len
;
const
int
bytesToRead
=
qMin
(
pending
,
(
int
)
sizeof
(
buf
)
-
offsetStartRead
);
int
bytesAvailable
=
read
(
mInotifyFd
,
&
buf
[
offsetStartRead
],
bytesToRead
);
pending
-=
bytesAvailable
;
bytesAvailable
+=
offsetStartRead
;
offsetStartRead
=
0
;
int
offsetCurrent
=
0
;
while
(
bytesAvailable
>=
(
int
)
sizeof
(
struct
inotify_event
)
)
{
const
struct
inotify_event
*
const
event
=
(
struct
inotify_event
*
)
&
buf
[
offsetCurrent
];
const
int
eventSize
=
sizeof
(
struct
inotify_event
)
+
event
->
len
;
if
(
bytesAvailable
<
eventSize
)
{
break
;
}
bytesAvailable
-=
eventSize
;
offsetCurrent
+=
eventSize
;
if
(
event
->
mask
&
IN_OPEN
)
{
mFileOpen
=
true
;
qDebug
()
<<
" IN OPEN"
;
}
if
(
event
->
mask
&
IN_CLOSE
)
{
mFileOpen
=
false
;
qDebug
()
<<
" IN CLOSE"
;
}
if
(
event
->
mask
&
IN_MODIFY
)
{
if
(
event
->
mask
&
(
IN_MODIFY
|
IN_ATTRIB
)
)
{
mFileModified
=
true
;
qDebug
()
<<
" IN MODIFY"
;
}
}
if
(
bytesAvailable
>
0
)
{
// copy partial event to beginning of buffer
memmove
(
buf
,
&
buf
[
offsetCurrent
],
bytesAvailable
);
offsetStartRead
=
bytesAvailable
;
}
}
#endif
mTimer
.
start
(
500
);
}
...
...
messageviewer/viewer/editorwatcher.h
View file @
606ebaa8
...
...
@@ -53,7 +53,7 @@ public:
*/
EditorWatcher
(
const
KUrl
&
url
,
const
QString
&
mimeType
,
OpenWithOption
option
,
QObject
*
parent
,
QWidget
*
parentWidget
);
~
EditorWatcher
();
bool
start
();
bool
fileChanged
()
const
;
KUrl
url
()
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment