Commit 6c492750 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

error handling

remove some TODOs
parent 51907115
......@@ -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) {
......
......@@ -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;
};
......
......@@ -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();
......
......@@ -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();
......
......@@ -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) {
......
......@@ -44,8 +44,8 @@ public:
void reload_document();
// document not open?
bool is_null() const;
// document opened correctly?
bool is_valid() const;
// page (meta)data
QImage *get_page(int page, int newWidth);
......
......@@ -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();
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment