Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philipp Erhardt
katarakt
Commits
6c492750
Commit
6c492750
authored
Apr 26, 2012
by
Philipp Erhardt
Browse files
error handling
remove some TODOs
parent
51907115
Changes
8
Hide whitespace changes
Inline
Side-by-side
canvas.cpp
View file @
6c492750
...
...
@@ -13,7 +13,8 @@ int Canvas::sig_fd[2];
Canvas
::
Canvas
(
ResourceManager
*
_res
,
QWidget
*
parent
)
:
QWidget
(
parent
),
res
(
_res
),
draw_overlay
(
true
)
{
draw_overlay
(
true
),
valid
(
true
)
{
setFocusPolicy
(
Qt
::
StrongFocus
);
res
->
set_canvas
(
this
);
...
...
@@ -22,7 +23,9 @@ Canvas::Canvas(ResourceManager *_res, QWidget *parent) :
// setup signal handling
if
(
socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
sig_fd
)
==
-
1
)
{
cerr
<<
"socketpair: "
<<
strerror
(
errno
)
<<
endl
;
// TODO exit
valid
=
false
;
sig_notifier
=
NULL
;
return
;
}
sig_notifier
=
new
QSocketNotifier
(
sig_fd
[
1
],
QSocketNotifier
::
Read
,
this
);
connect
(
sig_notifier
,
SIGNAL
(
activated
(
int
)),
this
,
SLOT
(
handle_signal
()));
...
...
@@ -34,7 +37,8 @@ Canvas::Canvas(ResourceManager *_res, QWidget *parent) :
if
(
sigaction
(
SIGUSR1
,
&
usr
,
0
)
>
0
)
{
cerr
<<
"sigaction: "
<<
strerror
(
errno
)
<<
endl
;
// TODO exit
valid
=
false
;
return
;
}
// prints the string representation of a key
...
...
@@ -84,6 +88,10 @@ Canvas::~Canvas() {
delete
layout
;
}
bool
Canvas
::
is_valid
()
const
{
return
valid
;
}
void
Canvas
::
signal_handler
(
int
/*unused*/
)
{
char
tmp
=
'1'
;
if
(
write
(
sig_fd
[
0
],
&
tmp
,
sizeof
(
char
))
<
0
)
{
...
...
canvas.h
View file @
6c492750
...
...
@@ -33,6 +33,7 @@ public:
Canvas
(
ResourceManager
*
res
,
QWidget
*
parent
=
0
);
~
Canvas
();
bool
is_valid
()
const
;
// signal handling
static
void
signal_handler
(
int
unused
);
public
slots
:
...
...
@@ -88,6 +89,7 @@ private:
// signal handling
static
int
sig_fd
[
2
];
QSocketNotifier
*
sig_notifier
;
bool
valid
;
};
...
...
layout.cpp
View file @
6c492750
...
...
@@ -34,7 +34,7 @@ void Layout::resize(int w, int h) {
}
void
Layout
::
set_zoom
(
int
/*new_zoom*/
,
bool
/*relative*/
)
{
//
TODO
implement in
all the
child classes
// implement in child classes
where necessary
}
void
Layout
::
set_columns
(
int
/*new_columns*/
,
bool
/*relative*/
)
{
...
...
@@ -216,7 +216,6 @@ void GridLayout::set_constants() {
// apply zoom value
size
*=
(
1
+
zoom
*
ZOOM_FACTOR
);
// TODO adjust offset values
horizontal_page
=
(
page
+
horizontal_page
)
%
grid
->
get_column_count
();
page
=
page
/
grid
->
get_column_count
()
*
grid
->
get_column_count
();
...
...
main.cpp
View file @
6c492750
...
...
@@ -18,10 +18,13 @@ int main(int argc, char *argv[]) {
}
ResourceManager
res
(
QString
::
fromUtf8
(
argv
[
1
]));
if
(
res
.
is_
null
())
{
if
(
!
res
.
is_
valid
())
{
return
1
;
}
Viewer
katarakt
(
&
res
);
if
(
!
katarakt
.
is_valid
())
{
return
1
;
}
katarakt
.
show
();
return
app
.
exec
();
...
...
resourcemanager.cpp
View file @
6c492750
...
...
@@ -175,8 +175,8 @@ void ResourceManager::reload_document() {
set_canvas
(
canvas
);
}
bool
ResourceManager
::
is_
null
()
const
{
return
(
doc
=
=
NULL
);
bool
ResourceManager
::
is_
valid
()
const
{
return
(
doc
!
=
NULL
);
}
void
ResourceManager
::
set_canvas
(
Canvas
*
c
)
{
...
...
resourcemanager.h
View file @
6c492750
...
...
@@ -44,8 +44,8 @@ public:
void
reload_document
();
// document
not
open?
bool
is_
null
()
const
;
// document open
ed correctly
?
bool
is_
valid
()
const
;
// page (meta)data
QImage
*
get_page
(
int
page
,
int
newWidth
);
...
...
viewer.cpp
View file @
6c492750
...
...
@@ -2,8 +2,15 @@
Viewer
::
Viewer
(
ResourceManager
*
res
,
QWidget
*
parent
)
:
QWidget
(
parent
)
{
QWidget
(
parent
),
valid
(
true
)
{
canvas
=
new
Canvas
(
res
,
this
);
if
(
!
canvas
->
is_valid
())
{
valid
=
false
;
search_bar
=
NULL
;
layout
=
NULL
;
return
;
}
search_bar
=
new
QLineEdit
(
this
);
// TODO these sequences conflict between widgets
...
...
@@ -29,6 +36,10 @@ Viewer::~Viewer() {
delete
canvas
;
}
bool
Viewer
::
is_valid
()
const
{
return
valid
;
}
void
Viewer
::
focus_search
()
{
search_bar
->
setFocus
(
Qt
::
OtherFocusReason
);
search_bar
->
selectAll
();
...
...
viewer.h
View file @
6c492750
...
...
@@ -20,6 +20,7 @@ public:
Viewer
(
ResourceManager
*
res
,
QWidget
*
parent
=
0
);
~
Viewer
();
bool
is_valid
()
const
;
void
focus_search
();
protected:
...
...
@@ -36,6 +37,7 @@ private:
// key sequences
std
::
map
<
QKeySequence
,
func_t
>
sequences
;
bool
valid
;
};
#endif
...
...
Write
Preview
Supports
Markdown
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