mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 17:01:22 +00:00
Reworked the background-image dialog. It doesn't touch any .directory
files anymore, it is a simple wallpaper selection dialog. The views take care of saving the settings. Removed bgColor from konqsettings - handled as a property now. BTW, if you want to contact me today, write to david.faure@cramersystems.com The KDE and Mandrake addresses don't work (problem on mandrakesoft's side). I feel blind without lists... :( svn path=/trunk/kdebase/libkonq/; revision=48835
This commit is contained in:
parent
630a531566
commit
9c9238d803
|
@ -36,27 +36,18 @@
|
|||
#include "konq_bgnddlg.h"
|
||||
|
||||
|
||||
KonqBgndDialog::KonqBgndDialog( const KURL & dirURL, KInstance *instance )
|
||||
KonqBgndDialog::KonqBgndDialog( const QString & pixmapFile, KInstance *instance )
|
||||
: KDialogBase( 0L, // no parent,
|
||||
"KonqBgndDialog",
|
||||
true, //modal
|
||||
i18n("Background image for %1").arg(dirURL.decodedURL()),
|
||||
Ok|Apply|Cancel,
|
||||
i18n("Select background image"),
|
||||
Ok|Cancel,
|
||||
Ok,
|
||||
true, // separator
|
||||
i18n( "Set as default" )
|
||||
)
|
||||
{
|
||||
// Is it the trash bin ?
|
||||
//QString path = item->url().path( 1 ); // adds trailing slash
|
||||
//if ( item->url().isLocalFile() && path == KGlobalSettings::trashPath() )
|
||||
// return false;
|
||||
|
||||
m_propsPage = new DirPropsPage( this, dirURL, instance );
|
||||
connect( this, SIGNAL( okClicked() ), m_propsPage, SLOT( slotApply() ) );
|
||||
connect( this, SIGNAL( applyClicked() ), m_propsPage, SLOT( slotApply() ) );
|
||||
connect( this, SIGNAL( user1Clicked() ), m_propsPage, SLOT( slotApplyGlobal() ) );
|
||||
|
||||
m_propsPage = new KBgndDialogPage( this, pixmapFile, instance );
|
||||
setMainWidget( m_propsPage );
|
||||
}
|
||||
|
||||
|
@ -64,11 +55,10 @@ KonqBgndDialog::~KonqBgndDialog()
|
|||
{
|
||||
}
|
||||
|
||||
DirPropsPage::DirPropsPage( QWidget * parent, const KURL & dirURL, KInstance *instance )
|
||||
: QWidget( parent, "DirPropsPage" ), m_url( dirURL )
|
||||
KBgndDialogPage::KBgndDialogPage( QWidget * parent, const QString & pixmapFile, KInstance *instance )
|
||||
: QWidget( parent, "KBgndDialogPage" )
|
||||
{
|
||||
m_instance = instance;
|
||||
m_fileitem = new KonqFileItem( -1, -1, dirURL );
|
||||
|
||||
QLabel* tmpQLabel = new QLabel( this, "Label_1" );
|
||||
tmpQLabel->setText( i18n("Background") );
|
||||
|
@ -76,92 +66,40 @@ DirPropsPage::DirPropsPage( QWidget * parent, const KURL & dirURL, KInstance *in
|
|||
tmpQLabel->adjustSize();
|
||||
|
||||
m_wallBox = new QComboBox( false, this, "ComboBox_1" );
|
||||
|
||||
QString tmp = dirURL.path();
|
||||
|
||||
if ( tmp.at(tmp.length() - 1) != '/' )
|
||||
tmp += "/.directory";
|
||||
else
|
||||
tmp += ".directory";
|
||||
|
||||
QString wallStr;
|
||||
QFile f( tmp );
|
||||
if ( f.open( IO_ReadOnly ) )
|
||||
{
|
||||
f.close();
|
||||
|
||||
KSimpleConfig config( tmp );
|
||||
config.setGroup( "URL properties" );
|
||||
wallStr = config.readEntry( "BgImage" );
|
||||
}
|
||||
m_wallBox->insertItem( i18n("None") );
|
||||
|
||||
QStringList list = KGlobal::dirs()->findAllResources("wallpaper");
|
||||
m_wallBox->insertItem( i18n("(Default)"), 0 );
|
||||
|
||||
for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++)
|
||||
m_wallBox->insertItem( ( (*it).at(0)=='/' ) ? // if absolute path
|
||||
KURL( *it ).filename() : // then only filename
|
||||
*it );
|
||||
|
||||
showSettings( wallStr );
|
||||
|
||||
m_wallBox->adjustSize();
|
||||
|
||||
m_browseButton = new QPushButton( i18n("&Browse..."), this );
|
||||
m_browseButton->adjustSize();
|
||||
connect( m_browseButton, SIGNAL( clicked() ), SLOT( slotBrowse() ) );
|
||||
|
||||
m_wallWidget = new QWidget( this );
|
||||
loadWallPaper();
|
||||
|
||||
showSettings( pixmapFile );
|
||||
|
||||
connect( m_wallBox, SIGNAL( activated( int ) ), this, SLOT( slotWallPaperChanged( int ) ) );
|
||||
|
||||
setMinimumSize( QSize( 400, 300 ) );
|
||||
}
|
||||
|
||||
DirPropsPage::~DirPropsPage()
|
||||
KBgndDialogPage::~KBgndDialogPage()
|
||||
{
|
||||
}
|
||||
|
||||
void DirPropsPage::slotApply()
|
||||
void KBgndDialogPage::showSettings( QString filename )
|
||||
{
|
||||
QString tmp = m_url.path();
|
||||
if ( tmp.at( tmp.length() - 1 ) != '/' )
|
||||
tmp += "/.directory";
|
||||
else
|
||||
tmp += ".directory";
|
||||
|
||||
QFile f( tmp );
|
||||
if ( !f.open( IO_ReadWrite ) )
|
||||
{
|
||||
KMessageBox::error( 0, i18n("Could not write to\n") + tmp);
|
||||
return;
|
||||
}
|
||||
f.close();
|
||||
|
||||
KSimpleConfig config( tmp );
|
||||
config.setGroup( "URL properties" );
|
||||
|
||||
int i = m_wallBox->currentItem();
|
||||
if ( i != -1 )
|
||||
{
|
||||
if ( strcmp( m_wallBox->text( i ), i18n("(Default)") ) == 0 )
|
||||
config.writeEntry( "BgImage", "" );
|
||||
else
|
||||
config.writeEntry( "BgImage", m_wallBox->text( i ) );
|
||||
}
|
||||
|
||||
config.sync();
|
||||
}
|
||||
|
||||
void DirPropsPage::showSettings( QString filename )
|
||||
{
|
||||
m_wallBox->setCurrentItem( 0 );
|
||||
for ( int i = 1; i < m_wallBox->count(); i++ )
|
||||
{
|
||||
if ( filename == m_wallBox->text( i ) )
|
||||
{
|
||||
m_wallBox->setCurrentItem( i );
|
||||
loadWallPaper();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -170,54 +108,59 @@ void DirPropsPage::showSettings( QString filename )
|
|||
{
|
||||
m_wallBox->insertItem( filename );
|
||||
m_wallBox->setCurrentItem( m_wallBox->count()-1 );
|
||||
m_wallBox->adjustSize();
|
||||
}
|
||||
else m_wallBox->setCurrentItem( 0 );
|
||||
|
||||
loadWallPaper();
|
||||
}
|
||||
|
||||
void DirPropsPage::slotBrowse( )
|
||||
void KBgndDialogPage::slotBrowse( )
|
||||
{
|
||||
KURL url = KFileDialog::getOpenURL( 0 );
|
||||
if (url.isEmpty())
|
||||
return;
|
||||
if (!url.isLocalFile()) {
|
||||
KMessageBox::sorry(this, i18n("Currently are only local wallpapers allowed."));
|
||||
}
|
||||
showSettings( url.path() );
|
||||
m_wallBox->adjustSize();
|
||||
loadWallPaper();
|
||||
} else
|
||||
showSettings( url.path() );
|
||||
}
|
||||
|
||||
void DirPropsPage::slotWallPaperChanged( int )
|
||||
void KBgndDialogPage::slotWallPaperChanged( int )
|
||||
{
|
||||
loadWallPaper();
|
||||
}
|
||||
|
||||
void DirPropsPage::loadWallPaper()
|
||||
void KBgndDialogPage::loadWallPaper()
|
||||
{
|
||||
int i = m_wallBox->currentItem();
|
||||
if ( i == -1 )
|
||||
if ( i == -1 || i == 0 ) // 0 is 'None'
|
||||
{
|
||||
m_wallPixmap.resize(0,0);
|
||||
m_wallFile = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
QString text = m_wallBox->text( i );
|
||||
if ( text == i18n( "(Default)" ) )
|
||||
m_wallPixmap.resize(0,0);
|
||||
m_wallFile = m_wallBox->text( i );
|
||||
QString file = locate("wallpaper", m_wallFile);
|
||||
if ( file.isEmpty() )
|
||||
{
|
||||
kdWarning(1203) << "Couldn't locate wallpaper " << m_wallFile << endl;
|
||||
m_wallPixmap.resize(0,0);
|
||||
m_wallFile = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
QString file = locate("wallpaper", text);
|
||||
if ( file != m_wallFile )
|
||||
{
|
||||
m_wallFile = file;
|
||||
m_wallPixmap.load( file );
|
||||
}
|
||||
m_wallPixmap.load( file );
|
||||
|
||||
if ( m_wallPixmap.isNull() )
|
||||
warning("Could not load wallpaper %s\n",file.ascii());
|
||||
if ( m_wallPixmap.isNull() )
|
||||
kdWarning(1203) << "Could not load wallpaper " << file << endl;
|
||||
}
|
||||
}
|
||||
m_wallWidget->setBackgroundPixmap( m_wallPixmap );
|
||||
}
|
||||
|
||||
void DirPropsPage::resizeEvent ( QResizeEvent *)
|
||||
void KBgndDialogPage::resizeEvent ( QResizeEvent *)
|
||||
{
|
||||
int fontHeight = 2*fontMetrics().height();
|
||||
m_wallBox->move( KDialog::marginHint(), KDialog::marginHint() + fontHeight );
|
||||
|
@ -230,28 +173,6 @@ void DirPropsPage::resizeEvent ( QResizeEvent *)
|
|||
imageH = height() - imageY - KDialog::marginHint()*2;
|
||||
|
||||
m_wallWidget->setGeometry( imageX, imageY, imageW, imageH );
|
||||
//applyButton->move( 10, imageY+imageH+KDialog::spacingHint() );
|
||||
//globalButton->move( applyButton->x() + applyButton->width() + KDialog::spacingHint(), applyButton->y() );
|
||||
}
|
||||
|
||||
void DirPropsPage::slotApplyGlobal()
|
||||
{
|
||||
// Write the image setting to the configuration file shared by
|
||||
// the builtin views (iconview/treeview)
|
||||
KConfig *config = new KConfig( "konqbuiltinviewrc", false, false );
|
||||
|
||||
config->setGroup( "Settings" );
|
||||
|
||||
int i = m_wallBox->currentItem();
|
||||
if ( i != -1 )
|
||||
{
|
||||
if ( strcmp( m_wallBox->text( i ), i18n("(None)") ) == 0 )
|
||||
config->writeEntry( "BackgroundPixmap", "" );
|
||||
else
|
||||
config->writeEntry( "BackgroundPixmap", m_wallBox->text( i ) );
|
||||
}
|
||||
|
||||
config->sync();
|
||||
}
|
||||
|
||||
#include "konq_bgnddlg.moc"
|
||||
|
|
|
@ -24,19 +24,22 @@
|
|||
#include <qstring.h>
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include <kurl.h>
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class KonqFileItem;
|
||||
class QComboBox;
|
||||
class QPushButton;
|
||||
|
||||
class DirPropsPage : public QWidget
|
||||
/**
|
||||
* Reuseable widget that is the core of the background-image dialog.
|
||||
* It features a combobox with a list of available 'wallpaper' pixmaps,
|
||||
* and an area to show the image, auto-sizing.
|
||||
*/
|
||||
class KBgndDialogPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DirPropsPage( QWidget * parent, const KURL & dirURL, KInstance *instance );
|
||||
virtual ~DirPropsPage();
|
||||
KBgndDialogPage( QWidget * parent, const QString & pixmapFile, KInstance *instance );
|
||||
virtual ~KBgndDialogPage();
|
||||
|
||||
QPixmap pixmap() { return m_wallPixmap; }
|
||||
QString pixmapFile() { return m_wallFile; }
|
||||
|
@ -44,17 +47,13 @@ public:
|
|||
public slots:
|
||||
void slotWallPaperChanged( int );
|
||||
void slotBrowse();
|
||||
void slotApply();
|
||||
void slotApplyGlobal();
|
||||
|
||||
protected:
|
||||
void showSettings( QString filename );
|
||||
void loadWallPaper();
|
||||
virtual void resizeEvent ( QResizeEvent * );
|
||||
|
||||
const KURL & m_url;
|
||||
QPushButton * m_browseButton;
|
||||
KonqFileItem * m_fileitem;
|
||||
QComboBox * m_wallBox;
|
||||
QWidget * m_wallWidget;
|
||||
QPixmap m_wallPixmap;
|
||||
|
@ -65,7 +64,7 @@ protected:
|
|||
|
||||
|
||||
/**
|
||||
* Dialog for configuring the background image for a directory
|
||||
* Dialog for configuring the background image
|
||||
*/
|
||||
class KonqBgndDialog : public KDialogBase
|
||||
{
|
||||
|
@ -74,14 +73,14 @@ public:
|
|||
/**
|
||||
* Constructor
|
||||
*/
|
||||
KonqBgndDialog( const KURL & dirURL, KInstance *instance );
|
||||
KonqBgndDialog( const QString & pixmapFile, KInstance *instance );
|
||||
~KonqBgndDialog();
|
||||
|
||||
QPixmap pixmap() { return m_propsPage->pixmap(); }
|
||||
QString pixmapFile() { return m_propsPage->pixmapFile(); }
|
||||
|
||||
private:
|
||||
DirPropsPage * m_propsPage;
|
||||
KBgndDialogPage * m_propsPage;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include <ksimpleconfig.h>
|
||||
|
||||
QPixmap wallpaperPixmap( const char *_wallpaper )
|
||||
static QPixmap wallpaperPixmap( const QString & _wallpaper )
|
||||
{
|
||||
QString key = "wallpapers/";
|
||||
key += _wallpaper;
|
||||
|
@ -50,11 +50,11 @@ QPixmap wallpaperPixmap( const char *_wallpaper )
|
|||
{
|
||||
pix.load( path, 0, KPixmap::LowColor ); // ?
|
||||
if ( pix.isNull() )
|
||||
debug("Wallpaper %s couldn't be loaded",path.ascii());
|
||||
kdWarning(1203) << "Could not load wallpaper " << path << endl;
|
||||
else
|
||||
QPixmapCache::insert( key, pix );
|
||||
return pix;
|
||||
} else debug("Wallpaper %s not found",_wallpaper);
|
||||
} else kdWarning(1203) << "Couldn't locate wallpaper " << _wallpaper << endl;
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
|
@ -73,11 +73,8 @@ KonqPropsView::KonqPropsView( KInstance * instance, KonqPropsView * defaultProps
|
|||
m_bShowDot = config->readBoolEntry( "ShowDotFiles", false );
|
||||
m_bImagePreview = config->readBoolEntry( "ImagePreview", false );
|
||||
|
||||
// Default background color is the one from the settings, i.e. configured in kcmkonq
|
||||
// TODO: remove it from there ?
|
||||
m_bgColor = KonqFMSettings::settings()->bgColor();
|
||||
|
||||
m_bgPixmapFile = config->readEntry( "BackgroundPixmap", "" );
|
||||
m_bgColor = config->readColorEntry( "BgColor", & Qt::white );
|
||||
m_bgPixmapFile = config->readEntry( "BgImage", "" );
|
||||
loadPixmap();
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ void KonqFMSettings::init( KConfig * config )
|
|||
// Fonts and colors
|
||||
m_standardFont = config->readFontEntry( "StandardFont" );
|
||||
|
||||
m_bgColor = config->readColorEntry( "BgColor", &FM_DEFAULT_BG_COLOR );
|
||||
m_normalTextColor = config->readColorEntry( "NormalTextColor", &FM_DEFAULT_TXT_COLOR );
|
||||
m_highlightedTextColor = config->readColorEntry( "HighlightedTextColor", &FM_DEFAULT_HIGHLIGHTED_TXT_COLOR );
|
||||
m_bWordWrapText = config->readBoolEntry( "WordWrapText", DEFAULT_WORDWRAPTEXT );
|
||||
|
|
|
@ -80,7 +80,6 @@ public:
|
|||
const QFont& standardFont() const { return m_standardFont; }
|
||||
|
||||
// Color settings
|
||||
const QColor& bgColor() const { return m_bgColor; }
|
||||
const QColor& normalTextColor() const { return m_normalTextColor; }
|
||||
const QColor& highlightedTextColor() const { return m_highlightedTextColor; }
|
||||
|
||||
|
@ -102,7 +101,6 @@ private:
|
|||
|
||||
QFont m_standardFont;
|
||||
|
||||
QColor m_bgColor;
|
||||
QColor m_normalTextColor;
|
||||
QColor m_highlightedTextColor;
|
||||
|
||||
|
|
Loading…
Reference in a new issue