2017-01-02 17:05:30 -05:00
/*
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
* Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2016-12-30 16:25:27 -05:00
# include "dockcorona.h"
2017-02-15 22:14:37 -05:00
# include "config-latte.h"
2017-07-22 23:15:54 +03:00
# include "importer.h"
2016-12-25 09:25:27 +02:00
# include <memory>
2017-02-26 12:37:46 -05:00
# include <csignal>
2016-12-25 09:25:27 +02:00
# include <QApplication>
2017-01-28 19:45:49 +02:00
# include <QDebug>
2016-12-25 09:25:27 +02:00
# include <QQuickWindow>
2016-12-30 16:25:27 -05:00
# include <QCommandLineParser>
# include <QCommandLineOption>
2016-12-25 09:25:27 +02:00
# include <QDebug>
2017-02-18 14:34:30 +02:00
# include <QDir>
# include <QLockFile>
2017-02-18 09:44:04 +02:00
# include <QSharedMemory>
2016-12-25 09:25:27 +02:00
2017-08-03 12:53:16 +03:00
# include <KCrash>
2016-12-25 09:25:27 +02:00
# include <KLocalizedString>
2017-01-29 00:16:28 -05:00
# include <KAboutData>
2017-03-11 10:06:10 +02:00
# include <KDBusService>
2017-05-26 15:36:50 +03:00
# include <KQuickAddons/QtQuickSettings>
2016-12-25 09:25:27 +02:00
2017-02-26 12:37:46 -05:00
2016-12-25 09:25:27 +02:00
//! COLORS
# define CNORMAL "\e[0m"
# define CIGREEN "\e[1;32m"
# define CGREEN "\e[0;32m"
# define CICYAN "\e[1;36m"
# define CCYAN "\e[0;36m"
# define CIRED "\e[1;31m"
# define CRED "\e[0;31m"
2017-01-29 00:16:28 -05:00
inline void configureAboutData ( ) ;
2017-01-28 19:45:49 +02:00
2016-12-25 09:25:27 +02:00
int main ( int argc , char * * argv )
2017-03-11 10:06:10 +02:00
{
// Devive pixel ratio has some problems in latte (plasmashell) currently.
2017-02-17 21:14:31 +02:00
// - dialog continually expands (347951)
// - Text element text is screwed (QTBUG-42606)
// - Panel struts (350614)
// This variable should possibly be removed when all are fixed
qunsetenv ( " QT_DEVICE_PIXEL_RATIO " ) ;
2017-02-26 12:49:19 -05:00
// qputenv("QT_QUICK_CONTROLS_1_STYLE", "Desktop");
2017-02-17 21:14:31 +02:00
QCoreApplication : : setAttribute ( Qt : : AA_DisableHighDpiScaling ) ;
2016-12-25 09:25:27 +02:00
QQuickWindow : : setDefaultAlphaBuffer ( true ) ;
QApplication app ( argc , argv ) ;
2017-05-26 15:36:50 +03:00
KQuickAddons : : QtQuickSettings : : init ( ) ;
2017-01-21 18:27:51 -05:00
KLocalizedString : : setApplicationDomain ( " latte-dock " ) ;
2017-01-08 17:40:05 -05:00
app . setWindowIcon ( QIcon : : fromTheme ( QStringLiteral ( " latte-dock " ) ) ) ;
2017-05-26 15:07:06 +03:00
//protect from closing app when changing to "alternative session" and back
app . setQuitOnLastWindowClosed ( false ) ;
2017-02-26 12:37:46 -05:00
2017-01-29 00:16:28 -05:00
configureAboutData ( ) ;
2017-02-26 12:37:46 -05:00
QCommandLineParser parser ;
parser . addHelpOption ( ) ;
parser . addVersionOption ( ) ;
parser . addOptions ( {
2017-03-11 10:06:10 +02:00
{ { " r " , " replace " } , i18nc ( " command line " , " Replace the current dock instance. " ) }
, { { " d " , " debug " } , i18nc ( " command line " , " Show the debugging messages on stdout. " ) }
, { " mask " , i18nc ( " command line " , " Show messages of debugging for the mask (Only useful to devs). " ) }
, { " graphics " , i18nc ( " command line " , " Draw boxes around of the applets. " ) }
, { " with-window " , i18nc ( " command line " , " Open a window with much debug information. " ) }
2017-03-20 12:20:37 -05:00
, { " import " , i18nc ( " command line " , " Import configuration. " ) , i18nc ( " command line: import " , " file_name " ) }
2017-02-26 12:37:46 -05:00
} ) ;
parser . process ( app ) ;
QLockFile lockFile { QDir : : tempPath ( ) + " /latte-dock.lock " } ;
int timeout { 100 } ;
2017-05-26 15:07:06 +03:00
2017-03-20 12:20:37 -05:00
if ( parser . isSet ( QStringLiteral ( " replace " ) ) | | parser . isSet ( QStringLiteral ( " import " ) ) ) {
2017-05-26 15:07:06 +03:00
qint64 pid { - 1 } ;
2017-02-26 12:37:46 -05:00
if ( lockFile . getLockInfo ( & pid , nullptr , nullptr ) ) {
2017-03-20 12:20:37 -05:00
kill ( static_cast < pid_t > ( pid ) , SIGINT ) ;
2017-02-26 12:37:46 -05:00
timeout = 3000 ;
}
}
if ( ! lockFile . tryLock ( timeout ) ) {
qInfo ( ) < < i18n ( " An instance is already running!, use --replace to restart Latte " ) ;
qGuiApp - > exit ( ) ;
}
2017-03-20 12:20:37 -05:00
if ( parser . isSet ( QStringLiteral ( " import " ) ) ) {
2017-07-22 23:15:54 +03:00
bool imported = Latte : : Importer : : importHelper ( parser . value ( QStringLiteral ( " import " ) ) ) ;
2017-03-20 12:20:37 -05:00
if ( ! imported ) {
qInfo ( ) < < i18n ( " The configuration cannot be imported " ) ;
app . quit ( ) ;
}
}
2017-02-26 12:49:19 -05:00
if ( parser . isSet ( QStringLiteral ( " debug " ) ) | | parser . isSet ( QStringLiteral ( " mask " ) ) ) {
2017-03-11 10:06:10 +02:00
//! set pattern for debug messages
//! [%{type}] [%{function}:%{line}] - %{message} [%{backtrace}]
2017-02-01 21:19:50 +02:00
2017-02-26 12:37:46 -05:00
qSetMessagePattern ( QStringLiteral (
CIGREEN " [%{type} " CGREEN " %{time h:mm:ss.zz} " CIGREEN " ] " CNORMAL
2017-03-11 10:06:10 +02:00
# ifndef QT_NO_DEBUG
2017-02-26 12:37:46 -05:00
CIRED " [ " CCYAN " %{function} " CIRED " : " CCYAN " %{line} " CIRED " ] "
2017-03-11 10:06:10 +02:00
# endif
2017-02-26 12:37:46 -05:00
CICYAN " - " CNORMAL " %{message} "
CIRED " %{if-fatal} \n %{backtrace depth=8 separator= \" \n \" }%{endif} "
" %{if-critical} \n %{backtrace depth=8 separator= \" \n \" }%{endif} " CNORMAL ) ) ;
2017-02-01 21:19:50 +02:00
} else {
2017-03-11 10:06:10 +02:00
const auto noMessageOutput = [ ] ( QtMsgType , const QMessageLogContext & , const QString & ) { } ;
2017-02-26 12:37:46 -05:00
qInstallMessageHandler ( noMessageOutput ) ;
}
2017-02-01 21:19:50 +02:00
2017-02-26 12:37:46 -05:00
auto signal_handler = [ ] ( int ) {
qGuiApp - > exit ( ) ;
} ;
std : : signal ( SIGKILL , signal_handler ) ;
std : : signal ( SIGINT , signal_handler ) ;
2017-01-29 00:16:28 -05:00
2017-08-03 12:53:16 +03:00
KCrash : : setDrKonqiEnabled ( true ) ;
KCrash : : setFlags ( KCrash : : AutoRestart | KCrash : : AlwaysDirectly ) ;
2017-02-26 12:37:46 -05:00
Latte : : DockCorona corona ;
2017-03-11 10:06:10 +02:00
KDBusService service ( KDBusService : : Unique ) ;
2016-12-25 09:25:27 +02:00
return app . exec ( ) ;
}
2017-01-29 00:16:28 -05:00
inline void configureAboutData ( )
{
KAboutData about ( QStringLiteral ( " lattedock " )
, QStringLiteral ( " Latte Dock " )
2017-02-15 22:14:37 -05:00
, QStringLiteral ( VERSION )
2017-01-29 17:17:28 -05:00
, i18n ( " Latte is a dock based on plasma frameworks that provides an elegant and "
" intuitive experience for your tasks and plasmoids. It animates its contents "
" by using parabolic zoom effect and trys to be there only when it is needed. "
" \n \n \" Art in Coffee \" " )
2017-01-29 00:16:28 -05:00
, KAboutLicense : : GPL_V2
, QStringLiteral ( " \251 2016-2017 Michail Vourlakos, Smith AR " ) ) ;
2017-02-03 00:21:51 -05:00
about . setHomepage ( WEBSITE ) ;
2017-01-29 00:16:28 -05:00
about . setBugAddress ( BUG_ADDRESS ) ;
about . setProgramLogo ( QIcon : : fromTheme ( QStringLiteral ( " latte-dock " ) ) ) ;
about . setDesktopFileName ( QStringLiteral ( " latte-dock " ) ) ;
// Authors
about . addAuthor ( QStringLiteral ( " Michail Vourlakos " ) , QString ( ) , QStringLiteral ( " mvourlakos@gmail.com " ) ) ;
about . addAuthor ( QStringLiteral ( " Smith AR " ) , QString ( ) , QStringLiteral ( " audoban@openmailbox.org " ) ) ;
// Credits
2017-01-29 16:52:28 -05:00
about . addCredit ( QStringLiteral ( " Alexey Varfolomeev (varlesh) " ) , i18n ( " Logo and Icons " )
2017-01-29 00:16:28 -05:00
, QString ( ) , QStringLiteral ( " https://github.com/varlesh " ) ) ;
2017-01-29 16:52:28 -05:00
about . addCredit ( QStringLiteral ( " Ivan Bordoni " ) , i18n ( " Many bug reports " )
2017-01-29 00:16:28 -05:00
, QString ( ) , QStringLiteral ( " https://github.com/JenaPlinsky " ) ) ;
2017-04-02 01:28:00 -05:00
about . addCredit ( QStringLiteral ( " Kupiqu " ) , i18n ( " Many bug reports " )
, QString ( ) , QStringLiteral ( " https://github.com/kupiqu " ) ) ;
2017-01-29 16:52:28 -05:00
about . addCredit ( QStringLiteral ( " Ernesto Acosta (elav) " ) , i18n ( " Reviews for Latte Dock, CandilDock and NowDock " )
2017-01-29 00:16:28 -05:00
, QString ( ) , QStringLiteral ( " https://github.com/elav " ) ) ;
// Translators
about . setTranslator ( QStringLiteral ( TRANSLATORS ) , QStringLiteral ( TRANSLATORS_EMAIL ) ) ;
KAboutData : : setApplicationData ( about ) ;
}