You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
345 lines
12 KiB
345 lines
12 KiB
15 years ago
|
/***************************************************************************
|
||
|
* Copyright (C) 2005-2007 by Stephen Leaf <smileaf@gmail.com> *
|
||
|
* Copyright (C) 2006 by Oswald Buddenhagen <ossi@kde.org> *
|
||
|
* *
|
||
|
* 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. *
|
||
|
***************************************************************************/
|
||
|
|
||
13 years ago
|
#include "tdmtheme.h"
|
||
15 years ago
|
|
||
|
#include <kdialog.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kio/job.h>
|
||
|
#include <kio/netaccess.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kmessagebox.h>
|
||
|
#include <kprogress.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <ktar.h>
|
||
|
#include <kurlrequester.h>
|
||
|
#include <kurlrequesterdlg.h>
|
||
|
#include <kparts/genericfactory.h>
|
||
|
|
||
13 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqdir.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
13 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqlistview.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqwidget.h>
|
||
15 years ago
|
|
||
|
#include <unistd.h>
|
||
|
|
||
13 years ago
|
class ThemeData : public TQListViewItem {
|
||
15 years ago
|
public:
|
||
13 years ago
|
ThemeData( TQListView *parent = 0 ) : TQListViewItem( parent ) {}
|
||
15 years ago
|
|
||
13 years ago
|
TQString name;
|
||
|
TQString path;
|
||
|
TQString screenShot;
|
||
|
TQString copyright;
|
||
|
TQString description;
|
||
15 years ago
|
};
|
||
|
|
||
13 years ago
|
typedef KGenericFactory<TDMThemeWidget, TQWidget> tdmthemeFactory;
|
||
|
K_EXPORT_COMPONENT_FACTORY( kcm_tdmtheme, tdmthemeFactory("kcmtdmtheme"))
|
||
15 years ago
|
|
||
13 years ago
|
TDMThemeWidget::TDMThemeWidget( TQWidget *parent, const char *name, const TQStringList& )
|
||
13 years ago
|
: KCModule(parent, name), config( 0L )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQGridLayout *ml = new TQGridLayout( this );
|
||
15 years ago
|
ml->setSpacing( KDialog::spacingHint() );
|
||
|
ml->setMargin( KDialog::marginHint() );
|
||
|
|
||
13 years ago
|
cUseTheme = new TQCheckBox( this );
|
||
13 years ago
|
cUseTheme->setText( i18n( "En&able TDM Themes" ) );
|
||
15 years ago
|
ml->addMultiCellWidget( cUseTheme, 0, 0, 0, 2 );
|
||
|
|
||
13 years ago
|
themeWidget = new TQListView( this );
|
||
15 years ago
|
themeWidget->addColumn( i18n( "Theme" ) );
|
||
|
themeWidget->addColumn( i18n( "Author" ) );
|
||
|
themeWidget->setAllColumnsShowFocus( true );
|
||
|
themeWidget->setShowSortIndicator( true );
|
||
|
themeWidget->setRootIsDecorated( false );
|
||
13 years ago
|
TQWhatsThis::add( themeWidget, i18n("This is a list of installed themes.\n"
|
||
15 years ago
|
"Click the one to be used.") );
|
||
|
|
||
|
ml->addMultiCellWidget( themeWidget, 1, 3, 0, 1 );
|
||
|
|
||
13 years ago
|
preview = new TQLabel( this );
|
||
|
preview->setFixedSize( TQSize( 200, 150 ) );
|
||
15 years ago
|
preview->setScaledContents( true );
|
||
13 years ago
|
TQWhatsThis::add(preview, i18n("This is a screen shot of what TDM will look like.") );
|
||
15 years ago
|
|
||
|
ml->addWidget( preview, 1, 2 );
|
||
|
|
||
13 years ago
|
info = new TQLabel( this );
|
||
15 years ago
|
info->setMaximumWidth( 200 );
|
||
13 years ago
|
info->setAlignment( int( TQLabel::AlignTop | TQLabel::WordBreak) );
|
||
13 years ago
|
TQWhatsThis::add(info, i18n("This contains information about the selected theme.") );
|
||
15 years ago
|
|
||
|
ml->addMultiCellWidget( info, 3, 4, 2, 2 );
|
||
|
|
||
13 years ago
|
bInstallTheme = new TQPushButton( i18n("Install &new theme"), this );
|
||
|
TQWhatsThis::add(bInstallTheme, i18n("This will install a theme into the theme directory.") );
|
||
15 years ago
|
|
||
|
ml->addWidget( bInstallTheme, 4, 0 );
|
||
|
|
||
13 years ago
|
bRemoveTheme = new TQPushButton( i18n("&Remove theme"), this );
|
||
|
TQWhatsThis::add(bRemoveTheme, i18n("This will remove the selected theme.") );
|
||
15 years ago
|
|
||
|
ml->addWidget( bRemoveTheme, 4, 1 );
|
||
|
|
||
13 years ago
|
connect( themeWidget, TQT_SIGNAL(selectionChanged()), TQT_SLOT(themeSelected()) );
|
||
|
connect( bInstallTheme, TQT_SIGNAL(clicked()), TQT_SLOT(installNewTheme()) );
|
||
|
connect( bRemoveTheme, TQT_SIGNAL(clicked()), TQT_SLOT(removeSelectedThemes()) );
|
||
|
connect( cUseTheme, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( toggleUseTheme( bool ) ) );
|
||
15 years ago
|
|
||
13 years ago
|
TQStringList themeDirs = KGlobal::dirs()->findDirs("data","tdm/");
|
||
|
themeDir = KGlobal::dirs()->findDirs("data","tdm/").last();
|
||
13 years ago
|
TQDir d;
|
||
|
for ( TQStringList::Iterator dirs = themeDirs.begin(); dirs != themeDirs.end(); ++dirs ) {
|
||
15 years ago
|
kdDebug() << "Loading themes... ( " + *dirs + "themes/" + " )" << endl;
|
||
|
d.setPath( *dirs + "themes/" );
|
||
13 years ago
|
d.setFilter( TQDir::Dirs );
|
||
|
TQStringList list = d.entryList();
|
||
|
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
|
||
15 years ago
|
if (*it == "." || *it == "..") continue;
|
||
|
insertTheme( *dirs + "themes/" + *it );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
load();
|
||
|
|
||
|
if (getuid() != 0) {
|
||
|
cUseTheme->setEnabled( false );
|
||
|
setReadOnly(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::selectTheme( const TQString &path )
|
||
15 years ago
|
{
|
||
13 years ago
|
for ( TQListViewItemIterator tdi( themeWidget ); tdi.current(); tdi++ ) {
|
||
15 years ago
|
ThemeData * td = ((ThemeData *)*tdi);
|
||
|
if (td->path == path) {
|
||
|
themeWidget->clearSelection();
|
||
|
themeWidget->setSelected(td, true );
|
||
|
updateInfoView( td );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::load()
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString tdmrc = KGlobal::dirs()->findResource("config", "tdm/tdmrc");
|
||
|
if ( tdmrc.isEmpty() ) {
|
||
|
kdError() << "Failed to find tdm resource file tdmrc!" << endl;
|
||
15 years ago
|
|
||
|
KMessageBox msgBox;
|
||
13 years ago
|
msgBox.sorry(0, i18n("I can't find the configuration file for the Login Manager, tdm. Check you have set up the Login Manager from the Control Center, and that you have permision to read and write the Login Manager's configuration file.\n\n You must set-up the Login Manager before you can use its themes."), i18n("Can't find Configuration File"));
|
||
15 years ago
|
|
||
|
delete config;
|
||
|
config = NULL;
|
||
|
} else {
|
||
13 years ago
|
kdDebug() << "Loading... ( " + tdmrc + " )" << endl;
|
||
15 years ago
|
|
||
|
delete config;
|
||
13 years ago
|
config = new KConfig( tdmrc );
|
||
15 years ago
|
config->setGroup( "X-*-Greeter" );
|
||
|
cUseTheme->setChecked( config->readBoolEntry( "UseTheme", false ) );
|
||
|
|
||
|
selectTheme( config->readEntry( "Theme", themeDir + "circles" ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::save()
|
||
15 years ago
|
{
|
||
|
kdDebug() << "Saving: Theme " << defaultTheme->path << " - UseTheme " << cUseTheme->isChecked() << endl;
|
||
|
config->writeEntry( "Theme", defaultTheme->path );
|
||
|
config->writeEntry( "UseTheme", cUseTheme->isChecked() );
|
||
|
config->sync();
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::defaults()
|
||
15 years ago
|
{
|
||
|
selectTheme( themeDir + "circles" );
|
||
|
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::toggleUseTheme(bool useTheme) {
|
||
15 years ago
|
setReadOnly( useTheme );
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::setReadOnly(bool ro)
|
||
15 years ago
|
{
|
||
|
themeWidget->setEnabled( ro );
|
||
|
bInstallTheme->setEnabled( ro );
|
||
|
bRemoveTheme->setEnabled( ro );
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::insertTheme( const TQString &_theme )
|
||
15 years ago
|
{
|
||
|
KConfig * themeConfig;
|
||
13 years ago
|
TQString name;
|
||
15 years ago
|
|
||
|
kdDebug() << "Looking for " << _theme << "/KdmGreeterTheme.desktop" << endl;
|
||
|
themeConfig = new KConfig( _theme + "/KdmGreeterTheme.desktop");
|
||
|
themeConfig->setGroup( "GdmGreeterTheme" );
|
||
|
name = themeConfig->readEntry( "Name" );
|
||
|
if (name.isEmpty()) {
|
||
|
kdDebug() << "Looking for " << _theme << "/GdmGreeterTheme.desktop" << endl;
|
||
|
themeConfig = new KConfig( _theme + "/GdmGreeterTheme.desktop");
|
||
|
themeConfig->setGroup( "GdmGreeterTheme" );
|
||
|
|
||
|
name = themeConfig->readEntry( "Name" );
|
||
|
if (name.isEmpty())
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
for ( TQListViewItemIterator tdi( themeWidget ); tdi.current(); tdi++ ) {
|
||
15 years ago
|
ThemeData * td = ((ThemeData *)*tdi);
|
||
|
if (td->name == name)
|
||
|
return;
|
||
|
}
|
||
|
kdDebug() << "Adding theme " << name << endl;
|
||
|
|
||
|
ThemeData *child = new ThemeData( themeWidget );
|
||
|
child->setText( 0, name );
|
||
|
child->setText( 1, themeConfig->readEntry( "Author" ) );
|
||
|
child->name = name;
|
||
|
child->path = _theme;
|
||
|
child->screenShot = themeConfig->readEntry( "Screenshot" );
|
||
|
child->copyright = themeConfig->readEntry( "Copyright" );
|
||
|
child->description = themeConfig->readEntry( "Description" );
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::updateInfoView( ThemeData *theme )
|
||
15 years ago
|
{
|
||
|
info->setText(
|
||
|
((theme->copyright.length() > 0) ?
|
||
|
i18n("<qt><strong>Copyright:</strong> %1<br/></qt>",
|
||
|
theme->copyright) : "") +
|
||
|
((theme->description.length() > 0) ?
|
||
|
i18n("<qt><strong>Description:</strong> %1</qt>",
|
||
|
theme->description) : "") );
|
||
|
preview->setPixmap( theme->path + '/' + theme->screenShot );
|
||
|
preview->setText( theme->screenShot.isEmpty() ?
|
||
13 years ago
|
"Screenshot not available" : TQString() );
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::installNewTheme()
|
||
15 years ago
|
{
|
||
13 years ago
|
KURLRequesterDlg fileRequester( TQString(), this, i18n("Drag or Type Theme URL") );
|
||
15 years ago
|
fileRequester.urlRequester()->setMode( KFile::File | KFile::Directory | KFile::ExistingOnly );
|
||
|
KURL themeURL = fileRequester.getURL();
|
||
|
if (themeURL.isEmpty())
|
||
|
return;
|
||
|
|
||
13 years ago
|
TQString themeTmpFile;
|
||
15 years ago
|
|
||
|
if (!KIO::NetAccess::download( themeURL, themeTmpFile, this )) {
|
||
13 years ago
|
TQString sorryText;
|
||
15 years ago
|
if (themeURL.isLocalFile())
|
||
13 years ago
|
sorryText = i18n("Unable to find the TDM theme archive %1.",themeURL.prettyURL());
|
||
15 years ago
|
else
|
||
13 years ago
|
sorryText = i18n("Unable to download the TDM theme archive;\n"
|
||
15 years ago
|
"please check that address %1 is correct.",themeURL.prettyURL());
|
||
|
KMessageBox::sorry( this, sorryText );
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQList<KArchiveDirectory> foundThemes;
|
||
15 years ago
|
|
||
|
KTar archive( themeTmpFile );
|
||
|
archive.open( IO_ReadOnly );
|
||
|
|
||
|
const KArchiveDirectory *archDir = archive.directory();
|
||
13 years ago
|
TQStringList entries = archDir->entries();
|
||
|
for (TQStringList::Iterator ent = entries.begin(); ent != entries.end(); ++ent) {
|
||
15 years ago
|
const KArchiveEntry *possibleDir = archDir->entry( *ent );
|
||
|
if (possibleDir->isDirectory()) {
|
||
|
const KArchiveDirectory *subDir =
|
||
|
static_cast<const KArchiveDirectory *>( possibleDir );
|
||
|
if (subDir->entry( "KdmGreeterTheme.desktop" ))
|
||
|
foundThemes.append( subDir );
|
||
|
else if (subDir->entry( "GdmGreeterTheme.desktop" ))
|
||
|
foundThemes.append( subDir );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (foundThemes.isEmpty())
|
||
13 years ago
|
KMessageBox::error( this, i18n("The file is not a valid TDM theme archive.") );
|
||
15 years ago
|
else {
|
||
|
KProgressDialog progressDiag( this,
|
||
13 years ago
|
i18n("Installing TDM themes"), TQString() );
|
||
15 years ago
|
progressDiag.setModal( true );
|
||
|
progressDiag.setAutoClose( true );
|
||
|
progressDiag.progressBar()->setTotalSteps( foundThemes.count() );
|
||
|
progressDiag.show();
|
||
|
|
||
|
for ( KArchiveDirectory * ard = foundThemes.first(); foundThemes.current(); foundThemes.next() ) {
|
||
|
progressDiag.setLabel(
|
||
|
i18n("<qt>Installing <strong>%1</strong> theme</qt>", ard->name() ) );
|
||
|
|
||
13 years ago
|
TQString path = themeDir + "themes/" + ard->name();
|
||
15 years ago
|
kdDebug() << "Unpacking new theme to " << path << endl;
|
||
|
ard->copyTo( path, true );
|
||
13 years ago
|
if (TQDir( path ).exists())
|
||
15 years ago
|
insertTheme( path );
|
||
|
|
||
|
progressDiag.progressBar()->setValue( progressDiag.progressBar()->value() + 1 );
|
||
|
if (progressDiag.wasCancelled())
|
||
|
break;
|
||
|
}
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
|
archive.close();
|
||
|
|
||
|
KIO::NetAccess::removeTempFile( themeTmpFile );
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::themeSelected()
|
||
15 years ago
|
{
|
||
|
if (themeWidget->selectedItem()) {
|
||
|
defaultTheme = (ThemeData *)(themeWidget->selectedItem());
|
||
|
updateInfoView( defaultTheme );
|
||
|
} else
|
||
|
updateInfoView( 0 );
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
13 years ago
|
void TDMThemeWidget::removeSelectedThemes()
|
||
15 years ago
|
{
|
||
13 years ago
|
TQListViewItem * themes = themeWidget->selectedItem();
|
||
15 years ago
|
if (!themes)
|
||
|
return;
|
||
|
if (KMessageBox::questionYesNoList( this,
|
||
13 years ago
|
i18n("Are you sure you want to remove this TDM theme?"),
|
||
15 years ago
|
themes->text(0), i18n("Remove theme?") ) != KMessageBox::Yes)
|
||
|
return;
|
||
|
KIO::del( ((ThemeData *)themes)->path ); // XXX error check
|
||
|
|
||
|
themeWidget->takeItem( themes );
|
||
|
}
|
||
|
|
||
13 years ago
|
#include "tdmtheme.moc"
|