2013-09-09 08:59:03 +00:00
|
|
|
/* main.c */
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2014-12-18 07:47:55 +00:00
|
|
|
#include "dive.h"
|
2013-09-09 08:59:03 +00:00
|
|
|
#include "qt-gui.h"
|
|
|
|
#include "subsurfacestartup.h"
|
|
|
|
#include "qt-ui/mainwindow.h"
|
2013-10-03 19:56:08 +00:00
|
|
|
#include "qt-ui/diveplanner.h"
|
2015-02-09 21:51:31 +00:00
|
|
|
#include "qt-ui/graphicsview-common.h"
|
2015-06-14 15:32:47 +00:00
|
|
|
#include "qthelper.h"
|
2013-09-09 08:59:03 +00:00
|
|
|
|
|
|
|
#include <QStringList>
|
2015-06-16 13:52:06 +00:00
|
|
|
#include <QApplication>
|
2015-07-06 14:11:02 +00:00
|
|
|
#include <QLoggingCategory>
|
2014-03-31 20:37:41 +00:00
|
|
|
#include <git2.h>
|
2013-09-09 08:59:03 +00:00
|
|
|
|
2013-10-09 05:25:02 +00:00
|
|
|
QTranslator *qtTranslator, *ssrfTranslator;
|
|
|
|
|
2013-09-09 08:59:03 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2013-09-22 15:30:25 +00:00
|
|
|
bool no_filenames = true;
|
2015-07-06 14:11:02 +00:00
|
|
|
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
|
2015-06-16 13:52:06 +00:00
|
|
|
QApplication *application = new QApplication(argc, argv);
|
2013-09-09 08:59:03 +00:00
|
|
|
QStringList files;
|
|
|
|
QStringList importedFiles;
|
2013-10-08 09:48:46 +00:00
|
|
|
QStringList arguments = QCoreApplication::arguments();
|
2014-03-25 14:55:56 +00:00
|
|
|
|
|
|
|
bool dedicated_console = arguments.length() > 1 &&
|
2014-05-22 18:40:22 +00:00
|
|
|
(arguments.at(1) == QString("--win32console"));
|
2014-03-25 14:55:56 +00:00
|
|
|
subsurface_console_init(dedicated_console);
|
|
|
|
|
2015-10-06 10:10:21 +00:00
|
|
|
const char *default_directory = system_default_directory();
|
|
|
|
const char *default_filename = system_default_filename();
|
2015-10-13 18:34:26 +00:00
|
|
|
subsurface_mkdir(default_directory);
|
2015-10-06 10:10:21 +00:00
|
|
|
|
2013-10-08 09:48:46 +00:00
|
|
|
for (i = 1; i < arguments.length(); i++) {
|
|
|
|
QString a = arguments.at(i);
|
2015-10-12 13:47:51 +00:00
|
|
|
if (a.isEmpty())
|
|
|
|
continue;
|
2013-10-08 09:48:46 +00:00
|
|
|
if (a.at(0) == '-') {
|
|
|
|
parse_argument(a.toLocal8Bit().data());
|
2013-09-09 08:59:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-22 15:30:25 +00:00
|
|
|
if (imported) {
|
2013-10-08 09:48:46 +00:00
|
|
|
importedFiles.push_back(a);
|
2013-09-22 15:30:25 +00:00
|
|
|
} else {
|
|
|
|
no_filenames = false;
|
2013-10-08 09:48:46 +00:00
|
|
|
files.push_back(a);
|
2013-09-22 15:30:25 +00:00
|
|
|
}
|
2013-09-09 08:59:03 +00:00
|
|
|
}
|
2014-12-07 19:14:58 +00:00
|
|
|
#if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22
|
2014-03-31 20:37:41 +00:00
|
|
|
git_threads_init();
|
2014-12-06 13:49:57 +00:00
|
|
|
#else
|
|
|
|
git_libgit2_init();
|
|
|
|
#endif
|
2014-03-19 16:23:43 +00:00
|
|
|
setup_system_prefs();
|
2015-10-06 09:15:38 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2014-03-19 16:23:43 +00:00
|
|
|
fill_profile_color();
|
|
|
|
parse_xml_init();
|
|
|
|
taglist_init_global();
|
|
|
|
init_ui();
|
2014-03-20 12:56:04 +00:00
|
|
|
if (no_filenames) {
|
2015-06-14 15:32:47 +00:00
|
|
|
if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) {
|
|
|
|
QString defaultFile(prefs.default_filename);
|
|
|
|
if (!defaultFile.isEmpty())
|
|
|
|
files.push_back(QString(prefs.default_filename));
|
|
|
|
} else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) {
|
|
|
|
QString cloudURL;
|
|
|
|
if (getCloudURL(cloudURL) == 0)
|
|
|
|
files.push_back(cloudURL);
|
|
|
|
}
|
2014-03-20 12:56:04 +00:00
|
|
|
}
|
2014-03-11 21:54:28 +00:00
|
|
|
MainWindow *m = MainWindow::instance();
|
2014-03-19 16:23:43 +00:00
|
|
|
m->setLoadedWithFiles(!files.isEmpty() || !importedFiles.isEmpty());
|
2014-03-11 21:54:28 +00:00
|
|
|
m->loadFiles(files);
|
|
|
|
m->importFiles(importedFiles);
|
2015-10-05 22:52:39 +00:00
|
|
|
// in case something has gone wrong make sure we show the error message
|
|
|
|
m->showError();
|
|
|
|
|
2015-09-23 09:13:07 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
print_files();
|
2013-11-02 19:00:16 +00:00
|
|
|
if (!quit)
|
|
|
|
run_ui();
|
2013-09-09 08:59:03 +00:00
|
|
|
exit_ui();
|
2014-12-18 07:47:55 +00:00
|
|
|
taglist_free(g_tag_list);
|
2014-03-19 16:23:43 +00:00
|
|
|
parse_xml_exit();
|
2015-10-06 10:10:21 +00:00
|
|
|
free((void *)default_directory);
|
|
|
|
free((void *)default_filename);
|
2014-03-25 14:55:56 +00:00
|
|
|
subsurface_console_exit();
|
2014-12-18 07:47:42 +00:00
|
|
|
free_prefs();
|
2013-09-09 08:59:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|