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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
Copyright (C) 2008 Xavier Vello <xavier.vello@gmail.com>
This program 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.
This program 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kio_bookmarks.h"
#include <stdio.h>
#include <stdlib.h>
#include <kshell.h>
#include <KLocalizedString>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kbookmark.h>
#include <kbookmarkmanager.h>
#include <kcolorscheme.h>
#include <kcolorutils.h>
#include <QStandardPaths>
#include <QFontDatabase>
void BookmarksProtocol::echoBookmark( const KBookmark &bm)
{
QString descriptionAsTitle = bm.description().toHtmlEscaped();
if (!descriptionAsTitle.isEmpty())
descriptionAsTitle.prepend(QLatin1String("\" title=\""));
echo ("<li class=\"link\"><a href=\"" + bm.url().url() + descriptionAsTitle + "\"><img src=\"/icon/" + bm.icon() + "\"/>" + bm.text().toHtmlEscaped() + "</a></li>");
}
void BookmarksProtocol::echoSeparator()
{
echo ("<hr/>");
}
void BookmarksProtocol::echoFolder( const KBookmarkGroup &folder )
{
if (sizeOfGroup(folder.toGroup(), true) > 1)
{
QString descriptionAsTitle = folder.description();
if (!descriptionAsTitle.isEmpty())
descriptionAsTitle.prepend(QLatin1String("\" title=\""));
if (folder.parentGroup() == tree)
{
if (config.readEntry("ShowBackgrounds", true))
echo("<ul style=\"background-image: url(/background/" + folder.icon() + ")\">");
else
echo("<ul>");
echo ("<li class=\"title" + descriptionAsTitle + "\">" + folder.fullText() + "</li>");
}
else
{
echo("<ul>");
echo ("<li class=\"title" + descriptionAsTitle + "\"><img src=\"/icon/" + folder.icon() + "\"/>" + folder.text() + "</li>");
}
indent++;
for (KBookmark bm = folder.first(); !bm.isNull(); bm = folder.next(bm))
{
if (bm.isGroup())
echoFolder(bm.toGroup());
else if (bm.isSeparator())
echoSeparator();
else
echoBookmark(bm);
}
indent--;
echo("</ul>");
}
}
void BookmarksProtocol::echoIndex()
{
parseTree();
echoHead();
KBookmark bm = tree.first();
if(bm.isNull()) {
echo("<p class=\"message\">" + i18n("There are no bookmarks to display yet.") + "</p>");
}
else {
for (int i = 1; i <= columns; i++)
{
int size = 0;
echo("<div class=\"column\">");
indent++;
while(!bm.isNull() && (size + sizeOfGroup(bm.toGroup())*2/3 < (totalsize / columns) || size == 0))
{
echoFolder(bm.toGroup());
size += sizeOfGroup(bm.toGroup());
bm = tree.next(bm);
}
if (i == columns)
{
while(!bm.isNull())
{
echoFolder(bm.toGroup());
bm = tree.next(bm);
}
}
indent--;
echo("</div>");
}
}
indent--;
echo("</body>");
echo("</html>");
}
void BookmarksProtocol::echoHead(const QString &redirect)
{
SlaveBase::mimeType("text/html");
QString css(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kio_bookmarks/kio_bookmarks.css"));
if (css.isEmpty())
this->warning(i18n("kio_bookmarks CSS file not found. Output will look ugly.\n"
"Check your installation."));
echo("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
echo("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
echo("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
echo("<head>");
indent++;
echo("<title>" + i18n("My Bookmarks") + "</title>");
echo("<link rel=\"stylesheet\" type=\"text/css\" href=\"file://" + QString::fromUtf8(css.toUtf8()) + "\" />");
echoStyle();
if (!redirect.isEmpty())
echo("<meta http-equiv=\"Refresh\" content=\"0;url=" + redirect + "\"/>");
indent--;
echo("</head>");
echo("<body>");
indent++;
/*echo("<div class=\"toolbar\">");
indent++;
echo("<a title=\"" + i18n("Configuration") + "\" href=\"/config\"><img src=\"/icon/preferences-system?size=32\"/></a>");
echo("<a title=\"" + i18n("Edit bookmarks") + "\" href=\"/editbookmarks\"><img src=\"/icon/bookmarks-organize?size=32\"/></a>");
echo("<a title=\"" + i18n("Help") + "\" href=\"help:/kioslave/bookmarks.html\"><img src=\"/icon/help-contents?size=32\"/></a>");
indent--;
echo("</div>");*/
if (!redirect.isEmpty())
echo("</body></html>");
}
void BookmarksProtocol::echoStyle()
{
KColorScheme window = KColorScheme(QPalette::Active, KColorScheme::Window);
KColorScheme view = KColorScheme(QPalette::Active, KColorScheme::View);
KColorScheme selection = KColorScheme(QPalette::Active, KColorScheme::Selection);
QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
echo("<style type=\"text/css\">");
indent++;
echo("li.link:hover, div.toolbar img:hover { background: " +
htmlColor(KColorUtils::tint(view.background().color(), view.decoration(KColorScheme::HoverColor).color(), 0.4)) + "; }");
echo("div.column > ul, div.toolbar, p.message { background-color: " + htmlColor(view.background()) + "; " +
"border: 1px solid " + htmlColor(view.shade(KColorScheme::LightShade)) + "; }");
echo("div.column > ul:hover, p.message:hover { border: 1px solid " + htmlColor(view.decoration(KColorScheme::HoverColor)) + "; }");
echo("div.toolbar {border-top: none; border-right: none;}");
echo("div.column { width : " + QString::number(100/columns) + "%; }");
echo("body { font-size: " + QString::number(font.pointSize()) + "pt; " +
"background: " + htmlColor(window.background()) + "; " +
"color: " + htmlColor(view.foreground()) + "; }");
indent--;
echo("</style>");
}
void BookmarksProtocol::echo( const QString &string )
{
for(int i = 0; i < indent; i++)
{
data(" ");
}
data(string.toUtf8() + '\n');
}
QString BookmarksProtocol::htmlColor(const QColor &col)
{
int r, g, b;
col.getRgb(&r, &g, &b);
QString num;
num.sprintf("#%02X%02X%02X", r, g, b);
return num;
}
QString BookmarksProtocol::htmlColor(const QBrush &brush)
{
return htmlColor(brush.color());
}
|