1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : tabbed queue items list.
9
* Copyright (C) 2009-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
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)
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.
22
* ============================================================ */
24
#include "queuepool.moc"
32
#include <kapplication.h>
33
#include <kdeversion.h>
34
#include <kiconloader.h>
36
#include <kmessagebox.h>
40
#include "ddragobjects.h"
41
#include "queuelist.h"
42
#include "loadingcacheinterface.h"
47
QueuePool::QueuePool(QWidget* parent)
50
setTabBarHidden(false);
51
#if KDE_IS_VERSION(4,3,0)
52
setTabsClosable(false);
54
setCloseButtonEnabled(false);
58
connect(this, SIGNAL(currentChanged(int)),
59
this, SLOT(slotQueueSelected(int)));
61
connect(this, SIGNAL(closeRequest(QWidget*)),
62
this, SLOT(slotCloseQueueRequest(QWidget*)));
64
connect(this, SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)),
65
this, SLOT(slotTestCanDecode(const QDragMoveEvent*,bool&)));
67
// -- FileWatch connections ------------------------------
69
LoadingCacheInterface::connectToSignalFileChanged(this,
70
SLOT(slotFileChanged(QString)));
73
QueuePool::~QueuePool()
77
void QueuePool::keyPressEvent(QKeyEvent* event)
79
if (event->key() == Qt::Key_Delete)
81
slotRemoveSelectedItems();
85
KTabWidget::keyPressEvent(event);
89
void QueuePool::setBusy(bool b)
91
tabBar()->setEnabled(!b);
93
for (int i = 0; i < count(); ++i)
95
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
96
queue->viewport()->setEnabled(!b);
100
QueueListView* QueuePool::currentQueue() const
102
return (dynamic_cast<QueueListView*>(currentWidget()));
105
QueueListView* QueuePool::findQueueById(int index) const
107
return (dynamic_cast<QueueListView*>(widget(index)));
110
QMap<int, QString> QueuePool::queuesMap() const
112
QMap<int, QString> map;
114
for (int i = 0; i < count(); ++i)
116
map.insert(i, queueTitle(i));
122
QString QueuePool::queueTitle(int index) const
124
// NOTE: clean up tab title. With KTabWidget, it sound like mistake is added, as '&' and space.
125
return (tabText(index).remove('&').remove(' '));
128
void QueuePool::slotAddQueue()
130
QueueListView* queue = new QueueListView(this);
131
int index = addTab(queue, SmallIcon("bqm-diff"), QString("#%1").arg(count()+1));
133
connect(queue, SIGNAL(signalQueueContentsChanged()),
134
this, SIGNAL(signalQueueContentsChanged()));
136
connect(queue, SIGNAL(itemSelectionChanged()),
137
this, SIGNAL(signalItemSelectionChanged()));
139
emit signalQueuePoolChanged();
141
setCurrentIndex(index);
144
QueuePoolItemsList QueuePool::totalPendingItemsList()
146
QueuePoolItemsList qpool;
148
for (int i = 0; i < count(); ++i)
150
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
151
ImageInfoList list = queue->pendingItemsList();
153
for (ImageInfoList::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
155
ImageInfo info = *it;
156
ItemInfoSet set(i, info);
164
int QueuePool::totalPendingItems()
168
for (int i = 0; i < count(); ++i)
170
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
171
items += queue->pendingItemsCount();
177
int QueuePool::totalPendingTasks()
181
for (int i = 0; i < count(); ++i)
183
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
184
tasks += queue->pendingTasksCount();
190
void QueuePool::slotRemoveCurrentQueue()
192
QueueListView* queue = currentQueue();
199
removeTab(indexOf(queue));
206
emit signalQueuePoolChanged();
209
void QueuePool::slotClearList()
211
QueueListView* queue = currentQueue();
215
queue->slotClearList();
219
void QueuePool::slotRemoveSelectedItems()
221
QueueListView* queue = currentQueue();
225
queue->slotRemoveSelectedItems();
229
void QueuePool::slotRemoveItemsDone()
231
QueueListView* queue = currentQueue();
235
queue->slotRemoveItemsDone();
239
void QueuePool::slotAddItems(const ImageInfoList& list, int queueId)
241
QueueListView* queue = findQueueById(queueId);
245
queue->slotAddItems(list);
249
void QueuePool::slotAssignedToolsChanged(const AssignedBatchTools& tools4Item)
251
QueueListView* queue = currentQueue();
255
queue->slotAssignedToolsChanged(tools4Item);
259
void QueuePool::slotQueueSelected(int index)
261
QueueListView* queue = dynamic_cast<QueueListView*>(widget(index));
265
emit signalItemSelectionChanged();
266
emit signalQueueSelected(index, queue->settings(), queue->assignedTools());
270
void QueuePool::slotCloseQueueRequest(QWidget* w)
272
removeTab(indexOf(w));
279
emit signalQueuePoolChanged();
282
void QueuePool::removeTab(int index)
284
QueueListView* queue = dynamic_cast<QueueListView*>(widget(index));
285
int count = queue->pendingItemsCount();
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)));
294
if (ret == KMessageBox::No)
300
KTabWidget::removeTab(index);
303
void QueuePool::slotTestCanDecode(const QDragMoveEvent* e, bool& accept)
307
QList<qlonglong> imageIDs;
311
if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs) ||
312
DAlbumDrag::decode(e->mimeData(), urls, albumID) ||
313
DTagDrag::canDecode(e->mimeData()))
322
void QueuePool::slotSettingsChanged(const QueueSettings& settings)
324
QueueListView* queue = currentQueue();
328
queue->setSettings(settings);
332
void QueuePool::setEnableToolTips(bool b)
334
for (int i = 0; i < count(); ++i)
336
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
340
queue->setEnableToolTips(b);
345
bool QueuePool::customRenamingRulesAreValid()
349
for (int i = 0; i < count(); ++i)
351
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
355
if (queue->settings().renamingRule == QueueSettings::CUSTOMIZE &&
356
queue->settings().renamingParser.isEmpty())
358
list.append(queueTitle(i));
365
KMessageBox::errorList(kapp->activeWindow(),
366
i18n("Custom renaming rules are invalid for Queues listed below. "
367
"Please fix them."), list);
374
bool QueuePool::assignedBatchToolsListsAreValid()
378
for (int i = 0; i < count(); ++i)
380
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
384
if (queue->assignedTools().m_toolsMap.isEmpty())
386
list.append(queueTitle(i));
393
KMessageBox::errorList(kapp->activeWindow(),
394
i18n("Assigned batch tools list is empty for Queues listed below. "
395
"Please assign tools."), list);
402
void QueuePool::slotFileChanged(const QString& filePath)
404
for (int i = 0; i < count(); ++i)
406
QueueListView* queue = dynamic_cast<QueueListView*>(widget(i));
410
queue->reloadThumbs(KUrl::fromPath(filePath));
415
} // namespace Digikam