1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <QTreeWidgetItem>
22 #include <QHeaderView>
28 #include <KGlobalSettings>
30 #include <KIO/NetAccess>
32 #include "managecapturesdialog.h"
36 ManageCapturesDialog::ManageCapturesDialog(KUrl::List files, QWidget * parent): QDialog(parent) {
37 setFont(KGlobalSettings::toolBarFont());
39 m_importButton = m_view.buttonBox->button(QDialogButtonBox::Ok);
40 m_importButton->setText(i18n("import"));
41 m_view.treeWidget->setIconSize(QSize(70, 50));
42 foreach(const KUrl url, files) {
44 text << url.fileName();
45 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
46 text << KIO::convertSize(file.size());
47 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.treeWidget, text);
48 item->setData(0, Qt::UserRole, url.path());
49 item->setToolTip(0, url.path());
50 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
51 item->setCheckState(0, Qt::Checked);
53 connect(m_view.treeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotRefreshButtons()));
54 connect(m_view.deleteButton, SIGNAL(pressed()), this, SLOT(slotDeleteCurrent()));
55 connect(m_view.toggleButton, SIGNAL(pressed()), this, SLOT(slotToggle()));
56 QTreeWidgetItem *item = m_view.treeWidget->topLevelItem(0);
57 if (item) m_view.treeWidget->setCurrentItem(item);
58 connect(m_view.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckItemIcon()));
59 QTimer::singleShot(500, this, SLOT(slotCheckItemIcon()));
60 m_view.treeWidget->resizeColumnToContents(0);
61 m_view.treeWidget->setEnabled(false);
65 ManageCapturesDialog::~ManageCapturesDialog() {}
67 void ManageCapturesDialog::slotCheckItemIcon() {
69 int count = m_view.treeWidget->topLevelItemCount();
71 QTreeWidgetItem *item = m_view.treeWidget->topLevelItem(ct);
72 //QTreeWidgetItem *item = m_view.treeWidget->currentItem();
73 if (item->icon(0).isNull()) {
74 QPixmap p = KThumb::getImage(KUrl(item->data(0, Qt::UserRole).toString()), 0, 70, 50);
75 item->setIcon(0, QIcon(p));
76 m_view.treeWidget->resizeColumnToContents(0);
78 //QTimer::singleShot(400, this, SLOT(slotCheckItemIcon()));
82 m_view.treeWidget->setEnabled(true);
85 void ManageCapturesDialog::slotRefreshButtons() {
86 int count = m_view.treeWidget->topLevelItemCount();
88 for (int i = 0; i < count; i++) {
89 QTreeWidgetItem *item = m_view.treeWidget->topLevelItem(i);
90 if (item && item->checkState(0) == Qt::Checked) {
95 m_importButton->setEnabled(enabled);
98 void ManageCapturesDialog::slotDeleteCurrent() {
99 QTreeWidgetItem *item = m_view.treeWidget->currentItem();
101 int i = m_view.treeWidget->indexOfTopLevelItem(item);
102 m_view.treeWidget->takeTopLevelItem(i);
103 kDebug() << "DELETING FILE: " << item->text(0);
104 //KIO::NetAccess::del(KUrl(item->text(0)), this);
105 QFile f(item->data(0, Qt::UserRole).toString());
111 void ManageCapturesDialog::slotToggle() {
112 int count = m_view.treeWidget->topLevelItemCount();
113 for (int i = 0; i < count; i++) {
114 QTreeWidgetItem *item = m_view.treeWidget->topLevelItem(i);
116 if (item->checkState(0) == Qt::Checked) item->setCheckState(0, Qt::Unchecked);
117 else item->setCheckState(0, Qt::Checked);
122 KUrl::List ManageCapturesDialog::importFiles() {
125 int count = m_view.treeWidget->topLevelItemCount();
126 for (int i = 0; i < count; i++) {
127 QTreeWidgetItem *item = m_view.treeWidget->topLevelItem(i);
128 if (item && item->checkState(0) == Qt::Checked)
129 result.append(KUrl(item->data(0, Qt::UserRole).toString()));
134 #include "managecapturesdialog.moc"