2
* Copyright (C) 2003 Fredrik Höglund <fredrik@kde.org>
4
* Based on the large cursor code written by Rik Hemsley,
5
* Copyright (c) 2000 Rik Hemsley <rik@kde.org>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public
9
* License version 2 as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
23
#include <kstandarddirs.h>
27
#include <kio/netaccess.h>
28
#include <kmessagebox.h>
38
#include "themepage.h"
39
#include <QTreeWidget>
40
#include "themepage.moc"
46
ThemePage::ThemePage( QWidget* parent, const char* name )
50
QBoxLayout *layout = new QVBoxLayout( this );
51
layout->setMargin( KDialog::marginHint() );
52
layout->setSpacing( KDialog::spacingHint() );
54
layout->addWidget(new QLabel( i18n("Select the cursor theme you want to use:"), this ));
56
// Create the theme list view
57
listview = new QTreeWidget( this );
58
QStringList lstHeader;
59
lstHeader<<i18n("Name")<<i18n("Description");
60
listview->setHeaderLabels( lstHeader );
61
listview->setSelectionMode( QAbstractItemView::SingleSelection );
62
listview->setRootIsDecorated( false );
63
connect( listview, SIGNAL(currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) )
64
, this, SLOT( selectionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );
65
layout->addWidget( listview );
70
ThemePage::~ThemePage()
75
void ThemePage::selectionChanged( QTreeWidgetItem*current,QTreeWidgetItem*previous )
78
selectedTheme = current->data( 0, Qt::UserRole + 1 ).toString();
79
emit changed( selectedTheme != currentTheme );
83
void ThemePage::save()
85
if ( currentTheme == selectedTheme )
88
bool whiteCursor = selectedTheme.right( 5 ) == "White";
89
bool largeCursor = selectedTheme.left( 5 ) == "Large";
91
KConfig config( "kcminputrc" );
92
KConfigGroup c( &config, "Mouse" );
93
c.writeEntry( "LargeCursor", largeCursor );
94
c.writeEntry( "WhiteCursor", whiteCursor );
96
currentTheme = selectedTheme;
100
KMessageBox::information( this, i18n("You have to restart KDE for these "
101
"changes to take effect."), i18n("Cursor Settings Changed"),
102
"CursorSettingsChanged" );
106
void ThemePage::load()
108
bool largeCursor, whiteCursor;
110
KConfig config( "kcminputrc" );
111
KConfigGroup c( &config, "Mouse" );
112
largeCursor = c.readEntry( "LargeCursor", false);
113
whiteCursor = c.readEntry( "WhiteCursor", false);
116
currentTheme = whiteCursor ? "LargeWhite" : "LargeBlack";
118
currentTheme = whiteCursor ? "SmallWhite" : "SmallBlack";
120
selectedTheme = currentTheme;
121
for ( int i = 0;i <listview->topLevelItemCount();++i )
123
QTreeWidgetItem *item = listview->topLevelItem( i );
124
if ( item && item->data(0, Qt::UserRole + 1 ) == currentTheme )
126
listview->setCurrentItem( item );
132
void ThemePage::defaults()
134
currentTheme = selectedTheme = "SmallBlack";
135
for ( int i = 0;i <listview->topLevelItemCount();++i )
137
QTreeWidgetItem *item = listview->topLevelItem( i );
138
if ( item && item->data(0, Qt::UserRole + 1 ) == currentTheme )
140
listview->setCurrentItem( item );
146
void ThemePage::insertThemes()
148
QList<QTreeWidgetItem *> lstChildren;
149
QTreeWidgetItem *item = new QTreeWidgetItem(listview );
151
item->setData( 0, Qt::DisplayRole,i18n("Small black") );
152
item->setData( 1, Qt::DisplayRole, i18n("Small black cursors") );
153
item->setData( 0, Qt::DecorationRole, QPixmap( arrow_small_black_xpm ) );
154
item->setData( 0, Qt::UserRole + 1,"SmallBlack" );
157
item = new QTreeWidgetItem(listview );
158
item->setData( 0, Qt::DisplayRole, i18n("Large black") );
159
item->setData( 1, Qt::DisplayRole, i18n("Large black cursors") );
160
item->setData( 0, Qt::DecorationRole, QPixmap( arrow_large_black_xpm ) );
161
item->setData( 0, Qt::UserRole + 1,"LargeBlack" );
164
item = new QTreeWidgetItem(listview );
165
item->setData( 0, Qt::DisplayRole, i18n("Small white") );
166
item->setData( 1, Qt::DisplayRole, i18n("Small white cursors") );
167
item->setData( 0, Qt::DecorationRole, QPixmap(arrow_small_white_xpm ) );
168
item->setData( 0, Qt::UserRole + 1,"SmallWhite" );
171
item = new QTreeWidgetItem(listview );
172
item->setData( 0, Qt::DisplayRole, i18n("Large white") );
173
item->setData( 1, Qt::DisplayRole, i18n("Large white cursors") );
174
item->setData( 0, Qt::DecorationRole, QPixmap( arrow_large_white_xpm ) );
175
item->setData( 0, Qt::UserRole + 1, "LargeWhite" );
178
listview->addTopLevelItems( lstChildren );
182
void ThemePage::fixCursorFile()
184
// Make sure we have the 'font' resource dir registered and can find the
187
// Next, if the user wants large cursors, copy the font
188
// cursor_large.pcf.gz to (localkdedir)/share/fonts/override/cursor.pcf.gz.
189
// Else remove the font cursor.pcf.gz from (localkdedir)/share/fonts/override.
191
// Run mkfontdir to update fonts.dir in that dir.
193
KGlobal::dirs()->addResourceType( "font", 0, "share/fonts/" );
194
KIO::mkdir( QDir::homePath() + "/.fonts/kde-override" );
195
QString overrideDir = QDir::homePath() + "/.fonts/kde-override/";
198
installedFont.setPath( overrideDir + "cursor.pcf.gz" );
200
if ( currentTheme == "SmallBlack" )
201
KIO::NetAccess::del( installedFont, this );
205
if ( currentTheme == "LargeBlack" )
206
source.setPath( KStandardDirs::locate("data", "kcminput/cursor_large_black.pcf.gz") );
207
else if ( currentTheme == "LargeWhite" )
208
source.setPath( KStandardDirs::locate("data", "kcminput/cursor_large_white.pcf.gz") );
209
else if ( currentTheme == "SmallWhite" )
210
source.setPath( KStandardDirs::locate("data", "kcminput/cursor_small_white.pcf.gz") );
212
KIO::Job* job = KIO::file_copy( source, installedFont, -1, KIO::Overwrite );
216
QString cmd = KGlobal::dirs()->findExe( "mkfontdir" );
217
if ( !cmd.isEmpty() )
220
p << cmd << overrideDir;
225
// vim: set noet ts=4 sw=4: