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>
31 #include <k3listview.h>
39 #include "themepage.h"
40 #include "themepage.moc"
47 enum Columns
{ NameColumn
= 0, DescColumn
, /* hidden */ DirColumn
};
51 ThemePage::ThemePage( QWidget
* parent
, const char* name
)
55 QBoxLayout
*layout
= new QVBoxLayout( this );
56 layout
->setMargin( KDialog::marginHint() );
57 layout
->setSpacing( KDialog::spacingHint() );
59 layout
->addWidget(new QLabel( i18n("Select the cursor theme you want to use:"), this ));
61 // Create the theme list view
62 listview
= new K3ListView( this );
63 listview
->setFullWidth( true );
64 listview
->setAllColumnsShowFocus( true );
65 listview
->addColumn( i18n("Name") );
66 listview
->addColumn( i18n("Description") );
67 layout
->addWidget(listview
);
69 connect( listview
, SIGNAL(selectionChanged(Q3ListViewItem
*)),
70 SLOT(selectionChanged(Q3ListViewItem
*)) );
76 ThemePage::~ThemePage()
81 void ThemePage::selectionChanged( Q3ListViewItem
*item
)
83 selectedTheme
= item
->text( DirColumn
);
84 emit
changed( selectedTheme
!= currentTheme
);
88 void ThemePage::save()
90 if ( currentTheme
== selectedTheme
)
93 bool whiteCursor
= selectedTheme
.right( 5 ) == "White";
94 bool largeCursor
= selectedTheme
.left( 5 ) == "Large";
96 KConfig
config( "kcminputrc" );
97 KConfigGroup
c( &config
, "Mouse" );
98 c
.writeEntry( "LargeCursor", largeCursor
);
99 c
.writeEntry( "WhiteCursor", whiteCursor
);
101 currentTheme
= selectedTheme
;
105 KMessageBox::information( this, i18n("You have to restart KDE for these "
106 "changes to take effect."), i18n("Cursor Settings Changed"),
107 "CursorSettingsChanged" );
111 void ThemePage::load()
113 bool largeCursor
, whiteCursor
;
115 KConfig
config( "kcminputrc" );
116 KConfigGroup
c( &config
, "Mouse" );
117 largeCursor
= c
.readEntry( "LargeCursor", false);
118 whiteCursor
= c
.readEntry( "WhiteCursor", false);
121 currentTheme
= whiteCursor
? "LargeWhite" : "LargeBlack";
123 currentTheme
= whiteCursor
? "SmallWhite" : "SmallBlack";
125 selectedTheme
= currentTheme
;
126 Q3ListViewItem
*item
= listview
->findItem( currentTheme
, DirColumn
);
127 item
->setSelected( true );
131 void ThemePage::defaults()
133 currentTheme
= selectedTheme
= "SmallBlack";
134 Q3ListViewItem
*item
= listview
->findItem( currentTheme
, DirColumn
);
135 item
->setSelected( true );
139 void ThemePage::insertThemes()
141 K3ListViewItem
*item
;
143 item
= new K3ListViewItem( listview
, i18n("Small black"),
144 i18n("Small black cursors"), "SmallBlack" );
145 item
->setPixmap( 0, QPixmap( arrow_small_black_xpm
) );
146 listview
->insertItem( item
);
148 item
= new K3ListViewItem( listview
, i18n("Large black"),
149 i18n("Large black cursors"), "LargeBlack" );
150 item
->setPixmap( 0, QPixmap( arrow_large_black_xpm
) );
151 listview
->insertItem( item
);
153 item
= new K3ListViewItem( listview
, i18n("Small white"),
154 i18n("Small white cursors"), "SmallWhite" );
155 item
->setPixmap( 0, QPixmap( arrow_small_white_xpm
) );
156 listview
->insertItem( item
);
158 item
= new K3ListViewItem( listview
, i18n("Large white"),
159 i18n("Large white cursors"), "LargeWhite" );
160 item
->setPixmap( 0, QPixmap( arrow_large_white_xpm
) );
161 listview
->insertItem( item
);
165 void ThemePage::fixCursorFile()
167 // Make sure we have the 'font' resource dir registered and can find the
170 // Next, if the user wants large cursors, copy the font
171 // cursor_large.pcf.gz to (localkdedir)/share/fonts/override/cursor.pcf.gz.
172 // Else remove the font cursor.pcf.gz from (localkdedir)/share/fonts/override.
174 // Run mkfontdir to update fonts.dir in that dir.
176 KGlobal::dirs()->addResourceType( "font", 0, "share/fonts/" );
177 KIO::mkdir( QDir::homePath() + "/.fonts/kde-override" );
178 QString overrideDir
= QDir::homePath() + "/.fonts/kde-override/";
181 installedFont
.setPath( overrideDir
+ "cursor.pcf.gz" );
183 if ( currentTheme
== "SmallBlack" )
184 KIO::NetAccess::del( installedFont
, this );
188 if ( currentTheme
== "LargeBlack" )
189 source
.setPath( KStandardDirs::locate("data", "kcminput/cursor_large_black.pcf.gz") );
190 else if ( currentTheme
== "LargeWhite" )
191 source
.setPath( KStandardDirs::locate("data", "kcminput/cursor_large_white.pcf.gz") );
192 else if ( currentTheme
== "SmallWhite" )
193 source
.setPath( KStandardDirs::locate("data", "kcminput/cursor_small_white.pcf.gz") );
195 KIO::Job
* job
= KIO::file_copy( source
, installedFont
, -1, KIO::Overwrite
);
199 QString cmd
= KGlobal::dirs()->findExe( "mkfontdir" );
200 if ( !cmd
.isEmpty() )
203 p
<< cmd
<< overrideDir
;
208 // vim: set noet ts=4 sw=4: