source: subsurface/subsurface-desktop-main.cpp

Last change on this file was 1fc4fba, checked in by Dirk Hohndel <dirk@…>, 3 weeks ago

Break down MainTab? into smaller classes

Maintab is one of our most complex classes, and it's
something I'm not actually proud of. But it currently
works and the idea of splitting it was in my head for
quite a while.

This is the third or fourth tentative of splitting it,
and this time I let the most complex part of it untouched,
the Notes and Equipment tab are way too complex to untangle
right now on my limited time.

A new class 'TabBase?' should be used for any new tab that
we may create, and added on the MainTab? (see the new lines
on the MainTab? constructor).

Also, Extra Info, Information, Photos and Statistics where
ported to this new way helping reduce the number of
lines and functions on the MainTab? quite a bit.

Overall this is a step in the right direction for the future.

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

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