1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/* vi: ts=8 sts=4 sw=4
This file is part of the KDE project, module kcmbackground.
Copyright (C) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <tqcheckbox.h>
#include <tqevent.h>
#include <tqpushbutton.h>
#include <tqspinbox.h>
#include <tdefiledialog.h>
#include <kimageio.h>
#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kurldrag.h>
#include "bgsettings.h"
#include "bgwallpaper.h"
#include "bgwallpaper_ui.h"
/**** BGMultiWallpaperList ****/
BGMultiWallpaperList::BGMultiWallpaperList(TQWidget *parent, const char *name)
: TQListBox(parent, name)
{
setAcceptDrops(true);
setSelectionMode(TQListBox::Extended);
}
void BGMultiWallpaperList::dragEnterEvent(TQDragEnterEvent *ev)
{
ev->accept(KURLDrag::canDecode(ev));
}
void BGMultiWallpaperList::dropEvent(TQDropEvent *ev)
{
TQStringList files;
KURL::List urls;
KURLDrag::decode(ev, urls);
for(KURL::List::ConstIterator it = urls.begin();
it != urls.end(); ++it)
{
// TODO: Download remote files
if ((*it).isLocalFile())
files.append((*it).path());
}
insertStringList(files);
}
bool BGMultiWallpaperList::hasSelection()
{
for ( unsigned i = 0; i < count(); i++)
{
if ( item( i ) && item( i )->isSelected() )
return true;
}
return false;
}
void BGMultiWallpaperList::ensureSelectionVisible()
{
for ( int i = topItem(); i < topItem() + numItemsVisible() - 1; i++)
if ( item( i ) && item( i )->isSelected() )
return;
for ( unsigned i = 0; i < count(); i++)
if ( item( i ) && item( i )->isSelected() )
{
setTopItem( i );
return;
}
}
/**** BGMultiWallpaperDialog ****/
BGMultiWallpaperDialog::BGMultiWallpaperDialog(KBackgroundSettings *settings,
TQWidget *parent, const char *name)
: KDialogBase(parent, name, true, i18n("Setup Slide Show"),
Ok | Cancel, Ok, true), m_pSettings(settings)
{
dlg = new BGMultiWallpaperBase(this);
setMainWidget(dlg);
dlg->m_spinInterval->setRange(1, 99999);
dlg->m_spinInterval->setSteps(1, 15);
dlg->m_spinInterval->setSuffix(i18n(" min"));
// Load
dlg->m_spinInterval->setValue(QMAX(1,m_pSettings->wallpaperChangeInterval()));
dlg->m_listImages->insertStringList(m_pSettings->wallpaperList());
if (m_pSettings->multiWallpaperMode() == KBackgroundSettings::Random)
dlg->m_cbRandom->setChecked(true);
connect(dlg->m_buttonAdd, TQT_SIGNAL(clicked()), TQT_SLOT(slotAdd()));
connect(dlg->m_buttonRemove, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemove()));
connect(dlg->m_buttonMoveUp, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveUp()));
connect(dlg->m_buttonMoveDown, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveDown()));
connect(dlg->m_listImages, TQT_SIGNAL(clicked ( TQListBoxItem * )), TQT_SLOT(slotItemSelected( TQListBoxItem *)));
dlg->m_buttonRemove->setEnabled( false );
dlg->m_buttonMoveUp->setEnabled( false );
dlg->m_buttonMoveDown->setEnabled( false );
}
void BGMultiWallpaperDialog::slotItemSelected( TQListBoxItem * )
{
dlg->m_buttonRemove->setEnabled( dlg->m_listImages->hasSelection() );
setEnabledMoveButtons();
}
void BGMultiWallpaperDialog::setEnabledMoveButtons()
{
bool hasSelection = dlg->m_listImages->hasSelection();
TQListBoxItem * item;
item = dlg->m_listImages->firstItem();
dlg->m_buttonMoveUp->setEnabled( hasSelection && item && !item->isSelected() );
item = dlg->m_listImages->item( dlg->m_listImages->count() - 1 );
dlg->m_buttonMoveDown->setEnabled( hasSelection && item && !item->isSelected() );
}
void BGMultiWallpaperDialog::slotAdd()
{
TQStringList mimeTypes = KImageIO::mimeTypes( KImageIO::Reading );
#ifdef HAVE_LIBART
mimeTypes += "image/svg+xml";
#endif
KFileDialog fileDialog(TDEGlobal::dirs()->findDirs("wallpaper", "").first(),
mimeTypes.join( " " ), this,
0L, true);
fileDialog.setCaption(i18n("Select Image"));
KFile::Mode mode = static_cast<KFile::Mode> (KFile::Files |
KFile::Directory |
KFile::ExistingOnly |
KFile::LocalOnly);
fileDialog.setMode(mode);
fileDialog.exec();
TQStringList files = fileDialog.selectedFiles();
if (files.isEmpty())
return;
dlg->m_listImages->insertStringList(files);
}
void BGMultiWallpaperDialog::slotRemove()
{
int current = -1;
for ( unsigned i = 0; i < dlg->m_listImages->count();)
{
TQListBoxItem * item = dlg->m_listImages->item( i );
if ( item && item->isSelected())
{
dlg->m_listImages->removeItem(i);
if (current == -1)
current = i;
}
else
i++;
}
if ((current != -1) && (current < (signed)dlg->m_listImages->count()))
dlg->m_listImages->setSelected(current, true);
dlg->m_buttonRemove->setEnabled(dlg->m_listImages->hasSelection());
setEnabledMoveButtons();
}
void BGMultiWallpaperDialog::slotMoveUp()
{
for ( unsigned i = 1; i < dlg->m_listImages->count(); i++)
{
TQListBoxItem * item = dlg->m_listImages->item( i );
if ( item && item->isSelected() )
{
dlg->m_listImages->takeItem( item );
dlg->m_listImages->insertItem( item, i - 1 );
}
}
dlg->m_listImages->ensureSelectionVisible();
setEnabledMoveButtons();
}
void BGMultiWallpaperDialog::slotMoveDown()
{
for ( unsigned i = dlg->m_listImages->count() - 1; i > 0; i--)
{
TQListBoxItem * item = dlg->m_listImages->item( i - 1 );
if ( item && item->isSelected())
{
dlg->m_listImages->takeItem( item );
dlg->m_listImages->insertItem( item, i );
}
}
dlg->m_listImages->ensureSelectionVisible();
setEnabledMoveButtons();
}
void BGMultiWallpaperDialog::slotOk()
{
TQStringList lst;
for (unsigned i=0; i < dlg->m_listImages->count(); i++)
lst.append(dlg->m_listImages->text(i));
m_pSettings->setWallpaperList(lst);
m_pSettings->setWallpaperChangeInterval(dlg->m_spinInterval->value());
if (dlg->m_cbRandom->isChecked())
m_pSettings->setMultiWallpaperMode(KBackgroundSettings::Random);
else
m_pSettings->setMultiWallpaperMode(KBackgroundSettings::InOrder);
accept();
}
#include "bgwallpaper.moc"
|