1/*
2 * Copyright (c) 2014 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kis_splash_screen.h"
19
20#include <QApplication>
21#include <QDesktopWidget>
22#include <QPixmap>
23#include <QCheckBox>
24#include <QDebug>
25#include <QFile>
26
27#include <KoPart.h>
28#include <KoApplication.h>
29
30#include <kcomponentdata.h>
31#include <klocale.h>
32#include <kconfig.h>
33#include <kglobal.h>
34#include <kconfiggroup.h>
35#include <kfileitem.h>
36
37#include <kis_factory2.h>
38
39KisSplashScreen::KisSplashScreen(const QString &version, const QPixmap &pixmap, QWidget *parent, Qt::WindowFlags f)
40 : QWidget(parent, Qt::SplashScreen | Qt::FramelessWindowHint | f)
41{
42 setupUi(this);
43
44 lblSplash->setPixmap(pixmap);
45 bnClose->hide();
46 connect(bnClose, SIGNAL(clicked()), this, SLOT(close()));
47 chkShowAtStartup->hide();
48 connect(chkShowAtStartup, SIGNAL(toggled(bool)), this, SLOT(toggleShowAtStartup(bool)));
49
50 KConfigGroup cfg(KisFactory2::componentData().config(), "SplashScreen");
51 bool hideSplash = cfg.readEntry("HideSplashAfterStartup", false);
52 chkShowAtStartup->setChecked(hideSplash);
53
54 lblLinks->setTextFormat(Qt::RichText);
55 lblLinks->setText(i18n("<html>"
56 "<head/>"
57 "<body>"
58 "<p align=\"center\"><b>Links</b></p>"
59
60 "<p><a href=\"http://krita.org/support-krita#general\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Donations</span></a></p>"
61 "<p><a href=\"http://www.zazzle.com/kritashop\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Merchandise</span></a></p>"
62
63 "<p><a href=\"http://krita.org/resources\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Getting Started</span></a></p>"
64// "<p><a href=\"http://userbase.kde.org/Krita\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Manual</span></a></p>"
65 "<p><a href=\"http://krita.org\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Krita Website</span></a></p>"
66 "<p><a href=\"http://forum.kde.org/viewforum.php?f=136\"><span style=\" text-decoration: underline; color:#FFFFFF;\">User Community</span></a></p>"
67
68 "<p><a href=\"https://projects.kde.org/projects/calligra\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Source Code</span></a></p>"
69
70 "<p><a href=\"http://kritastudio.com\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Commercial Support</span></a></p>"
71 "<p><a href=\"http://store.steampowered.com/app/280680/\"><span style=\" text-decoration: underline; color:#FFFFFF;\">Krita on Steam</span></a></p>"
72 "</body>"
73 "</html>"));
74
75 lblVersion->setText(i18n("Version: %1", version));
76
77 KConfigGroup cfg2(KisFactory2::componentData().config(), "RecentFiles");
78 int i = 1;
79
80 QString recent = i18n("<html>"
81 "<head/>"
82 "<body>"
83 "<p align=\"center\"><b>Recent Files</b></p>");
84
85 QString path;
86 QStringList recentfiles;
87
88 do {
89 path = cfg2.readPathEntry(QString("File%1").arg(i), QString());
90 if (!path.isEmpty()) {
91 QString name = cfg2.readPathEntry(QString("Name%1").arg(i), QString());
92 KUrl url(path);
93 if (name.isEmpty())
94 name = url.fileName();
95
96 if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
97 recentfiles.insert(0, QString("<p><a href=\"%1\"><span style=\"color:#FFFFFF;\">%2</span></a></p>").arg(path).arg(name));
98 }
99 }
100
101 i++;
102 } while (!path.isEmpty() || i <= 8);
103
104 recent += recentfiles.join("\n");
105 recent += "</body>"
106 "</html>";
107 lblRecent->setText(recent);
108 connect(lblRecent, SIGNAL(linkActivated(QString)), SLOT(linkClicked(QString)));
109}
110
111
112void KisSplashScreen::repaint()
113{
114 QWidget::repaint();
115 QApplication::flush();
116}
117
118void KisSplashScreen::show()
119{
120 QRect r(QPoint(), sizeHint());
121 resize(r.size());
122 move(QApplication::desktop()->screenGeometry().center() - r.center());
123 if (isVisible()) {
124 repaint();
125 }
126
127}
128
129void KisSplashScreen::toggleShowAtStartup(bool toggle)
130{
131 KConfigGroup cfg(KGlobal::config(), "SplashScreen");
132 cfg.writeEntry("HideSplashAfterStartup", toggle);
133}
134
135void KisSplashScreen::linkClicked(const QString &link)
136{
137 if (koApp && koApp->partList().size() > 0) {
138 koApp->partList().first()->openExistingFile(KUrl(link));
139 }
140 close();
141}
142