RazorAutostartEntry => LxQt::AutostartEntry
[lxde/liblxqt.git] / lxqtapplication.cpp
CommitLineData
8966cbec 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
f18f98db
PV
28#include <QtCore/QDir>
29
8966cbec 30#include <qtxdg/xdgicon.h>
00f0a23a 31#include <qtxdg/xdgdirs.h>
f18f98db 32
077c1e76 33#include "lxqtapplication.h"
f18f98db
PV
34#include "razorsettings.h"
35
077c1e76 36using namespace LxQt;
8966cbec 37
00f0a23a
AS
38#define COLOR_DEBUG "\033[32;2m"
39#define COLOR_WARN "\033[33;2m"
2f7229d2 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
619f3aee 46#include <cstdio>
47#include <cstdlib>
3048adf5 48#include <unistd.h>
619f3aee 49#include <QDateTime>
bc341bc6 50/*! \brief Log qDebug input to file
5af80cab
PV
51Used only in pure Debug builds or when is the system environment
52variable RAZOR_DEBUG set
619f3aee 53*/
54void dbgMessageOutput(QtMsgType type, const char *msg)
5af80cab 55{
bc341bc6 56 QDir dir(XdgDirs::configHome().toUtf8() + "/razor");
00f0a23a
AS
57 dir.mkpath(".");
58
3048adf5
AM
59 const char* typestr;
60 const char* color;
619f3aee 61 switch (type) {
62 case QtDebugMsg:
3048adf5
AM
63 typestr = "Debug";
64 color = COLOR_DEBUG;
619f3aee 65 break;
66 case QtWarningMsg:
3048adf5
AM
67 typestr = "Warning";
68 color = COLOR_WARN;
619f3aee 69 break;
70 case QtFatalMsg:
3048adf5
AM
71 typestr = "Fatal";
72 color = COLOR_FATAL;
73 break;
74 default: // QtCriticalMsg
75 typestr = "Critical";
76 color = COLOR_CRITICAL;
619f3aee 77 }
3048adf5
AM
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);
619f3aee 87 fclose(f);
3048adf5
AM
88
89 if (type == QtFatalMsg)
90 abort();
619f3aee 91}
8966cbec 92
077c1e76 93Application::Application(int &argc, char** argv)
8966cbec 94 : QApplication(argc, argv)
95{
619f3aee 96#ifdef DEBUG
97 qInstallMsgHandler(dbgMessageOutput);
5af80cab
PV
98#else
99 if (!qgetenv("RAZOR_DEBUG").isNull())
100 qInstallMsgHandler(dbgMessageOutput);
619f3aee 101#endif
102
8966cbec 103 XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
af223b3d 104 setWindowIcon(QIcon(QString(LXQT_SHARE_DIR) + "/graphics/razor_logo.png"));
63a934d5
AS
105 connect(RazorSettings::globalSettings(), SIGNAL(razorThemeChanged()), this, SLOT(updateTheme()));
106 updateTheme();
107}
8966cbec 108
8966cbec 109
077c1e76 110void Application::updateTheme()
63a934d5
AS
111{
112 QString styleSheetKey = QFileInfo(applicationFilePath()).fileName();
113 setStyleSheet(razorTheme.qss(styleSheetKey));
114 emit themeChanged();
8966cbec 115}