~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to core/digikam/dragdrop/albumdragdrop.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2009-04-16
 
7
 * Description : Qt Model for Albums - drag and drop handling
 
8
 *
 
9
 * Copyright (C) 2005-2006 by Joern Ahrens <joern.ahrens@kdemail.net>
 
10
 * Copyright (C) 2006-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
11
 * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 
12
 * Copyright (C) 2009 by Andi Clemens <andi dot clemens at gmx dot net>
 
13
 *
 
14
 * This program is free software; you can redistribute it
 
15
 * and/or modify it under the terms of the GNU General
 
16
 * Public License as published by the Free Software Foundation;
 
17
 * either version 2, or (at your option)
 
18
 * any later version.
 
19
 *
 
20
 * This program is distributed in the hope that it will be useful,
 
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
 * GNU General Public License for more details.
 
24
 *
 
25
 * ============================================================ */
 
26
 
 
27
#include "albumdragdrop.moc"
 
28
 
 
29
// Qt includes
 
30
 
 
31
#include <QDropEvent>
 
32
 
 
33
// KDE includes
 
34
 
 
35
#include <kiconloader.h>
 
36
#include <kio/job.h>
 
37
#include <klocale.h>
 
38
#include <kmenu.h>
 
39
#include <kdebug.h>
 
40
 
 
41
// Local includes
 
42
 
 
43
#include "albummanager.h"
 
44
#include "cameraui.h"
 
45
#include "ddragobjects.h"
 
46
#include "dio.h"
 
47
#include "imageinfo.h"
 
48
#include "imageinfolist.h"
 
49
 
 
50
namespace Digikam
 
51
{
 
52
 
 
53
AlbumDragDropHandler::AlbumDragDropHandler(AlbumModel* model)
 
54
    : AlbumModelDragDropHandler(model)
 
55
{
 
56
}
 
57
 
 
58
bool AlbumDragDropHandler::dropEvent(QAbstractItemView* view, const QDropEvent* e, const QModelIndex& droppedOn)
 
59
{
 
60
    if (accepts(e, droppedOn) == Qt::IgnoreAction)
 
61
    {
 
62
        return false;
 
63
    }
 
64
 
 
65
    AlbumPointer<PAlbum> destAlbum = model()->albumForIndex(droppedOn);
 
66
 
 
67
    if (!destAlbum)
 
68
    {
 
69
        return false;
 
70
    }
 
71
 
 
72
    if (DAlbumDrag::canDecode(e->mimeData()))
 
73
    {
 
74
        KUrl::List urls;
 
75
        int albumId;
 
76
 
 
77
        if (!DAlbumDrag::decode(e->mimeData(), urls, albumId))
 
78
        {
 
79
            return false;
 
80
        }
 
81
 
 
82
        AlbumPointer<PAlbum> droppedAlbum = AlbumManager::instance()->findPAlbum(albumId);
 
83
 
 
84
        if (!droppedAlbum)
 
85
        {
 
86
            return false;
 
87
        }
 
88
 
 
89
        // TODO Copy?
 
90
        KMenu popMenu(view);
 
91
        popMenu.addTitle(SmallIcon("digikam"), i18n("My Albums"));
 
92
        QAction* moveAction = popMenu.addAction(SmallIcon("go-jump"), i18n("&Move Here"));
 
93
        popMenu.addSeparator();
 
94
        popMenu.addAction(SmallIcon("dialog-cancel"), i18n("C&ancel"));
 
95
        popMenu.setMouseTracking(true);
 
96
        QAction* choice = popMenu.exec(QCursor::pos());
 
97
 
 
98
        if (!droppedAlbum || !destAlbum)
 
99
        {
 
100
            return false;
 
101
        }
 
102
 
 
103
        if (choice == moveAction)
 
104
        {
 
105
            KIO::Job* job = DIO::move(droppedAlbum, destAlbum);
 
106
            connect(job, SIGNAL(result(KJob*)),
 
107
                    this, SIGNAL(dioResult(KJob*)));
 
108
        }
 
109
 
 
110
        return true;
 
111
    }
 
112
    else if (DItemDrag::canDecode(e->mimeData()))
 
113
    {
 
114
 
 
115
        KUrl::List urls;
 
116
        KUrl::List kioURLs;
 
117
        QList<int> albumIDs;
 
118
        QList<qlonglong> imageIDs;
 
119
 
 
120
        if (!DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
 
121
        {
 
122
            return false;
 
123
        }
 
124
 
 
125
        if (urls.isEmpty() || kioURLs.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
 
126
        {
 
127
            return false;
 
128
        }
 
129
 
 
130
        // Check if items dropped come from outside current album.
 
131
        // This can be the case with recursive content album mode.
 
132
        KUrl::List       extUrls;
 
133
        ImageInfoList    extImgInfList;
 
134
        QList<qlonglong> extImageIDs;
 
135
 
 
136
        for (QList<qlonglong>::const_iterator it = imageIDs.constBegin(); it != imageIDs.constEnd(); ++it)
 
137
        {
 
138
            ImageInfo info(*it);
 
139
 
 
140
            if (info.albumId() != destAlbum->id())
 
141
            {
 
142
                extUrls.append(info.databaseUrl());
 
143
                extImgInfList.append(info);
 
144
                extImageIDs << *it;
 
145
            }
 
146
        }
 
147
 
 
148
        if (extUrls.isEmpty())
 
149
        {
 
150
            // Setting the dropped image as the album thumbnail
 
151
            // If the ctrl key is pressed, when dropping the image, the
 
152
            // thumbnail is set without a popup menu
 
153
            bool set = false;
 
154
 
 
155
            if (e->keyboardModifiers() == Qt::ControlModifier)
 
156
            {
 
157
                set = true;
 
158
            }
 
159
            else
 
160
            {
 
161
                KMenu popMenu(view);
 
162
                popMenu.addTitle(SmallIcon("digikam"), i18n("My Albums"));
 
163
                QAction* setAction = 0;
 
164
 
 
165
                if (imageIDs.count() == 1)
 
166
                {
 
167
                    setAction = popMenu.addAction(i18n("Set as Album Thumbnail"));
 
168
                }
 
169
 
 
170
                popMenu.addSeparator();
 
171
                popMenu.addAction(SmallIcon("dialog-cancel"), i18n("C&ancel"));
 
172
                popMenu.setMouseTracking(true);
 
173
                QAction* choice = popMenu.exec(QCursor::pos());
 
174
                set = (setAction == choice);
 
175
            }
 
176
 
 
177
            if (set && destAlbum)
 
178
            {
 
179
                QString errMsg;
 
180
                AlbumManager::instance()->updatePAlbumIcon(destAlbum, imageIDs.first(), errMsg);
 
181
            }
 
182
 
 
183
            return true;
 
184
        }
 
185
 
 
186
        // If shift key is pressed while dragging, move the drag object without
 
187
        // displaying popup menu -> move
 
188
        bool move = false, copy = false, setThumbnail = false;
 
189
 
 
190
        if (e->keyboardModifiers() == Qt::ShiftModifier)
 
191
        {
 
192
            move = true;
 
193
        }
 
194
        // If ctrl key is pressed while dragging, copy the drag object without
 
195
        // displaying popup menu -> copy
 
196
        else if (e->keyboardModifiers() == Qt::ControlModifier)
 
197
        {
 
198
            copy = true;
 
199
        }
 
200
        else
 
201
        {
 
202
            KMenu popMenu(view);
 
203
            popMenu.addTitle(SmallIcon("digikam"), i18n("My Albums"));
 
204
            QAction* moveAction      = popMenu.addAction(SmallIcon("go-jump"), i18n("&Move Here"));
 
205
            QAction* copyAction      = popMenu.addAction(SmallIcon("edit-copy"), i18n("&Copy Here"));
 
206
            QAction* thumbnailAction = 0;
 
207
 
 
208
            if (imageIDs.count() == 1)
 
209
            {
 
210
                thumbnailAction = popMenu.addAction(i18n("Set as Album Thumbnail"));
 
211
            }
 
212
 
 
213
            popMenu.addSeparator();
 
214
            popMenu.addAction(SmallIcon("dialog-cancel"), i18n("C&ancel"));
 
215
            popMenu.setMouseTracking(true);
 
216
            QAction* choice = popMenu.exec(QCursor::pos());
 
217
 
 
218
            if (choice)
 
219
            {
 
220
                if (choice == moveAction)
 
221
                {
 
222
                    move = true;
 
223
                }
 
224
                else if (choice == copyAction)
 
225
                {
 
226
                    copy = true;
 
227
                }
 
228
                else if (choice == thumbnailAction)
 
229
                {
 
230
                    setThumbnail = true;
 
231
                }
 
232
            }
 
233
        }
 
234
 
 
235
        if (!destAlbum)
 
236
        {
 
237
            return false;
 
238
        }
 
239
 
 
240
        if (move)
 
241
        {
 
242
            KIO::Job* job = DIO::move(extUrls, extImageIDs, destAlbum);
 
243
            connect(job, SIGNAL(result(KJob*)),
 
244
                    this, SIGNAL(dioResult(KJob*)));
 
245
        }
 
246
        else if (copy)
 
247
        {
 
248
            KIO::Job* job = DIO::copy(extUrls, extImageIDs, destAlbum);
 
249
            connect(job, SIGNAL(result(KJob*)),
 
250
                    this, SIGNAL(dioResult(KJob*)));
 
251
        }
 
252
        else if (setThumbnail)
 
253
        {
 
254
            QString errMsg;
 
255
            AlbumManager::instance()->updatePAlbumIcon(destAlbum, imageIDs.first(), errMsg);
 
256
        }
 
257
 
 
258
        return true;
 
259
    }
 
260
    // -- DnD from Camera GUI ----------------------------
 
261
    else if (DCameraItemListDrag::canDecode(e->mimeData()))
 
262
    {
 
263
        CameraUI* ui = dynamic_cast<CameraUI*>(e->source());
 
264
 
 
265
        if (ui)
 
266
        {
 
267
            KMenu popMenu(view);
 
268
            popMenu.addTitle(SmallIcon("digikam"), i18n("My Albums"));
 
269
            QAction* downAction    = popMenu.addAction(SmallIcon("file-export"),
 
270
                                                       i18n("Download From Camera"));
 
271
            QAction* downDelAction = popMenu.addAction(SmallIcon("file-export"),
 
272
                                                       i18n("Download && Delete From Camera"));
 
273
            popMenu.addSeparator();
 
274
            popMenu.addAction(SmallIcon("dialog-cancel"), i18n("C&ancel"));
 
275
            popMenu.setMouseTracking(true);
 
276
            QAction* choice = popMenu.exec(QCursor::pos());
 
277
 
 
278
            if (choice && destAlbum)
 
279
            {
 
280
                if (choice == downAction)
 
281
                {
 
282
                    ui->slotDownload(true, false, destAlbum);
 
283
                }
 
284
                else if (choice == downDelAction)
 
285
                {
 
286
                    ui->slotDownload(true, true, destAlbum);
 
287
                }
 
288
            }
 
289
        }
 
290
    }
 
291
    // -- DnD from an external source ---------------------
 
292
    else if (KUrl::List::canDecode(e->mimeData()))
 
293
    {
 
294
        KUrl destURL(destAlbum->databaseUrl());
 
295
 
 
296
        KUrl::List srcURLs = KUrl::List::fromMimeData(e->mimeData());
 
297
 
 
298
        bool move = false, copy = false;
 
299
 
 
300
        // If shift key is pressed while dropping, move the drag object without
 
301
        // displaying popup menu -> move
 
302
        if (e->keyboardModifiers() == Qt::ShiftModifier)
 
303
        {
 
304
            move = true;
 
305
        }
 
306
        // If ctrl key is pressed while dropping, copy the drag object without
 
307
        // displaying popup menu -> copy
 
308
        else if (e->keyboardModifiers() == Qt::ControlModifier)
 
309
        {
 
310
            copy = true;
 
311
        }
 
312
        else
 
313
        {
 
314
            KMenu popMenu(view);
 
315
            popMenu.addTitle(SmallIcon("digikam"), i18n("My Albums"));
 
316
            QAction* moveAction = popMenu.addAction(SmallIcon("go-jump"), i18n("&Move Here"));
 
317
            QAction* copyAction = popMenu.addAction(SmallIcon("edit-copy"), i18n("&Copy Here"));
 
318
            popMenu.addSeparator();
 
319
            popMenu.addAction(SmallIcon("dialog-cancel"), i18n("C&ancel"));
 
320
            popMenu.setMouseTracking(true);
 
321
            QAction* choice = popMenu.exec(QCursor::pos());
 
322
 
 
323
            if (choice == copyAction)
 
324
            {
 
325
                copy = true;
 
326
            }
 
327
            else if (choice == moveAction)
 
328
            {
 
329
                move = true;
 
330
            }
 
331
        }
 
332
 
 
333
        if (!destAlbum)
 
334
        {
 
335
            return false;
 
336
        }
 
337
 
 
338
        if (move)
 
339
        {
 
340
            KIO::Job* job = DIO::move(srcURLs, destAlbum);
 
341
            connect(job, SIGNAL(result(KJob*)),
 
342
                    this, SIGNAL(dioResult(KJob*)));
 
343
        }
 
344
        else if (copy)
 
345
        {
 
346
            KIO::Job* job = DIO::copy(srcURLs, destAlbum);
 
347
            connect(job, SIGNAL(result(KJob*)),
 
348
                    this, SIGNAL(dioResult(KJob*)));
 
349
        }
 
350
 
 
351
        return true;
 
352
    }
 
353
 
 
354
    return false;
 
355
}
 
356
 
 
357
Qt::DropAction AlbumDragDropHandler::accepts(const QDropEvent* e, const QModelIndex& dropIndex)
 
358
{
 
359
    PAlbum* destAlbum = model()->albumForIndex(dropIndex);
 
360
 
 
361
    if (DAlbumDrag::canDecode(e->mimeData()))
 
362
    {
 
363
        // do not allow to drop on root
 
364
        if (dropIndex == model()->rootAlbumIndex())
 
365
        {
 
366
            return Qt::IgnoreAction;
 
367
        }
 
368
 
 
369
        if (!destAlbum)
 
370
        {
 
371
            return Qt::IgnoreAction;
 
372
        }
 
373
 
 
374
        KUrl::List urls;
 
375
        int albumId;
 
376
 
 
377
        if (!DAlbumDrag::decode(e->mimeData(), urls, albumId))
 
378
        {
 
379
            return Qt::IgnoreAction;
 
380
        }
 
381
 
 
382
        PAlbum* droppedAlbum = AlbumManager::instance()->findPAlbum(albumId);
 
383
 
 
384
        if (!droppedAlbum)
 
385
        {
 
386
            return Qt::IgnoreAction;
 
387
        }
 
388
 
 
389
        // Dragging an item on itself makes no sense
 
390
        if (droppedAlbum == destAlbum)
 
391
        {
 
392
            return Qt::IgnoreAction;
 
393
        }
 
394
 
 
395
        // Dragging a parent on its child makes no sense
 
396
        if (droppedAlbum->isAncestorOf(destAlbum))
 
397
        {
 
398
            return Qt::IgnoreAction;
 
399
        }
 
400
 
 
401
        return Qt::MoveAction;
 
402
    }
 
403
    else if (DItemDrag::canDecode(e->mimeData()) ||
 
404
             DCameraItemListDrag::canDecode(e->mimeData()) ||
 
405
             KUrl::List::canDecode(e->mimeData()))
 
406
    {
 
407
        // Do not allow drop images on album root
 
408
        if (destAlbum && !destAlbum->isRoot())
 
409
        {
 
410
            return Qt::MoveAction;
 
411
        }
 
412
    }
 
413
 
 
414
    return Qt::IgnoreAction;
 
415
}
 
416
 
 
417
QStringList AlbumDragDropHandler::mimeTypes() const
 
418
{
 
419
    QStringList mimeTypes;
 
420
    mimeTypes << DAlbumDrag::mimeTypes()
 
421
              << DItemDrag::mimeTypes()
 
422
              << DCameraItemListDrag::mimeTypes()
 
423
              << KUrl::List::mimeDataTypes();
 
424
    return mimeTypes;
 
425
}
 
426
 
 
427
QMimeData* AlbumDragDropHandler::createMimeData(const QList<Album*>& albums)
 
428
{
 
429
    if (albums.isEmpty())
 
430
    {
 
431
        return 0;
 
432
    }
 
433
 
 
434
    if (albums.size() > 1)
 
435
    {
 
436
        kWarning() << "Dragging multiple albums is not implemented";
 
437
    }
 
438
 
 
439
    PAlbum* palbum = dynamic_cast<PAlbum*>(albums.first());
 
440
    return new DAlbumDrag(albums.first()->databaseUrl(), albums.first()->id(),
 
441
                          palbum ? palbum->fileUrl() : KUrl());
 
442
}
 
443
 
 
444
} // namespace Digikam