RazorAutostartEntry => LxQt::AutostartEntry
[lxde/liblxqt.git] / lxqtapplication.cpp
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * Razor - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2012-2013 Razor team
8 * Authors:
9 * Petr Vanek <petr@scribus.info>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28 #include <QtCore/QDir>
29
30 #include <qtxdg/xdgicon.h>
31 #include <qtxdg/xdgdirs.h>
32
33 #include "lxqtapplication.h"
34 #include "razorsettings.h"
35
36 using namespace LxQt;
37
38 #define COLOR_DEBUG "\033[32;2m"
39 #define COLOR_WARN "\033[33;2m"
40 #define COLOR_CRITICAL "\033[31;1m"
41 #define COLOR_FATAL "\033[33;1m"
42 #define COLOR_RESET "\033[0m"
43
44 #define QAPP_NAME qApp ? qApp->objectName().toUtf8().constData() : ""
45
46 #include <cstdio>
47 #include <cstdlib>
48 #include <unistd.h>
49 #include <QDateTime>
50 /*! \brief Log qDebug input to file
51 Used only in pure Debug builds or when is the system environment
52 variable RAZOR_DEBUG set
53 */
54 void dbgMessageOutput(QtMsgType type, const char *msg)
55 {
56 QDir dir(XdgDirs::configHome().toUtf8() + "/razor");
57 dir.mkpath(".");
58
59 const char* typestr;
60 const char* color;
61 switch (type) {
62 case QtDebugMsg:
63 typestr = "Debug";
64 color = COLOR_DEBUG;
65 break;
66 case QtWarningMsg:
67 typestr = "Warning";
68 color = COLOR_WARN;
69 break;
70 case QtFatalMsg:
71 typestr = "Fatal";
72 color = COLOR_FATAL;
73 break;
74 default: // QtCriticalMsg
75 typestr = "Critical";
76 color = COLOR_CRITICAL;
77 }
78
79 QByteArray dt = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toUtf8();
80 if (isatty(STDERR_FILENO))
81 fprintf(stderr, "%s %s(%p) %s: %s%s\n", color, QAPP_NAME, qApp, typestr, msg, COLOR_RESET);
82 else
83 fprintf(stderr, "%s(%p) %s: %s\n", QAPP_NAME, qApp, typestr, msg);
84
85 FILE *f = fopen(dir.absoluteFilePath("debug.log").toUtf8().constData(), "a+");
86 fprintf(f, "%s %s(%p) %s: %s\n", dt.constData(), QAPP_NAME, qApp, typestr, msg);
87 fclose(f);
88
89 if (type == QtFatalMsg)
90 abort();
91 }
92
93 Application::Application(int &argc, char** argv)
94 : QApplication(argc, argv)
95 {
96 #ifdef DEBUG
97 qInstallMsgHandler(dbgMessageOutput);
98 #else
99 if (!qgetenv("RAZOR_DEBUG").isNull())
100 qInstallMsgHandler(dbgMessageOutput);
101 #endif
102
103 XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
104 setWindowIcon(QIcon(QString(LXQT_SHARE_DIR) + "/graphics/razor_logo.png"));
105 connect(RazorSettings::globalSettings(), SIGNAL(razorThemeChanged()), this, SLOT(updateTheme()));
106 updateTheme();
107 }
108
109
110 void Application::updateTheme()
111 {
112 QString styleSheetKey = QFileInfo(applicationFilePath()).fileName();
113 setStyleSheet(razorTheme.qss(styleSheetKey));
114 emit themeChanged();
115 }