~ubuntu-branches/ubuntu/karmic/digikam/karmic-backports

« back to all changes in this revision

Viewing changes to digikam/contextmenuhelper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ubuntu Archive Auto-Backport
  • Date: 2009-12-07 19:03:53 UTC
  • mfrom: (54.1.4 lucid)
  • Revision ID: james.westby@ubuntu.com-20091207190353-oara3lenjxymto3i
Tags: 2:1.0.0~rc-1ubuntu1~karmic1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 *
22
22
 * ============================================================ */
23
23
 
24
 
#include "contextmenuhelper.h"
25
24
#include "contextmenuhelper.moc"
26
25
 
27
26
// Qt includes
39
38
#include <kaction.h>
40
39
#include <kactioncollection.h>
41
40
#include <kapplication.h>
42
 
 
43
41
#include <klocale.h>
44
42
#include <kmenu.h>
45
43
#include <kmimetype.h>
66
64
#include "queuemgrwindow.h"
67
65
#include "ratingpopupmenu.h"
68
66
#include "tagspopupmenu.h"
69
 
 
70
67
#include "config-digikam.h"
71
68
#ifdef HAVE_KDEPIMLIBS
72
69
#include <kabc/stdaddressbook.h>
79
76
{
80
77
public:
81
78
 
82
 
    ContextMenuHelperPriv()
83
 
    {
84
 
        parent              = 0;
85
 
        gotoAlbumAction     = 0;
86
 
        gotoDateAction      = 0;
87
 
        setThumbnailAction  = 0;
88
 
        stdActionCollection = 0;
89
 
        ABCmenu             = 0;
90
 
    }
91
 
 
92
 
    QAction*                      gotoAlbumAction;
93
 
    QAction*                      gotoDateAction;
94
 
    QAction*                      setThumbnailAction;
95
 
 
96
 
    QList<qlonglong>              selectedIds;
97
 
    KUrl::List                    selectedItems;
98
 
 
99
 
    QMap<int, QAction*>           queueActions;
100
 
    QMap<QString, KService::Ptr>  servicesMap;
101
 
 
102
 
    QMenu*                        parent;
103
 
    QMenu*                        ABCmenu;
104
 
 
105
 
    KActionCollection*            stdActionCollection;
 
79
    ContextMenuHelperPriv() :
 
80
        gotoAlbumAction(0),
 
81
        gotoDateAction(0),
 
82
        setThumbnailAction(0),
 
83
        parent(0),
 
84
        ABCmenu(0),
 
85
        stdActionCollection(0)
 
86
        {}
 
87
 
 
88
    QAction*                     gotoAlbumAction;
 
89
    QAction*                     gotoDateAction;
 
90
    QAction*                     setThumbnailAction;
 
91
 
 
92
    QList<qlonglong>             selectedIds;
 
93
    KUrl::List                   selectedItems;
 
94
 
 
95
    QMap<int, QAction*>          queueActions;
 
96
    QMap<QString, KService::Ptr> servicesMap;
 
97
 
 
98
    QMenu*                       parent;
 
99
    QMenu*                       ABCmenu;
 
100
 
 
101
    KActionCollection*           stdActionCollection;
106
102
};
107
103
 
108
104
ContextMenuHelper::ContextMenuHelper(QMenu* parent, KActionCollection* actionCollection)
188
184
    // kdebase/apps/lib/konq/konq_menuactions.cpp
189
185
 
190
186
    QStringList mimeTypes;
 
187
    KService::List offers;
 
188
 
191
189
    foreach(const KUrl& item, d->selectedItems)
192
190
    {
193
191
        const QString mimeType = KMimeType::findByUrl(item, 0, true, true)->name();
195
193
            mimeTypes << mimeType;
196
194
    }
197
195
 
198
 
    // Query trader
199
 
    const QString firstMimeType = mimeTypes.takeFirst();
200
 
    const QString constraintTemplate = "'%1' in ServiceTypes";
201
 
    QStringList constraints;
202
 
    foreach(const QString& mimeType, mimeTypes)
203
 
    {
204
 
        constraints << constraintTemplate.arg(mimeType);
205
 
    }
206
 
 
207
 
    KService::List offers = KMimeTypeTrader::self()->query(firstMimeType,
208
 
                                                           "Application",
209
 
                                                           constraints.join( " and "));
210
 
 
211
 
    // remove duplicate service entries
212
 
    QSet<QString> seenApps;
213
 
    for (KService::List::iterator it = offers.begin(); it != offers.end();)
214
 
    {
215
 
        const QString appName((*it)->name());
216
 
        if (!seenApps.contains(appName))
 
196
    if (!mimeTypes.isEmpty())
 
197
    {
 
198
        // Query trader
 
199
        const QString firstMimeType = mimeTypes.takeFirst();
 
200
        const QString constraintTemplate = "'%1' in ServiceTypes";
 
201
        QStringList constraints;
 
202
        foreach(const QString& mimeType, mimeTypes)
217
203
        {
218
 
            seenApps.insert(appName);
219
 
            ++it;
 
204
            constraints << constraintTemplate.arg(mimeType);
220
205
        }
221
 
        else
 
206
 
 
207
        offers = KMimeTypeTrader::self()->query(firstMimeType, "Application", constraints.join( " and "));
 
208
 
 
209
        // remove duplicate service entries
 
210
        QSet<QString> seenApps;
 
211
        for (KService::List::iterator it = offers.begin(); it != offers.end();)
222
212
        {
223
 
            it = offers.erase(it);
 
213
            const QString appName((*it)->name());
 
214
            if (!seenApps.contains(appName))
 
215
            {
 
216
                seenApps.insert(appName);
 
217
                ++it;
 
218
            }
 
219
            else
 
220
            {
 
221
                it = offers.erase(it);
 
222
            }
224
223
        }
225
224
    }
226
225
 
274
273
    if (name.isEmpty())
275
274
    {
276
275
        QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(list);
277
 
        if (!dlg->exec())
 
276
        if (!dlg->exec() == KOpenWithDialog::Accepted)
278
277
        {
279
278
            delete dlg;
280
279
            return;
301
300
    KRun::run(*service, list, d->parent);
302
301
}
303
302
 
304
 
void ContextMenuHelper::addKipiActions()
 
303
void ContextMenuHelper::addKipiActions(imageIds& ids)
305
304
{
306
 
    KAction* action = kipiRotateAction();
307
 
    if (action)
308
 
        d->parent->addAction(action);
 
305
    setSelectedIds(ids);
 
306
    if (imageIdsHaveSameCategory(ids, DatabaseItem::Image))
 
307
    {
 
308
        KAction* action = kipiRotateAction();
 
309
        if (action)
 
310
            d->parent->addAction(action);
 
311
    }
309
312
}
310
313
 
311
314
KAction* ContextMenuHelper::kipiRotateAction()
330
333
    return 0;
331
334
}
332
335
 
 
336
bool ContextMenuHelper::imageIdsHaveSameCategory(const imageIds& ids, DatabaseItem::Category category)
 
337
{
 
338
    bool sameCategory = true;
 
339
    QVariantList varList;
 
340
 
 
341
    foreach (const qlonglong& id, ids)
 
342
    {
 
343
        varList = DatabaseAccess().db()->getImagesFields(id, DatabaseFields::Category);
 
344
        if ( varList.isEmpty() ||
 
345
             (DatabaseItem::Category)varList.first().toInt() != category )
 
346
        {
 
347
            sameCategory = false;
 
348
            break;
 
349
        }
 
350
    }
 
351
    return sameCategory;
 
352
}
 
353
 
333
354
void ContextMenuHelper::addAssignTagsMenu(imageIds& ids)
334
355
{
335
356
    setSelectedIds(ids);
488
509
void ContextMenuHelper::addGotoMenu(imageIds& ids)
489
510
{
490
511
    if (d->gotoAlbumAction && d->gotoDateAction)
 
512
    {
491
513
        return;
 
514
    }
492
515
    setSelectedIds(ids);
493
516
 
 
517
    // the currently selected image is always the first item
 
518
    ImageInfo item;
 
519
    if (!d->selectedIds.isEmpty())
 
520
    {
 
521
        item = ImageInfo(d->selectedIds.first());
 
522
    }
 
523
 
 
524
    if (item.isNull())
 
525
    {
 
526
        return;
 
527
    }
 
528
 
494
529
    // when more then one item is selected, don't add the menu
495
530
    if (d->selectedIds.count() > 1) return;
496
531
 
497
532
    d->gotoAlbumAction = new QAction(SmallIcon("folder-image"),        i18n("Album"), this);
498
533
    d->gotoDateAction  = new QAction(SmallIcon("view-calendar-month"), i18n("Date"),  this);
499
534
 
500
 
    // the currently selected image is always the first item
501
 
    ImageInfo item(d->selectedIds.first());
502
 
 
503
535
    KMenu *gotoMenu  = new KMenu(d->parent);
504
536
    gotoMenu->addAction(d->gotoAlbumAction);
505
537
    gotoMenu->addAction(d->gotoDateAction);
577
609
    d->parent->addMenu(bqmMenu);
578
610
}
579
611
 
 
612
void ContextMenuHelper::addActionCut(QObject* recv, const char* slot)
 
613
{
 
614
    KAction* cut = KStandardAction::cut(recv, slot, d->parent);
 
615
    addAction(cut);
 
616
}
 
617
 
580
618
void ContextMenuHelper::addActionCopy(QObject* recv, const char* slot)
581
619
{
582
620
    KAction* copy = KStandardAction::copy(recv, slot, d->parent);