main.cpp 6.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/* This file is part of the KDE project
 * Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include <QApplication>
#include <QFontDatabase>
#include <QFile>
#include <QStringList>
#include <QString>
#include <QDesktopServices>
#include <QProcessEnvironment>
#include <QDir>
#include <QMessageBox>
#include <QSplashScreen>

#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <kcomponentdata.h>
#include <kstandarddirs.h>
36
#include <kiconloader.h>
37 38 39 40 41
#include "data/splash/splash_screen.xpm"
#include "MainWindow.h"

#include "sketch/SketchInputContext.h"

42 43
#include <calligraversion.h>
#include <calligragitversion.h>
44 45

#if defined Q_OS_WIN
46
#include "stdlib.h"
47 48 49 50
#include <ui/input/wintab/kis_tablet_support_win.h>
#elif defined Q_WS_X11
#include <ui/input/wintab/kis_tablet_support_x11.h>
#endif
51 52 53 54


int main( int argc, char** argv )
{
55 56 57 58 59 60 61 62 63 64 65 66
    QString calligraVersion(CALLIGRA_VERSION_STRING);
    QString version;


#ifdef CALLIGRA_GIT_SHA1_STRING
    QString gitVersion(CALLIGRA_GIT_SHA1_STRING);
    version = QString("%1 (git %2)").arg(calligraVersion).arg(gitVersion).toLatin1();
#else
    version = calligraVersion;
#endif


67 68
    KAboutData aboutData("kritagemini",
                         "krita",
69
                         ki18n("Krita Gemini"),
70
                         version.toLatin1(),
71 72
                         ki18n("Krita Gemini: Painting at Home and on the Go for Artists"),
                         KAboutData::License_GPL,
73
                         ki18n("(c) 1999-%1 The Krita team and KO GmbH.\n").subs(CALLIGRA_YEAR),
74
                         KLocalizedString(),
75
                         "http://www.kritastudio.com",
76 77 78 79 80 81
                         "submit@bugs.kde.org");

    KCmdLineArgs::init (argc, argv, &aboutData);

    KCmdLineOptions options;
    options.add( "+[files]", ki18n( "Images to open" ) );
82
    options.add( "vkb", ki18n( "Use the virtual keyboard" ) );
83
    options.add( "fullscreen", ki18n( "Use full-screen display" ) );
84
    options.add( "sketch", ki18n( "Start with the Sketch interface" ) );
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    KCmdLineArgs::addCmdLineOptions( options );

    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
    QStringList fileNames;
    if (args->count() > 0) {
        for (int i = 0; i < args->count(); ++i) {
            QString fileName = args->arg(i);
            if (QFile::exists(fileName)) {
                fileNames << fileName;
            }
        }
    }

    KApplication app;
99
    app.setApplicationName("kritagemini");
100
    KIconLoader::global()->addAppDir("krita");
101
    KIconLoader::global()->addAppDir("kritasketch");
102

103
#ifdef Q_OS_WIN
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    QDir appdir(app.applicationDirPath());
    appdir.cdUp();

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    // If there's no kdehome, set it and restart the process.
    //QMessageBox::information(0, "krita sketch", "KDEHOME: " + env.value("KDEHOME"));
    if (!env.contains("KDEHOME") ) {
        _putenv_s("KDEHOME", QDesktopServices::storageLocation(QDesktopServices::DataLocation).toLocal8Bit());
    }
    if (!env.contains("KDESYCOCA")) {
        _putenv_s("KDESYCOCA", QString(appdir.absolutePath() + "/sycoca").toLocal8Bit());
    }
    if (!env.contains("XDG_DATA_DIRS")) {
        _putenv_s("XDG_DATA_DIRS", QString(appdir.absolutePath() + "/share").toLocal8Bit());
    }
    if (!env.contains("KDEDIR")) {
        _putenv_s("KDEDIR", appdir.absolutePath().toLocal8Bit());
    }
    if (!env.contains("KDEDIRS")) {
        _putenv_s("KDEDIRS", appdir.absolutePath().toLocal8Bit());
    }
    _putenv_s("PATH", QString(appdir.absolutePath() + "/bin" + ";"
              + appdir.absolutePath() + "/lib" + ";"
              + appdir.absolutePath() + "/lib"  +  "/kde4" + ";"
              + appdir.absolutePath()).toLocal8Bit());

    app.addLibraryPath(appdir.absolutePath());
    app.addLibraryPath(appdir.absolutePath() + "/bin");
    app.addLibraryPath(appdir.absolutePath() + "/lib");
    app.addLibraryPath(appdir.absolutePath() + "/lib/kde4");
#endif

136 137 138 139 140 141 142
#if defined Q_OS_WIN
    KisTabletSupportWin::init();
    app.setEventFilter(&KisTabletSupportWin::eventFilter);
#elif defined Q_WS_X11
    KisTabletSupportX11::init();
    app.setEventFilter(&KisTabletSupportX11::eventFilter);
#endif
143 144 145 146 147 148
	
	if (qgetenv("KDE_FULL_SESSION").isEmpty()) {
        // There are two themes that work for Krita, oxygen and plastique. Try to set plastique first, then oxygen
        qobject_cast<QApplication*>(QApplication::instance())->setStyle("Plastique");
		qobject_cast<QApplication*>(QApplication::instance())->setStyle("Oxygen");
    }
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163
    // Prepare to show window fullscreen if required
    bool showFullscreen = false;

#ifdef HAVE_STEAMWORKS
    if (steamClient->isInBigPictureMode()) {
        // Show main window full screen
        showFullscreen = true;
    }
#endif

    if (args->isSet("sketch")) {
        showFullscreen = true;
    }

164 165 166 167
	if (args->isSet("fullscreen")) {
        showFullscreen = true;
    }

168 169 170
    // then create the pixmap from an xpm: we cannot get the
    // location of our datadir before we've started our components,
    // so use an xpm.
171
    // If fullscreen, hide splash screen
172 173
    QPixmap pm(splash_screen_xpm);
    QSplashScreen splash(pm);
174 175 176 177 178
    if (!showFullscreen) {
        splash.show();
        splash.showMessage(".");
        app.processEvents();
    }
179

180
#if defined Q_WS_X11 && QT_VERSION >= 0x040800
181
    QApplication::setAttribute(Qt::AA_X11InitThreads);
182
#endif
183 184 185 186 187 188 189

    MainWindow window(fileNames);

    if (args->isSet("vkb")) {
        app.setInputContext(new SketchInputContext(&app));
    }

190 191 192 193
    if (args->isSet("sketch")) {
        window.setSlateMode(true);
    }

194 195 196
    if (showFullscreen) {
        window.showFullScreen();
    } else {
197
#ifdef Q_OS_WIN
198
		window.showMaximized();
199
#else
200
		window.show();
201
#endif
202
	}
203 204 205 206
    splash.finish(&window);

    return app.exec();
}