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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.kipi-plugins.org
*
* Date : 2008-05-21
* Description : a kipi plugin to export images to Flickr web service
*
* Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* 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, 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.
*
* ============================================================ */
#define ICONSIZE 64
// QT includes.
#include <tqpushbutton.h>
#include <tqpainter.h>
#include <tqfileinfo.h>
#include <tqlayout.h>
#include <tqwhatsthis.h>
#include <tqdragobject.h>
#include <tqimage.h>
// KDE includes.
#include <tdelocale.h>
#include <kdialog.h>
#include <knuminput.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <tdeio/previewjob.h>
// Libkipi includes.
#include <libkipi/interface.h>
#include <libkipi/imagedialog.h>
#include <libkipi/imagecollection.h>
// Local includes.
#include "imageslist.h"
#include "imageslist.moc"
namespace KIPIFlickrExportPlugin
{
ImagesListViewItem::ImagesListViewItem(TQListView *view, const KURL& url)
: TQListViewItem(view)
{
setThumb(SmallIcon("file_broken", ICONSIZE, TDEIcon::DisabledState));
setUrl(url);
}
ImagesListViewItem::~ImagesListViewItem()
{
}
void ImagesListViewItem::setUrl(const KURL& url)
{
m_url = url;
setText(1, m_url.fileName());
}
KURL ImagesListViewItem::url() const
{
return m_url;
}
void ImagesListViewItem::setThumb(const TQPixmap& pix)
{
TQPixmap pixmap(ICONSIZE+2, ICONSIZE+2);
pixmap.fill(TQt::color0);
TQPainter p(&pixmap);
p.drawPixmap((pixmap.width()/2) - (pix.width()/2), (pixmap.height()/2) - (pix.height()/2), pix);
setPixmap(0, pixmap);
}
// ---------------------------------------------------------------------------
ImagesListView::ImagesListView(TQWidget *parent)
: TQListView(parent)
{
addColumn(i18n("Thumbnail"));
addColumn(i18n("File Name"));
TQWhatsThis::add(this, i18n("<p>This is the list of images to upload on your Flickr account."));
setAcceptDrops(true);
setResizeMode(TQListView::AllColumns);
setAllColumnsShowFocus(true);
setSorting(-1);
setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
setSelectionMode(TQListView::Extended);
}
ImagesListView::~ImagesListView()
{
}
void ImagesListView::dragEnterEvent(TQDragEnterEvent *e)
{
e->accept(TQUriDrag::canDecode(e));
}
void ImagesListView::dropEvent(TQDropEvent *e)
{
TQStrList strList;
KURL::List urls;
if (!TQUriDrag::decode(e, strList))
return;
TQStrList stringList;
TQStrListIterator it(strList);
char *str;
while ((str = it.current()) != 0)
{
TQString filePath = TQUriDrag::uriToLocalFile(str);
TQFileInfo fileInfo(filePath);
if (fileInfo.isFile() && fileInfo.exists())
urls.append(fileInfo.filePath());
++it;
}
if (!urls.isEmpty())
emit signalDropedItems(urls);
}
// ---------------------------------------------------------------------------
class ImagesPagePriv
{
public:
ImagesPagePriv()
{
listView = 0;
addButton = 0;
removeButton = 0;
iface = 0;
}
TQPushButton *addButton;
TQPushButton *removeButton;
ImagesListView *listView;
KIPI::Interface *iface;
};
ImagesList::ImagesList(TQWidget* parent, KIPI::Interface *iface)
: TQWidget(parent)
{
d = new ImagesPagePriv;
d->iface = iface;
// --------------------------------------------------------
TQGridLayout* grid = new TQGridLayout(this, 2, 3);
d->listView = new ImagesListView(this);
// --------------------------------------------------------
d->addButton = new TQPushButton(this);
d->removeButton = new TQPushButton(this);
d->addButton->setText(i18n("&Add"));
d->addButton->setIconSet(SmallIcon("add"));
d->removeButton->setText(i18n("&Remove"));
d->removeButton->setIconSet(SmallIcon("remove"));
// --------------------------------------------------------
grid->addMultiCellWidget(d->listView, 0, 2, 0, 2);
grid->addMultiCellWidget(d->addButton, 0, 0, 3, 3);
grid->addMultiCellWidget(d->removeButton, 1, 1, 3, 3);
grid->setColStretch(0, 10);
grid->setRowStretch(2, 10);
grid->setMargin(KDialog::spacingHint());
grid->setSpacing(KDialog::spacingHint());
// --------------------------------------------------------
connect(d->addButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotAddItems()));
connect(d->removeButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotRemoveItems()));
connect(d->listView, TQ_SIGNAL(signalDropedItems(const KURL::List&)),
this, TQ_SLOT(slotAddImages(const KURL::List&)));
// --------------------------------------------------------
KIPI::ImageCollection images = d->iface->currentSelection();
if (images.isValid())
slotAddImages(images.images());
}
ImagesList::~ImagesList()
{
delete d;
}
void ImagesList::slotAddImages(const KURL::List& list)
{
if (list.count() == 0) return;
KURL::List urls;
for(KURL::List::const_iterator it = list.begin(); it != list.end(); ++it)
{
KURL imageUrl = *it;
// Check if the new item already exist in the list.
bool find = false;
TQListViewItemIterator it2(d->listView);
while (it2.current())
{
ImagesListViewItem* item = dynamic_cast<ImagesListViewItem*>(*it2);
if (item->url() == imageUrl)
find = true;
++it2;
}
if (!find)
{
new ImagesListViewItem(d->listView, imageUrl);
urls.append(imageUrl);
}
}
emit signalImageListChanged(imageUrls().isEmpty());
TDEIO::PreviewJob *thumbnailJob = TDEIO::filePreview(urls, ICONSIZE);
connect(thumbnailJob, TQ_SIGNAL(gotPreview(const KFileItem*, const TQPixmap&)),
this, TQ_SLOT(slotGotThumbnail(const KFileItem*, const TQPixmap&)));
}
void ImagesList::slotGotThumbnail(const KFileItem *item, const TQPixmap& pix)
{
TQListViewItemIterator it2(d->listView);
while (it2.current())
{
ImagesListViewItem *selItem = dynamic_cast<ImagesListViewItem*>(*it2);
if (selItem->url() == item->url())
{
selItem->setPixmap(0, pix);
}
++it2;
}
}
void ImagesList::slotAddItems()
{
KURL::List urls = KIPI::ImageDialog::getImageURLs(this, d->iface);
if (!urls.isEmpty())
slotAddImages(urls);
emit signalImageListChanged(imageUrls().isEmpty());
}
void ImagesList::slotRemoveItems()
{
bool find;
do
{
find = false;
TQListViewItemIterator it2(d->listView);
while (it2.current())
{
ImagesListViewItem* item = dynamic_cast<ImagesListViewItem*>(*it2);
if (item->isSelected())
{
delete item;
find = true;
break;
}
++it2;
}
}
while(find);
emit signalImageListChanged(imageUrls().isEmpty());
}
void ImagesList::removeItemByUrl(const KURL& url)
{
bool find;
do
{
find = false;
TQListViewItemIterator it2(d->listView);
while (it2.current())
{
ImagesListViewItem* item = dynamic_cast<ImagesListViewItem*>(*it2);
if (item->url() == url)
{
delete item;
find = true;
break;
}
++it2;
}
}
while(find);
emit signalImageListChanged(imageUrls().isEmpty());
}
KURL::List ImagesList::imageUrls() const
{
KURL::List list;
TQListViewItemIterator it2(d->listView);
while (it2.current())
{
ImagesListViewItem* item = dynamic_cast<ImagesListViewItem*>(*it2);
list.append(item->url());
++it2;
}
return list;
}
} // namespace KIPIFlickrExportPlugin
|