Fix PDF content type, better publisher initialization
[pykit.git] / main.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
4 //     Stefan Bund <info@j32.de>
5
6 /** \file
7     \brief main non-inline non-template implementation */
8
9 //#include "main.hh"
10 //#include "main.ih"
11
12 // Custom includes
13 #include <stdlib.h>
14 #include <iostream>
15 #include <QApplication>
16 #include <QSplashScreen>
17 #include <QSettings>
18 #include <QDir>
19 #include <QFileInfo>
20 #include <QFontDatabase>
21 #include <boost/scoped_ptr.hpp>
22 #include "MainWindow.hh"
23 #include "PythonPublisher.hh"
24
25 //#include "main.mpp"
26 #define prefix_
27 ///////////////////////////////cc.p////////////////////////////////////////
28
29 int main(int argc, char *argv[])
30 {
31     try {
32         QApplication app (argc, argv);
33
34         QSettings settings ("pykit.ini", QSettings::IniFormat);
35         QStringList arguments (app.arguments());
36         settings.beginGroup("AppData");
37
38         app.setApplicationName(settings.value("name").toString());
39         app.setApplicationVersion(settings.value("version").toString());
40         app.setOrganizationDomain(settings.value("organization").toString());
41         app.setOrganizationName(settings.value("organization").toString());
42
43         QString splashPath (settings.value("splash").toString());
44         boost::scoped_ptr<QSplashScreen> splash;
45         if (!splashPath.isEmpty()) {
46             QPixmap splashPixmap (settings.value("splash").toString());
47             splash.reset(new QSplashScreen (splashPixmap));
48             splash->show();
49         }
50
51         QString iconPath (settings.value("icon").toString());
52
53         settings.endGroup();
54
55         settings.beginGroup("Fonts");
56         QString loadFontDir (settings.value("loaddir").toString());
57         if (!loadFontDir.isEmpty()) {
58             QDir dir (loadFontDir);
59             if (dir.exists()) {
60                 QFileInfoList files (dir.entryInfoList(QDir::Files));
61                 for (QFileInfoList::iterator i (files.begin()), i_end (files.end());
62                      i != i_end; ++i)
63                     QFontDatabase::addApplicationFont(i->absoluteFilePath());
64             }
65             else
66                 std::cerr << "WARNING: Font directory not found" << std::endl;
67         }
68         settings.endGroup();
69
70         settings.beginGroup("Viewer");
71
72         pykit::PythonPublisher publisher;
73
74         QString url (settings.value("home").toString());
75         if (arguments.size()>1)
76             url = arguments.at(1);
77         pykit::MainWindow window (QUrl(url), &publisher);
78         window.setWindowTitle(app.applicationName());
79         if (!iconPath.isEmpty())
80             window.setWindowIcon(QIcon(iconPath));
81         window.setWindowIconText(window.windowTitle());
82
83         window.show();
84         if (splash)
85             splash->finish(&window);
86
87         return app.exec();
88     }
89     catch (std::exception & ex) {
90         std::cerr << "Exception:\n" << ex.what() << "\n";
91         throw;
92     }
93 }
94
95 ///////////////////////////////cc.e////////////////////////////////////////
96 #undef prefix_
97 //#include "main.mpp"
98
99 \f
100 // Local Variables:
101 // mode: c++
102 // fill-column: 100
103 // comment-column: 40
104 // c-file-style: "j32"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -U"
108 // End: