mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use the same code for command line and gui for file handling.
The Command line execution of Subsurface happened before the GUI was created, this leaded to various bugs by me(tm) over time. This patch seems to fix all of those, by reusing the same code for GUI interaction and CommandLine interaction. I had to rework how the main.c worked, it used to be C code calling C++ code, and this is non desirable, since C doesn't really understand C++. I Moved all of C-related code to 'subsurfacestartup.c/h' and created a tiny wrapper to call it, so all of the C code is still C code, and the new main.cpp calls the mainwindow->loadFiles and mainWindow->importFiles to get rid of the bugs that happened before. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
6a7256fdd5
commit
96d1cc570e
9 changed files with 167 additions and 129 deletions
63
main.cpp
Normal file
63
main.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* main.c */
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <libintl.h>
|
||||
|
||||
#include "qt-gui.h"
|
||||
#include "version.h"
|
||||
#include "subsurfacestartup.h"
|
||||
#include "qt-ui/mainwindow.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
bool 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
|
||||
* subsurface isn't run from the local directory */
|
||||
path = subsurface_gettext_domainpath(argv[0]);
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain("subsurface", path);
|
||||
bind_textdomain_codeset("subsurface", "utf-8");
|
||||
textdomain("subsurface");
|
||||
|
||||
setup_system_prefs();
|
||||
prefs = default_prefs;
|
||||
|
||||
subsurface_command_line_init(&argc, &argv);
|
||||
init_ui(&argc, &argv);
|
||||
parse_xml_init();
|
||||
|
||||
QStringList files;
|
||||
QStringList importedFiles;
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *a = argv[i];
|
||||
if (a[0] == '-') {
|
||||
parse_argument(a);
|
||||
continue;
|
||||
}
|
||||
if (imported)
|
||||
importedFiles.push_back( QString(a) );
|
||||
else
|
||||
files.push_back( QString(a) );
|
||||
}
|
||||
if (no_filenames) {
|
||||
files.push_back( QString(prefs.default_filename) );
|
||||
}
|
||||
process_dives(imported, FALSE);
|
||||
parse_xml_exit();
|
||||
subsurface_command_line_exit(&argc, &argv);
|
||||
mainWindow()->loadFiles(files);
|
||||
mainWindow()->importFiles(importedFiles);
|
||||
run_ui();
|
||||
exit_ui();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue