aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h8
-rw-r--r--file.c19
-rw-r--r--main.c21
-rw-r--r--parse-xml.c24
-rw-r--r--qt-gui.cpp3
-rw-r--r--qt-ui/mainwindow.cpp18
-rw-r--r--qt-ui/mainwindow.h1
-rw-r--r--qt-ui/mainwindow.ui3
8 files changed, 55 insertions, 42 deletions
diff --git a/dive.h b/dive.h
index 15c334ae1..d16d2445a 100644
--- a/dive.h
+++ b/dive.h
@@ -584,13 +584,13 @@ struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset);
extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
extern void parse_xml_init(void);
-extern void parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, GError **error);
+extern void parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, char **error);
extern void parse_xml_exit(void);
extern void set_filename(const char *filename, gboolean force);
-extern int parse_dm4_buffer(const char *url, const char *buf, int size, struct dive_table *table, GError **error);
+extern int parse_dm4_buffer(const char *url, const char *buf, int size, struct dive_table *table, char **error);
-extern void parse_file(const char *filename, GError **error);
+extern void parse_file(const char *filename, char **error);
extern void show_dive_info(struct dive *);
@@ -634,7 +634,7 @@ extern void add_event(struct divecomputer *dc, int time, int type, int flags, in
/* UI related protopypes */
extern void init_ui(int *argcp, char ***argvp);
-extern void init_qt_ui(int *argcp, char ***argvp);
+extern void init_qt_ui(int *argcp, char ***argvp, char *errormessage);
extern void run_ui(void);
extern void exit_ui(void);
diff --git a/file.c b/file.c
index bb7121bbd..14607bab2 100644
--- a/file.c
+++ b/file.c
@@ -61,7 +61,7 @@ out:
}
-static void zip_read(struct zip_file *file, GError **error, const char *filename)
+static void zip_read(struct zip_file *file, char **error, const char *filename)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@@ -76,7 +76,7 @@ static void zip_read(struct zip_file *file, GError **error, const char *filename
free(mem);
}
-static int try_to_open_zip(const char *filename, struct memblock *mem, GError **error)
+static int try_to_open_zip(const char *filename, struct memblock *mem, char **error)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@@ -97,7 +97,7 @@ static int try_to_open_zip(const char *filename, struct memblock *mem, GError **
return success;
}
-static int try_to_open_db(const char *filename, struct memblock *mem, GError **error)
+static int try_to_open_db(const char *filename, struct memblock *mem, char **error)
{
return parse_dm4_buffer(filename, mem->buffer, mem->size, &dive_table, error);
}
@@ -223,7 +223,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_
return 1;
}
-static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, GError **error)
+static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, char **error)
{
/* Suunto Dive Manager files: SDE */
if (!strcasecmp(fmt, "SDE"))
@@ -250,7 +250,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
return 0;
}
-static void parse_file_buffer(const char *filename, struct memblock *mem, GError **error)
+static void parse_file_buffer(const char *filename, struct memblock *mem, char **error)
{
char *fmt = strrchr(filename, '.');
if (fmt && open_by_filename(filename, fmt+1, mem, error))
@@ -259,7 +259,7 @@ static void parse_file_buffer(const char *filename, struct memblock *mem, GError
parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, error);
}
-void parse_file(const char *filename, GError **error)
+void parse_file(const char *filename, char **error)
{
struct memblock mem;
char *fmt;
@@ -269,12 +269,9 @@ void parse_file(const char *filename, GError **error)
if (prefs.default_filename && ! strcmp(filename, prefs.default_filename))
return;
- g_warning(_("Failed to read '%s'.\n"), filename);
if (error) {
- *error = g_error_new(g_quark_from_string("subsurface"),
- DIVE_ERROR_PARSE,
- _("Failed to read '%s'"),
- filename);
+ *error = malloc(1024);
+ snprintf(*error, 1024, _("Failed to read '%s'"), filename);
}
return;
diff --git a/main.c b/main.c
index 82e82b2e9..009218c0c 100644
--- a/main.c
+++ b/main.c
@@ -159,6 +159,7 @@ int main(int argc, char **argv)
int i;
gboolean no_filenames = TRUE;
const char *path;
+ char *error_message = NULL;
/* set up l18n - the search directory needs to change
* so that it uses the correct system directory when
@@ -179,34 +180,22 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) {
const char *a = argv[i];
-
if (a[0] == '-') {
parse_argument(a);
continue;
}
- GError *error = NULL;
- /* if we have exactly one filename, parse_file will set
- * that to be the default. Otherwise there will be no default filename */
set_filename(NULL, TRUE);
- parse_file(a, &error);
+
+ parse_file(a, &error_message);
if (no_filenames)
{
set_filename(a, TRUE);
no_filenames = FALSE;
}
- if (error != NULL)
- {
-#if USE_GTK_UI
- report_error(error);
-#endif
- g_error_free(error);
- error = NULL;
- }
}
if (no_filenames) {
- GError *error = NULL;
const char *filename = prefs.default_filename;
- parse_file(filename, &error);
+ parse_file(filename, NULL);
/* don't report errors - this file may not exist, but make
sure we remember this as the filename in use */
set_filename(filename, FALSE);
@@ -215,7 +204,7 @@ int main(int argc, char **argv)
parse_xml_exit();
subsurface_command_line_exit(&argc, &argv);
- init_qt_ui(&argc, &argv); /* qt bit delayed until dives are parsed */
+ init_qt_ui(&argc, &argv, error_message); /* qt bit delayed until dives are parsed */
run_ui();
exit_ui();
return 0;
diff --git a/parse-xml.c b/parse-xml.c
index 698b31171..58a9019c9 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -19,22 +19,34 @@
int verbose;
-static xmlDoc *test_xslt_transforms(xmlDoc *doc, GError **error);
+static xmlDoc *test_xslt_transforms(xmlDoc *doc, char **error);
/* the dive table holds the overall dive list; target table points at
* the table we are currently filling */
struct dive_table dive_table;
struct dive_table *target_table = NULL;
-static void parser_error(GError **error, const char *fmt, ...)
+static void parser_error(char **error, const char *fmt, ...)
{
va_list args;
+ char *tmp;
if (!error)
return;
+
+ tmp = malloc(1024);
va_start(args, fmt);
- *error = g_error_new_valist(g_quark_from_string("subsurface"), DIVE_ERROR_PARSE, fmt, args);
+ vsnprintf(tmp, 1024, fmt, args);
va_end(args);
+
+ if (*error) {
+ int len = strlen(*error) + strlen(tmp) + 1;
+ *error = realloc(*error, len);
+ strncat(*error, tmp, strlen(tmp));
+ free(tmp);
+ } else {
+ *error = tmp;
+ }
}
/*
@@ -1579,7 +1591,7 @@ const char *preprocess_divelog_de(const char *buffer)
}
void parse_xml_buffer(const char *url, const char *buffer, int size,
- struct dive_table *table, GError **error)
+ struct dive_table *table, char **error)
{
xmlDoc *doc;
const char *res = preprocess_divelog_de(buffer);
@@ -1802,7 +1814,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
}
int parse_dm4_buffer(const char *url, const char *buffer, int size,
- struct dive_table *table, GError **error)
+ struct dive_table *table, char **error)
{
int retval;
char *err = NULL;
@@ -1906,7 +1918,7 @@ static struct xslt_files {
{ NULL, }
};
-static xmlDoc *test_xslt_transforms(xmlDoc *doc, GError **error)
+static xmlDoc *test_xslt_transforms(xmlDoc *doc, char **error)
{
struct xslt_files *info = xslt_files;
xmlDoc *transformed;
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 21dd18271..7aeea36a3 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -58,10 +58,11 @@ static QApplication *application = NULL;
int error_count;
const char *existing_filename;
-void init_qt_ui(int *argcp, char ***argvp)
+void init_qt_ui(int *argcp, char ***argvp, char *errormessage)
{
application->installTranslator(new Translator(application));
MainWindow *window = new MainWindow();
+ window->showError(errormessage);
window->show();
}
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index deaab4715..12c803786 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -40,6 +40,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow())
setWindowIcon(QIcon(":subsurface-icon"));
connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int)));
ui->globeMessage->hide();
+ ui->mainErrorMessage->hide();
ui->globe->setMessageWidget(ui->globeMessage);
ui->globeMessage->setCloseButtonVisible(false);
ui->ProfileWidget->setFocusProxy(ui->ListWidget);
@@ -79,14 +80,13 @@ void MainWindow::on_actionOpen_triggered()
on_actionClose_triggered();
- GError *error = NULL;
+ char *error = NULL;
parse_file(fileNamePtr.data(), &error);
set_filename(fileNamePtr.data(), TRUE);
if (error != NULL) {
- QMessageBox::warning(this, "Error", error->message);
- g_error_free(error);
- error = NULL;
+ showError(error);
+ free(error);
}
process_dives(FALSE, FALSE);
@@ -533,3 +533,13 @@ void MainWindow::file_save(void)
save_dives(existing_filename);
mark_divelist_changed(FALSE);
}
+
+void MainWindow::showError(QString message)
+{
+ if (message.isEmpty())
+ return;
+ ui->mainErrorMessage->setText(message);
+ ui->mainErrorMessage->setCloseButtonVisible(true);
+ ui->mainErrorMessage->setMessageType(KMessageWidget::Error);
+ ui->mainErrorMessage->animatedShow();
+}
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 121b5c74d..a5b1a9b48 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -39,6 +39,7 @@ public:
MainTab *information();
DiveListView *dive_list();
GlobeGPS *globe();
+ void showError(QString message);
private Q_SLOTS:
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index 36f594d2d..658f22c41 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -95,6 +95,9 @@
</widget>
</widget>
</item>
+ <item>
+ <widget class="KMessageWidget" name="mainErrorMessage" native="true"/>
+ </item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">