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

« back to all changes in this revision

Viewing changes to core/utilities/queuemanager/views/queuepool.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-02-13
 
7
 * Description : tabbed queue items list.
 
8
 *
 
9
 * Copyright (C) 2009-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "queuepool.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QTabBar>
 
29
 
 
30
// KDE includes
 
31
 
 
32
#include <kapplication.h>
 
33
#include <kdeversion.h>
 
34
#include <kiconloader.h>
 
35
#include <klocale.h>
 
36
#include <kmessagebox.h>
 
37
 
 
38
// Local includes
 
39
 
 
40
#include "ddragobjects.h"
 
41
#include "queuelist.h"
 
42
#include "loadingcacheinterface.h"
 
43
 
 
44
namespace Digikam
 
45
{
 
46
 
 
47
QueuePool::QueuePool(QWidget* parent)
 
48
    : KTabWidget(parent)
 
49
{
 
50
    setTabBarHidden(false);
 
51
#if KDE_IS_VERSION(4,3,0)
 
52
    setTabsClosable(false);
 
53
#else
 
54
    setCloseButtonEnabled(false);
 
55
#endif
 
56
    slotAddQueue();
 
57
 
 
58
    connect(this, SIGNAL(currentChanged(int)),
 
59
            this, SLOT(slotQueueSelected(int)));
 
60
 
 
61
    connect(this, SIGNAL(closeRequest(QWidget*)),
 
62
            this, SLOT(slotCloseQueueRequest(QWidget*)));
 
63
 
 
64
    connect(this, SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)),
 
65
            this, SLOT(slotTestCanDecode(const QDragMoveEvent*,bool&)));
 
66
 
 
67
    // -- FileWatch connections ------------------------------
 
68
 
 
69
    LoadingCacheInterface::connectToSignalFileChanged(this,
 
70
            SLOT(slotFileChanged(QString)));
 
71
}
 
72
 
 
73
QueuePool::~QueuePool()
 
74
{
 
75
}
 
76
 
 
77
void QueuePool::keyPressEvent(QKeyEvent* event)
 
78
{
 
79
    if (event->key() == Qt::Key_Delete)
 
80
    {
 
81
        slotRemoveSelectedItems();
 
82
    }
 
83
    else
 
84
    {
 
85
        KTabWidget::keyPressEvent(event);
 
86
    }
 
87
}
 
88
 
 
89
void QueuePool::setBusy(bool b)
 
90
{
 
91
    tabBar()->setEnabled(!b);
 
92
 
 
93
    for (int i = 0; i < count(); ++i)
 
94
    {
 
95
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
96
        queue->viewport()->setEnabled(!b);
 
97
    }
 
98
}
 
99
 
 
100
QueueListView* QueuePool::currentQueue() const
 
101
{
 
102
    return (dynamic_cast<QueueListView*>(currentWidget()));
 
103
}
 
104
 
 
105
QueueListView* QueuePool::findQueueById(int index) const
 
106
{
 
107
    return (dynamic_cast<QueueListView*>(widget(index)));
 
108
}
 
109
 
 
110
QMap<int, QString> QueuePool::queuesMap() const
 
111
{
 
112
    QMap<int, QString> map;
 
113
 
 
114
    for (int i = 0; i < count(); ++i)
 
115
    {
 
116
        map.insert(i, queueTitle(i));
 
117
    }
 
118
 
 
119
    return map;
 
120
}
 
121
 
 
122
QString QueuePool::queueTitle(int index) const
 
123
{
 
124
    // NOTE: clean up tab title. With KTabWidget, it sound like mistake is added, as '&' and space.
 
125
    return (tabText(index).remove('&').remove(' '));
 
126
}
 
127
 
 
128
void QueuePool::slotAddQueue()
 
129
{
 
130
    QueueListView* queue = new QueueListView(this);
 
131
    int index            = addTab(queue, SmallIcon("bqm-diff"), QString("#%1").arg(count()+1));
 
132
 
 
133
    connect(queue, SIGNAL(signalQueueContentsChanged()),
 
134
            this, SIGNAL(signalQueueContentsChanged()));
 
135
 
 
136
    connect(queue, SIGNAL(itemSelectionChanged()),
 
137
            this, SIGNAL(signalItemSelectionChanged()));
 
138
 
 
139
    emit signalQueuePoolChanged();
 
140
 
 
141
    setCurrentIndex(index);
 
142
}
 
143
 
 
144
QueuePoolItemsList QueuePool::totalPendingItemsList()
 
145
{
 
146
    QueuePoolItemsList qpool;
 
147
 
 
148
    for (int i = 0; i < count(); ++i)
 
149
    {
 
150
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
151
        ImageInfoList list   = queue->pendingItemsList();
 
152
 
 
153
        for (ImageInfoList::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
 
154
        {
 
155
            ImageInfo info = *it;
 
156
            ItemInfoSet set(i, info);
 
157
            qpool.append(set);
 
158
        }
 
159
    }
 
160
 
 
161
    return qpool;
 
162
}
 
163
 
 
164
int QueuePool::totalPendingItems()
 
165
{
 
166
    int items = 0;
 
167
 
 
168
    for (int i = 0; i < count(); ++i)
 
169
    {
 
170
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
171
        items                += queue->pendingItemsCount();
 
172
    }
 
173
 
 
174
    return items;
 
175
}
 
176
 
 
177
int QueuePool::totalPendingTasks()
 
178
{
 
179
    int tasks = 0;
 
180
 
 
181
    for (int i = 0; i < count(); ++i)
 
182
    {
 
183
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
184
        tasks                += queue->pendingTasksCount();
 
185
    }
 
186
 
 
187
    return tasks;
 
188
}
 
189
 
 
190
void QueuePool::slotRemoveCurrentQueue()
 
191
{
 
192
    QueueListView* queue = currentQueue();
 
193
 
 
194
    if (!queue)
 
195
    {
 
196
        return;
 
197
    }
 
198
 
 
199
    removeTab(indexOf(queue));
 
200
 
 
201
    if (count() == 0)
 
202
    {
 
203
        slotAddQueue();
 
204
    }
 
205
 
 
206
    emit signalQueuePoolChanged();
 
207
}
 
208
 
 
209
void QueuePool::slotClearList()
 
210
{
 
211
    QueueListView* queue = currentQueue();
 
212
 
 
213
    if (queue)
 
214
    {
 
215
        queue->slotClearList();
 
216
    }
 
217
}
 
218
 
 
219
void QueuePool::slotRemoveSelectedItems()
 
220
{
 
221
    QueueListView* queue = currentQueue();
 
222
 
 
223
    if (queue)
 
224
    {
 
225
        queue->slotRemoveSelectedItems();
 
226
    }
 
227
}
 
228
 
 
229
void QueuePool::slotRemoveItemsDone()
 
230
{
 
231
    QueueListView* queue = currentQueue();
 
232
 
 
233
    if (queue)
 
234
    {
 
235
        queue->slotRemoveItemsDone();
 
236
    }
 
237
}
 
238
 
 
239
void QueuePool::slotAddItems(const ImageInfoList& list, int queueId)
 
240
{
 
241
    QueueListView* queue = findQueueById(queueId);
 
242
 
 
243
    if (queue)
 
244
    {
 
245
        queue->slotAddItems(list);
 
246
    }
 
247
}
 
248
 
 
249
void QueuePool::slotAssignedToolsChanged(const AssignedBatchTools& tools4Item)
 
250
{
 
251
    QueueListView* queue = currentQueue();
 
252
 
 
253
    if (queue)
 
254
    {
 
255
        queue->slotAssignedToolsChanged(tools4Item);
 
256
    }
 
257
}
 
258
 
 
259
void QueuePool::slotQueueSelected(int index)
 
260
{
 
261
    QueueListView* queue = dynamic_cast<QueueListView*>(widget(index));
 
262
 
 
263
    if (queue)
 
264
    {
 
265
        emit signalItemSelectionChanged();
 
266
        emit signalQueueSelected(index, queue->settings(), queue->assignedTools());
 
267
    }
 
268
}
 
269
 
 
270
void QueuePool::slotCloseQueueRequest(QWidget* w)
 
271
{
 
272
    removeTab(indexOf(w));
 
273
 
 
274
    if (count() == 0)
 
275
    {
 
276
        slotAddQueue();
 
277
    }
 
278
 
 
279
    emit signalQueuePoolChanged();
 
280
}
 
281
 
 
282
void QueuePool::removeTab(int index)
 
283
{
 
284
    QueueListView* queue = dynamic_cast<QueueListView*>(widget(index));
 
285
    int count            = queue->pendingItemsCount();
 
286
 
 
287
    if (count > 0)
 
288
    {
 
289
        int ret = KMessageBox::questionYesNo(this,
 
290
                                             i18np("There is still 1 unprocessed item in \"%2\". Do you want to close this queue?",
 
291
                                                   "There are still %1 unprocessed items in \"%2\". Do you want to close this queue?",
 
292
                                                   count, queueTitle(index)));
 
293
 
 
294
        if (ret == KMessageBox::No)
 
295
        {
 
296
            return;
 
297
        }
 
298
    }
 
299
 
 
300
    KTabWidget::removeTab(index);
 
301
}
 
302
 
 
303
void QueuePool::slotTestCanDecode(const QDragMoveEvent* e, bool& accept)
 
304
{
 
305
    int        albumID;
 
306
    QList<int> albumIDs;
 
307
    QList<qlonglong> imageIDs;
 
308
    KUrl::List urls;
 
309
    KUrl::List kioURLs;
 
310
 
 
311
    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs) ||
 
312
        DAlbumDrag::decode(e->mimeData(), urls, albumID) ||
 
313
        DTagDrag::canDecode(e->mimeData()))
 
314
    {
 
315
        accept = true;
 
316
        return;
 
317
    }
 
318
 
 
319
    accept = false;
 
320
}
 
321
 
 
322
void QueuePool::slotSettingsChanged(const QueueSettings& settings)
 
323
{
 
324
    QueueListView* queue = currentQueue();
 
325
 
 
326
    if (queue)
 
327
    {
 
328
        queue->setSettings(settings);
 
329
    }
 
330
}
 
331
 
 
332
void QueuePool::setEnableToolTips(bool b)
 
333
{
 
334
    for (int i = 0; i < count(); ++i)
 
335
    {
 
336
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
337
 
 
338
        if (queue)
 
339
        {
 
340
            queue->setEnableToolTips(b);
 
341
        }
 
342
    }
 
343
}
 
344
 
 
345
bool QueuePool::customRenamingRulesAreValid()
 
346
{
 
347
    QStringList list;
 
348
 
 
349
    for (int i = 0; i < count(); ++i)
 
350
    {
 
351
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
352
 
 
353
        if (queue)
 
354
        {
 
355
            if (queue->settings().renamingRule == QueueSettings::CUSTOMIZE &&
 
356
                queue->settings().renamingParser.isEmpty())
 
357
            {
 
358
                list.append(queueTitle(i));
 
359
            }
 
360
        }
 
361
    }
 
362
 
 
363
    if (!list.isEmpty())
 
364
    {
 
365
        KMessageBox::errorList(kapp->activeWindow(),
 
366
                               i18n("Custom renaming rules are invalid for Queues listed below. "
 
367
                                    "Please fix them."), list);
 
368
        return false;
 
369
    }
 
370
 
 
371
    return true;
 
372
}
 
373
 
 
374
bool QueuePool::assignedBatchToolsListsAreValid()
 
375
{
 
376
    QStringList list;
 
377
 
 
378
    for (int i = 0; i < count(); ++i)
 
379
    {
 
380
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
381
 
 
382
        if (queue)
 
383
        {
 
384
            if (queue->assignedTools().m_toolsMap.isEmpty())
 
385
            {
 
386
                list.append(queueTitle(i));
 
387
            }
 
388
        }
 
389
    }
 
390
 
 
391
    if (!list.isEmpty())
 
392
    {
 
393
        KMessageBox::errorList(kapp->activeWindow(),
 
394
                               i18n("Assigned batch tools list is empty for Queues listed below. "
 
395
                                    "Please assign tools."), list);
 
396
        return false;
 
397
    }
 
398
 
 
399
    return true;
 
400
}
 
401
 
 
402
void QueuePool::slotFileChanged(const QString& filePath)
 
403
{
 
404
    for (int i = 0; i < count(); ++i)
 
405
    {
 
406
        QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
 
407
 
 
408
        if (queue)
 
409
        {
 
410
            queue->reloadThumbs(KUrl::fromPath(filePath));
 
411
        }
 
412
    }
 
413
}
 
414
 
 
415
}  // namespace Digikam