~ubuntu-branches/ubuntu/oneiric/gtk-qt-engine/oneiric

« back to all changes in this revision

Viewing changes to kcm_gtk/firefoxfix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra, Didier Raboud, Fathi Boudra
  • Date: 2009-06-25 09:35:02 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090625093502-ovidnbr0okqkm6ua
Tags: 1:1.1+svn5-1
* New svn repository (http://code.google.com/p/gtk-qt-engine)
  - Update upstream package to revision 5
    "Updated Norwegian Nynorsk translation by Karl Ove Hufthammer"

[ Didier Raboud ]

* Change source and binary name to gtk-qt-engine.
  - Bump epoch to 1 due to previous gtk-qt-engine being 1:0.8.
    (Closes: 480696)
  - Use the actual repository revision.
* Update debian/control:
  - Add myself to Uploaders field.
  - Add Vcs-{Svn,Browser} fields.
* Refactorize debian/rules:
  - Remove the custom debian/cdbs directory.
  - Add get-orig-source target.
* Add 04_no_kde4_in_configfile.diff patch (Closes: 527340).

[ Fathi Boudra ]

* Bump Standard-Version to 3.8.2 (no changes needed).
* Update debian/control: drop cdbs build dependency.
* Update debian/copyright: update upstream url.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by David Sansome                                   *
 
3
 *   me@davidsansome.com                                                   *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "firefoxfix.h"
 
22
 
 
23
#include <kmessagebox.h>
 
24
#include <klocale.h>
 
25
 
 
26
#include <QDir>
 
27
#include <QSettings>
 
28
#include <QFile>
 
29
#include <QDebug>
 
30
#include <QScrollBar>
 
31
#include <QStyle>
 
32
#include <QApplication>
 
33
#include <QStyleOptionSlider>
 
34
 
 
35
bool FirefoxFix::s_scrollBarHasBack1;
 
36
bool FirefoxFix::s_scrollBarHasForward1;
 
37
bool FirefoxFix::s_scrollBarHasBack2;
 
38
bool FirefoxFix::s_scrollBarHasForward2;
 
39
 
 
40
void FirefoxFix::go()
 
41
{
 
42
        QStringList profiles;
 
43
        profiles << getProfiles(QDir::homePath() + "/.mozilla/firefox/");
 
44
        profiles << getProfiles(QDir::homePath() + "/.thunderbird/");
 
45
        
 
46
        if (profiles.count() == 0)
 
47
        {
 
48
                KMessageBox::error(0, i18n("No Mozilla profiles found"), i18n("Could not load Mozilla profiles"));
 
49
                return;
 
50
        }
 
51
        
 
52
        Q_FOREACH (QString profile, profiles)
 
53
                fixProfile(profile);
 
54
        
 
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"));
 
56
}
 
57
 
 
58
QStringList FirefoxFix::getProfiles(const QString& basePath)
 
59
{
 
60
        QStringList ret;
 
61
        
 
62
        QString fileName = basePath + "/profiles.ini";
 
63
        if (QFile::exists(fileName))
 
64
        {
 
65
                QSettings settings(fileName, QSettings::IniFormat);
 
66
                
 
67
                Q_FOREACH (QString group, settings.childGroups())
 
68
                {
 
69
                        if (!group.toLower().startsWith("profile"))
 
70
                                continue;
 
71
                        
 
72
                        settings.beginGroup(group);
 
73
                        QString path = settings.value("Path").toString();
 
74
                        settings.endGroup();
 
75
                        
 
76
                        if (!path.startsWith("/"))
 
77
                                path = basePath + path;
 
78
                        
 
79
                        ret << path;
 
80
                }
 
81
        }
 
82
        
 
83
        return ret;
 
84
}
 
85
 
 
86
void FirefoxFix::fixProfile(const QString& path)
 
87
{
 
88
        if (!QFile::exists(path + "/chrome"))
 
89
        {
 
90
                QDir dir(path);
 
91
                dir.mkdir("chrome");
 
92
        }
 
93
        
 
94
        QString data = scrollBarCSS();
 
95
        writeFirefoxCSS(path + "/chrome/userChrome.css", data);
 
96
        writeFirefoxCSS(path + "/chrome/userContent.css", data);
 
97
}
 
98
 
 
99
// Nicked from rcproperties.cpp
 
100
void FirefoxFix::findScrollBarButtons()
 
101
{
 
102
        static bool beenHereDoneThat = false;
 
103
        if (beenHereDoneThat)
 
104
                return;
 
105
        beenHereDoneThat = true;
 
106
        
 
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.
 
109
        
 
110
        QScrollBar* scrollBar = new QScrollBar(0);
 
111
        QStyle* qtStyle = QApplication::style();
 
112
        
 
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;
 
119
        
 
120
        QRect rect = qtStyle->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarGroove, scrollBar);
 
121
        
 
122
        s_scrollBarHasBack1 = false;
 
123
        s_scrollBarHasForward1 = false;
 
124
        s_scrollBarHasBack2 = false;
 
125
        s_scrollBarHasForward2 = false;
 
126
        
 
127
        for (QPoint pos(0,7) ; pos.x()<rect.x() ; pos.setX(pos.x()+1))
 
128
        {
 
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;
 
132
        }
 
133
        
 
134
        for (QPoint pos(rect.x()+rect.width(),7) ; pos.x()<200 ; pos.setX(pos.x()+1))
 
135
        {
 
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;
 
139
        }
 
140
        
 
141
        delete scrollBar;
 
142
}
 
143
 
 
144
QString FirefoxFix::scrollBarCSS()
 
145
{
 
146
        findScrollBarButtons();
 
147
        
 
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");
 
152
        
 
153
        QString data;
 
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";
 
159
        
 
160
        return data;
 
161
}
 
162
 
 
163
void FirefoxFix::writeFirefoxCSS(const QString& path, const QString& data)
 
164
{
 
165
        QString fileData;
 
166
        QFile file(path);
 
167
        if (file.open(QIODevice::ReadOnly))
 
168
        {
 
169
                QTextStream stream(&file);
 
170
                for (;;)
 
171
                {
 
172
                        QString line = stream.readLine();
 
173
                        if (line.isNull())
 
174
                                break;
 
175
                        
 
176
                        if ((line == "# The following four lines were added by KDE") ||
 
177
                            (line == "/* The following four lines were added by KDE */"))
 
178
                        {
 
179
                                for (int i=0 ; i<4 ; i++)
 
180
                                        stream.readLine();
 
181
                                continue;
 
182
                        }
 
183
                        
 
184
                        fileData += line + "\n";
 
185
                }
 
186
                file.close();
 
187
        }
 
188
        
 
189
        if (!file.open(QIODevice::WriteOnly))
 
190
        {
 
191
                KMessageBox::error(0, i18n("Could not write to %1").arg(path), i18n("Mozilla profile"));
 
192
                return;
 
193
        }
 
194
        QTextStream stream(&file);
 
195
        stream << fileData << data;
 
196
        file.close();
 
197
        
 
198
        return;
 
199
}