3
This file is part of the KDE project, module kcmbackground.
5
Copyright (C) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
6
Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
version 2 as published by the Free Software Foundation.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public License
18
along with this library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
Boston, MA 02110-1301, USA.
23
#include <config-workspace.h>
27
#include <QPushButton>
30
#include <QDragEnterEvent>
33
#include <kfiledialog.h>
36
#include <kstandarddirs.h>
37
#include <k3urldrag.h>
39
#include "bgsettings.h"
40
#include "bgwallpaper.h"
41
#include "bgwallpaper_ui.h"
43
/**** BGMultiWallpaperList ****/
45
BGMultiWallpaperList::BGMultiWallpaperList(QWidget *parent, const char *name)
50
setSelectionMode(QListWidget::ExtendedSelection);
54
void BGMultiWallpaperList::dragEnterEvent(QDragEnterEvent *ev)
56
ev->setAccepted(K3URLDrag::canDecode(ev));
60
void BGMultiWallpaperList::dropEvent(QDropEvent *ev)
64
K3URLDrag::decode(ev, urls);
65
for(KUrl::List::ConstIterator it = urls.begin();
66
it != urls.end(); ++it)
68
// TODO: Download remote files
69
if ((*it).isLocalFile())
70
files.append((*it).path());
75
bool BGMultiWallpaperList::hasSelection()
77
for ( int i = 0; i < count(); i++)
79
if ( item( i ) && item( i )->isSelected() )
85
void BGMultiWallpaperList::ensureSelectionVisible()
87
// KDE 4 - I believe the three lines below are redundant
89
//for ( int i = topItem(); i < topItem() + numItemsVisible() - 1; i++)
90
// if ( item( i ) && item( i )->isSelected() )
93
for ( int i = 0; i < count(); i++)
94
if ( item( i ) && item( i )->isSelected() )
96
scrollToItem( item(i) , QAbstractItemView::PositionAtTop );
101
/**** BGMultiWallpaperDialog ****/
103
BGMultiWallpaperDialog::BGMultiWallpaperDialog(KBackgroundSettings *settings,
104
QWidget *parent, const char *name)
105
: KDialog( parent ), m_pSettings(settings)
107
setObjectName( name );
109
setCaption( i18n("Setup Slide Show") );
110
setButtons( Ok | Cancel );
111
showButtonSeparator( true );
113
dlg = new BGMultiWallpaperBase(this);
116
dlg->m_spinInterval->setRange(1, 99999);
117
dlg->m_spinInterval->setSingleStep(15);
118
dlg->m_spinInterval->setSuffix(i18n(" min"));
121
dlg->m_spinInterval->setValue(qMax(1,m_pSettings->wallpaperChangeInterval()));
123
dlg->m_listImages->addItems(m_pSettings->wallpaperList());
125
if (m_pSettings->multiWallpaperMode() == KBackgroundSettings::Random)
126
dlg->m_cbRandom->setChecked(true);
128
connect(dlg->m_buttonAdd, SIGNAL(clicked()), SLOT(slotAdd()));
129
connect(dlg->m_buttonRemove, SIGNAL(clicked()), SLOT(slotRemove()));
130
connect(dlg->m_buttonMoveUp, SIGNAL(clicked()), SLOT(slotMoveUp()));
131
connect(dlg->m_buttonMoveDown, SIGNAL(clicked()), SLOT(slotMoveDown()));
132
connect(dlg->m_listImages, SIGNAL(itemClicked ( QListWidgetItem * )), SLOT(slotItemSelected( QListWidgetItem *)));
133
connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
134
dlg->m_buttonRemove->setEnabled( false );
135
dlg->m_buttonMoveUp->setEnabled( false );
136
dlg->m_buttonMoveDown->setEnabled( false );
140
void BGMultiWallpaperDialog::slotItemSelected( QListWidgetItem * )
142
dlg->m_buttonRemove->setEnabled( dlg->m_listImages->hasSelection() );
143
setEnabledMoveButtons();
146
void BGMultiWallpaperDialog::setEnabledMoveButtons()
148
bool hasSelection = dlg->m_listImages->hasSelection();
149
QListWidgetItem * item;
151
item = dlg->m_listImages->item(0);
152
dlg->m_buttonMoveUp->setEnabled( hasSelection && item && !item->isSelected() );
153
item = dlg->m_listImages->item( dlg->m_listImages->count() - 1 );
154
dlg->m_buttonMoveDown->setEnabled( hasSelection && item && !item->isSelected() );
157
void BGMultiWallpaperDialog::slotAdd()
159
QStringList mimeTypes = KImageIO::mimeTypes( KImageIO::Reading );
160
mimeTypes += "image/svg+xml";
162
QStringList lstWallpaper = KGlobal::dirs()->findDirs("wallpaper", "");
163
KFileDialog fileDialog((lstWallpaper.count()>0) ? lstWallpaper.first() : QString(),
164
mimeTypes.join( " " ), this);
166
fileDialog.setCaption(i18n("Select Image"));
167
KFile::Modes mode = KFile::Files |
169
KFile::ExistingOnly |
171
fileDialog.setMode(mode);
173
QStringList files = fileDialog.selectedFiles();
177
dlg->m_listImages->addItems(files);
180
void BGMultiWallpaperDialog::slotRemove()
183
for ( int i = 0; i < dlg->m_listImages->count();)
185
QListWidgetItem * item = dlg->m_listImages->item( i );
186
if ( item && item->isSelected())
188
delete dlg->m_listImages->takeItem(i);
195
if ((current != -1) && (current < (signed)dlg->m_listImages->count()))
196
dlg->m_listImages->item(current)->setSelected(true);
198
dlg->m_buttonRemove->setEnabled(dlg->m_listImages->hasSelection());
200
setEnabledMoveButtons();
203
void BGMultiWallpaperDialog::slotMoveUp()
205
for ( int i = 1; i < dlg->m_listImages->count(); i++)
207
QListWidgetItem * item = dlg->m_listImages->item( i );
208
if ( item && item->isSelected() )
210
dlg->m_listImages->takeItem( i );
211
dlg->m_listImages->insertItem( i - 1 , item );
214
dlg->m_listImages->ensureSelectionVisible();
215
setEnabledMoveButtons();
218
void BGMultiWallpaperDialog::slotMoveDown()
220
for ( int i = dlg->m_listImages->count() - 1; i > 0; i--)
222
QListWidgetItem * item = dlg->m_listImages->item( i - 1 );
223
if ( item && item->isSelected())
225
dlg->m_listImages->takeItem( i - 1 );
226
dlg->m_listImages->insertItem( i , item );
229
dlg->m_listImages->ensureSelectionVisible();
230
setEnabledMoveButtons();
233
void BGMultiWallpaperDialog::slotOk()
236
for ( int i=0; i < dlg->m_listImages->count(); i++)
237
lst.append(dlg->m_listImages->item(i)->text());
238
m_pSettings->setWallpaperList(lst);
239
m_pSettings->setWallpaperChangeInterval(dlg->m_spinInterval->value());
240
if (dlg->m_cbRandom->isChecked())
241
m_pSettings->setMultiWallpaperMode(KBackgroundSettings::Random);
243
m_pSettings->setMultiWallpaperMode(KBackgroundSettings::InOrder);
249
#include "bgwallpaper.moc"