initial; functional, might as well release
[sispare-qt.git] / main.cc
blob66e921d95bd543f4d6512e554f75b58aeb635642
1 /*
2 * Copyright (c) 2021, S. Gilles <sgilles@sgilles.net>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
7 * in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <cstdlib>
19 #include <iostream>
20 #include <QApplication>
22 #include <unistd.h>
24 #include "session.hh"
25 #include "ui.hh"
26 #include "util.hh"
28 int
29 main(int argc, char *argv[])
31 try {
32 /* The only option is [ -d <directory> ] */
33 int c;
34 char *explicit_data_dir_str = nullptr;
36 while ((c = getopt(argc, argv, "d:")) != -1) {
37 switch (c) {
38 case 'd':
40 if (optarg) {
41 explicit_data_dir_str = optarg;
44 break;
48 /* Read in the cards */
49 std::filesystem::path data_dir;
51 if (explicit_data_dir_str) {
52 data_dir = std::filesystem::path(explicit_data_dir_str);
53 } else {
54 data_dir = Util::find_data_dir();
57 Session session(data_dir);
59 /* Set up qt */
60 QCoreApplication::setOrganizationName("sispare");
61 QCoreApplication::setApplicationName("sispare-qt");
62 QApplication qa(argc, argv);
63 UI ui(&session);
65 ui.show();
67 return qa.exec();
68 } catch (const std::exception& ex) {
69 Util::output_nested_ex(ex);