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"
26 #include <kstandarddirs.h>
27 #include <kcomponentdata.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()
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() + ")\">");
58 echo ("<li class=\"title\">" + folder
.fullText() + "</li>");
63 echo ("<li class=\"title\">" + QString() + "<img src=\"/icon/" + folder
.icon() + "\"/>" + folder
.text() + "</li>");
67 for (KBookmark bm
= folder
.first(); !bm
.isNull(); bm
= folder
.next(bm
))
70 echoFolder(bm
.toGroup());
71 else if (bm
.isSeparator())
82 void BookmarksProtocol::echoIndex()
88 KBookmark bm
= tree
.first();
91 echo("<p class=\"message\">" + i18n("There are no bookmarks to display yet.") + "</p>");
94 for (int i
= 1; i
<= columns
; i
++)
97 echo("<div class=\"column\">");
100 while(!bm
.isNull() && (size
+ sizeOfGroup(bm
.toGroup())*2/3 < (totalsize
/ columns
) || size
== 0))
102 echoFolder(bm
.toGroup());
103 size
+= sizeOfGroup(bm
.toGroup());
111 echoFolder(bm
.toGroup());
124 void BookmarksProtocol::echoHead(const QString
&redirect
)
126 SlaveBase::mimeType("text/html");
128 QString
css(KStandardDirs::locate("data","kio_bookmarks/kio_bookmarks.css"));
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\">");
139 echo("<title>" + i18n("My Bookmarks") + "</title>");
140 echo("<link rel=\"stylesheet\" type=\"text/css\" href=\"file://" + css
.toUtf8() + "\" />");
143 if (!redirect
.isEmpty())
144 echo("<meta http-equiv=\"Refresh\" content=\"0;url=" + redirect
+ "\"/>");
151 /*echo("<div class=\"toolbar\">");
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>");
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\">");
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()) + "; }");
188 void BookmarksProtocol::echo( const QString
&string
)
190 for(int i
= 0; i
< indent
; i
++)
194 data(string
.toUtf8() + '\n');
197 QString
BookmarksProtocol::htmlColor(const QColor
&col
)
200 col
.getRgb(&r
, &g
, &b
);
203 num
.sprintf("#%02X%02X%02X", r
, g
, b
);
207 QString
BookmarksProtocol::htmlColor(const QBrush
&brush
)
209 return htmlColor(brush
.color());