Skip to content

Commit 549699b

Browse files
committed
Monitor documents.
1 parent 5a8a93c commit 549699b

3 files changed

Lines changed: 135 additions & 102 deletions

File tree

Source/wise-pdf-view.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ wise_pdf_view::wise_pdf_view
183183
{
184184
m_bookmark_model = new QPdfBookmarkModel(this);
185185
m_bookmark_model->setDocument(m_document = new QPdfDocument(this));
186+
m_file_system_watcher.addPath(url.path()) ?
187+
(void) 0 : (void) (qDebug() << tr("Cannot monitor %1.").arg(url.path()));
186188
m_page_renderer = new QPdfPageRenderer(this);
187189
m_page_renderer->setDocument(m_document);
188190
m_page_renderer->setRenderMode(wise_settings::render_mode());
@@ -198,9 +200,14 @@ wise_pdf_view::wise_pdf_view
198200
m_ui.contents->setModel(m_bookmark_model);
199201
m_ui.left_panel->setChecked(false);
200202
m_ui.print->setVisible(false);
203+
m_ui.reload_frame->setVisible(false);
201204
m_ui.search_frame->setVisible(false);
202205
m_ui.search_view->setModel(m_search_model);
203206
m_ui.view_size->setMenu(new QMenu(this));
207+
connect(&m_file_system_watcher,
208+
SIGNAL(fileChanged(const QString &)),
209+
this,
210+
SLOT(slot_file_changed(const QString &)));
204211
connect(m_document,
205212
SIGNAL(statusChanged(QPdfDocument::Status)),
206213
this,
@@ -283,6 +290,18 @@ wise_pdf_view::wise_pdf_view
283290
SIGNAL(clicked(void)),
284291
this,
285292
SLOT(slot_print(void)));
293+
connect(m_ui.reload_no,
294+
&QPushButton::clicked,
295+
m_ui.reload_frame,
296+
&QFrame::hide);
297+
connect(m_ui.reload_yes,
298+
&QPushButton::clicked,
299+
m_ui.reload_frame,
300+
&QFrame::hide);
301+
connect(m_ui.reload_yes,
302+
&QPushButton::clicked,
303+
this,
304+
&wise_pdf_view::slot_reload_document);
286305
connect(m_ui.search,
287306
&QLineEdit::returnPressed,
288307
this,
@@ -509,11 +528,19 @@ void wise_pdf_view::slot_document_status_changed(QPdfDocument::Status status)
509528
{
510529
if(status == QPdfDocument::Status::Ready)
511530
{
531+
m_search_model->setSearchString("");
532+
m_ui.page->setValue(m_ui.page->minimum());
533+
m_ui.search->setText("");
512534
prepare();
513535
prepare_widget_states();
514536
}
515537
}
516538

539+
void wise_pdf_view::slot_file_changed(const QString &path)
540+
{
541+
m_ui.reload_frame->setVisible(m_url.path() == path);
542+
}
543+
517544
void wise_pdf_view::slot_first_page(void)
518545
{
519546
m_ui.page->setValue(m_ui.page->minimum());
@@ -618,6 +645,11 @@ void wise_pdf_view::slot_print(void)
618645
QApplication::processEvents();
619646
}
620647

648+
void wise_pdf_view::slot_reload_document(void)
649+
{
650+
QTimer::singleShot(10, this, SLOT(slot_load_document(void)));
651+
}
652+
621653
void wise_pdf_view::slot_scrolled(int value)
622654
{
623655
Q_UNUSED(value);

Source/wise-pdf-view.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "ui_wise-pdf-view.h"
3232

33+
#include <QFileSystemWatcher>
3334
#include <QPdfDocument>
3435
#include <QPdfView>
3536
#include <QStyledItemDelegate>
@@ -86,6 +87,7 @@ class wise_pdf_view: public QWidget
8687
void set_page_mode(const QPdfView::PageMode page_mode);
8788

8889
private:
90+
QFileSystemWatcher m_file_system_watcher;
8991
QPdfBookmarkModel *m_bookmark_model;
9092
QPdfDocument *m_document;
9193
QPdfPageRenderer *m_page_renderer;
@@ -104,12 +106,14 @@ class wise_pdf_view: public QWidget
104106
void slot_contents_selected
105107
(const QModelIndex &current, const QModelIndex &previous);
106108
void slot_document_status_changed(QPdfDocument::Status status);
109+
void slot_file_changed(const QString &path);
107110
void slot_first_page(void);
108111
void slot_last_page(void);
109112
void slot_load_document(void);
110113
void slot_password_changed(void);
111114
void slot_print(QPrinter *printer);
112115
void slot_print(void);
116+
void slot_reload_document(void);
113117
void slot_scrolled(int value);
114118
void slot_search(void);
115119
void slot_search_count_changed(void);

UI/wise-pdf-view.ui

Lines changed: 99 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,101 @@
1414
<string>Form</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout_4">
17+
<item>
18+
<widget class="QFrame" name="password_frame">
19+
<property name="sizePolicy">
20+
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
21+
<horstretch>0</horstretch>
22+
<verstretch>0</verstretch>
23+
</sizepolicy>
24+
</property>
25+
<layout class="QHBoxLayout" name="horizontalLayout_2">
26+
<item>
27+
<widget class="QLabel" name="label_3">
28+
<property name="text">
29+
<string>The document is password-protected. Please provide the correct password.</string>
30+
</property>
31+
<property name="wordWrap">
32+
<bool>true</bool>
33+
</property>
34+
</widget>
35+
</item>
36+
<item>
37+
<widget class="QLineEdit" name="password">
38+
<property name="styleSheet">
39+
<string notr="true">QLineEdit {border: 2px solid #fd6c9e;}</string>
40+
</property>
41+
<property name="placeholderText">
42+
<string>Document Password</string>
43+
</property>
44+
</widget>
45+
</item>
46+
<item>
47+
<widget class="QToolButton" name="password_accept">
48+
<property name="toolTip">
49+
<string>Set Password</string>
50+
</property>
51+
<property name="icon">
52+
<iconset resource="../Icons/icons.qrc">
53+
<normaloff>:/ok.svg</normaloff>:/ok.svg</iconset>
54+
</property>
55+
<property name="iconSize">
56+
<size>
57+
<width>25</width>
58+
<height>25</height>
59+
</size>
60+
</property>
61+
</widget>
62+
</item>
63+
</layout>
64+
</widget>
65+
</item>
66+
<item>
67+
<widget class="QFrame" name="reload_frame">
68+
<property name="sizePolicy">
69+
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
70+
<horstretch>0</horstretch>
71+
<verstretch>0</verstretch>
72+
</sizepolicy>
73+
</property>
74+
<layout class="QHBoxLayout" name="horizontalLayout_3">
75+
<item>
76+
<widget class="QLabel" name="label_2">
77+
<property name="text">
78+
<string>The PDF document changed on disk. Reload?</string>
79+
</property>
80+
</widget>
81+
</item>
82+
<item>
83+
<widget class="QPushButton" name="reload_yes">
84+
<property name="text">
85+
<string>Yes</string>
86+
</property>
87+
</widget>
88+
</item>
89+
<item>
90+
<widget class="QPushButton" name="reload_no">
91+
<property name="text">
92+
<string>No</string>
93+
</property>
94+
</widget>
95+
</item>
96+
<item>
97+
<spacer name="horizontalSpacer_3">
98+
<property name="orientation">
99+
<enum>Qt::Orientation::Horizontal</enum>
100+
</property>
101+
<property name="sizeHint" stdset="0">
102+
<size>
103+
<width>40</width>
104+
<height>20</height>
105+
</size>
106+
</property>
107+
</spacer>
108+
</item>
109+
</layout>
110+
</widget>
111+
</item>
17112
<item>
18113
<layout class="QHBoxLayout" name="horizontalLayout">
19114
<item>
@@ -208,104 +303,6 @@
208303
</item>
209304
</layout>
210305
</item>
211-
<item>
212-
<widget class="QFrame" name="password_frame">
213-
<property name="sizePolicy">
214-
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
215-
<horstretch>0</horstretch>
216-
<verstretch>0</verstretch>
217-
</sizepolicy>
218-
</property>
219-
<layout class="QHBoxLayout" name="horizontalLayout_2">
220-
<item>
221-
<widget class="QLabel" name="label_3">
222-
<property name="text">
223-
<string>The document is password-protected. Please provide the correct password.</string>
224-
</property>
225-
<property name="wordWrap">
226-
<bool>true</bool>
227-
</property>
228-
</widget>
229-
</item>
230-
<item>
231-
<widget class="QLineEdit" name="password">
232-
<property name="styleSheet">
233-
<string notr="true">QLineEdit {border: 2px solid #fd6c9e;}</string>
234-
</property>
235-
<property name="placeholderText">
236-
<string>Document Password</string>
237-
</property>
238-
</widget>
239-
</item>
240-
<item>
241-
<widget class="QToolButton" name="password_accept">
242-
<property name="toolTip">
243-
<string>Set Password</string>
244-
</property>
245-
<property name="icon">
246-
<iconset resource="../Icons/icons.qrc">
247-
<normaloff>:/ok.svg</normaloff>:/ok.svg</iconset>
248-
</property>
249-
<property name="iconSize">
250-
<size>
251-
<width>25</width>
252-
<height>25</height>
253-
</size>
254-
</property>
255-
</widget>
256-
</item>
257-
</layout>
258-
</widget>
259-
</item>
260-
<item>
261-
<widget class="QFrame" name="reload_frame">
262-
<property name="sizePolicy">
263-
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
264-
<horstretch>0</horstretch>
265-
<verstretch>0</verstretch>
266-
</sizepolicy>
267-
</property>
268-
<layout class="QHBoxLayout" name="horizontalLayout_3">
269-
<item>
270-
<widget class="QLabel" name="label_2">
271-
<property name="text">
272-
<string>The PDF document changed on disk. Reload?</string>
273-
</property>
274-
<property name="wordWrap">
275-
<bool>true</bool>
276-
</property>
277-
</widget>
278-
</item>
279-
<item>
280-
<widget class="QPushButton" name="reload_yes">
281-
<property name="text">
282-
<string>Yes</string>
283-
</property>
284-
</widget>
285-
</item>
286-
<item>
287-
<widget class="QPushButton" name="reload_no">
288-
<property name="text">
289-
<string>No</string>
290-
</property>
291-
</widget>
292-
</item>
293-
<item>
294-
<spacer name="horizontalSpacer_3">
295-
<property name="orientation">
296-
<enum>Qt::Orientation::Horizontal</enum>
297-
</property>
298-
<property name="sizeHint" stdset="0">
299-
<size>
300-
<width>40</width>
301-
<height>20</height>
302-
</size>
303-
</property>
304-
</spacer>
305-
</item>
306-
</layout>
307-
</widget>
308-
</item>
309306
<item>
310307
<widget class="QSplitter" name="splitter">
311308
<property name="orientation">
@@ -494,6 +491,10 @@
494491
</layout>
495492
</widget>
496493
<tabstops>
494+
<tabstop>password</tabstop>
495+
<tabstop>password_accept</tabstop>
496+
<tabstop>reload_yes</tabstop>
497+
<tabstop>reload_no</tabstop>
497498
<tabstop>left_panel</tabstop>
498499
<tabstop>first_page</tabstop>
499500
<tabstop>previous_page</tabstop>
@@ -505,10 +506,6 @@
505506
<tabstop>zoom_out</tabstop>
506507
<tabstop>print</tabstop>
507508
<tabstop>search_show</tabstop>
508-
<tabstop>password</tabstop>
509-
<tabstop>password_accept</tabstop>
510-
<tabstop>reload_yes</tabstop>
511-
<tabstop>reload_no</tabstop>
512509
<tabstop>contents</tabstop>
513510
<tabstop>search_view</tabstop>
514511
<tabstop>meta</tabstop>

0 commit comments

Comments
 (0)