source: subsurface/subsurface-desktop-main.cpp

Last change on this file was a55efcf, checked in by Dirk Hohndel <dirk@…>, 5 weeks ago

Move the fill_computer_list() out of widgets

fill_computer_list() creates a Qt friendly
structure that contains all of the necessary
information about dive computers and it's
devices, and it's needed both in Qml and Widgets
to allow the user to download their dives.

This patch makes it possible to use the code
in QML without duplication.

Signed-off-by: Tomaz Canabrava <tcanabrava@…>
Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100644
File size: 3.4 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2/* main.c */
3#include <locale.h>
4#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
7#include <time.h>
8
9#include "core/dive.h"
10#include "core/qt-gui.h"
11#include "core/subsurfacestartup.h"
12#include "desktop-widgets/mainwindow.h"
13#include "desktop-widgets/tab-widgets/maintab.h"
14#include "profile-widget/profilewidget2.h"
15#include "desktop-widgets/preferences/preferencesdialog.h"
16#include "desktop-widgets/diveplanner.h"
17#include "core/color.h"
18#include "core/qthelper.h"
19#include "core/downloadfromdcthread.h" // for fill_computer_list
20
21#include <QStringList>
22#include <QApplication>
23#include <QLoggingCategory>
24#include <git2.h>
25
26static bool filesOnCommandLine = false;
27
28int main(int argc, char **argv)
29{
30        int i;
31        bool no_filenames = true;
32        QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
33        QApplication *application = new QApplication(argc, argv);
34        (void)application;
35        QStringList files;
36        QStringList importedFiles;
37        QStringList arguments = QCoreApplication::arguments();
38
39        bool win32_log = arguments.length() > 1 &&
40                (arguments.at(1) == QString("--win32log"));
41        if (win32_log) {
42                subsurface_console_init(true, true);
43        } else {
44                bool dedicated_console = arguments.length() > 1 &&
45                        (arguments.at(1) == QString("--win32console"));
46                subsurface_console_init(dedicated_console, false);
47        }
48
49        const char *default_directory = system_default_directory();
50        const char *default_filename = system_default_filename();
51        subsurface_mkdir(default_directory);
52
53        for (i = 1; i < arguments.length(); i++) {
54                QString a = arguments.at(i);
55                if (a.isEmpty())
56                        continue;
57                if (a.at(0) == '-') {
58                        parse_argument(a.toLocal8Bit().data());
59                        continue;
60                }
61                if (imported) {
62                        importedFiles.push_back(a);
63                } else {
64                        no_filenames = false;
65                        files.push_back(a);
66                }
67        }
68        if (subsurface_user_is_root() && !force_root) {
69                printf("You are running Subsurface as root. This is not recommended.\n");
70                printf("If you insist to do so, run with option --allow_run_as_root.\n");
71                exit(0);
72        }
73#if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22
74        git_threads_init();
75#else
76        git_libgit2_init();
77#endif
78        /*
79         * Initialize the random number generator - not really secure as
80         * this is based only on current time, but it should not matter
81         * that much in our context. Moreover this is better than
82         * the constant numbers we used to get before.
83         */
84        qsrand(time(NULL));
85        setup_system_prefs();
86        copy_prefs(&default_prefs, &prefs);
87        fill_profile_color();
88        fill_computer_list();
89        parse_xml_init();
90        taglist_init_global();
91        init_ui();
92        if (no_filenames) {
93                if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) {
94                        QString defaultFile(prefs.default_filename);
95                        if (!defaultFile.isEmpty())
96                                files.push_back(QString(prefs.default_filename));
97                } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) {
98                        QString cloudURL;
99                        if (getCloudURL(cloudURL) == 0)
100                                files.push_back(cloudURL);
101                }
102        }
103        MainWindow *m = MainWindow::instance();
104        filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty();
105        m->loadFiles(files);
106        m->importFiles(importedFiles);
107        // in case something has gone wrong make sure we show the error message
108        m->showError();
109
110        if (verbose > 0)
111                print_files();
112        if (!quit)
113                run_ui();
114        exit_ui();
115        taglist_free(g_tag_list);
116        parse_xml_exit();
117        free((void *)default_directory);
118        free((void *)default_filename);
119        subsurface_console_exit();
120        free_prefs();
121        return 0;
122}
123
124bool haveFilesOnCommandLine()
125{
126        return filesOnCommandLine;
127}
Note: See TracBrowser for help on using the repository browser.