add more spacing
[personal-kdebase.git] / runtime / kioslave / bookmarks / kio_bookmarks_html.cpp
blobed219720d55460243acdc610651201c3a6c98981
1 /*
2 Copyright (C) 2008 Xavier Vello <xavier.vello@gmail.com>
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.
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.
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.
19 #include "kio_bookmarks.h"
21 #include <stdio.h>
22 #include <stdlib.h>
24 #include <kdebug.h>
25 #include <kshell.h>
26 #include <kstandarddirs.h>
27 #include <kcomponentdata.h>
28 #include <klocale.h>
29 #include <kconfig.h>
30 #include <kconfiggroup.h>
31 #include <kbookmark.h>
32 #include <kbookmarkmanager.h>
33 #include <kcolorscheme.h>
34 #include <kcolorutils.h>
35 #include <kglobalsettings.h>
37 void BookmarksProtocol::echoBookmark( const KBookmark &bm)
39 echo ("<li class=\"link\"><a href=\"" + bm.url().prettyUrl() + "\">" + "<img src=\"/icon/" + bm.icon() + "\"/>" + bm.text() + "</a></li>");
42 void BookmarksProtocol::echoSeparator()
44 echo ("<hr/>");
47 void BookmarksProtocol::echoFolder( const KBookmarkGroup &folder )
49 if (sizeOfGroup(folder.toGroup(), true) > 1)
51 if (folder.parentGroup() == tree)
53 if (config.readEntry("ShowBackgrounds", true))
54 echo("<ul style=\"background-image: url(/background/" + folder.icon() + ")\">");
55 else
56 echo("<ul>");
58 echo ("<li class=\"title\">" + folder.fullText() + "</li>");
60 else
62 echo("<ul>");
63 echo ("<li class=\"title\">" + QString() + "<img src=\"/icon/" + folder.icon() + "\"/>" + folder.text() + "</li>");
65 indent++;
67 for (KBookmark bm = folder.first(); !bm.isNull(); bm = folder.next(bm))
69 if (bm.isGroup())
70 echoFolder(bm.toGroup());
71 else if (bm.isSeparator())
72 echoSeparator();
73 else
74 echoBookmark(bm);
77 indent--;
78 echo("</ul>");
82 void BookmarksProtocol::echoIndex()
84 parseTree();
86 echoHead();
88 KBookmark bm = tree.first();
90 if(bm.isNull()) {
91 echo("<p class=\"message\">" + i18n("There are no bookmarks to display yet.") + "</p>");
93 else {
94 for (int i = 1; i <= columns; i++)
96 int size = 0;
97 echo("<div class=\"column\">");
98 indent++;
100 while(!bm.isNull() && (size + sizeOfGroup(bm.toGroup())*2/3 < (totalsize / columns) || size == 0))
102 echoFolder(bm.toGroup());
103 size += sizeOfGroup(bm.toGroup());
104 bm = tree.next(bm);
107 if (i == columns)
109 while(!bm.isNull())
111 echoFolder(bm.toGroup());
112 bm = tree.next(bm);
115 indent--;
116 echo("</div>");
119 indent--;
120 echo("</body>");
121 echo("</html>");
124 void BookmarksProtocol::echoHead(const QString &redirect)
126 SlaveBase::mimeType("text/html");
128 QString css(KStandardDirs::locate("data","kio_bookmarks/kio_bookmarks.css"));
129 if (css.isEmpty())
130 this->warning(i18n("kio_bookmarks CSS file not found. Output will look ugly.\n"
131 "Check your installation."));
133 echo("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
134 echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
135 echo("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
136 echo("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
137 echo("<head>");
138 indent++;
139 echo("<title>" + i18n("My Bookmarks") + "</title>");
140 echo("<link rel=\"stylesheet\" type=\"text/css\" href=\"file://" + css.toUtf8() + "\" />");
141 echoStyle();
143 if (!redirect.isEmpty())
144 echo("<meta http-equiv=\"Refresh\" content=\"0;url=" + redirect + "\"/>");
146 indent--;
147 echo("</head>");
148 echo("<body>");
149 indent++;
151 /*echo("<div class=\"toolbar\">");
152 indent++;
153 echo("<a title=\"" + i18n("Configuration") + "\" href=\"/config\"><img src=\"/icon/preferences-system?size=32\"/></a>");
154 echo("<a title=\"" + i18n("Edit bookmarks") + "\" href=\"/editbookmarks\"><img src=\"/icon/bookmarks-organize?size=32\"/></a>");
155 echo("<a title=\"" + i18n("Help") + "\" href=\"help:/kioslave/bookmarks.html\"><img src=\"/icon/help-contents?size=32\"/></a>");
156 indent--;
157 echo("</div>");*/
159 if (!redirect.isEmpty())
160 echo("</body></html>");
164 void BookmarksProtocol::echoStyle()
166 KColorScheme window = KColorScheme(QPalette::Active, KColorScheme::Window);
167 KColorScheme view = KColorScheme(QPalette::Active, KColorScheme::View);
168 KColorScheme selection = KColorScheme(QPalette::Active, KColorScheme::Selection);
170 QFont font = KGlobalSettings::generalFont();
172 echo("<style type=\"text/css\">");
173 indent++;
174 echo("li.link:hover, div.toolbar img:hover { background: " +
175 htmlColor(KColorUtils::tint(view.background().color(), view.decoration(KColorScheme::HoverColor).color(), 0.4)) + "; }");
176 echo("div.column > ul, div.toolbar, p.message { background-color: " + htmlColor(view.background()) + "; " +
177 "border: 1px solid " + htmlColor(view.shade(KColorScheme::LightShade)) + "; }");
178 echo("div.column > ul:hover, p.message:hover { border: 1px solid " + htmlColor(view.decoration(KColorScheme::HoverColor)) + "; }");
179 echo("div.toolbar {border-top: none; border-right: none;}");
180 echo("div.column { width : " + QString::number(100/columns) + "%; }");
181 echo("body { font-size: " + QString::number(font.pointSize()) + "pt; " +
182 "background: " + htmlColor(window.background()) + "; " +
183 "color: " + htmlColor(view.foreground()) + "; }");
184 indent--;
185 echo("</style>");
188 void BookmarksProtocol::echo( const QString &string )
190 for(int i = 0; i < indent; i++)
192 data(" ");
194 data(string.toUtf8() + '\n');
197 QString BookmarksProtocol::htmlColor(const QColor &col)
199 int r, g, b;
200 col.getRgb(&r, &g, &b);
201 QString num;
203 num.sprintf("#%02X%02X%02X", r, g, b);
204 return num;
207 QString BookmarksProtocol::htmlColor(const QBrush &brush)
209 return htmlColor(brush.color());