File indexing completed on 2023-09-24 08:52:51

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
0004    Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
0005    Copyright (C) 2007 Javier Goday <jgoday @ gmail.com>
0006    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
0007    Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
0008 
0009    This program is free software; you can redistribute it and/or
0010    modify it under the terms of the GNU General Public
0011    License as published by the Free Software Foundation; either
0012    version 2 of the License, or (at your option) any later version.
0013 */
0014 
0015 #include "transfersgroupwidget.h"
0016 #include "transfersgrouptree.h"
0017 
0018 #include "core/kget.h"
0019 #include "core/transfertreemodel.h"
0020 #include "core/transfertreeselectionmodel.h"
0021 
0022 #include <KGuiItem>
0023 #include <KStandardGuiItem>
0024 
0025 #include <QPushButton>
0026 
0027 TransfersGroupWidget::TransfersGroupWidget(QWidget *parent)
0028     : QWidget(parent)
0029 {
0030     ui.setupUi(this);
0031 
0032     ui.treeView->setModel(KGet::model());
0033     ui.treeView->setSelectionModel(KGet::selectionModel());
0034 
0035     ui.treeView->header()->hideSection(TransferTreeModel::Progress);
0036     ui.treeView->header()->hideSection(TransferTreeModel::RemainingTime);
0037     ui.treeView->header()->hideSection(TransferTreeModel::Size);
0038     ui.treeView->header()->hideSection(TransferTreeModel::Speed);
0039 
0040     KGuiItem::assign(ui.add, KStandardGuiItem::add());
0041     KGuiItem::assign(ui.remove, KStandardGuiItem::remove());
0042     KGuiItem::assign(ui.configure, KStandardGuiItem::configure());
0043 
0044     connect(ui.add, &QPushButton::clicked, ui.treeView, &TransfersGroupTree::addGroup);
0045     connect(ui.remove, &QPushButton::clicked, ui.treeView, &TransfersGroupTree::deleteSelectedGroup);
0046     connect(ui.rename, &QPushButton::clicked, ui.treeView, &TransfersGroupTree::renameSelectedGroup);
0047     connect(ui.selectIcon, &KIconButton::iconChanged, ui.treeView, &TransfersGroupTree::changeIcon);
0048     connect(ui.configure, SIGNAL(clicked()), KGet::actionCollection()->action("transfer_group_settings"), SLOT(trigger()));
0049     connect(ui.treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotSelectionChanged()));
0050 
0051     slotSelectionChanged();
0052 }
0053 
0054 void TransfersGroupWidget::slotSelectionChanged()
0055 {
0056     const QModelIndexList selectedGroups = ui.treeView->selectionModel()->selectedRows();
0057     const bool somethingSelected = !selectedGroups.isEmpty();
0058     bool canDelete = somethingSelected && KGet::selectedTransferGroups().count() != KGet::allTransferGroups().count();
0059 
0060     ui.rename->setEnabled(canDelete);
0061     ui.remove->setEnabled(canDelete);
0062     ui.configure->setEnabled(somethingSelected);
0063     ui.selectIcon->setEnabled(somethingSelected);
0064 
0065     if (somethingSelected && !KGet::selectedTransferGroups().isEmpty()) {
0066         ui.selectIcon->setIcon(QIcon::fromTheme(KGet::selectedTransferGroups().first()->iconName()));
0067     } else {
0068         ui.selectIcon->setIcon(QIcon::fromTheme("preferences-desktop-icons"));
0069     }
0070 }
0071 
0072 #include "moc_transfersgroupwidget.cpp"