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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
/* KPilot
**
** Copyright (C) 1998-2001 by Dan Pilone
**
** This file defines the internal conduit "File Installer"
** that accepts drags of URLs containing Palm DBs, prcs, and
** such. It also does the HotSync part of installing files
** on the Pilot.
*/
/*
** 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 in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/
/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/
#ifndef _KPILOT_OPTIONS_H
#include "options.h"
#endif
#include <unistd.h>
#include <qlistbox.h>
#include <qstring.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qwhatsthis.h>
#include <qmultilineedit.h>
#include <qpixmap.h>
#include <qpopupmenu.h>
#include <kfiledialog.h>
#include <kurldrag.h>
#include <kiconloader.h>
#include <kiconview.h>
#include <kglobal.h>
#include <kurl.h>
#include "kpilotConfig.h"
#include "fileInstaller.h"
#include "fileInstallWidget.moc"
FileInstallWidget::FileInstallWidget(QWidget * parent,
const QString & path) :
PilotComponent(parent, "component_files", path),
fSaveFileList(false),
fInstaller(0L)
{
FUNCTIONSETUP;
QGridLayout *grid = new QGridLayout(this, 5, 5, SPACING);
QLabel *label = new QLabel(i18n("Files to install:"), this);
grid->addWidget(label, 1, 1);
QPushButton *abutton;
abutton = addButton = new QPushButton(i18n("Add File..."), this);
connect(abutton, SIGNAL(clicked()), this, SLOT(slotAddFile()));
grid->addWidget(abutton, 3, 1);
QWhatsThis::add(abutton,
i18n("<qt>Choose a file to add to the list of files to install.</qt>"));
abutton = clearButton= new QPushButton(i18n("Clear List"), this);
connect(abutton, SIGNAL(clicked()), this, SLOT(slotClearButton()));
grid->addWidget(abutton, 4, 1);
QWhatsThis::add(abutton,
i18n("<qt>Clear the list of files to install. No files will be installed.</qt>"));
fIconView = new KIconView(this);
connect(fIconView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)),
this, SLOT(slotDropEvent(QDropEvent *, const QValueList<QIconDragItem> &)));
grid->addMultiCellWidget(fIconView, 1, 4, 2, 3);
QWhatsThis::add(fIconView,
i18n
("<qt>This lists files that will be installed on the Pilot during the next HotSync. Drag files here or use the Add button.</qt>"));
fIconView->setAcceptDrops(true);
fIconView->setSelectionMode(QIconView::Extended);
fIconView->viewport()->installEventFilter(this);
grid->setRowStretch(2, 100);
grid->setColStretch(2, 50);
grid->setColStretch(2, 50);
grid->addColSpacing(4, SPACING);
grid->addRowSpacing(5, SPACING);
fInstaller = new FileInstaller;
connect(fInstaller, SIGNAL(filesChanged()),
this, SLOT(refreshFileInstallList()));
}
FileInstallWidget::~FileInstallWidget()
{
KPILOT_DELETE(fInstaller);
}
static inline bool pdbOrPrc(const QString &s)
{
return s.endsWith(CSL1(".pdb"),false) || s.endsWith(CSL1(".prc"),false) ;
}
void FileInstallWidget::dragEnterEvent(QDragEnterEvent *event)
{
FUNCTIONSETUP;
KURL::List urls;
if(!KURLDrag::decode(event, urls)) {
event->accept(false);
return;
}
KURL::List::const_iterator it;
QString filename;
for ( it = urls.begin(); it != urls.end(); ++it ) {
filename = (*it).fileName();
if(!pdbOrPrc(filename)) {
event->accept(false);
return;
}
}
event->accept(true);
}
bool FileInstallWidget::eventFilter(QObject *watched, QEvent *event)
{
FUNCTIONSETUP;
if(watched == fIconView->viewport())
{
if(event->type() == QEvent::DragEnter) {
dragEnterEvent(static_cast<QDragEnterEvent*>(event));
return true;
}
// We have to skip the DragMove event, because it seems to override the
// accept state, when it is set to false by dragEnterEvent() (event->accept(false);)
if(event->type() == QEvent::DragMove) {
return true;
}
if(event->type() == QEvent::MouseButtonPress) {
contextMenu(static_cast<QMouseEvent*>(event));
}
}
return false;
}
void FileInstallWidget::dropEvent(QDropEvent * drop)
{
FUNCTIONSETUP;
if (!shown) return;
KURL::List list;
if (!KURLDrag::decode(drop, list) || list.isEmpty())
return;
#ifdef DEBUG
DEBUGKPILOT << ": Got " << list.first().prettyURL() << endl;
#endif
QStringList files;
for(KURL::List::ConstIterator it = list.begin(); it != list.end(); ++it)
{
if ((*it).isLocalFile())
files << (*it).path();
}
fInstaller->addFiles(files, this );
}
void FileInstallWidget::slotDropEvent(QDropEvent * drop, const QValueList<QIconDragItem> & /*lst*/)
{
FUNCTIONSETUP;
dropEvent(drop);
}
void FileInstallWidget::slotClearButton()
{
FUNCTIONSETUP;
fInstaller->clearPending();
}
void FileInstallWidget::showComponent()
{
FUNCTIONSETUP;
refreshFileInstallList();
}
void FileInstallWidget::slotAddFile()
{
FUNCTIONSETUP;
if (!shown) return;
QStringList fileNames = KFileDialog::getOpenFileNames(
QString::null, i18n("*.pdb *.prc|PalmOS Databases (*.pdb *.prc)"));
for (QStringList::Iterator fileName = fileNames.begin(); fileName != fileNames.end(); ++fileName)
{
fInstaller->addFile(*fileName, this );
}
}
bool FileInstallWidget::preHotSync(QString &)
{
FUNCTIONSETUP;
fIconView->setEnabled(false);
fInstaller->setEnabled(false);
addButton->setEnabled(false);
clearButton->setEnabled(false);
return true;
}
void FileInstallWidget::postHotSync()
{
FUNCTIONSETUP;
fInstaller->setEnabled(true);
fIconView->setEnabled(true);
addButton->setEnabled(true);
clearButton->setEnabled(true);
if (shown) refreshFileInstallList();
}
void FileInstallWidget::refreshFileInstallList()
{
FUNCTIONSETUP;
QStringList fileNames = fInstaller->fileNames();
QPixmap kpilotIcon = KGlobal::iconLoader()->loadIcon(CSL1("kpilot"), KIcon::Desktop);
fIconView->clear();
for (QStringList::Iterator fileName = fileNames.begin(); fileName != fileNames.end(); ++fileName)
{
if(pdbOrPrc(*fileName))
{
new KIconViewItem(fIconView, *fileName, kpilotIcon);
}
else
{
new KIconViewItem(fIconView, *fileName);
}
}
}
void FileInstallWidget::contextMenu(QMouseEvent *event)
{
FUNCTIONSETUP;
if(event->button() == Qt::LeftButton)
return;
QIconViewItem *item;
QStringList files;
for(item = fIconView->firstItem(); item; item = item->nextItem())
{
if(item->isSelected())
files.append(item->text());
}
QPopupMenu popup(fIconView);
item = fIconView->findItem(event->pos());
if(item) {
// Popup for the right clicked item
popup.insertItem(i18n("Delete a single file item","Delete"), 10);
}
popup.insertItem(i18n("Delete selected files"), 11);
if(files.empty())
popup.setItemEnabled(11, false);
int id = popup.exec(fIconView->viewport()->mapToGlobal(event->pos()));
if(id == 10)
fInstaller->deleteFile(item->text());
else if(id == 11)
fInstaller->deleteFiles(files);
}
|