1
/***************************************************************************
2
* Copyright (C) 2008 by David Sansome *
3
* me@davidsansome.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#include "firefoxfix.h"
23
#include <kmessagebox.h>
32
#include <QApplication>
33
#include <QStyleOptionSlider>
35
bool FirefoxFix::s_scrollBarHasBack1;
36
bool FirefoxFix::s_scrollBarHasForward1;
37
bool FirefoxFix::s_scrollBarHasBack2;
38
bool FirefoxFix::s_scrollBarHasForward2;
43
profiles << getProfiles(QDir::homePath() + "/.mozilla/firefox/");
44
profiles << getProfiles(QDir::homePath() + "/.thunderbird/");
46
if (profiles.count() == 0)
48
KMessageBox::error(0, i18n("No Mozilla profiles found"), i18n("Could not load Mozilla profiles"));
52
Q_FOREACH (QString profile, profiles)
55
KMessageBox::information(0, i18n("Your Mozilla profile was updated sucessfully. You must close and restart all Firefox and Thunderbird windows for the changes to take effect"), i18n("Mozilla profile"));
58
QStringList FirefoxFix::getProfiles(const QString& basePath)
62
QString fileName = basePath + "/profiles.ini";
63
if (QFile::exists(fileName))
65
QSettings settings(fileName, QSettings::IniFormat);
67
Q_FOREACH (QString group, settings.childGroups())
69
if (!group.toLower().startsWith("profile"))
72
settings.beginGroup(group);
73
QString path = settings.value("Path").toString();
76
if (!path.startsWith("/"))
77
path = basePath + path;
86
void FirefoxFix::fixProfile(const QString& path)
88
if (!QFile::exists(path + "/chrome"))
94
QString data = scrollBarCSS();
95
writeFirefoxCSS(path + "/chrome/userChrome.css", data);
96
writeFirefoxCSS(path + "/chrome/userContent.css", data);
99
// Nicked from rcproperties.cpp
100
void FirefoxFix::findScrollBarButtons()
102
static bool beenHereDoneThat = false;
103
if (beenHereDoneThat)
105
beenHereDoneThat = true;
107
// I'm really quite ashamed of this function.
108
// It loops over the ends of a scrollbar looking to see if each pixel is part of a button.
110
QScrollBar* scrollBar = new QScrollBar(0);
111
QStyle* qtStyle = QApplication::style();
113
QStyleOptionSlider option;
114
option.sliderValue = 1;
115
option.sliderPosition = 1;
116
option.rect = QRect(0, 0, 200, 25);
117
option.state = QStyle::State_Horizontal;
118
option.orientation = Qt::Horizontal;
120
QRect rect = qtStyle->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarGroove, scrollBar);
122
s_scrollBarHasBack1 = false;
123
s_scrollBarHasForward1 = false;
124
s_scrollBarHasBack2 = false;
125
s_scrollBarHasForward2 = false;
127
for (QPoint pos(0,7) ; pos.x()<rect.x() ; pos.setX(pos.x()+1))
129
QStyle::SubControl sc = qtStyle->hitTestComplexControl(QStyle::CC_ScrollBar, &option, pos, scrollBar);
130
if (sc == QStyle::SC_ScrollBarAddLine) s_scrollBarHasForward1 = true;
131
if (sc == QStyle::SC_ScrollBarSubLine) s_scrollBarHasBack1 = true;
134
for (QPoint pos(rect.x()+rect.width(),7) ; pos.x()<200 ; pos.setX(pos.x()+1))
136
QStyle::SubControl sc = qtStyle->hitTestComplexControl(QStyle::CC_ScrollBar, &option, pos, scrollBar);
137
if (sc == QStyle::SC_ScrollBarAddLine) s_scrollBarHasForward2 = true;
138
if (sc == QStyle::SC_ScrollBarSubLine) s_scrollBarHasBack2 = true;
144
QString FirefoxFix::scrollBarCSS()
146
findScrollBarButtons();
148
QString upTop = (s_scrollBarHasBack1 ? "-moz-box" : "none");
149
QString downTop = (s_scrollBarHasForward1 ? "-moz-box" : "none");
150
QString upBottom = (s_scrollBarHasBack2 ? "-moz-box" : "none");
151
QString downBottom = (s_scrollBarHasForward2 ? "-moz-box" : "none");
154
data += "/* The following four lines were added by KDE */\n";
155
data += "scrollbarbutton[sbattr=\"scrollbar-up-top\"] { display: " + upTop + " !important; }\n";
156
data += "scrollbarbutton[sbattr=\"scrollbar-down-top\"] { display: " + downTop + " !important; }\n";
157
data += "scrollbarbutton[sbattr=\"scrollbar-up-bottom\"] { display: " + upBottom + " !important; }\n";
158
data += "scrollbarbutton[sbattr=\"scrollbar-down-bottom\"] { display: " + downBottom + " !important; }\n";
163
void FirefoxFix::writeFirefoxCSS(const QString& path, const QString& data)
167
if (file.open(QIODevice::ReadOnly))
169
QTextStream stream(&file);
172
QString line = stream.readLine();
176
if ((line == "# The following four lines were added by KDE") ||
177
(line == "/* The following four lines were added by KDE */"))
179
for (int i=0 ; i<4 ; i++)
184
fileData += line + "\n";
189
if (!file.open(QIODevice::WriteOnly))
191
KMessageBox::error(0, i18n("Could not write to %1").arg(path), i18n("Mozilla profile"));
194
QTextStream stream(&file);
195
stream << fileData << data;